Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorials:beginner:location_designators [2016/01/25 21:23] gkazhoyatutorials:beginner:location_designators [2016/01/25 21:44] gkazhoya
Line 209: Line 209:
 </code> </code>
  
 +This will resolve any action designator with properties ''( (:type :goal) (:goal some-location-designator) )'' into ''(go-to some-location-designator)'' instruction.
  
- ''process-modules.lisp'':+Now for the process module, let's add a new process module called ''simple-navigation'' that accepts action designators with above-mentioned properties and a function ''goto-location'' that will invoke the new process module. Also, let's add ''simple-navigation'' to the running process modules in our ''with-turtle-process-modules'' macro. You ''process-modules.lisp'' should now look something like this:
  
 <code lisp> <code lisp>
 +(in-package :tut)
 +
 +(def-process-module actionlib-navigation (action-designator)
 +  (roslisp:ros-info (turtle-process-modules)
 +                    "Turtle shape navigation invoked with action designator `~a'."
 +                    action-designator)
 +  (destructuring-bind (command action-goal) (reference action-designator)
 +    (ecase command
 +      (draw-shape
 +       (call-shape-action
 +        :edges (turtle-shape-edges action-goal)
 +        :radius (turtle-shape-radius action-goal))))))
 +
 (def-process-module simple-navigation (action-designator) (def-process-module simple-navigation (action-designator)
   (roslisp:ros-info (turtle-process-modules)   (roslisp:ros-info (turtle-process-modules)
-                    "Turtle navigation invoked with location designator `~a'." +                    "Turtle simple navigation invoked with action designator `~a'." 
-                    location-designator) +                    action-designator) 
-  (let ((target-pose (reference location-designator))) +  (destructuring-bind (command action-goal) (reference action-designator) 
-       (print (cl-transforms:origin target-pose)+    (ecase command 
-       (move-to (cl-transforms:origin target-pose))))+      (go-to 
 +       (when (typep action-goal 'location-designator) 
 +         (let ((target-point (reference action-goal))) 
 +           (roslisp:ros-info (turtle-process-modules) 
 +                             "Going to point ~a." target-point
 +           (move-to target-point)))))))
  
-(defun goto-location (location-desig)+(defmacro with-turtle-process-modules (&body body) 
 +  `(with-process-modules-running 
 +       (actionlib-navigation 
 +        simple-navigation) 
 +     ,@body)) 
 + 
 +(defun draw-hexagon (radius)
   (let ((turtle-name "turtle1"))   (let ((turtle-name "turtle1"))
     (start-ros-node turtle-name)     (start-ros-node turtle-name)
     (init-ros-turtle turtle-name)     (init-ros-turtle turtle-name)
     (top-level     (top-level
-      (cpm:with-process-modules-running (turtle-navigation) +      (with-turtle-process-modules 
-        (cpm:process-module-alias :navigation 'turtle-navigation) +        (process-module-alias :navigation 'actionlib-navigation) 
-            (cpm:pm-execute :navigation location-desig)))))+        (with-designators 
 +            ((trajectory :action `((:type :shape) (:shape :hexagon) (:radius ,radius)))) 
 +          (pm-execute :navigation trajectory)))))) 
 + 
 +(defun goto-location (horizontal-position vertical-position) 
 +  (let ((turtle-name "turtle1")) 
 +    (start-ros-node turtle-name) 
 +    (init-ros-turtle turtle-name) 
 +    (top-level 
 +      (with-turtle-process-modules 
 +        (process-module-alias :navigation 'simple-navigation) 
 +        (with-designators 
 +            ((area :location `((:horizontal-position ,horizontal-position) 
 +                               (:vertical-position ,vertical-position))) 
 +             (goal :action `((:type :goal) (:goal ,area)))) 
 +          (pm-execute :navigation goal))))))
 </code> </code>
  
-And let's give it a go. Reload the tutorial into roslisp_repl then in the command line of REPL:+And let's give it a go. Reload the tutorial in ''roslisp_repl'' then in the command line of REPL:
  
 <code lisp> <code lisp>
-TUT> (defparameter turtle-target (make-designator 'location `((vpos center) (hpos center)))) +TUT> (goto-location :center :center
-TURTLE-TARGET +[(ROSLISP TOP) INFO] 1453758117.881: Node name is /turtle1 
-TUT> (goto-location turtle-target) +[(ROSLISP TOP) INFO] 1453758117.881: Namespace is / 
-WARNING: +[(ROSLISP TOP) INFO] 1453758117.885: Params are NIL 
-   Before starting node, node-status equalled RUNNING instead of :shutdown.  Shutting the previous node invocation down now. +[(ROSLISP TOP) INFO] 1453758117.885: Remappings are: 
-[(ROSLISP EVENT-LOOPINFO] 1414081756.703: Terminating ROS Node event loop +[(ROSLISP TOP) INFO] 1453758117.885: master URI is 127.0.0.1:11311 
-[(ROSLISP TOP) INFO] 1414081757.022: Shutdown complete +[(ROSLISP TOP) INFO] 1453758119.036: Node startup complete 
-[(ROSLISP TOP) INFO] 1414081757.028: Node name is /turtle1 +[(TURTLE-PROCESS-MODULES) INFO] 1453758119.377: Turtle simple navigation invoked with action designator 
-[(ROSLISP TOP) INFO] 1414081757.028: Namespace is / +`#<ACTION-DESIGNATOR ((TYPE GOAL) 
-[(ROSLISP TOP) INFO] 1414081757.028: Params are NIL +                      (GOAL #<LOCATION-DESIGNATOR ((HORIZONTAL-POSITION CENTER) 
-[(ROSLISP TOP) INFO] 1414081757.028: Remappings are: +                                                   (VERTICAL-POSITION CENTER)) {10095B8283}>)) {10095B87D3}>'
-[(ROSLISP TOP) INFO] 1414081757.028: master URI is 127.0.0.1:11311 +[(TURTLE-PROCESS-MODULES) INFO] 1453758119.386: Going to point #<3D-VECTOR (6.038690567016602d0 6.027290344238281d0 0.0d0)>.
-[(ROSLISP TOP) INFO] 1414081758.033: Node startup complete +
-[(TURTLE-PROCESS-MODULES) INFO] 1414081758.183: Turtle navigation invoked with location designator `#<LOCATION-DESIGNATOR ((VPOS +
-                                                                            CENTER) +
-                                                                           (HPOS +
-                                                                            CENTER)) {10078A2C53}>'+
- +
-#<CL-TRANSFORMS:3D-VECTOR (6.383428573608398d0 5.245925426483154d0 0.0d0)> +
 T T
 </code> </code>
  
-The turtle should also have moved to somewhere in the vecinity of the center of its window.+The turtle should also have moved to somewhere in the vicinity of the center of its window.
  
 == Next == == Next ==