## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= ## descriptive title for the tutorial ## title = PR2 Simulator Workshop ## multi-line description to be displayed in search ## description = This tutorial explores basic PR2 interfaces while using the PR2 in simulation. ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link= ## next.1.link= ## what level user is this tutorial for ## level= BeginnerCategory ## keywords = #################################### <> <> == The PR2 Simulator == In this lab, you will be working mostly with a simulated version of the PR2. First, set your `ROS_MASTER_URI` to localhost and export `ROBOT` as sim to trigger the system to use [[pr2_machine|pr2_machine/sim.machine]] by typing the following or adding them to your `.bashrc`: {{{ export ROS_MASTER_URI=http://localhost:11311 export ROBOT=sim }}} In a separate terminal, launch the simulator using the roslaunch command. The roslaunch command operates on special xml files to launch your ROS programs and executables. {{{ roslaunch pr2_gazebo pr2_empty_world.launch }}} {{attachment:pr2_empty_world.png}} You should see the simulator come up in a separate window. Recall we can use the ROS tools to explore the ROS API and environment that the simulator offers. The main concepts that you should focus on are the following: * ROS nodes - ROS nodes are the executables in ROS. ROS is designed to be lightweight specifically so that you can easily wrap your library into a ROS node. * ROS topics and services - topics and services are the two means of communication between nodes. Services let you query a node and receive a reply for your query within one call while topics let you broadcase information that other nodes can subscribe and listen to. * ROS parameter server - the ROS parameter server stores parameters and lets you access them at runtime. The parameter server provides an easy interface to configure your nodes using parameters specified in launch files. == PR2 Dashboard == You can use [rqt_pr2_dashboard] to visualize the state of the robot {{{ rosmake rqt_pr2_dashboard rosrun rqt_pr2_dashboard rqt_pr2_dashboard }}} {{attachment:pr2_dashboard.png}} Feel free to browse around and see what's available while running the simulator. Notice that motor diagnostics, breakers and runstops are not simulated by the simulator. == Robot Visualization == By now you should be familiar rviz so you can visualize everything from the robot model to sensor data. Start rviz in a separate terminal: 1. Start up [[rviz]] {{{ rosrun rviz rviz }}} (you will have to do this twice the very first time you start rviz on a fresh install) 1. Click on the Add button and choose "Robot Model" from the drop-down list. Click "OK". 1. If the simulator is not running, start the simulator. 1. Click on the field next to the "Fixed Frame" field. From the drop-down list, choose "/base_link" as your fixed frame. (More about these frames in workshop). 1. You should see the robot in the visualizer window now. {{attachment:rviz.png}} Explore the other things you can add using the Add button. E.g., click on the camera and set the image topic to /wide_stereo/left/image_rect_color to see the rectified image from left wide stereo camera. {{attachment:wide_stereo_left_rect_color.png}} == Controlling the PR2 Mobile Base == In addition to driving the PR2 with the joystick, you can drive the PR2 around using the keyboard quite easily as well. (You need to keep the window in which you launch this node in focus while you drive the robot around). {{{ roslaunch pr2_teleop teleop_keyboard.launch }}} What topic do you think the command to the base controller is going out on? Use the ROS tools you have learnt about so far to display the command going to the base controller. Also display the odometric frame in rviz. == PR2 Laser Tilt Service Call Example == You can invoke the tilt laser trajectory by making a service call on the robot or in simulation, for example: {{{ rosservice call laser_tilt_controller/set_periodic_cmd '{ command: { header: { stamp: 0 }, profile: "linear" , period: 3 , amplitude: 1 , offset: 0 }}' }}} Use rviz to visualize the laser scans produced under ROS topic `tilt_scan`. == Controlling the PR2 Arm (C-Turtle ONLY) == /!\ Please note this controller is no longer offered in diamondback. For moving PR2 gripper in diamondback, please see [[pr2_controllers/Tutorials/Moving the gripper|this tutorial]]. We can control the arm from the command line by publishing messages to actions. As an example, we will try to open the PR2's right gripper. First we need to find the appropriate topic. {{{ rostopic list | grep r_gripper }}} We see that there is a topic called "/r_gripper_controller/command", which seems like a good choice. Let's see what type of message it requires. {{{ rostopic info /r_gripper_controller/command }}} From this we see that we need to produce a message of type "pr2_controllers_msgs/Pr2GripperCommand". The following command allows us to see the details of this message. {{{ rosmsg show pr2_controllers_msgs/Pr2GripperCommand }}} In order to command the gripper, we need to supply a floating point position and max_effort value. We now have enough information to open the gripper by publishing a message to "r_gripper_controller/command" using the "pr2_controllers_msgs/Pr2GripperCommand" message {{{ rostopic pub r_gripper_controller/command pr2_controllers_msgs/Pr2GripperCommand "{position: 0.06, max_effort: 100.0}" }}} == PR2 Navigation Stack Demo == Details of the PR2 navigation stack will be covered later, but for now, we can use it to take the simulated PR2 for a test drive. To do so, you will have to first rosmake the necessary components {{{ rosmake pr2_navigation_perception pr2_navigation_teleop pr2_navigation_global fake_localization amcl map_server }}} Create a launch script for starting all necessary navigation components, and save it as ~/pr2_nav_tutorial.launch: {{{ }}} And roslaunch the script: {{{ roslaunch ~/pr2_nav_tutorial.launch }}} Startup rviz for navigation {{{ roslaunch pr2_navigation_global rviz_move_base.launch }}} {{attachment:rviz_move_base.png}} p This brings up the 2D navigation stack with a "blank" map. Next, click on '''2D Pose Estimate''' button on top of the screen and click+drag any location in the area marked in white to specify an initial pose estimate. Click on the '''2D Nav Goal''' button and click+drag the mouse on the area to set a navigation goal. The robot will begin to drive towards the goal you have just chosen, but notice that in this particular test case, the red arrows (AMCL cloud) does not converge due to lack of obstacles. {{attachment:rviz_move_base_diverge.png}} == Building a Custom Object for Testing == In the next exercise, we'll create an URDF object and spawn it in simulation. Copy and past the following code block into a file named `drawer.urdf`: {{{#!xml GazeboWorlds/StereoProjectionPattern false Gazebo/Green false 0.02 0.01 Gazebo/Red false Gazebo/Green false 0.02 0.01 Gazebo/Red false true 100.0 top_drawer_knob top_drawer_knob_pose /base_link true drawer set_drawer_pose_topic set_drawer_pose_service /base_link 0 0 0 0 0 0 0 0 0 0 0 0 }}} Next, select File-->Reset in the Gazebo GUI to reset simulation. Then spawn the object URDF by calling {{{ rosrun gazebo spawn_model -urdf -file drawer.urdf -model drawer1 -x 1.0 }}} and the drawer should appear before the PR2 {{attachment:pr2_drawer.png}} == Adding an STL Mesh Object in Simulation == You can also use trimeshes as visual and collision bodies for objects in simulation. For example, here's a [[http://sketchup.google.com/3dwarehouse/download?mid=2a94366f2020aabd9bf6576bfdf7d207&rtyp=zip&fn=table&ctyp=other&ts=1202485736000|table from the Google 3D warehouse]]. Unfortunately boxturtle version of Gazebo does not support exported formats from Google 3D warehouse, so you must convert it to a `STL` mesh. The COLLADA file has been converted to a STL file [[attachment:simulator_gazebo/Tutorials/table.stl|here]] for your convenience. Save this file in [[gazebo_worlds]]/Media/models, {{{ cp table.stl `rospack find gazebo_worlds`/Media/models/ }}} Next, create an [[urdf]] file called `table.urdf` {{{ Gazebo/LightWood }}} Note that the Center of mass is placed near the center of the table top given the STL mesh origin {{attachment:table_meshlab.png}} . Start the PR2 in an empty world {{{ roslaunch pr2_gazebo pr2_empty_world.launch }}} and spawn the table in simulation {{{ rosrun gazebo spawn_model -urdf -file table.urdf -model table -x 1.0 -y 0.5 -z 0.3 }}} spawn a cup on the table {{{ rosrun gazebo spawn_model -gazebo -file `rospack find gazebo_worlds`/objects/coffee_cup.model -model coffee_cup -x 1.2 -z 1 }}} {{attachment:pr2_table_cup.png}} ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE