Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorials:beginner:process_modules [2016/01/22 16:52] – gkazhoya | tutorials:beginner:process_modules [2016/01/25 10:30] – [A process module for the turtlesim] gkazhoya | ||
---|---|---|---|
Line 30: | Line 30: | ||
===== 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. | ||
Line 70: | Line 72: | ||
</ | </ | ||
+ | Finally, let's also add '': | ||
+ | <code lisp> | ||
+ | (:use :cpl :roslisp : | ||
+ | </ | ||
- | ==== A process module for the turtlesim ==== | ||
- | For this tutorial we will use the [[http:// | + | ==== A process module for the turtlesim |
- | We first need to connect to the turtlesim action server | + | We first need to connect to the turtlesim action server |
<code lisp> | <code lisp> | ||
Line 127: | Line 132: | ||
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 is taken care of, it's finally time to look at process modules and their interface to the higher levels. | + | Now that the lower level of controlling the turtlesim is taken care of, it's finally time to look at process modules and their interface to the higher levels. |
<code lisp> | <code lisp> | ||
(in-package :tut) | (in-package :tut) | ||
- | (cram-process-modules: | + | (def-process-module turtle-actuators (action-designator) |
(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)))))) |
- | </ | + | |
- | First, we use the '' | + | (defmacro with-turtle-process-modules (&body body) |
+ | `(with-process-modules-running | ||
+ | (turtle-actuators) | ||
+ | , | ||
+ | </ | ||
- | destructuring-bind | + | First, we use 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: | + | The '' |
Let's try this out. Make sure you have roscore, turtlesim, and turtle_actionlib running. In a terminal tab for each, | Let's try this out. Make sure you have roscore, turtlesim, and turtle_actionlib running. In a terminal tab for each, |