Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
tutorials:beginner:controlling_turtlesim_2 [2016/01/22 11:50] – [Updating the Lisp Package] gkazhoya | tutorials:beginner:controlling_turtlesim_2 [2019/07/09 18:06] – [The code] gkazhoya | ||
---|---|---|---|
Line 5: | Line 5: | ||
**Previous Tutorial:** [[tutorials: | **Previous Tutorial:** [[tutorials: | ||
**Next Tutorial:** [[tutorials: | **Next Tutorial:** [[tutorials: | ||
+ | |||
===== Updating the dependencies ===== | ===== Updating the dependencies ===== | ||
- | In this tutorial we will re-use the package '' | ||
- | ==== Updating | + | ==== ROS dependencies ==== |
+ | |||
+ | In this tutorial we will re-use the package '' | ||
+ | |||
+ | ==== ASDF dependencies | ||
- | Now open '' | + | Now open '' |
<code lisp> | <code lisp> | ||
- | (defsystem cram-beginner-tutorial | + | (defsystem cram-my-beginner-tutorial |
- | :depends-on (roslisp cram-language turtlesim-msg cl-transforms geometry_msgs-msg) | + | :depends-on (roslisp cram-language turtlesim-msg |
:components | :components | ||
((:module " | ((:module " | ||
Line 26: | Line 30: | ||
We also want to add '' | We also want to add '' | ||
<code lisp> | <code lisp> | ||
- | (defpackage : | + | (defpackage :cram-my-beginner-tutorial |
- | (: | + | (:nicknames :tut) |
- | (:use #:cpl #: | + | (:use :cpl :roslisp : |
</ | </ | ||
===== Writing the communication glue code ===== | ===== Writing the communication glue code ===== | ||
- | Now it's time to use roslisp to connect to turtlesim. Turtlesim creates one ROS topic namespace per turtle. For each turtle name ('' | + | Now it's time to use roslisp to connect to turtlesim. Turtlesim creates one ROS topic namespace per turtle. For each turtle name ('' |
==== The code ==== | ==== The code ==== | ||
Open the file '' | Open the file '' | ||
- | |||
- | === hydro === | ||
<code lisp> | <code lisp> | ||
Line 50: | Line 52: | ||
(defvar *pose-sub* nil "pose ROS subscriber" | (defvar *pose-sub* nil "pose ROS subscriber" | ||
(defvar *cmd-vel-pub* nil " | (defvar *cmd-vel-pub* nil " | ||
+ | |||
+ | (defvar *pen-srv* nil "name of ROS service for controlling the pen") | ||
+ | |||
(defun init-ros-turtle (name) | (defun init-ros-turtle (name) | ||
- | "subscribes | + | "Subscribes |
+ | `name' specifies the name of the turtle." | ||
(setf *color-sub* (subscribe (format nil " | (setf *color-sub* (subscribe (format nil " | ||
" | " | ||
#' | #' | ||
(setf *pose-sub* (subscribe (format nil " | (setf *pose-sub* (subscribe (format nil " | ||
- | " | + | |
- | | + | #' |
(setf *cmd-vel-pub* (advertise (format nil " | (setf *cmd-vel-pub* (advertise (format nil " | ||
- | " | + | " |
+ | (setf *pen-srv* (concatenate ' | ||
(defun color-cb (msg) | (defun color-cb (msg) | ||
Line 71: | Line 78: | ||
(defun send-vel-cmd (lin ang) | (defun send-vel-cmd (lin ang) | ||
- | " | + | " |
- | (publish *cmd-vel-pub* (make-message " | + | (publish *cmd-vel-pub* |
- | | + | ;; short syntax: |
- | :x lin) | + | ;; |
- | | + | ;; more understandable syntax: |
- | | + | |
- | </ | + | :linear (make-msg " |
- | + | | |
- | === groovy and older === | + | |
- | + | (defun | |
- | <code lisp> | + | "Function |
- | (in-package :tut) | + | (call-service |
- | + | :r r | |
- | (defvar *color-value* (make-fluent :name : | + | :g g |
- | (defvar *turtle-pose* (make-fluent :name : | + | :b b |
- | + | : | |
- | (defvar *color-sub* nil "color subscription client" | + | :off off)) |
- | (defvar *pose-sub* nil "pose subscription client" | + | </ |
- | (defvar *cmd-vel-pub* nil " | + | |
- | + | ||
- | (defun | + | |
- | "subscribes | + | |
- | (setf *color-sub* (subscribe (format nil " | + | |
- | " | + | |
- | #' | + | |
- | (setf *pose-sub* (subscribe (format nil " | + | |
- | " | + | |
- | #'pose-cb)) | + | |
- | (setf *cmd-vel-pub* (advertise (format nil " | + | |
- | " | + | |
- | + | ||
- | (defun color-cb (msg) | + | |
- | " | + | |
- | (setf (value *color-value*) msg)) | + | |
- | + | ||
- | (defun pose-cb (msg) | + | |
- | " | + | |
- | (setf (value *turtle-pose*) msg)) | + | |
- | + | ||
- | (defun send-vel-cmd (lin ang) | + | |
- | " | + | |
- | (publish *cmd-vel-pub* (make-message " | + | |
- | | + | |
- | | + | |
- | </ | + | |
=== The code explained === | === The code explained === | ||
- | In '' | + | In '' |
We use callback functions '' | We use callback functions '' | ||
Line 127: | Line 107: | ||
===== Experimenting in the REPL ===== | ===== Experimenting in the REPL ===== | ||
- | Now let's try it out. Open your Lisp REPL and make sure that you loaded the system '' | + | Now let's try it out. Open your Lisp REPL and make sure that you loaded the system '' |
<code lisp> | <code lisp> | ||
- | CL-USER> (ros-load: | + | CL-USER> (ros-load: |
... | ... | ||
CL-USER> (in-package :tut) | CL-USER> (in-package :tut) | ||
Line 154: | Line 134: | ||
<code lisp> | <code lisp> | ||
- | TUT> (init-ros-turtle "/turtle1" | + | TUT> (init-ros-turtle " |
</ | </ | ||
Line 249: | Line 229: | ||
=== Moving the turtle === | === Moving the turtle === | ||
- | Let's see if we can also move the turtle from LISP. Try the following: | + | Let's see if we can also move the turtle from Lisp. Try the following: |
<code lisp> | <code lisp> | ||
TUT> (dotimes (i 10) (send-vel-cmd 1 1) (sleep 1)) | TUT> (dotimes (i 10) (send-vel-cmd 1 1) (sleep 1)) | ||
</ | </ | ||
- | We use the '' | + | We use the '' |
- | == Next == | ||
+ | === Setting the pen === | ||
+ | |||
+ | We also can change how the turtle writes on the background. Try: | ||
+ | <code lisp> | ||
+ | TUT> (call-set-pen 255 0 0 10 0) | ||
+ | </ | ||
+ | |||
+ | We use the '' | ||
+ | |||
+ | |||
+ | == Next == | ||
Now that we have functions and fluents to connect to the turtlesim, let's implement some simple plans. | Now that we have functions and fluents to connect to the turtlesim, let's implement some simple plans. | ||
[[tutorials: | [[tutorials: |