Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
tutorials:beginner:motion_designators [2019/07/03 11:55] – [Using motion designators] tlipps | tutorials:beginner:motion_designators [2019/07/29 10:35] – Added turtlesim-srv to the dependencies amar |
---|
**Description:** In this tutorial you will learn what designators are, and in particular, work with motion designators: you will learn how to define one and how to use it. | **Description:** In this tutorial you will learn what designators are, and in particular, work with motion designators: you will learn how to define one and how to use it. |
| |
**Previous Tutorial:** [[tutorials:beginner:simple_plans|Implementing simple plans to move a turtle]]\\ | **Previous Tutorial:** [[tutorials:beginner:cram_prolog|Using Prolog for reasoning]]\\ |
**Next Tutorial:** [[tutorials:beginner:process_modules_2|Creating process modules]] | **Next Tutorial:** [[tutorials:beginner:process_modules_2|Creating process modules]] |
| |
| |
<code lisp> | <code lisp> |
(defparameter spy-location (desig:a location (to see) (object ?prime-minister))) | (defparameter *spy-location* (desig:a location (to see) (object ?prime-minister))) |
</code> | </code> |
| |
(Do not add this code to your tutorial files, it is meant simply for illustration here.) | (Do not add this code to your tutorial files, it is meant simply for illustration here.) |
| |
This line of code creates a location designator (''spy-location'') which "knows" of the given object (''?prime-minister'', which we assume is an already defined object designator), and knows that its purpose is to see the object. We do not actually specify a location in terms of coordinates at this moment. When we do want to find a suitable set of coordinates for this location, we would call | This line of code creates a location designator (''*spy-location*'') which "knows" of the given object (''?prime-minister'', which we assume is an already defined object designator), and knows that its purpose is to see the object. We do not actually specify a location in terms of coordinates at this moment. When we do want to find a suitable set of coordinates for this location, we would call |
| |
<code lisp> | <code lisp> |
(reference spy-location) | (reference *spy-location*) |
</code> | </code> |
| |
</code> | </code> |
| |
In your ''cram-my-beginner-tutorial.asd'' file, on the '':depends-on'' line, add dependencies to ''cram-designators'' and ''cram-prolog''. Let's also create a new source file for the code in this tutorial (under ''src'' directory), call it ''motion-designators.lisp''. We will need to add the file to the '':components'' of the ''src'' module in your ''cram-my-beginner-tutorial.asd'', which should now look something like this: | In your ''cram-my-beginner-tutorial.asd'' file, on the '':depends-on'' line, add dependencies to ''cram-designators'' and ''cram-prolog''. Let's also create a new source file for the code in this tutorial (under ''src'' directory), call it ''motion-designators.lisp''. It can be empty for now. We will need to add the file to the '':components'' of the ''src'' module in your ''cram-my-beginner-tutorial.asd'', which should now look something like this: |
| |
<code lisp> | <code lisp> |
(defsystem cram-my-beginner-tutorial | (defsystem cram-my-beginner-tutorial |
:depends-on (cram-language roslisp turtlesim-msg geometry_msgs-msg cl-transforms | :depends-on (cram-language roslisp turtlesim-msg turtlesim-srv |
| geometry_msgs-msg cl-transforms |
cram-designators cram-prolog) | cram-designators cram-prolog) |
:components | :components |
</code> | </code> |
| |
Now, reload the tutorial in ''roslisp_repl'' (which also loads the newly added dependencies). | Now, reload the tutorial in ''roslisp_repl'' (which also loads the newly added dependencies): |
| |
| <code lisp> |
| PROLOG> (ros-load:load-system "cram_my_beginner_tutorial" :cram-my-beginner-tutorial) |
| PROLOG> (in-package :tut) |
| </code> |
| |
==== Creating a motion designator ==== | ==== Creating a motion designator ==== |
| |
<code lisp> | <code lisp> |
TUT> (defparameter my-desig (desig:a motion (type driving) (speed 1.5))) | TUT> (defparameter *my-desig* (desig:a motion (type driving) (speed 1.5))) |
MY-DESIG | *MY-DESIG* |
TUT> (desig-prop-value my-desig :speed) | TUT> (desig-prop-value *my-desig* :speed) |
1.5 | 1.5 |
</code> | </code> |
| |
| We call the variable ''*my-desig*'' with asterisks as this is the common convention in Common Lisp for naming global variables. |
| |
We use the ''a'' macro to create designators. Internally it uses the ''make-designator'' function to create a designator of the specified type. The macro allows us to write cleaner code for designator creation. | We use the ''a'' macro to create designators. Internally it uses the ''make-designator'' function to create a designator of the specified type. The macro allows us to write cleaner code for designator creation. |
| |
<code lisp> | <code lisp> |
TUT> (reference my-desig) | TUT> (reference *my-desig*) |
Cannot resolve motion designator #<MOTION-DESIGNATOR ((TYPE | Cannot resolve motion designator #<MOTION-DESIGNATOR ((TYPE |
DRIVING) | DRIVING) |
| |
<code lisp> | <code lisp> |
TUT> (defparameter my-desig2 (desig:a motion (type driving) (speed 1.5) (angle 2))) | TUT> (defparameter *my-desig2* (desig:a motion (type driving) (speed 1.5) (angle 2))) |
MY-DESIG2 | *MY-DESIG2 |
TUT> (reference my-desig2) | TUT> (reference *my-desig2*) |
(DRIVE #S(TURTLE-MOTION :SPEED 1.5 :ANGLE 2)) | (DRIVE #S(TURTLE-MOTION :SPEED 1.5 :ANGLE 2)) |
</code> | </code> |
<code lisp> | <code lisp> |
TUT> (desig:a motion (type moving) (goal (1 1 0))) | TUT> (desig:a motion (type moving) (goal (1 1 0))) |
#<MOTION-DESIGNATOR ((:TYPE :MOVING) (:GOAL (1 1 0))) {10042C61F3}> | #<A MOTION |
| (TYPE MOVING) |
| (GOAL (1 1 0))> |
</code> | </code> |
| |
| |
<code lisp> | <code lisp> |
TUT> (defparameter my-desig3 (desig:a motion (type setting-pen) (r 100) (g 150) (b 0) (width 5))) | TUT> (defparameter *my-desig3* (desig:a motion (type setting-pen) (r 100) (g 150) (b 0) (width 5))) |
MY-DESIG3 | *MY-DESIG3* |
TUT> (reference my-desig3) | TUT> (reference *my-desig3*) |
(SET-PEN #S(PEN-MOTION :R 100 :G 150 :B 0 :WIDTH 5 :OFF 0)) | (SET-PEN #S(PEN-MOTION :R 100 :G 150 :B 0 :WIDTH 5 :OFF 0)) |
</code> | </code> |