Before launching Baxter Simulator in Gazebo, it is important to check the ROS environment variables. To start up Baxter Simulator, use the following commands to get to your Baxter catkin workspace and run your baxter.sh
script with the sim
parameter:
$ cd ~/baxter_ws $ ./baxter.sh sim
The command prompt should return with the following tag appended to the beginning of the prompt:
[baxter - http://localhost:11311]
You are now talking to the simulated Baxter! At this point, check your ROS environment with the following command:
$ env | grep ROS
Within the output screen text, look for the following result:
ROS_MASTER_URI=http://localhost:11311 ROS_IP= <your workstation's IP address>
or
ROS_HOSTNAME=<your workstation's hostname>
The ROS_HOSTNAME
field need not be present.
If the ROS_IP
or ROS_HOSTNAME
environment variables does not match the IP address of your workstation (use ifconfig
to check), type exit
to stop communication with the simulated Baxter. Then, edit the baxter.sh
script to change the your_ip
variable (near line 26) to the current IP address of your workstation. To continue, repeat the preceding steps for a final check.
If there are issues with Baxter's hardware, software, or network, refer to the general Baxter troubleshooting website at http://sdk.rethinkrobotics.com/wiki/Troubleshooting.
The baxter.sh
script should run without errors and the ROS environment variables should be correct. The next section covers running Baxter Simulator for the first time.
To start Baxter Simulator, go to the baxter_ws
workspace and run the Baxter shell script with the sim parameter specified:
$ cd ~/baxter_ws $ ./baxter.sh sim
Next, call the roslaunch
command to start the simulation with controllers:
$ roslaunch baxter_gazebo baxter_world.launch
The following lines are some of the results you will see on the screen while Baxter Simulator starts:
NODES / base_to_world (tf2_ros/static_transform_publisher) baxter_emulator (baxter_sim_hardware/baxter_emulator) baxter_sim_io (baxter_sim_io/baxter_sim_io) baxter_sim_kinematics_left (baxter_sim_kinematics/kinematics) baxter_sim_kinematics_right (baxter_sim_kinematics/kinematics) gazebo (gazebo_ros/gzserver) gazebo_gui (gazebo_ros/gzclient) robot_state_publisher (robot_state_publisher/robot_state_publisher) urdf_spawner (gazebo_ros/spawn_model) /robot/ controller_spawner (controller_manager/controller_manager) controller_spawner_stopped (controller_manager/controller_manager) left_gripper_controller_spawner_stopped (controller_manager/controller_manager) right_gripper_controller_spawner_stopped (controller_manager/controller_manager)
As the process is completing, look for these lines:
[ INFO] [1502315064.794924787, 0.718000000]: Simulator is loaded and started successfully [ INFO] [1502315064.905968083, 0.830000000]: Robot is disabled [ INFO] [1502315064.906014361, 0.830000000]: Gravity compensation was turned off
The following screenshot should appear with Baxter in a disabled state:
If Gazebo and Baxter Simulator fail to appear or there are red error messages in your terminal window, refer to the Gazebo Troubleshooting page provided by Rethink Robotics at http://sdk.rethinkrobotics.com/wiki/Gazebo_Troubleshooting.
For an introduction to using Gazebo, refer to the Gazebo section in Chapter 2, Creating Your First Two-Wheeled ROS Robot (in Simulation). In that section, the various Gazebo display panels, menus, and toolbars are explained. Gazebo uses similar cursor/mouse controls to those of rviz, and these mouse/cursor actions are described in the Introducing rviz: Mouse control section of Chapter 2, Creating Your First Two-Wheeled ROS Robot (in Simulation).
In the previous screenshot, the World panel on the left shows the Models element open to reveal the two models in the environment: ground_plane
and baxter
. Under the baxter
model, all of Baxter's links are listed and you are welcome to select the links to explore the details about each one. The screenshot also shows the smaller display window that contains Baxter's IO. Baxter's four navigators, located one on each side of the rear torso (near the shoulders) and one on each arm, are also shown. The oval-shaped navigators have three push buttons, one of which is a scroll wheel. Baxter's cuff buttons are also shown in this window. There are two buttons and one touch sensor on each cuff.
The terminal window in which the roslaunch
command was performed will be unable to run additional commands, so a second terminal window should be opened. In this window, go to the baxter_ws
workspace and run the baxter.sh
script with the sim
parameter:
$ cd ~/baxter_ws $ ./baxter.sh sim
Baxter (in simulation) is initially in a disabled state. To confirm this, use the enable_robot
script from the baxter_tools
package using the following command:
$ rosrun baxter_tools enable_robot.py -s
The screen should display the following output:
ready: False enabled: False stopped: False error: False estop_button: 0 estop_source: 0
To enable Baxter, use the same enable_robot
script with the -e
option:
$ rosrun baxter_tools enable_robot.py -e
The output is similar to the following:
[INFO] [1501189929.999603, 141.690000]: Robot Enabled
Confirm Baxter is enabled using the following command:
$ rosrun baxter_tools enable_robot.py -s
The output should be as follows:
ready: False enabled: True stopped: False error: False estop_button: 0 estop_source: 0
At this point, a cheat sheet for use with Baxter Simulator is provided for you to use with the example programs that follow. The commands for launching, enabling, and untucking are provided here for your reference:
Baxter Simulator cheat sheet
To launch Baxter Simulator in Gazebo, use the following commands:
$ cd ~/baxter_ws $ ./baxter.sh sim $ roslaunch baxter_gazebo baxter_world.launch
For subsequent terminal windows, use the following commands:
$ cd ~/baxter_ws $ ./baxter.sh sim
To enable the robot, use the following command:
$ rosrun baxter_tools enable_robot.py -e
To enable and set the arms in a known position, use the following command:
$ rosrun baxter_tools tuck_arms.py -u
With Baxter enabled, the next section describes some of Baxter's example scripts using the head display screen.
Rethink Robotics has provided a collection of example scripts to demonstrate Baxter's interfaces and features. These example programs are contained in the baxter_examples
package and work primarily with a real Baxter and the SDK. A portion of these example programs also work with Baxter Simulator.
The baxter_examples
are Python programs that access Baxter's hardware and functionality through the baxter_interface
package. The baxter_examples
programs are written to demonstrate how to use Baxter interfaces. The baxter_interface
package is a repository of Python APIs to use for interacting with the Baxter Research Robot. The repository contains a set of classes that are ROS wrappers to communicate with and control Baxter's hardware and functionality. These Python classes are built on top of the ROS API layer.
This section and the following sections present SDK example programs that can be used with Baxter Simulator. To find additional information on the SDK example programs implemented in Baxter Simulator, visit the following website:
http://sdk.rethinkrobotics.com/wiki/API_Reference#tab=Simulator_API
The first example program will display an image on Baxter's (simulated) head display screen using the following command:
$ rosrun baxter_examples xdisplay_image.py --file=`rospack find baxter_examples`/share/images/baxterworking.png
Your screen should look similar to the following screenshot:
The xdisplay_image.py
program locates the baxterworking.png
image in the specified location under the baxter_examples
package. This image data is published as a sensor_msgs/Image
ROS message. The display image must be a .png
or .jpg
file with a display resolution of 1024 x 600 pixels or smaller. Smaller images will appear in the top-left corner of Baxter's display screen.
A second baxter_examples
program will cause Baxter Simulator to nod Baxter's head up and down, then turn from side to side:
$ rosrun baxter_examples head_wobbler.py
The simulated Baxter should randomly wobble its head until Ctrl + C is pressed. The movement demonstrates both the head pan motion (side to side) and head nod motion (up and down) interfaces. This program shows the use of the baxter_interface
Head
class (head.py
). The command_nod
function is called first to trigger an up-down motion of the head. It is not possible to command a specific angle for the nod motion. The pan motion is achieved with several calls to the set_pan
function, with random angles provided as the parameter.
Another baxter_examples
program also moves Baxter's head through a set of head positions and velocities. The Head Action Client Example demonstrates the use of the Head Action Server. This example is similar to the head wobble just performed, but provides a good example of an action server and client interaction. If you wish to try the Head Action Client Example, access the instructions and explanations at http://sdk.rethinkrobotics.com/wiki/Head_Action_Client_Example.
The next section will demonstrate some example programs for Baxter's arms.
The focus of the following sections will be on Baxter's arms. The section on Bringing Baxter Simulator to life should be completed before starting these sections. Baxter Simulator should be launched in Gazebo and the robot should be enabled with its arms untucked.
The following example programs use the baxter_interface Limb
class (limb.py
) to create instances for each arm. The joint_names
function is used to return an array of all the joints in the limb.
Commands for the joint control modes are via ROS messages within the baxter_core_msgs
package. To move the arm, a JointCommand
message must be published on the robot/limb/<left/right>/joint_command
topic. Within the JointCommand
message, a mode field indicates the control mode to the Joint Controller Boards as POSITION_MODE
, VELOCITY_MODE
, TORQUE_MODE
, or RAW_POSITON_MODE
.
In the following sections, various methods of controlling Baxter's arm movements will be demonstrated. After several example arm programs have been presented, a Python script to command Baxter's arms to move to a home position will be shown.
Before Baxter's arms can be commanded, Baxter must be enabled. This can be accomplished using the tuck_arms.py
program provided by Rethink using the untuck
option. During untuck movements, Baxter's collision avoidance is disabled. Collision avoidance for Baxter Simulator is modeled as part of the URDF. Each of Baxter's links is tagged with a collision block that is slightly larger than the visual element. For further details on the URDF, collision blocks, and the visual element, refer to Chapter 2, Creating Your First Two-Wheeled ROS Robot (in Simulation). Typically, when the position of the arms places the collision blocks into contact with each other, the collision model detects the contact and ends the movement to avoid the parts colliding.
To command Baxter into the untuck position, use the following command:
$ rosrun baxter_tools tuck_arms.py –u
The output should be similar to the following:
[INFO] [1501190044.262606, 0.000000]: Untucking arms [INFO] [1501190044.375889, 255.938000]: Moving head to neutral position [INFO] [1501190044.376109, 255.938000]: Untucking: Arms already Untucked; Moving to neutral position. [INFO] [1501190045.673587, 257.234000]: Finished tuck
The following screenshot shows the simulated Baxter in the untucked position:
To explore Baxter's untuck operation further, refer to the Rethink wiki Tuck Arms Tool information at http://sdk.rethinkrobotics.com/wiki/Tuck_Arms_Tool.
The next example program provides a demonstration of controlling Baxter's arms using joint velocity control. The joint control modes for Baxter's arms were described in the Baxter's arms section. In simulation, the joint velocity wobble can be observed by typing the following command:
$ rosrun baxter_examples joint_velocity_wobbler.py
The output should be as follows:
Initializing node... Getting robot state... Enabling robot... [INFO] [1501190177.147845, 388.564000]: Robot Enabled Moving to neutral pose... Wobbling. Press Ctrl-C to stop...
The program will begin by moving Baxter's arms to a preset neutral starting position. Next, random velocity commands are sent to each arm to create a sinusoidal motion across both limbs. The following screenshot shows Baxter's neutral starting position:
To explore Baxter's arms' joint_velocity_wobbler
operation in more detail, refer to the Rethink wiki Wobbler Example information at http://sdk.rethinkrobotics.com/wiki/Wobbler_Example.
Baxter's arms can also be controlled with keyboard keystrokes. Keystrokes are used to control the positions of the joints, with each keyboard key mapped to either increase or decrease the angle of one of Baxter's 14 arm joints. Keys on the right side of the keyboard are mapped to Baxter's left arm and keys on the left side of the keyboard are mapped to Baxter's right arm.
This example demonstrates another of Baxter's arm control modes: joint position control.
To start the keyboard joint position control example, use the following command:
$ rosrun baxter_examples joint_position_keyboard.py
This should be the output on the screen:
Initializing node... Getting robot state... Enabling robot... [INFO] [1501190427.217690, 638.355000]: Robot Enabled Controlling joints. Press ? for help, Esc to quit. key bindings: Esc: Quit ?: Help
|
|
This example program uses a joystick to control Baxter's arms. The joint_position_joystick
program uses the ROS drivers from the joy
package to interface with a generic Linux joystick. Joysticks with a USB interface are supported by the joy
package. The joy
package creates a joy_node
to generate a sensor_msgs/Joy
message containing the various button-push and joystick-move events.
The first step is to check for the joystick driver package joy
using the following command:
$ rospack find joy
If the ROS package is on the computer, the screen should display this:
/opt/ros/kinetic/share/joy
If it is not, then an error message is displayed:
[rospack] Error: stack/package joy not found
If the joy
package is not present, install it with the following command:
$ sudo apt-get install ros-kinetic-joystick-drivers
For a PS3 joystick controller, you will need the ps3joy
package. Instructions can be found at http://wiki.ros.org/ps3joy/Tutorials/PairingJoystickAndBluetoothDongle.
Next, type the command to start the joint_position_joystick
program using one of the joystick types (xbox
, logitech
, or ps3
):
$ roslaunch baxter_examples joint_position_joystick.launch joystick:=<joystick_type>
We used the Xbox controller joystick in our example; the output is as follows:
... NODES / joy_node (joy/joy_node) rsdk_joint_position_joystick (baxter_examples/joint_position_joystick.py) ... [INFO] [1501196267.914400, 251.752000]: Robot Enabled Press Ctrl-C to quit. rightTrigger: left gripper close rightTrigger: left gripper open leftTrigger: right gripper close leftTrigger: right gripper open leftStickHorz: right inc right_s0 leftStickHorz: right dec right_s0 rightStickHorz: left inc left_s0 rightStickHorz: left dec left_s0 leftStickVert: right inc right_s1 leftStickVert: right dec right_s1 rightStickVert: left inc left_s1 rightStickVert: left dec left_s1 rightBumper: left: cycle joint leftBumper: right: cycle joint btnRight: left calibrate btnLeft: right calibrate function1: help function2: help Press Ctrl-C to stop.
The preceding output shows the Xbox joystick buttons and knobs to move Baxter's joints. The joystick controls two joints at a time on each of Baxter's two arms using the Left Stick and the Right Stick (see the following diagram). The up-down (vertical) control of the stick controls increasing and decreasing one of the joint angles. The side-to-side (horizontal) control increases and decreases another joint angle. The Left Bumper and Right Bumper cycle the joystick control through all of Baxter's arm joints in the order: S0-S1-E0-E1-W0-W1-W2. For example, initially, the Left Stick control will be in command of the (right arm) S0 joint using horizontal direction, and the S1 joint using vertical direction. When the Left Bumper is pressed, the Left Stick horizontal control will command the S1 joint, and the vertical control will command the E0 joint. Cycling the joints continues in a continuous loop, where the S0 joint will be selected after the W2 joint.
The following image and table describe the mapping of the Xbox joystick controls:
Buttons |
Action for RIGHT Arm |
Buttons |
Action for LEFT Arm |
---|---|---|---|
Back |
Help |
Ctrl + C or Ctrl + Z |
Quit |
Left Button (X) |
gripper calibrate |
Right Button (B) |
gripper calibrate |
Top Button (Y) |
none |
Bottom Button (A) |
none |
Left Trigger [PRESS] |
gripper close |
Right Trigger[PRESS] |
gripper close |
Left Trigger [RELEASE] |
gripper open |
Right Trigger[RELEASE] |
gripper open |
Left Bumper |
cycle joints |
Right Bumper |
cycle joints |
Stick Axes |
Action | ||
Left Stick Horizontal |
right: increase/decrease <current joint 1> (S0) | ||
Left Stick Vertical |
right: increase/decrease <current joint 2> (S1) | ||
Right Stick Horizontal |
left: increase/decrease <current joint 1> (S0) | ||
Right Stick Vertical |
left: increase/decrease <current joint 2> (S1) |
In this section, we will create a simple Python script to command Baxter's arms into a specific pose. The following script commands Baxter's arms to a home position, similar to the untuck position. Comments have been placed throughout the code to provide information on the process. Further explanation of this Python code operation is given following the script:
#!/usr/bin/env python """ Script to return Baxter's arms to a "home" position """ # rospy - ROS Python API import rospy # baxter_interface - Baxter Python API import baxter_interface # initialize our ROS node, registering it with the Master rospy.init_node('Home_Arms') # create instances of baxter_interface's Limb class limb_right = baxter_interface.Limb('right') limb_left = baxter_interface.Limb('left') # store the home position of the arms home_right = {'right_s0': 0.08, 'right_s1': -1.00, 'right_w0': -0.67, 'right_w1': 1.03, 'right_w2': 0.50, 'right_e0': 1.18, 'right_e1': 1.94} home_left = {'left_s0': -0.08, 'left_s1': -1.00, 'left_w0': 0.67, 'left_w1': 1.03, 'left_w2': -0.50, 'left_e0': -1.18, 'left_e1': 1.94} # move both arms to home position limb_right.move_to_joint_positions(home_right) limb_left.move_to_joint_positions(home_left) quit()
This code can be placed in a file named home_arms.py.
Then, it can be made executable using the Ubuntu chmod + x
command. Execute this Python script with this terminal command:
$ python home_arms.py
In this script, the rospy
ROS-Python interface package is used to create ROS components from Python code. The rospy
client API provides software routines for initializing the ROS node, Home_Arms
, to invoke the process. The baxter_interface
package provides the API for interacting with Baxter. In the script, we instantiate instances of the Limb
class for both the right and left arms. A Python dictionary is used to assign joint angles to specific joints for both the right and left arms. These joint angle dictionaries are passed to the move_to_joint_positions
method to command the respective arm to the provided position. The move_to_joint_positions
method is also a part of the baxter_interface
package.
Another capability provided by the baxter_examples
programs is the ability to record and play back arm positions. A recorder program captures the time and joint positions in an external file. The armRoutine
filename is used in the following command lines, but you may substitute your own filename instead. After the command for the recorder program is executed, the operator should move Baxter's arms manually or using the keyboard, joystick, ROS commands, or a script. When the operator wishes to end the recording, Ctrl + C or Ctrl + Z must be pressed to stop the recording. The playback program can be executed with the external file passed as a parameter. The playback program will run through the arm positions in the file once and then exit. The following instructions show the commands and the order of operation:
$ rosrun baxter_examples joint_recorder.py -f armRoutine
The output should be as follows:
Initializing node... Getting robot state... Enabling robot... [INFO] [1501198989.301174, 2970.058000]: Robot Enabled Recording. Press Ctrl-C to stop.
At this time, you should use your hands or the joystick, keyboard, Python script, and/or commands to move Baxter's arms. Press Ctrl + C when you are finished moving Baxter's arms. Next, execute the following command to play the file back:
$ rosrun baxter_examples joint_position_file_playback.py -f armRoutine
The output on the screen should be similar to the following:
Initializing node... Getting robot state... Enabling robot... [INFO] [1501199319.366765, 3299.749000]: Robot Enabled Playing back: armRoutine Moving to start position... Record 10462 of 10462, loop 1 of 1 Exiting example...
If the file armRoutine
is brought up in an editor, you should see that it contains data similar to the following:
time,left_s0,left_s1,left_e0,left_e1,left_w0,left_w1,left_w2,left_gripper,right_s0,right_s1,right_e0,right_e1,right_w0,right_w1,right_w2,right_gripper 0.221000,-0.0799704928309,-1.0000362209,-0.745950772448,-0.0499208630966,-1.6948350728,1.03001017593,-0.500000660376,0.0,-1.04466483018,-0.129655442605,1.5342459042,1.94952695585,-0.909650985497,1.03000093981,0.825985250377,0.0 ...
As shown, the first line contains the labels for the data on each of the subsequent rows. As the first label indicates, the first field contains the timestamp. The subsequent fields hold the joint positions for each of the left and right arm joints and grippers.