Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorials:beginner:process_modules [2015/05/11 17:01] – created gkazhoya | tutorials:beginner:process_modules [2016/03/04 14:25] (current) – old revision restored (2016/01/25 18:26) gkazhoya | ||
---|---|---|---|
Line 8: | Line 8: | ||
===== Process modules: an overview ===== | ===== Process modules: an overview ===== | ||
- | A process module is a program that controls a robot actuator. Different robots will have different kinds of actuators, requiring different kinds of controllers, | + | A process module is a program that controls a robot actuator. Different robots will have different kinds of actuators, requiring different kinds of controllers, |
- | For better organization, | + | For better organization, |
* :navigation | * :navigation | ||
Line 22: | Line 22: | ||
<code lisp> | <code lisp> | ||
- | (with-designators ((my-designator | + | (with-designators |
+ | | ||
(pm-execute :navigation my-designator)) | (pm-execute :navigation my-designator)) | ||
</ | </ | ||
- | This will run a process module associated | + | This will run a process module associated |
===== Writing a process module for the turtlesim ===== | ===== Writing a process module for the turtlesim ===== | ||
+ | |||
+ | For this tutorial we will use the [[http:// | ||
Once again, some new dependencies must be declared in the tutorial files you've been working on. | Once again, some new dependencies must be declared in the tutorial files you've been working on. | ||
- | In your package.xml file you need to add build and runtime dependencies on actionlib_lisp, | + | In your '' |
< | < | ||
< | < | ||
+ | < | ||
< | < | ||
< | < | ||
- | < | ||
< | < | ||
+ | < | ||
< | < | ||
+ | < | ||
</ | </ | ||
- | Similarly, in your .asd file you should add cram-language-designator-support, | + | Similarly, in your '' |
<code lisp> | <code lisp> | ||
(defsystem cram-beginner-tutorial | (defsystem cram-beginner-tutorial | ||
- | :depends-on (roslisp | + | :depends-on (cram-language |
- | | + | |
+ | actionlib | ||
+ | cram-process-modules | ||
:components | :components | ||
((:module " | ((:module " | ||
:components | :components | ||
((:file " | ((:file " | ||
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
</ | </ | ||
+ | |||
+ | Finally, let's also add '': | ||
+ | <code lisp> | ||
+ | (:use :cpl :roslisp : | ||
+ | : | ||
+ | </ | ||
+ | |||
==== A process module for the turtlesim ==== | ==== A process module for the turtlesim ==== | ||
- | We first need to connect to the turtlesim | + | We first need to connect to the turtlesim |
<code lisp> | <code lisp> | ||
Line 88: | Line 106: | ||
</ | </ | ||
- | The above code simply declares a variable *navp-client* which we can then initialize with a pointer to our ROS action client and retrieve this pointer later with the init-action-client and get-action-client functions, respectively. | + | The above code simply declares a variable |
- | We' | + | We will need an action goal for our action client |
<code lisp> | <code lisp> | ||
Line 115: | Line 133: | ||
In the above code we define a simple function to convert an edge and radius pair of values into a goal for the action client, and a function that will call said action client, with some error handling built in (for example, if the function is called without an action client being defined, it will (re)initialize one and retry). | In the above code we define a simple function to convert an edge and radius pair of values into a goal for the action client, and a function that will call said action client, with some error handling built in (for example, if the function is called without an action client being defined, it will (re)initialize one and retry). | ||
- | Now that the lower level of controlling the turtlesim | + | Now that the lower level of controlling the TurtleSim |
<code lisp> | <code lisp> | ||
(in-package :tut) | (in-package :tut) | ||
- | (cram-process-modules: | + | (def-process-module |
(roslisp: | (roslisp: | ||
- | " | + | " |
action-designator) | action-designator) | ||
- | (destructuring-bind (cmd action-goal) (reference action-designator) | + | (destructuring-bind (command |
- | (ecase | + | (ecase |
- | (shape | + | (draw-shape |
- | | + | |
- | :edges (turtle-shape-edges action-goal) | + | :edges (turtle-shape-edges action-goal) |
- | :radius (turtle-shape-radius action-goal)))))) | + | :radius (turtle-shape-radius action-goal)))))) |
(defmacro with-turtle-process-modules (&body body) | (defmacro with-turtle-process-modules (&body body) | ||
- | `(cpm:with-process-modules-running | + | `(with-process-modules-running |
- | (turtle-actuators) | + | (actionlib-navigation) |
, | , | ||
</ | </ | ||
- | First, we use the cram-process-modules: | + | First, we use the '' |
- | destructuring-bind will map the results from (reference action-designator) to the variables cmd and action-goal respectively. Note that the inference rules we defined | + | The '' |
- | The with-turtle-process-modules macro is a macro we define for convenience. It allows us to set up a context in which to run commands, knowing that the turtle process modules are all running concurrently. Right now we only have one defined, turtle-actuators. When we will have several, we will add them to the list we pass to cpm: | + | Let's try this out. Make sure you have '' |
- | + | ||
- | Let's try this out. Make sure you have roscore, turtlesim, and turtle_actionlib running. In a terminal tab for each, | + | |
< | < | ||
Line 152: | Line 167: | ||
</ | </ | ||
- | (**Note** on Oct. 21st 2014: you should check out then catkin_make the ROS common_tutorials from github to make sure you have the newest turtle_actionlib version available, otherwise the turtle might not move. To clone the ros_common tutorials, you will need to | + | For convenience, |
- | + | ||
- | < | + | |
- | git clone https:// | + | |
- | </ | + | |
- | + | ||
- | inside the src folder of a ROS workspace, then catkin_make it.) | + | |
- | + | ||
- | For convenience, | + | |
<code lisp> | <code lisp> | ||
- | (defun draw-hexagon (r) | + | (defun draw-hexagon (radius) |
(let ((turtle-name " | (let ((turtle-name " | ||
(start-ros-node turtle-name) | (start-ros-node turtle-name) | ||
Line 169: | Line 176: | ||
(top-level | (top-level | ||
(with-turtle-process-modules | (with-turtle-process-modules | ||
- | (cpm:process-module-alias :manipulation | + | (process-module-alias :navigation |
- | (cram-language-designator-support: | + | (with-designators |
- | ((trajectory | + | ((trajectory |
- | (cpm:pm-execute :manipulation | + | (pm-execute :navigation |
</ | </ | ||
- | What the function does is simply start a ROS node for our turtle and sets up the action client, then activates the turtle process modules (in our case, the sole existing one), creates a designator to describe how the turtle should move, and calls the cpm:pm-execute macro to have the process module follow the trajectory specified by the designator. | + | What the function does is simply start a ROS node for our turtle and sets up the action client, then activates the turtle process modules (in our case, the sole existing one), creates a designator to describe how the turtle should move, and calls the '' |
- | Two other things to observe here are the use of the top-level macro, which sets up a CRAM running context and is needed for with-turtle-process-modules. Also, we declare that :manipulation | + | Two other things to observe here are the use of the '' |
Reload the tutorial in REPL, and let's try to start the tutorial | Reload the tutorial in REPL, and let's try to start the tutorial | ||
<code lisp> | <code lisp> | ||
- | TUT> (draw-hexagon | + | TUT> (draw-hexagon |
- | [(ROSLISP TOP) INFO] 1413894471.489: Node name is /turtle1 | + | [(ROSLISP TOP) INFO] 1453721727.445: Node name is /turtle1 |
- | [(ROSLISP TOP) INFO] 1413894471.489: Namespace is / | + | [(ROSLISP TOP) INFO] 1453721727.446: Namespace is / |
- | [(ROSLISP TOP) INFO] 1413894471.489: Params are NIL | + | [(ROSLISP TOP) INFO] 1453721727.446: Params are NIL |
- | [(ROSLISP TOP) INFO] 1413894471.489: Remappings are: | + | [(ROSLISP TOP) INFO] 1453721727.446: Remappings are: |
- | [(ROSLISP TOP) INFO] 1413894471.489: master URI is 127.0.0.1: | + | [(ROSLISP TOP) INFO] 1453721727.446: master URI is 127.0.0.1: |
- | [(ROSLISP TOP) INFO] 1413894472.493: Node startup complete | + | [(ROSLISP TOP) INFO] 1453721728.452: Node startup complete |
- | [(TURTLE-PROCESS-MODULES) INFO] 1413894472.501: Turtle navigation invoked with action designator `#< | + | [(TURTLE-PROCESS-MODULES) INFO] 1453721728.467: Turtle |
SHAPE) | SHAPE) | ||
| | ||
HEXAGON) | HEXAGON) | ||
| | ||
- | | + | |
An error occured! | An error occured! | ||
Client lost connection to server. | Client lost connection to server. | ||
Reinitializing... | Reinitializing... | ||
- | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1413894480.479: Waiting for turtle shape action server... | + | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1453721736.385: Waiting for turtle shape action server... |
- | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1413894482.480: Turtle shape action client created. | + | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1453721738.386: Turtle shape action client created. |
- | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1413894505.711: Nav action finished. | + | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1453721761.206: Nav action finished. |
[TURTLE_ACTIONLIB-MSG: | [TURTLE_ACTIONLIB-MSG: | ||
| | ||
| | ||
| | ||
- | 2.598076105117798d0] | + | 1.7320507764816284d0] |
:SUCCEEDED | :SUCCEEDED | ||
</ | </ | ||
- | You should also see the turtle move in the turtlesim | + | You should also see the turtle move in the TurtleSim |
== Next == | == Next == | ||
Line 217: | Line 224: | ||
[[tutorials: | [[tutorials: | ||
- |