Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorials:beginner:process_modules_2 [2017/07/18 15:07] – [Executing process modules in parallel] cpo | tutorials:beginner:process_modules_2 [2020/09/03 10:34] (current) – [Writing a process module for the turtlesim] gkazhoya | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| **Description: | **Description: | ||
| - | **Previous Tutorial:** [[tutorials: | + | **Previous Tutorial:** [[tutorials: |
| - | **Next Tutorial:** [[tutorials: | + | **Next Tutorial:** [[tutorials: |
| ===== Process modules: an overview ===== | ===== Process modules: an overview ===== | ||
| Line 26: | Line 26: | ||
| Once again, some new dependencies must be declared in the tutorial files you've been working on. | Once again, some new dependencies must be declared in the tutorial files you've been working on. | ||
| - | In your '' | + | In your '' |
| < | < | ||
| - | <build_depend> | + | <depend> |
| - | + | ||
| - | < | + | |
| </ | </ | ||
| Line 37: | Line 35: | ||
| <code lisp> | <code lisp> | ||
| - | (defsystem cram-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 |
| | | ||
| | | ||
| Line 47: | Line 45: | ||
| | | ||
| | | ||
| - | | + | |
| | | ||
| " | " | ||
| " | " | ||
| - | " | + | " |
| </ | </ | ||
| Line 80: | Line 78: | ||
| </ | </ | ||
| - | First, we use the '' | + | First, we use the '' |
| Let's try this out. Make sure you have '' | Let's try this out. Make sure you have '' | ||
| Line 116: | Line 114: | ||
| <code lisp> | <code lisp> | ||
| TUT> (drive 5 2) | TUT> (drive 5 2) | ||
| - | [(TURTLE-PROCESS-MODULES) INFO] 1499958119.336: TurtleSim navigation invoked with motion designator `#< | + | [(TURTLE-PROCESS-MODULES) INFO] 1562698751.679: TurtleSim navigation invoked with motion designator `#<A MOTION |
| - | DRIVING) | + | |
| - | (SPEED | + | (SPEED 5) |
| - | 5) | + | (ANGLE 2)>' |
| - | (ANGLE | + | |
| - | 2)) {1006979703}>'. | + | |
| 1 | 1 | ||
| </ | </ | ||
| Line 134: | Line 130: | ||
| So to make this decision, we need to think about resources on the robot (eg. arms or the base of the robot). | So to make this decision, we need to think about resources on the robot (eg. arms or the base of the robot). | ||
| - | Our '' | + | Our '' |
| - | Append | + | To add the move motion to the existing process module, we add a new case to the '' |
| + | |||
| + | <code lisp> | ||
| + | (def-process-module turtlesim-navigation (motion-designator) | ||
| + | (roslisp: | ||
| + | " | ||
| + | motion-designator) | ||
| + | (destructuring-bind (command motion) (reference motion-designator) | ||
| + | (ecase command | ||
| + | (drive | ||
| + | | ||
| + | (turtle-motion-speed motion) | ||
| + | (turtle-motion-angle motion))) | ||
| + | (move | ||
| + | | ||
| + | </ | ||
| + | |||
| + | Since '' | ||
| + | |||
| + | |||
| + | To add the new process module, append | ||
| <code lisp> | <code lisp> | ||
| Line 159: | Line 175: | ||
| ==== Executing process modules in parallel ==== | ==== Executing process modules in parallel ==== | ||
| - | To demonstrate how process modules work when called in parallel, we will make a little adjustment to the code of '' | + | To demonstrate how process modules work when called in parallel, we will call the same process module |
| - | + | ||
| - | <code lisp> | + | |
| - | (def-process-module | + | |
| - | (roslisp: | + | |
| - | " | + | |
| - | motion-designator) | + | |
| - | (destructuring-bind (command motion) (reference motion-designator) | + | |
| - | (ecase command | + | |
| - | (drive | + | |
| - | | + | |
| - | | + | |
| - | (turtle-motion-speed motion) | + | |
| - | (turtle-motion-angle motion)) | + | |
| - | | + | |
| - | </ | + | |
| - | + | ||
| - | Instead of just sending a single command, we send ten commands over the course of ten seconds. This way the process module will be occupied while executing a drive designator. Without this, all executions would be instantaneous and we wouldn' | + | |
| - | But this change is only temporary for the sake of this demonstration. | + | |
| - | + | ||
| - | After the change you can execute the following in your REPL and look at the TurtleSim. | + | |
| <code lisp> | <code lisp> | ||
| TUT> (top-level | TUT> (top-level | ||
| (with-process-modules-running (turtlesim-navigation turtlesim-pen-control) | (with-process-modules-running (turtlesim-navigation turtlesim-pen-control) | ||
| - | (let ((trajectory | + | (let ((goal (desig:a motion (type moving) (goal (9 1 0)))) |
| - | (trajectory2 | + | (trajectory |
| (cpl:par | (cpl:par | ||
| - | (pm-execute ' | + | (pm-execute ' |
| - | (pm-execute ' | + | (pm-execute ' |
| - | + | [(TURTLE-PROCESS-MODULES) INFO] 1500997686.711: TurtleSim navigation invoked with motion designator `#< | |
| - | [(TURTLE-PROCESS-MODULES) INFO] 1500389140.365: TurtleSim navigation invoked with motion designator `#< | + | MOVING) |
| - | DRIVING) | + | (GOAL |
| - | (SPEED | + | (9 1 |
| - | 1) | + | 0))) {1006DBC893}>' |
| - | (ANGLE | + | |
| - | 1)) {100680BC83}>' | + | |
| WARNING: | WARNING: | ||
| | | ||
| - | {1006E78283}> already processing input. Waiting for it to become free. | + | {10074C0293}> already processing input. Waiting for it to become free. |
| - | [(TURTLE-PROCESS-MODULES) INFO] 1500389150.382: TurtleSim navigation invoked with motion designator `#< | + | [(TURTLE-PROCESS-MODULES) INFO] 1500997690.065: TurtleSim navigation invoked with motion designator `#< |
| | | ||
| (SPEED | (SPEED | ||
| - | 1) | + | 3) |
| (ANGLE | (ANGLE | ||
| - | 2)) {100680C063}>' | + | 8)) {1006DBCC73}>' |
| - | NIL | + | T |
| </ | </ | ||
| - | Here we use the '' | + | Here we use the '' |
| If we use two different process modules, they can in fact be called in parallel: | If we use two different process modules, they can in fact be called in parallel: | ||
| Line 215: | Line 209: | ||
| TUT> (top-level | TUT> (top-level | ||
| (with-process-modules-running (turtlesim-navigation turtlesim-pen-control) | (with-process-modules-running (turtlesim-navigation turtlesim-pen-control) | ||
| - | (let ((trajectory | + | (let ((goal (desig:a motion (type moving) (goal (9 9 0))))) |
| (cpl:par | (cpl:par | ||
| - | (pm-execute ' | + | (pm-execute ' |
| (dotimes (i 10) | (dotimes (i 10) | ||
| (pm-execute ' | (pm-execute ' | ||
| Line 223: | Line 217: | ||
| (?g (random 255)) | (?g (random 255)) | ||
| (?b (random 255)) | (?b (random 255)) | ||
| - | (?width (random 5))) | + | (? |
| (desig:a motion (type setting-pen) (r ?r) (g ?g) (b ?b) (width ?width)))) | (desig:a motion (type setting-pen) (r ?r) (g ?g) (b ?b) (width ?width)))) | ||
| - | (sleep | + | (sleep |
| - | [(TURTLE-PROCESS-MODULES) INFO] 1500389629.839: TurtleSim navigation invoked with motion designator `#< | + | [(TURTLE-PROCESS-MODULES) INFO] 1500997786.329: TurtleSim navigation invoked with motion designator `#< |
| - | DRIVING) | + | MOVING) |
| - | (SPEED | + | (GOAL |
| - | 1) | + | (9 9 |
| - | | + | 0))) {1005164AC3}>' |
| - | | + | [(TURTLE-PROCESS-MODULES) INFO] 1500997786.347: TurtleSim pen control invoked with motion designator `#< |
| - | [(TURTLE-PROCESS-MODULES) INFO] 1500389629.855: TurtleSim pen control invoked with motion designator `#< | + | |
| SETTING-PEN) | SETTING-PEN) | ||
| (R | (R | ||
| - | | + | |
| (G | (G | ||
| - | | + | |
| (B | (B | ||
| - | | + | |
| | | ||
| - | | + | |
| + | |||
| [ ... ] | [ ... ] | ||
| - | + | | |
| - | [(TURTLE-PROCESS-MODULES) INFO] 1500389639.067: TurtleSim pen control invoked with motion designator `#< | + | [(TURTLE-PROCESS-MODULES) INFO] 1500997791.126: TurtleSim pen control invoked with motion designator `#< |
| SETTING-PEN) | SETTING-PEN) | ||
| (R | (R | ||
| - | | + | |
| (G | (G | ||
| - | | + | |
| (B | (B | ||
| - | | + | |
| | | ||
| - | 3)) {1008E58DD3}>' | + | 3)) {1002B903C3}>' |
| - | NIL | + | T |
| </ | </ | ||
| - | Here we call our modified '' | + | Here we call the navigation |
| As stated above this behaviour is to ensure that a single resource on a robot isn't used by multiple functions at once, while not hindering the parallel execution of independent resources. But keep in mind, that this is only true for the low-level motions. If a robots arms should grasp something and its base is moved, the grasping might fail, although these motions are not necessarily controlled by the same process module. | As stated above this behaviour is to ensure that a single resource on a robot isn't used by multiple functions at once, while not hindering the parallel execution of independent resources. But keep in mind, that this is only true for the low-level motions. If a robots arms should grasp something and its base is moved, the grasping might fail, although these motions are not necessarily controlled by the same process module. | ||
| - | |||
| - | Now, don't forget to change '' | ||
| == Next == | == Next == | ||
| + | So far we called process modules directly. Sometimes it's better to let the system decide on its own … | ||
| - | Let's have a look at location designators and other ways to move the turtle, as well as have some more practice with designator resolution and process modules ... | + | [[tutorials: |
| - | + | ||
| - | [[tutorials: | + | |

