Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:beginner:controlling_turtlesim_2 [2017/07/18 11:01] cpotutorials:beginner:controlling_turtlesim_2 [2022/02/21 10:08] (current) – [Fluents] schimpf
Line 10: Line 10:
 ==== ROS dependencies ==== ==== ROS dependencies ====
  
-In this tutorial we will re-use the package ''cram_beginner_tutorial'' that you have created in the previous tutorial. For controlling the turtle, we need to depend on the ''turtlesim'' package, since it contains the message definitions we will use. Further, we will want to use the communication functionality of ROS to talk to the ''turtlesim'' from inside Lisp, so we depend on ''roslisp''. Finally, we will have to deal with poses. For that, we want to use the package ''cl_transforms'' and ''geometry_msgs''. Add these dependencies to the ''package.xml'' as described in [[http://wiki.ros.org/catkin/Tutorials/CreatingPackage|Package creation]]. You can find the resulting code in the corresponding [[https://github.com/cram-code/cram_tutorials/tree/master/cram_beginner_tutorial|Github repo]].+In this tutorial we will re-use the package ''cram_my_beginner_tutorial'' that you have created in the previous tutorial. For controlling the turtle, we need to depend on the ''turtlesim'' package, since it contains the message definitions we will use. Further, we will want to use the communication functionality of ROS to talk to the ''turtlesim'' from inside Lisp, so we depend on ''roslisp''. Finally, we will have to deal with poses. For that, we want to use the package ''cl_transforms'' and ''geometry_msgs''. Add these dependencies to the ''package.xml'' as described in [[http://wiki.ros.org/catkin/Tutorials/CreatingPackage|Package creation]]. You can find the resulting code in the corresponding [[https://github.com/cram2/cram/tree/master/cram_tutorials/cram_beginner_tutorial|Github repo]].
  
 ==== ASDF dependencies ==== ==== ASDF dependencies ====
  
-Now open ''cram-beginner-tutorial.asd'' and update the system dependencies to include the system  ''roslisp'', ''turtlesim-msg'', ''geometry_msgs-msg'' and ''cl-transforms''. The systems that correspond to the messages of a package are always named like the package name with a ''-msg'' suffix. Your system should now look like this:+Now open ''cram-my-beginner-tutorial.asd'' and update the system dependencies to include the system  ''roslisp'', ''turtlesim-msg'', ''turtlesim-srv'', ''geometry_msgs-msg'' and ''cl-transforms''. The systems that correspond to the messages of a package are always named like the package name with a ''-msg'' suffix. Your system should now look like this:
  
 <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 turtlesim-srv cl-transforms geometry_msgs-msg)
   :components   :components
   ((:module "src"   ((:module "src"
Line 30: Line 30:
 We also want to add ''roslisp'' and ''cl-transforms'' to our namespace in the file ''package.lisp'' so that we don't have to specify the namespace each time we use a function from that package in our code. We also want to add ''roslisp'' and ''cl-transforms'' to our namespace in the file ''package.lisp'' so that we don't have to specify the namespace each time we use a function from that package in our code.
 <code lisp> <code lisp>
-(defpackage :cram-beginner-tutorial+(defpackage :cram-my-beginner-tutorial
   (:nicknames :tut)   (:nicknames :tut)
   (:use :cpl :roslisp :cl-transforms))   (:use :cpl :roslisp :cl-transforms))
Line 87: Line 87:
                          :angular (make-msg "geometry_msgs/Vector3" :z ang))))                          :angular (make-msg "geometry_msgs/Vector3" :z ang))))
                                                    
-(defun set-pen (r g b width off)+(defun call-set-pen (r g b width off)
   "Function to call the SetPen service."   "Function to call the SetPen service."
   (call-service *pen-srv* 'turtlesim-srv:SetPen   (call-service *pen-srv* 'turtlesim-srv:SetPen
Line 94: Line 94:
                 :b b                 :b b
                 :width width                 :width width
-                :off off))                         +                :off off))
 </code>                            </code>                           
                                                                                
Line 107: 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 ''cram-beginner-tutorial'' and switched to the package ''tut'', hint:+Now let's try it out. Open your Lisp REPL and make sure that you loaded the system ''cram-my-beginner-tutorial'' and switched to the package ''tut'', hint:
  
 <code lisp> <code lisp>
-CL-USER> (ros-load:load-system "cram_beginner_tutorial" :cram-beginner-tutorial)+CL-USER> (ros-load:load-system "cram_my_beginner_tutorial" :cram-my-beginner-tutorial)
 ... ...
 CL-USER> (in-package :tut) CL-USER> (in-package :tut)
Line 134: Line 134:
  
 <code lisp> <code lisp>
-TUT> (init-ros-turtle "/turtle1")+TUT> (init-ros-turtle "turtle1")
 </code> </code>
  
Line 231: Line 231:
 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) (wait-duration 1))
 </code> </code>
 We use the ''send-vel-cmd'' function that we defined in ''control-turtlesim.lisp''. We send the same command 10 times, once every second. The turtle should now move along a circle. We use the ''send-vel-cmd'' function that we defined in ''control-turtlesim.lisp''. We send the same command 10 times, once every second. The turtle should now move along a circle.
Line 240: Line 240:
 We also can change how the turtle writes on the background. Try: We also can change how the turtle writes on the background. Try:
 <code lisp> <code lisp>
-TUT> (set-pen 255 0 0 10 0)+TUT> (call-set-pen 255 0 0 10 0)
 </code> </code>
  
-We use the ''set-pen'' function, also defined in ''control-turtlesim.lisp''. The line the turtle leaves on the ground should be red. Try moving the turtle, either with the teleop or the ''send-vel-cmd'' function.+We use the ''call-set-pen'' function, also defined in ''control-turtlesim.lisp''. The line the turtle leaves on the ground should be red. Try moving the turtle, either with the teleop or the ''send-vel-cmd'' function.