Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
doc:beginner:controlling_turtlesim [2013/12/09 16:28] – created bbrieber | doc:beginner:controlling_turtlesim [2014/01/19 12:51] (current) – gkazhoya | ||
---|---|---|---|
Line 3: | Line 3: | ||
**Description: | **Description: | ||
- | **Next Tutorial: | + | **Next Tutorial: |
+ | |||
+ | In this tutorial we will re-use the package '' | ||
===== Updating the dependencies ===== | ===== Updating the dependencies ===== | ||
+ | ==== Updating ROS dependecies ==== | ||
- | In this tutorial we will re-use the package '' | + | ==== catkin ==== |
- | + | Open '' | |
- | ==== Updating ros dependecies ==== | + | <code xml> |
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | under ''< | ||
+ | <code xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | under ''< | ||
==== rosbuild ==== | ==== rosbuild ==== | ||
Open '' | Open '' | ||
- | < | + | < |
+ | <depend package=" | ||
<depend package=" | <depend package=" | ||
<depend package=" | <depend package=" | ||
<depend package=" | <depend package=" | ||
</ | </ | ||
- | + | under '' | |
- | ==== catkin ==== | + | |
- | + | ||
- | Open '' | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | </ | + | |
==== Updating cram dependecies ==== | ==== Updating cram dependecies ==== | ||
+ | Now open '' | ||
- | + | < | |
- | Now open '' | + | (defsystem cram-beginner-tutorial |
- | + | ||
- | < | + | |
- | (defsystem cram-tutorial | + | |
:depends-on (roslisp cram-language turtlesim-msg cl-transforms geometry_msgs-msg) | :depends-on (roslisp cram-language turtlesim-msg cl-transforms geometry_msgs-msg) | ||
:components | :components | ||
Line 47: | Line 52: | ||
((:file " | ((:file " | ||
| | ||
- | </ | + | </ |
- | ===== Updating the the Lisp Package ===== | + | |
+ | ===== Updating the Lisp Package ===== | ||
- | We also need to add '' | + | We also want to add '' |
- | < | + | < |
- | (defpackage cram-tutorial | + | (defpackage cram-beginner-tutorial |
(:nicknames :tut) | (:nicknames :tut) | ||
(:use #:cpl #:roslisp #: | (:use #:cpl #:roslisp #: | ||
- | </ | + | </ |
===== Writing the communication glue code ===== | ===== Writing the communication glue code ===== | ||
- | + | Now it's time to use roslisp to connect to turtlesim. Turtlesim creates one ROS topic namespace per turtle. For each turtle name (turtle1, turtle2, etc.) it publishes the pose of the turtle | |
- | Now it's time to use roslisp to connect to turtlesim. Turtlesim creates one namespace per turtle. For each turtle name turtle1, turtle2, etc. it publishes the pose of the turtles | + | |
==== The code ==== | ==== The code ==== | ||
- | |||
Open the file '' | Open the file '' | ||
Line 69: | Line 73: | ||
=== hydro === | === hydro === | ||
- | < | + | < |
(in-package :tut) | (in-package :tut) | ||
- | (defvar *color-value* (make-fluent :name : | + | (defvar *color-value* (make-fluent :name : |
(defvar *turtle-pose* (make-fluent :name : | (defvar *turtle-pose* (make-fluent :name : | ||
- | (defvar *color-sub* nil " | + | (defvar *color-sub* nil " |
- | (defvar *pose-sub* nil " | + | (defvar *pose-sub* nil " |
- | (defvar *cmd-vel-pub* nil "command | + | (defvar *cmd-vel-pub* nil " |
(defun init-ros-turtle (name) | (defun init-ros-turtle (name) | ||
Line 88: | Line 92: | ||
#' | #' | ||
(setf *cmd-vel-pub* (advertise (format nil " | (setf *cmd-vel-pub* (advertise (format nil " | ||
- | " | + | " |
(defun color-cb (msg) | (defun color-cb (msg) | ||
- | " | + | " |
(setf (value *color-value*) msg)) | (setf (value *color-value*) msg)) | ||
(defun pose-cb (msg) | (defun pose-cb (msg) | ||
- | " | + | " |
(setf (value *turtle-pose*) msg)) | (setf (value *turtle-pose*) msg)) | ||
(defun send-vel-cmd (lin ang) | (defun send-vel-cmd (lin ang) | ||
- | "function | + | "Function |
(publish *cmd-vel-pub* (make-message " | (publish *cmd-vel-pub* (make-message " | ||
- | (linear) (make-msg " | + | :linear (make-msg " |
- | (angular) (make-msg " | + | :x lin) |
- | </ | + | :angular (make-msg " |
+ | :z ang)))) | ||
+ | </ | ||
=== groovy and older === | === groovy and older === | ||
- | < | + | < |
(in-package :tut) | (in-package :tut) | ||
Line 145: | Line 151: | ||
=== The code explained === | === The code explained === | ||
+ | In '' | ||
- | In '' | + | We use callback functions |
- | We use callback function ...-cb for all updates on the pose of the turtle and the color sensor value to a fluent in order to be able to use those values in a reactive control program. | + | A fluent is a proxy around a value with support for notification on change. Further, fluents can be combined to so-called fluent networks. There will be some more explanations about fluents later in this tutorial. |
- | + | ||
- | A fluent is a proxy around a value with support for notification on change. Further, fluents can be combined to so-called fluent networks. | + | |
===== Experimenting in the REPL ===== | ===== Experimenting in the REPL ===== | ||
+ | Now let's try it out. Open your Lisp REPL and make sure that you loaded the system '' | ||
- | Now let's try it out. Open your Lisp REPL and make sure that you loaded the system cram-tutorial and switched to the package tut, hint: | + | < |
- | < | + | CL-USER> (ros-load: |
- | CL-USER> (ros-load: | + | |
... | ... | ||
CL-USER> (in-package :tut) | CL-USER> (in-package :tut) | ||
</ | </ | ||
+ | |||
For experiments in the REPL, we want to initialize a Lisp ROS node and then call '' | For experiments in the REPL, we want to initialize a Lisp ROS node and then call '' | ||
- | Make sure '' | + | Make sure '' |
Enter the following commands: | Enter the following commands: | ||
- | < | + | |
+ | < | ||
TUT> (start-ros-node " | TUT> (start-ros-node " | ||
[(ROSLISP TOP) INFO] 1292688669.674: | [(ROSLISP TOP) INFO] 1292688669.674: | ||
Line 175: | Line 182: | ||
[(ROSLISP TOP) INFO] 1292688670.875: | [(ROSLISP TOP) INFO] 1292688670.875: | ||
</ | </ | ||
- | The name of the node is arbitrary, we need to call '' | ||
- | < | + | The name of the node is arbitrary. We need to call '' |
+ | |||
+ | < | ||
TUT> (init-ros-turtle "/ | TUT> (init-ros-turtle "/ | ||
</ | </ | ||
+ | |||
This calls our function '' | This calls our function '' | ||
Now we should start up turtlesim in a new terminal: | Now we should start up turtlesim in a new terminal: | ||
- | < | + | |
+ | < | ||
$ rosrun turtlesim turtlesim_node | $ rosrun turtlesim turtlesim_node | ||
</ | </ | ||
- | You will see the turtlesim window: | ||
+ | (Note: if you're using turtlesim for the first time, you might need to compile the package first: '' | ||
- | {{: | + | You will see the turtlesim window: |
+ | |||
+ | {{: | ||
Notice that thanks to ROS, we could subscribe to the topics even before they had been advertised by the turtlesim. | Notice that thanks to ROS, we could subscribe to the topics even before they had been advertised by the turtlesim. | ||
We are ready for experiments now. Let's see if the fluents are containing the right values: | We are ready for experiments now. Let's see if the fluents are containing the right values: | ||
- | < | + | |
+ | < | ||
TUT> | TUT> | ||
[TURTLESIM-MSG:< | [TURTLESIM-MSG:< | ||
Line 208: | Line 221: | ||
| | ||
TUT> | TUT> | ||
- | |||
[TURTLESIM-MSG:< | [TURTLESIM-MSG:< | ||
R: | R: | ||
Line 217: | Line 229: | ||
255] | 255] | ||
</ | </ | ||
+ | |||
You see that the value of the fluents contain structured data, which contains the pose and color information as provided by the turtlesim simulator. | You see that the value of the fluents contain structured data, which contains the pose and color information as provided by the turtlesim simulator. | ||
- | Let's see if the pose changes if we move the turtle. Start up turtle_teleop_key and move the turtle a little bit: | + | Let's see if the pose changes if we move the turtle. Start up '' |
- | < | + | |
- | $ rosrun turtlesim turtle_teleop_key | + | < |
- | </ | + | |
Try evaluating '' | Try evaluating '' | ||
- | < | + | < |
TUT> | TUT> | ||
- | |||
[TURTLESIM-MSG:< | [TURTLESIM-MSG:< | ||
X: | X: | ||
Line 241: | Line 253: | ||
As the pose fluent has been updated, the subscribers seem to work. | As the pose fluent has been updated, the subscribers seem to work. | ||
- | ==== Fluents ==== | ||
+ | ==== Fluents ==== | ||
Now let's play around with fluents a little bit more. | Now let's play around with fluents a little bit more. | ||
Line 248: | Line 260: | ||
Notice how in the checks before, we used the function '' | Notice how in the checks before, we used the function '' | ||
- | Fluents allow us to wait for specific events. For instance, we can wait for the '' | + | Fluents allow us to wait for specific events. For instance, we can wait for the '' |
- | < | + | < |
TUT> (wait-for (< (fl-funcall #' | TUT> (wait-for (< (fl-funcall #' | ||
5.0)) | 5.0)) | ||
</ | </ | ||
The code above constructs a fluent network. The expression | The code above constructs a fluent network. The expression | ||
- | < | + | < |
(fl-funcall #' | (fl-funcall #' | ||
</ | </ | ||
- | returns a new fluent that contains the x-value of the turtle pose. So from a proxy that wrapped the whole pose of a turtle, we got a new proxy that wraps just the x coordinate. The expression | + | returns a new fluent that contains the '' |
- | < | + | < |
(< (fl-funcall #' | (< (fl-funcall #' | ||
5.0) | 5.0) | ||
</ | </ | ||
- | returns a fluent that is either '' | + | returns a fluent that is either '' |
- | Execute the above expression. If the turtle' | + | Execute the above expression. If the turtle' |
- | === Moving the turtle === | ||
+ | === Moving the turtle === | ||
Let's see if we can also move the turtle from LISP. Try the following: | Let's see if we can also move the turtle from LISP. Try the following: | ||
- | < | + | < |
TUT> (dotimes (i 10) (send-vel-cmd 1 1) (sleep 1)) | TUT> (dotimes (i 10) (send-vel-cmd 1 1) (sleep 1)) | ||
</ | </ | ||
Line 278: | Line 290: | ||
- | Now that we have functions and fluents to connect to the turtlesim, let' | + | Now that we have functions and fluents to connect to the turtlesim, let' |
+ | |||
+ | [[doc: |