Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
tutorials:beginner:process_modules [2016/01/25 17:13] – [Process modules: an overview] gkazhoyatutorials:beginner:process_modules [2016/03/04 14:09] gkazhoya
Line 23: Line 23:
 <code lisp> <code lisp>
 (with-designators (with-designators
-    ((my-designator :location '((:close-to :fridge))))+    ((my-designator location '((:close-to :fridge))))
   (pm-execute :navigation my-designator))   (pm-execute :navigation my-designator))
 </code> </code>
Line 133: 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 is taken care of, it's finally time to look at process modules and their interface to the higher levels. Append the following to your ''process-modules.lisp'' file:+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. Append the following to your ''process-modules.lisp'' file:
  
 <code lisp> <code lisp>
 (in-package :tut) (in-package :tut)
  
-(def-process-module turtle-actuators (action-designator)+(def-process-module actionlib-navigation (action-designator)
   (roslisp:ros-info (turtle-process-modules)   (roslisp:ros-info (turtle-process-modules)
-                    "Turtle navigation invoked with action designator `~a'."+                    "Turtle shape navigation invoked with action designator `~a'."
                     action-designator)                     action-designator)
   (destructuring-bind (command action-goal) (reference action-designator)   (destructuring-bind (command action-goal) (reference action-designator)
Line 151: Line 151:
 (defmacro with-turtle-process-modules (&body body) (defmacro with-turtle-process-modules (&body body)
   `(with-process-modules-running   `(with-process-modules-running
-       (turtle-actuators)+       (actionlib-navigation)
      ,@body))      ,@body))
 </code> </code>
  
-First, we use the ''cram-process-modules:def-process-module'' macro to define ''turtle-actuators'' as a process module taking one parameter (''action-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 action-designator)'' to the variables ''command'' and ''action-goal'' respectively. Note that the inference rules we defined previously provide a name for the kind of action goal we have (currently, all are ''draw-shape''), and a ''turtle-shape'' object. We run an ''ecase'' on the kind of goal (currently, we only have the shape case) and use ''call-shape-action'' 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 ''actionlib-navigation'' as a process module taking one parameter (''action-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 action-designator)'' to the variables ''command'' and ''action-goal'' respectively. Note that the inference rules we defined previously provide a name for the kind of action goal we have (currently, all are ''draw-shape''), and a ''turtle-shape'' object. We run an ''ecase'' on the kind of goal (currently, we only have the shape case) and use ''call-shape-action'' to tell the lower level to move the turtle around, given these parameters we infer from designator resolution.
  
-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 ''cram-process-modules:with-process-modules-running''. Note that the ''with-process-modules-running'' macro (and therefore ''with-turtle-process-modules'' too) needs to be run inside a ''top-level'' form. We will see this below.+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, ''actionlib-navigation''. When we will have several, we will add them to the list we pass to ''cram-process-modules:with-process-modules-running''. Note that the ''with-process-modules-running'' macro (and therefore ''with-turtle-process-modules'' too) needs to be run inside a ''top-level'' form. We will see this below.
  
 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,
Line 176: Line 176:
     (top-level     (top-level
       (with-turtle-process-modules       (with-turtle-process-modules
-        (process-module-alias :navigation 'turtle-actuators)+        (process-module-alias :navigation 'actionlib-navigation)
         (with-designators         (with-designators
-            ((trajectory :action `((:type :shape) (:shape :hexagon) (:radius ,radius))))+            ((trajectory action `((:type :shape) (:shape :hexagon) (:radius ,radius))))
           (pm-execute :navigation trajectory))))))           (pm-execute :navigation trajectory))))))
 </code> </code>
Line 184: Line 184:
 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 ''cram-process-modules: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 ''cram-process-modules:pm-execute'' macro to have the process module follow the trajectory specified by the designator. 
  
-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 '':navigation'' is the alias for our turtle-actuators process module. That way, our plan can invoke a generic name like '':navigation'', rather than a robot-specific one like turtle-actuators.+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 '':navigation'' is the alias for our ''actionlib-navigation'' process module. That way, our plan can invoke a generic name like '':navigation'', rather than a robot-specific one like ''actionlib-navigation''.
  
 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
Line 196: Line 196:
 [(ROSLISP TOP) INFO] 1453721727.446: master URI is 127.0.0.1:11311 [(ROSLISP TOP) INFO] 1453721727.446: master URI is 127.0.0.1:11311
 [(ROSLISP TOP) INFO] 1453721728.452: Node startup complete [(ROSLISP TOP) INFO] 1453721728.452: Node startup complete
-[(TURTLE-PROCESS-MODULES) INFO] 1453721728.467: Turtle navigation invoked with action designator `#<ACTION-DESIGNATOR ((TYPE+[(TURTLE-PROCESS-MODULES) INFO] 1453721728.467: Turtle shape navigation invoked with action designator `#<ACTION-DESIGNATOR ((TYPE
                                                                         SHAPE)                                                                         SHAPE)
                                                                        (SHAPE                                                                        (SHAPE
Line 217: Line 217:
 </code> </code>
  
-You should also see the turtle move in the turtlesim window and trace the required trajectory.+You should also see the turtle move in the TurtleSim window and trace the required trajectory.
  
 == Next == == Next ==
Line 224: Line 224:
  
 [[tutorials:beginner:location_designators|Using location designators with the turtlesim]] [[tutorials:beginner:location_designators|Using location designators with the turtlesim]]
-