Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorials:beginner:assigning_actions [2015/05/11 17:03] – created gkazhoya | tutorials:beginner:assigning_actions [2016/03/04 14:25] (current) – old revision restored (2016/01/25 23:21) gkazhoya | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Automatically choosing a process module for an action | ====== Automatically choosing a process module for an action | ||
- | **Description: | + | **Description: |
**Previous Tutorial:** [[tutorials: | **Previous Tutorial:** [[tutorials: | ||
Line 7: | Line 7: | ||
===== Setting up fact groups to select a process module ===== | ===== Setting up fact groups to select a process module ===== | ||
- | We'll need to update | + | First let's create |
<code lisp> | <code lisp> | ||
(defsystem cram-beginner-tutorial | (defsystem cram-beginner-tutorial | ||
- | :depends-on (roslisp | + | :depends-on (cram-language |
- | | + | |
+ | actionlib | ||
+ | cram-process-modules | ||
:components | :components | ||
((:module " | ((:module " | ||
:components | :components | ||
((:file " | ((:file " | ||
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | | ||
+ | " | ||
+ | " | ||
+ | " | ||
</ | </ | ||
- | We' | + | We only need to add a couple |
- | + | ||
- | <code lisp> | + | |
- | (in-package :cl-user) | + | |
- | + | ||
- | (desig-props: | + | |
- | (:nicknames :tut) | + | |
- | (:use #:cpl | + | |
- | #:roslisp | + | |
- | #: | + | |
- | #: | + | |
- | + | ||
- | (: | + | |
- | ;; action properties | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | ;; location Properties | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | #: | + | |
- | </ | + | |
- | + | ||
- | Prerequisites done, let's now create a selecting-process-modules.lisp | + | |
<code lisp> | <code lisp> | ||
(in-package :tut) | (in-package :tut) | ||
- | (cram-reasoning: | + | (def-fact-group navigation-process-modules |
- | (cram-reasoning: | + | matching-process-module) |
- | (desig-prop ? | + | (<- (available-process-module actionlib-navigation)) |
- | (desig-prop ?designator (goal ?goal)))) | + | (<- (available-process-module simple-navigation)) |
- | </ | + | |
- | What this snippet of code does is create a fact group that will be used to resolve action designators. In particular, if the designator contains a (type navigation) pair, and a (goal <an object, assumed to be a location designator by other code in this tutorial> | + | |
- | + | | |
- | Let's create a process module that can consume designators of type navigation, and append it to selecting-process-modules.lisp: | + | (<- (matching-process-module ?designator |
- | + | (desig-prop ? | |
- | <code lisp> | + | |
- | (cram-process-modules: | + | |
- | | + | |
- | " | + | |
- | action-designator) | + | |
- | (destructuring-bind (cmd action-goal) (reference action-designator) | + | |
- | (ecase cmd | + | |
- | (navigation | + | |
- | (print (cl-transforms: | + | |
- | (move-to (cl-transforms:origin (reference action-goal))))))) | + | |
</ | </ | ||
- | What this process | + | The '' |
- | Now comes the part where we instruct the system how to reason about process modules, and we need to append the following | + | The first two facts say that we have two process modules available for automatically matching them to designators (this is used for switching |
- | <code lisp> | + | For convenience, |
- | (cram-reasoning: | + | |
- | | + | |
- | (cram-reasoning:< | + | |
- | (desig-prop ?designator (type navigation))) | + | |
- | (cram-reasoning:< | + | |
- | + | ||
- | (cram-reasoning: | + | |
- | cram-process-modules: | + | |
- | (cram-reasoning:< | + | |
- | (desig-prop ?designator (type shape))) | + | |
- | (cram-reasoning:< | + | |
- | </ | + | |
- | + | ||
- | These fact groups extend the predicates cpm: | + | |
- | + | ||
- | Notice that in this tutorial, available-process-module always gets our process modules. No conditions need to be true, our process modules are simply available. | + | |
- | + | ||
- | For convenience, | + | |
<code lisp> | <code lisp> | ||
- | (defun | + | (defun |
(let ((turtle-name " | (let ((turtle-name " | ||
(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-handler turtle-actuators) | + | (with-turtle-process-modules |
- | (cram-plan-library: | + | (pm-execute-matching |
</ | </ | ||
- | This function is mostly similar to previous ones we used to call process modules; the difference is that rather than calling | + | This function is mostly similar to previous ones we used to call process modules; the difference is that rather than calling |
===== Running action designators ===== | ===== Running action designators ===== | ||
- | Let's load our code in roslisp repl. Make sure you have roscore, turtlesim, and the turtle actionlib | + | Let's load our code in '' |
- | With that, let's first make a couple of designators for test, so type this in roslisp repl's command line: | + | With that, let's first make a couple of designators for test, so type this in REPL's command line: |
<code lisp> | <code lisp> | ||
- | CL-USER> (in-package | + | TUT> (defparameter center-location |
- | TUT> (defparameter shape-action (make-designator | + | |
+ | CENTER-LOCATION | ||
+ | TUT> (defparameter goal-action | ||
+ | | ||
+ | GOAL-ACTION | ||
+ | TUT> (defparameter shape-action | ||
+ | (make-designator | ||
SHAPE-ACTION | SHAPE-ACTION | ||
- | TUT> (defparameter navigation-action (make-designator ' | ||
- | NAVIGATION-ACTION | ||
</ | </ | ||
- | With these designators defined, see what happens if you try to call them. For example, | + | With these designators defined, see what happens if you try to execute |
<code lisp> | <code lisp> | ||
- | TUT> (do-action-designator shape-action) | + | TUT> (perform-some-action goal-action) |
WARNING: | WARNING: | ||
| | ||
- | [(ROSLISP EVENT-LOOP) INFO] 1415203378.618: Terminating ROS Node event loop | + | [(ROSLISP EVENT-LOOP) INFO] 1453760373.719: Terminating ROS Node event loop |
- | [(ROSLISP TOP) INFO] 1415203379.040: Shutdown complete | + | [(ROSLISP TOP) INFO] 1453760374.142: Shutdown complete |
- | [(ROSLISP TOP) INFO] 1415203379.042: Node name is /turtle1 | + | [(ROSLISP TOP) INFO] 1453760374.149: Node name is /turtle1 |
- | [(ROSLISP TOP) INFO] 1415203379.042: Namespace is / | + | [(ROSLISP TOP) INFO] 1453760374.149: Namespace is / |
- | [(ROSLISP TOP) INFO] 1415203379.042: Params are NIL | + | [(ROSLISP TOP) INFO] 1453760374.150: Params are NIL |
- | [(ROSLISP TOP) INFO] 1415203379.042: Remappings are: | + | [(ROSLISP TOP) INFO] 1453760374.150: Remappings are: |
- | [(ROSLISP TOP) INFO] 1415203379.042: master URI is 127.0.0.1: | + | [(ROSLISP TOP) INFO] 1453760374.150: master URI is 127.0.0.1: |
- | [(ROSLISP TOP) INFO] 1415203380.047: Node startup complete | + | [(ROSLISP TOP) INFO] 1453760375.155: Node startup complete |
- | [(TURTLE-PROCESS-MODULES) INFO] 1415203380.190: Turtle navigation invoked with action designator `#< | + | [(TURTLE-PROCESS-MODULES) INFO] 1453760375.181: Turtle |
- | SHAPE) | + | GOAL) |
- | | + | (GOAL |
- | | + | #< |
- | | + | |
- | 1.6)) {1005C58BE3}>' | + | |
- | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1415203380.231: Waiting for turtle shape action server... | + | (VERTICAL-POSITION |
- | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1415203382.278: | + | CENTER)) |
- | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1415203394.276: | + | {100A70EDE3}> |
- | [TURTLE_ACTIONLIB-MSG: | + | [(TURTLE-PROCESS-MODULES) INFO] 1453760375.184: Going to point #< |
- | | + | T |
- | | + | |
- | | + | |
- | | + | |
</ | </ | ||
- | The turtle should | + | The turtle should have moved somewhere |
+ | |||
+ | Let's see if it will draw the triangle shape: | ||
<code lisp> | <code lisp> | ||
- | TUT> (do-action-designator navigation-action) | + | TUT> (perform-some-action shape-action) |
WARNING: | WARNING: | ||
| | ||
- | [(ROSLISP EVENT-LOOP) INFO] 1415203565.890: Terminating ROS Node event loop | + | [(ROSLISP EVENT-LOOP) INFO] 1453760384.426: Terminating ROS Node event loop |
- | [(ROSLISP TOP) INFO] 1415203566.382: Shutdown complete | + | [(ROSLISP TOP) INFO] 1453760384.903: Shutdown complete |
- | [(ROSLISP TOP) INFO] 1415203566.385: Node name is /turtle1 | + | [(ROSLISP TOP) INFO] 1453760384.906: Node name is /turtle1 |
- | [(ROSLISP TOP) INFO] 1415203566.385: Namespace is / | + | [(ROSLISP TOP) INFO] 1453760384.907: Namespace is / |
- | [(ROSLISP TOP) INFO] 1415203566.385: Params are NIL | + | [(ROSLISP TOP) INFO] 1453760384.907: Params are NIL |
- | [(ROSLISP TOP) INFO] 1415203566.385: Remappings are: | + | [(ROSLISP TOP) INFO] 1453760384.907: Remappings are: |
- | [(ROSLISP TOP) INFO] 1415203566.386: master URI is 127.0.0.1: | + | [(ROSLISP TOP) INFO] 1453760384.907: master URI is 127.0.0.1: |
- | [(ROSLISP TOP) INFO] 1415203567.392: Node startup complete | + | [(ROSLISP TOP) INFO] 1453760385.913: Node startup complete |
- | [(TURTLE-PROCESS-MODULES) INFO] 1415203567.525: Turtle navigation invoked with action designator `#< | + | [(TURTLE-PROCESS-MODULES) INFO] 1453760385.930: Turtle |
- | | + | SHAPE) |
- | | + | |
- | #< | + | |
- | ((VPOS | + | |
- | CENTER) | + | 1.6)) {100BA6F7A3}>' |
- | | + | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1453760385.968: Waiting for turtle shape action server... |
- | | + | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1453760387.968: |
- | | + | [(TURTLE-SHAPE-ACTION-CLIENT) INFO] 1453760399.919: Nav action finished. |
- | + | [TURTLE_ACTIONLIB-MSG: | |
- | #<CL-TRANSFORMS:3D-VECTOR | + | |
- | T | + | 1.0471975803375244d0 |
+ | APOTHEM: | ||
+ | | ||
</ | </ | ||
- | |||
- | You should also see the turtle move to a central location. | ||
- |