Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
tutorials:beginner:process_modules_2 [2017/09/06 13:26] – [Adding more process modules for the TurtleSim] ended code block cpo | tutorials:beginner:process_modules_2 [2019/07/09 18:19] – [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 geometry_msgs-msg cl-transforms |
cram-designators cram-prolog | cram-designators cram-prolog |
(: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, |
| |
== 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]] | |