$\color{white}\colorbox{FE9227}{Attaining mastery and unlocking the full potential of knowledge!}$
$$▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100%
Now it's time to create moveable joints for the robot. First, we are going to change all the fixed
joint types back to continuous
. This will break your tf2
tree in RVIZ, but that’s okay because we are going to be adding Gazebo
plugins to fix this.
Navigate to your tracer_wheels.xacro
, tracer_castor_joints.xacro
, and tracer_castor_wheels.xacro
and change all the previously fixed
joint types back to continuous.
Next, we are going to be creating a new XACRO
called tracer_gazebo.xacro
.
cd ~/humble_ws/src/tracer/tracer_description/models/xacro
touch tracer_gazebo.xacro
Open your tracer_gazebo.xacro
e the following code:
<?xml version="1.0"?>
<robot name="tracer_gazebo" xmlns:xacro="<http://wiki.ros.org/xacro>">
<xacro:macro name="diff_drive_control">
<gazebo>
<plugin name="gazebo_ros_diff_drive" filename="libgazebo_ros_diff_drive.so">
<ros>
<namespace>${robot_namespace}</namespace>
</ros>
<!-- Update rate in Hz -->
<update_rate>50</update_rate>
<!-- wheels -->
<left_joint>left_wheel_joint</left_joint>
<right_joint>right_wheel_joint</right_joint>
<!-- kinematics -->
<wheel_separation>${wheelbase}</wheel_separation>
<wheel_diameter>${2*wheel_radius}</wheel_diameter>
<!-- limits -->
<max_wheel_torque>20</max_wheel_torque>
<max_wheel_acceleration>1.0</max_wheel_acceleration>
<!-- input -->
<command_topic>cmd_vel</command_topic>
<!-- output -->
<publish_odom>true</publish_odom>
<publish_odom_tf>true</publish_odom_tf>
<publish_wheel_tf>true</publish_wheel_tf>
<odometry_topic>odom</odometry_topic>
<odometry_frame>odom</odometry_frame>
<robot_base_frame>base_link</robot_base_frame>
</plugin>
<plugin name="gazebo_ros_joint_state_publisher"
filename="libgazebo_ros_joint_state_publisher.so">
<ros>
<namespace>${robot_namespace}</namespace>
</ros>
<!-- Update rate in Hertz -->
<update_rate>2</update_rate>
<!-- Name of joints in the model whose states will be published. -->
<joint_name>front_right_castor_joint</joint_name>
<joint_name>front_right_wheel_joint</joint_name>
<joint_name>front_left_castor_joint</joint_name>
<joint_name>front_left_wheel_joint</joint_name>
<joint_name>rear_right_castor_joint</joint_name>
<joint_name>rear_right_wheel_joint</joint_name>
<joint_name>rear_left_castor_joint</joint_name>
<joint_name>rear_left_wheel_joint</joint_name>
</plugin>
</gazebo>
</xacro:macro>
</robot>
The <gazebo>
tag declares that the code following should be used in association with the Gazebo
server. Within the <gazebo>
tags, we are first going to call on the libgazebo_ros_diff_drive.so
plugin.
<gazebo>
<plugin name="gazebo_ros_diff_drive" filename="libgazebo_ros_diff_drive.so">
We then declare the robot namespace to match our launch
file, and define an update rate for the controller. Next, we start passing configuration parameters into the plugin. We define the <left_joint>
and <right_joint>
such that the wheels will turn in the right frame. We also set the wheelbase
, and wheel_diameter
parameters such that odometry
can be generated from the plugin.
<left_joint>left_wheel_joint</left_joint>
<right_joint>right_wheel_joint</right_joint>
<!-- kinematics -->
<wheel_separation>${wheelbase}</wheel_separation>
<wheel_diameter>${2*wheel_radius}</wheel_diameter>
Next, we set some wheel limitations for torque and acceleration, and define the command topic for control. In this case, we are setting the topic to cmd_vel
.
<max_wheel_torque>20</max_wheel_torque>
<max_wheel_acceleration>1.0</max_wheel_acceleration>
<!-- input -->
<command_topic>cmd_vel</command_topic>
Finally, we define the outputs we want the plugin to generate. We set the differential drive plugin to publish odometry, the transform between the base_link
and odometry
(will be used in NAVIGATION ODOMETRY TUTORIAL), and most importantly for our tf2
tree we set the plugin to publish_wheel_tf
.
We also pass through the odometry topic, frame, and robot base link.