| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| tutorials:beginner:process_modules_2 [2017/07/25 15:53] – Add move motion and change part about parallelism cpo | tutorials:beginner:process_modules_2 [2020/09/03 10:34] (current) – [Writing a process module for the turtlesim] gkazhoya |
|---|
| **Description:** in this tutorial you will learn about CRAM process modules and write a simple one to move the turtlesim. | **Description:** in this tutorial you will learn about CRAM process modules and write a simple one to move the turtlesim. |
| |
| **Previous Tutorial:** [[tutorials:beginner:designators|Creating action designators for the turtlesim]]\\ | **Previous Tutorial:** [[tutorials:beginner:motion_designators|Creating motion designators for the turtlesim]]\\ |
| **Next Tutorial:** [[tutorials:beginner:location_designators|Using location designators with the turtlesim]] | **Next Tutorial:** [[tutorials:beginner:assigning_actions_2|Automatically choosing a process module for a motion]] |
| |
| ===== Process modules: an overview ===== | ===== Process modules: an overview ===== |
| 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 ''cram_process_modules'': | In your ''package.xml'' file you need to add a dependency on ''cram_process_modules'': |
| |
| <code> | <code> |
| <build_depend>cram_process_modules</build_depend> | <depend>cram_process_modules</depend> |
| | |
| <run_depend>cram_process_modules</run_depend> | |
| </code> | </code> |
| |
| |
| <code lisp> | <code lisp> |
| (defsystem cram-beginner-tutorial | (defsystem cram-my-beginner-tutorial |
| :depends-on (cram-language roslisp turtlesim-msg geometry_msgs-msg cl-transforms | :depends-on (cram-language roslisp turtlesim-msg turtlesim-srv geometry_msgs-msg cl-transforms |
| cram-designators cram-prolog | cram-designators cram-prolog |
| cram-process-modules cram-language-designator-support) | cram-process-modules cram-language-designator-support) |
| (:file "control-turtlesim" :depends-on ("package")) | (:file "control-turtlesim" :depends-on ("package")) |
| (:file "simple-plans" :depends-on ("package" "control-turtlesim")) | (:file "simple-plans" :depends-on ("package" "control-turtlesim")) |
| (:file "action-designators" :depends-on ("package")) | (:file "motion-designators" :depends-on ("package")) |
| (:file "process-modules" :depends-on ("package" | (:file "process-modules" :depends-on ("package" |
| "control-turtlesim" | "control-turtlesim" |
| "simple-plans" | "simple-plans" |
| "action-designators")))))) | "motion-designators")))))) |
| </code> | </code> |
| |
| </code> | </code> |
| |
| First, we use the ''cram-process-modules:def-process-module'' macro to define ''turtlesim-navigation'' as a process module taking one parameter (''motion-designator''). The process module then chooses which action to perform depending on the command specified in the designator: ''destructuring-bind'' maps the results from ''(reference motion-designator)'' to the variables ''command'' and ''motion'' respectively. Note that the inference rules we defined previously provide a name for the kind of motion we have (currently, all are ''drive''), and a ''turtle-motion'' object. We run an ''ecase'' on the kind of goal (currently, we only have the drive case) and use ''send-vel-cmd'' to tell the lower level to move the turtle around, given these parameters we infer from designator resolution. | First, we use the ''cram-process-modules:def-process-module'' macro to define ''turtlesim-navigation'' as a process module taking one parameter (''motion-designator''). The process module then chooses which motion to perform depending on the command specified in the designator: ''destructuring-bind'' maps the results from ''(reference motion-designator)'' to the variables ''command'' and ''motion'' respectively. Note that the inference rules we defined previously provide a name for the kind of motion we have (currently, all are ''drive''), and a ''turtle-motion'' object. We run an ''ecase'' on the kind of goal (currently, we only have the drive case) and use ''send-vel-cmd'' to tell the lower level to move the turtle around, given these parameters we infer from designator resolution. |
| |
| Let's try this out. Make sure you have ''roscore'' and ''turtlesim_node'' running. In a terminal tab for each, | Let's try this out. Make sure you have ''roscore'' and ''turtlesim_node'' running. In a terminal tab for each, |
| <code lisp> | <code lisp> |
| TUT> (drive 5 2) | TUT> (drive 5 2) |
| [(TURTLE-PROCESS-MODULES) INFO] 1499958119.336: TurtleSim navigation invoked with motion designator `#<MOTION-DESIGNATOR ((TYPE | [(TURTLE-PROCESS-MODULES) INFO] 1562698751.679: TurtleSim navigation invoked with motion designator `#<A MOTION |
| DRIVING) | (TYPE DRIVING) |
| (SPEED | (SPEED 5) |
| 5) | (ANGLE 2)>'. |
| (ANGLE | |
| 2)) {1006979703}>'. | |
| 1 | 1 |
| </code> | </code> |
| (move | (move |
| (move-to motion))))) | (move-to motion))))) |
| <code> | </code> |
| |
| Since ''move-to'' takes a 3d-vector as a parameter we only have to pass ''motion'' to it. | Since ''move-to'' takes a 3d-vector as a parameter we only have to pass ''motion'' to it. |
| |
| == Next == | == Next == |
| | So far we called process modules directly. Sometimes it's better to let the system decide on its own … |
| |
| Let's have a look at location designators and other ways to move the turtle, as well as have some more practice with designator resolution and process modules ... | [[tutorials:beginner:assigning_actions_2|Automatically choosing a process module for a motion]] |
| | |
| [[tutorials:beginner:location_designators|Using location designators with the turtlesim]] | |