Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
tutorials:beginner:assigning_actions [2016/01/25 21:45] – [Automatically choosing a process module for an action] gkazhoya | tutorials:beginner:assigning_actions [2016/01/25 22:12] – gkazhoya | ||
---|---|---|---|
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 module does is resolve the action designator it receives as a parameter, and if the designator is of type navigation, resolves the goal as a location designator, then moves the turtle to the resolved location. | + | The '' |
- | + | ||
- | Now comes the part where we instruct the system how to reason about process modules, and we need to append the following to selecting-process-modules.lisp: | + | |
- | + | ||
- | <code lisp> | + | |
- | (cram-reasoning: | + | |
- | cram-process-modules: | + | |
- | (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 | + | The first two facts say that we have two process modules available for automatically matching them to designators (this is used for switching process modules for simulating and executing on the real robot in parallel), in our case no conditions need to be true for this fact to hold, our process modules are always |
- | For convenience, | + | 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> | ||
Line 194: | Line 142: | ||
You should also see the turtle move to a central location. | You should also see the turtle move to a central location. | ||
- |