Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorials:beginner:location_designators_2 [2017/07/27 08:13] – Rearrange previous tutorial cpo | tutorials:beginner:location_designators_2 [2022/02/25 23:20] (current) – [Using location designators with the TurtleSim] schimpf | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Using location designators with the TurtleSim | ====== Using location designators with the TurtleSim | ||
| - | **Description: | + | **Description: |
| - | **Previous Tutorial:** [[tutorials: | + | **Previous Tutorial:** [[tutorials: |
| + | **Next Tutorial:** [[tutorials: | ||
| + | To run the code in the tutuorial the roscore and the turtlesim need to be started over the terminal. Each in their own tab. | ||
| + | <code bash> | ||
| + | $ roscore | ||
| + | </ | ||
| + | <code bash> | ||
| + | $ rosrun turtlesim turtlesim_node | ||
| + | </ | ||
| + | |||
| + | And in the REPL the following commands should be executed: | ||
| + | <code lisp> | ||
| + | CL-USER> | ||
| + | ... | ||
| + | CL-USER> | ||
| + | </ | ||
| ===== Location designators: | ===== Location designators: | ||
| - | As mentioned previously, location designators are a way to describe a location in symbolic terms, and have actual coordinates for it generated later, when needed. The crucial difference between location and action | + | As mentioned previously, location designators are a way to describe a location in symbolic terms, and have actual coordinates for it generated later, when needed. The crucial difference between location and motion |
| * location-generator: | * location-generator: | ||
| Line 31: | Line 46: | ||
| ===== Location designator generators ===== | ===== Location designator generators ===== | ||
| - | Let's create a new file called '' | + | Let's create a new file called '' |
| <code lisp> | <code lisp> | ||
| - | (defsystem cram-beginner-tutorial | + | (defsystem cram-my-beginner-tutorial |
| - | :depends-on (cram-language | + | :depends-on (roslisp |
| - | cram-designators cram-prolog | + | |
| - | actionlib actionlib_msgs-msg turtle_actionlib-msg | + | |
| - | cram-process-modules cram-language-designator-support) | + | |
| :components | :components | ||
| ((:module " | ((:module " | ||
| Line 45: | Line 58: | ||
| | | ||
| | | ||
| - | | + | |
| - | | + | |
| | | ||
| | | ||
| " | " | ||
| " | " | ||
| - | " | + | " |
| - | | + | (: |
| + | " | ||
| + | " | ||
| </ | </ | ||
| Line 62: | Line 76: | ||
| | | ||
| TUT> goal-desig | TUT> goal-desig | ||
| - | #< | + | #<A LOCATION |
| - | | + | |
| + | (HORIZONTAL-POSITION LEFT)> | ||
| </ | </ | ||
| Line 194: | Line 209: | ||
| </ | </ | ||
| - | Depending on the random number generator we will get some or none of the solutions rejected and, therefore, ''< | + | Depending on the random number generator we will get some or none of the solutions rejected and, therefore, ''< |
| ===== Using a location designator ===== | ===== Using a location designator ===== | ||
| - | Let's try to create | + | Let's try to expand |
| <code lisp> | <code lisp> | ||
| - | (def-fact-group goal-actions | + | (def-fact-group goal-motions |
| - | (<- (action-desig ?desig (go-to ?point)) | + | (<- (motion-grounding |
| - | (desig-prop ?desig (:type :goal)) | + | (desig-prop ?desig (:type :going-to)) |
| (desig-prop ?desig (:goal ?point)))) | (desig-prop ?desig (:goal ?point)))) | ||
| </ | </ | ||
| - | This will resolve any action | + | This will resolve any motion |
| - | Now for the process module, let's add a new process module | + | Now for the process module, let's add a new case to our navigation |
| <code lisp> | <code lisp> | ||
| (in-package :tut) | (in-package :tut) | ||
| - | (def-process-module | + | (def-process-module |
| (roslisp: | (roslisp: | ||
| - | "Turtle shape navigation invoked with action | + | "TurtleSim |
| - | | + | |
| - | (destructuring-bind (command | + | (destructuring-bind (command |
| - | (ecase command | + | |
| - | (draw-shape | + | |
| - | | + | |
| - | :edges (turtle-shape-edges action-goal) | + | |
| - | :radius (turtle-shape-radius action-goal)))))) | + | |
| - | + | ||
| - | (def-process-module simple-navigation (action-designator) | + | |
| - | (roslisp: | + | |
| - | " | + | |
| - | action-designator) | + | |
| - | (destructuring-bind (command action-goal) (reference | + | |
| (ecase command | (ecase command | ||
| + | (drive | ||
| + | | ||
| + | (turtle-motion-speed motion) | ||
| + | (turtle-motion-angle motion))) | ||
| + | (move | ||
| + | | ||
| (go-to | (go-to | ||
| - | (when (typep | + | (when (typep |
| - | (let ((target-point (reference | + | (let ((target-point (reference |
| | | ||
| " | " | ||
| | | ||
| - | (defmacro with-turtle-process-modules | + | (def-process-module turtlesim-pen-control |
| - | | + | (roslisp: |
| - | (actionlib-navigation | + | " |
| - | | + | motion-designator) |
| - | ,@body)) | + | (destructuring-bind (command motion) (reference motion-designator) |
| + | (ecase command | ||
| + | (set-pen | ||
| + | (call-set-pen | ||
| + | | ||
| + | | ||
| + | (pen-motion-b motion) | ||
| + | (pen-motion-width motion) | ||
| + | (pen-motion-off motion)))))) | ||
| - | (defun | + | (defun |
| - | (let ((turtle-name " | + | (top-level |
| - | (start-ros-node turtle-name) | + | (with-process-modules-running (turtlesim-navigation) |
| - | (init-ros-turtle turtle-name) | + | (let ((trajectory (desig:a motion (type driving) (speed ?speed) (angle ? |
| - | (top-level | + | (pm-execute ' |
| - | (with-turtle-process-modules | + | |
| - | | + | (defun move (?x ?y) |
| - | (with-designators | + | |
| - | | + | (with-process-modules-running |
| - | (pm-execute | + | (let ((goal (desig:a motion (type moving) (goal (?x ?y 0))))) |
| + | (pm-execute | ||
| - | (defun goto-location (horizontal-position vertical-position) | + | (defun goto-location (?horizontal-position |
| (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 | ||
| - | (with-turtle-process-modules | + | (with-process-modules-running |
| - | | + | (let* ((?area (desig:a location |
| - | (with-designators | + | (horizontal-position |
| - | | + | |
| - | (:vertical-position | + | |
| - | | + | (cram-executive:perform |
| - | (pm-execute | + | |
| </ | </ | ||
| - | And let's give it a go. Reload | + | In '' |
| <code lisp> | <code lisp> | ||
| - | TUT> (goto-location :center | + | (in-package :tut) |
| - | [(ROSLISP TOP) INFO] 1453758117.881: Node name is /turtle1 | + | |
| - | [(ROSLISP TOP) INFO] 1453758117.881: Namespace is / | + | (def-fact-group available-turtle-process-modules (available-process-module |
| - | [(ROSLISP TOP) INFO] 1453758117.885: Params are NIL | + | matching-process-module) |
| - | [(ROSLISP TOP) INFO] 1453758117.885: Remappings are: | + | (<- (available-process-module turtlesim-navigation)) |
| - | [(ROSLISP TOP) INFO] 1453758117.885: master URI is 127.0.0.1: | + | (<- (available-process-module turtlesim-pen-control)) |
| - | [(ROSLISP TOP) INFO] 1453758119.036: Node startup complete | + | |
| - | [(TURTLE-PROCESS-MODULES) INFO] 1453758119.377: Turtle simple | + | (<- (matching-process-module ?desig turtlesim-navigation) |
| - | `#<ACTION-DESIGNATOR ((TYPE GOAL) | + | (desig-prop ?desig (:type : |
| - | (GOAL #< | + | (<- (matching-process-module ?desig turtlesim-navigation) |
| - | | + | (desig-prop ?desig (:type : |
| - | [(TURTLE-PROCESS-MODULES) INFO] 1453758119.386: Going to point #< | + | (<- (matching-process-module ?desig turtlesim-navigation) |
| + | (desig-prop ?desig (:type : | ||
| + | (<- (matching-process-module ?desig turtlesim-pen-control) | ||
| + | (desig-prop ?desig (:type : | ||
| + | |||
| + | (defun perform-some-motion (motion-desig) | ||
| + | (top-level | ||
| + | (with-process-modules-running (turtlesim-navigation turtlesim-pen-control) | ||
| + | (cram-executive: | ||
| + | </ | ||
| + | |||
| + | It's the same as the other ones. If the type of ''? | ||
| + | |||
| + | Now let's give it a go. Reload the tutorial in '' | ||
| + | |||
| + | <code lisp> | ||
| + | TUT> (goto-location :right :top) | ||
| + | [(ROSLISP TOP) INFO] 1501153969.640: Node name is /turtle1 | ||
| + | [(ROSLISP TOP) INFO] 1501153969.640: Namespace is / | ||
| + | [(ROSLISP TOP) INFO] 1501153969.641: Params are NIL | ||
| + | [(ROSLISP TOP) INFO] 1501153969.641: Remappings are: | ||
| + | [(ROSLISP TOP) INFO] 1501153969.641: master URI is 127.0.0.1: | ||
| + | [(ROSLISP TOP) INFO] 1501153970.649: Node startup complete | ||
| + | [(TURTLE-PROCESS-MODULES) INFO] 1562698457.619: TurtleSim | ||
| + | | ||
| + | (GOAL #<A LOCATION | ||
| + | | ||
| + | (VERTICAL-POSITION | ||
| + | [(TURTLE-PROCESS-MODULES) INFO] 1501153970.691: Going to point #< | ||
| T | T | ||
| </ | </ | ||
| - | The turtle should also have moved to somewhere in the vicinity of the center | + | If you already had a running node in the REPL, you might get the error shown below but that is absolutely normal: ROS simply notifies you that it is going to shut down the previous node and start a new one. |
| + | <code lisp> | ||
| + | WARNING: | ||
| + | | ||
| + | </ | ||
| + | |||
| + | The turtle should also have moved to somewhere in the vicinity of the top-right corner | ||
| == Next == | == Next == | ||
| - | So far we called process modules directly. Sometimes it' | + | Let' |
| - | [[tutorials: | + | [[tutorials: |

