Controlling the robot

The differential drive robot is also known as a skid-steer robot, whose motion is defined by separately driven wheels fixed on either side of the robot's body. There is no steering mechanism, which is its primary design, but we can change its direction by varying the relative rate of rotation of its wheels on either side.

Gazebo requires that we program the behaviors of the robot, joints, and sensors in the virtual world. It also provides a skid drive plugin called libgazebo_ros_skid_steer_drive.so to control the differential drive robot, which we designed in the previous section.

We will integrate this controller into the robot model by adding the following lines of code to robot_gazebo.xacro (refer to the complete code in GitHub):

<!-- Drive controller --> 
<gazebo> 
  <plugin name="skid_steer_drive_controller" filename="libgazebo_ros_skid_steer_drive.so"> 
    <updateRate>100.0</updateRate> 
    <robotNamespace>/</robotNamespace> 
    <leftFrontJoint>base_to_wheel1</leftFrontJoint> 
    <rightFrontJoint>base_to_wheel3</rightFrontJoint> 
    <leftRearJoint>base_to_wheel2</leftRearJoint> 
    <rightRearJoint>base_to_wheel4</rightRearJoint> 
    <wheelSeparation>4</wheelSeparation> 
    <wheelDiameter>0.1</wheelDiameter> 
    <robotBaseFrame>base_link</robotBaseFrame> 
    <torque>1</torque> 
    <topicName>cmd_vel</topicName> 
    <broadcastTF>0</broadcastTF> 
  </plugin> 
</gazebo> 

Here, in the preceding code segment, we will primarily perform the configuration setup for the controller where the base_to_wheel1, base_to_wheel2, base_to_wheel3, and base_to_wheel4 joints are selected as wheels to move the robot. In addition, we will also configure the topicName to publish commands so that we can control the robot. In this case, the /cmd_vel topic, which has the sensor_msgs/Twist type as the default, is configured to move the mobile robot.

Finally, we will launch the mobile robot model with the controller and the map using the following command:

$ roslaunch robot_gazebo gazebo.launch model:="'rospack find robot1_description'/urdf/robot_gazebo.xacro"

We will see the robot with the map on the Gazebo screen, as shown in the preceding screenshot of the previous section. Subsequently, we would like to move the robot using the keyboard. Therefore, we will use the teleop_twist_keyboard package that publishes the /cmd_vel topic upon a key press. The teleop-twist-keyboard package must be installed:

$ sudo apt-get install ros-kinetic-teleop-twist-keyboard

Then, we will start the node so that it captures the key press and publishes the command velocities:

$ rosrun teleop_twist_keyboard teleop_twist_keyboard.py

You may have noticed a new terminal with some instructions and the keys to move the robot. The terminal must be in focus or on the top to receive the key inputs:

Moving the robot in the virtual world

Amen! Everything has gone well, and we can drive the robot across the residential space. We can also visualize images from the camera and see the laser sensor's output, as shown in the preceding screenshot.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.116.183