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
doc:beginner:process_modules [2014/10/21 11:26] – Added "Writing a process module for the turtlesim" section. mpomarlandoc:beginner:process_modules [2015/05/11 17:01] (current) – removed gkazhoya
Line 1: Line 1:
-====== Creating process modules ====== 
- 
-**Description:** in this tutorial you will learn about CRAM process modules and write a simple one to move the turtlesim. 
- 
-**Previous Tutorial:** [[doc:beginner:designators|Creating designators for the turtlesim]]\\ 
-**Next Tutorial:**  
- 
-===== 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, and we would like to abstract away such specifics at the high level of task specification. When we ask a robot to clean a kitchen, we don't care that it has two arms or one; rather, as long as it has some capacity to manipulate objects, and some ability to move around, we can issue the cleaning task to it. Process modules allow us this flexibility by providing a well-defined, robot-independent interface to high level planning which works as an abstraction layer over the robot controllers. 
- 
-For better organization, process modules can also be referenced by aliases that describe what kind of function they can perform. Currently, in the cram_highlevel stack for manipulation platforms the following aliases are defined: 
- 
-  * :navigation 
-  * :ptu 
-  * :manipulation 
-  * :perception 
- 
-A plan will typically refer to a process module by the alias. The process module would be defined for the particular robot in use and associated with the proper alias when the system is initialized. 
- 
-Here's an example of invoking a process module: 
- 
-<code lisp> 
-(with-designators ((my-designator (location '((close-to 'fridge))))) 
-  (pm-execute :navigation my-designator)) 
-</code> 
- 
-This will run a process module associated to :navigation and use my-designator to pass parameters to it. In this case, the designator is a semantic description of a target location and it's up to the process module to ask that this designator be resolved (by some appropriate other module in the system) so as to get an actual location and then control the robot to reach the target. The specifics of the controller may vary enormously; the robot might be differential drive, or legged. But these details are not important for this high level plan. All we want is for the robot to approach the fridge, in whatever way it can carry itself there. 
- 
-===== Writing a process module for the turtlesim ===== 
- 
-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, turtle_actionlib, and cram_process_modules: 
- 
-<code> 
-  <build_depend>actionlib_lisp</build_depend> 
-  <build_depend>turtle_actionlib</build_depend> 
-  <build_depend>cram_process_modules</build_depend> 
- 
-  <run_depend>cram_process_modules</run_depend> 
-  <run_depend>actionlib_lisp</run_depend> 
-  <run_depend>turtle_actionlib</run_depend> 
-</code> 
- 
-Similarly, in your .asd file you should add actionlib, actionlib_tutorials-msg, process-modules, turtle_actionlib-msg to the :depends-on list, so your .asd file should now look like this 
- 
-<code lisp> 
-(defsystem cram-beginner-tutorial-workthrough 
-  :depends-on (roslisp cram-language turtlesim-msg cl-transforms geometry_msgs-msg designators cram-reasoning  
-                 actionlib actionlib_tutorials-msg process-modules turtle_actionlib-msg) 
-  :components 
-  ((:module "src" 
-            :components 
-            ((:file "package") 
-             (:file "tutorial" :depends-on ("package")))))) 
-</code> 
- 
-==== A process module for the turtlesim ==== 
- 
-We first need to connect to the turtlesim as a client for an action that will have the turtle draw a shape. To do this, append the following to your tutorial.lisp file 
- 
-<code lisp> 
-(defvar *navp-client* nil) 
- 
-(defun init-action-client () 
-  (setf *navp-client* (actionlib:make-action-client 
-                       "turtle_shape" 
-                       "turtle_actionlib/ShapeAction")) 
-  (roslisp:ros-info (turtle-shape-action-client) 
-                    "Waiting for turtle shape action server...") 
-  ;; workaround for race condition in actionlib wait-for server 
-  (loop until 
-    (actionlib:wait-for-server *navp-client*)) 
-  (roslisp:ros-info (turtle-shape-action-client) 
-                    "Turtle shape action client created.")) 
- 
-(defun get-action-client () 
-  (when (null *navp-client*) 
-    (init-action-client)) 
-  *navp-client*) 
-</code> 
- 
-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. 
- 
-<code lisp> 
-(defun make-shape-action-goal (in-edges in-radius) 
-  (actionlib:make-action-goal (get-action-client) 
-                        edges in-edges 
-                        radius in-radius)) 
- 
-(defun call-shape-action (&key edges radius) 
-  (multiple-value-bind (result status) 
-      (with-failure-handling 
-          ((simple-error (e) 
-             (format t "An error occured!~%~a~%Reinitializing...~%~%" e) 
-             (setf *navp-client* nil) 
-             (retry))) 
-        (let ((actionlib:*action-server-timeout* 10.0)) 
-          (actionlib:call-goal 
-           (get-action-client) 
-           (make-shape-action-goal edges radius)))) 
-    (roslisp:ros-info (turtle-shape-action-client) "Nav action finished.") 
-    (values result status))) 
-</code> 
- 
-<code> 
-(top-level (with-turtle-process-modules (with-designators (( my-desig (action '((type shape) (shape hexagon))))) (perform my-desig)))) 
-</code> 
- 
- 
-== Next == 
- 
-