|Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.|
Set-up and first steps with CRAM and the CRAM languageDescription: In this tutorial, you learn how to set up your environment and how to use the CRAM language from the lisp REPL
Tutorial Level: BEGINNER
Next Tutorial: Create a CRAM Package
The cram_core stack is available from https://github.com/moesenle/cram_core.git. Either install the Debian package ros-fuerte-cram-core or use rosws to install it. You can use this rosinstall file. If you already have a rosinstall based ROS installation at ~/ros you can just add the cram_core stack as follows:
rosinstall ~/ros cram-core.rosinstall rosmake cram_language
In Fuerte, you can also just install the Debian package ros-fuerte-cram-core:
sudo apt-get install ros-fuerte-cram-core
Now it's time for setting up your emacs. You need to have rosemacs installed:
sudo apt-get install rosemacs-el
To get a lisp REPL, you can run:
rosrun roslisp_repl repl
An emacs window should pop up and a lisp REPL should show up.
First steps in the REPL
After starting up emacs and slime, you should see a prompt like this:
; SLIME 2010-12-02 CL-USER>
You should first load cram_language with
CL-USER> (ros-load:load-system "cram_language" :cram-language)
Experts with slime and emacs can instead use ",", ros-load-system, cram_language, cram-language, or define convenience functions or shortcuts.
Now change the current package to the CPL package:
CL-USER> (in-package :cpl) CPL>
The system is ready to accept CPL expressions now. Enter the following one:
CPL> (top-level (par (format t "First~%") (seq (sleep 2) (format t "Third~%")) (seq (sleep 1) (format t "Second~%"))))
The output should then be
First Second Third
Note that if you do not see any output, this may be due to a missing or corrupt ~/.swank.lisp. It should exist and contain:
(setf swank:*globally-redirect-io* t)
(This should have been prepared by rosmake cram_emacs_repl)
All CPL expressions need to be wrapped in a top-level form. It sets up the environment for multithreaded execution and for failure handling across threads. par executes its sub-forms in parallel and terminates when all terminated. In our example, three sub-forms are executed. The first is simple output of the text First. The other two forms are seq forms. seq executes its sub-forms sequentially and terminates when the last one finished. The second form first sleeps for two seconds and then prints the text, the third form only sleeps for one second before printing.
Apart from par, cram_language also knows the form pursue which is slightly different in that it returns after the first of its sub-forms terminated. The other sub-forms are then evaporated. So let's see what happens when we change par to pursue:
CPL> (top-level (pursue (format t "First~%") (seq (sleep 2) (format t "Third~%")) (seq (sleep 1) (format t "Second~%")))) First NIL CPL>
Only the first form is executed. The other forms are evaporated.