Defining ROS_CONTROLLERS

Finally, we need to port the plugins that are needed to establish communication between Gazebo and ROD. For these, we need to create another file called gazebo_essentials_base.xacro that will contain the <Gazebo> tags.

In the created file, add the following gazebo_ros_control plugin:

<Gazebo>
<plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
<robotNamespace>/</robotNamespace>
<controlPeriod>0.001</controlPeriod>
<legacyModeNS>false</legacyModeNS>
</plugin>
</Gazebo>

The robot's differential drive plugin is as follows:

<Gazebo>

<plugin name="diff_drive_controller" filename="libgazebo_ros_diff_drive.so">
<legacyMode>false</legacyMode>
<alwaysOn>true</alwaysOn>
<updateRate>1000.0</updateRate>
<leftJoint>front_left_wheel_joint, rear_left_wheel_joint</leftJoint>
<rightJoint>front_right_wheel_joint, rear_right_wheel_joint</rightJoint>
<wheelSeparation>0.5</wheelSeparation>
<wheelDiameter>0.2</wheelDiameter>
<wheelTorque>10</wheelTorque>
<publishTf>1</publishTf>
<odometryFrame>map</odometryFrame>
<commandTopic>cmd_vel</commandTopic>
<odometryTopic>odom</odometryTopic>
<robotBaseFrame>base_link</robotBaseFrame>
<wheelAcceleration>2.8</wheelAcceleration>
<publishWheelJointState>true</publishWheelJointState>
<publishWheelTF>false</publishWheelTF>
<odometrySource>world</odometrySource>
<rosDebugLevel>Debug</rosDebugLevel>
</plugin>

</Gazebo>

The friction property for the wheels as macros is as follows:

<xacro:macro name="wheel_friction" params="prefix ">
<Gazebo reference="${prefix}_wheel">
<mu1 value="1.0"/>
<mu2 value="1.0"/>
<kp value="10000000.0" />
<kd value="1.0" />
<fdir1 value="1 0 0"/>
</Gazebo>
</xacro:macro>

The call macro in the robot file is as follows:

<xacro:wheel_friction prefix="front_left"/>
<xacro:wheel_friction prefix="front_right"/>
<xacro:wheel_friction prefix="rear_left"/>
<xacro:wheel_friction prefix="rear_right"/>

Now that we have defined the macros for our robot, along with the Gazebo plugins, let's add them to our robot file. This can be easily done by just adding the following two lines in the robot file inside the <robot> macro tag:

<xacro:include filename="$(find robot_description)/urdf/robot_base_essentials.xacro" />
<xacro:include filename="$(find robot_description)/urdf/gazebo_essentials_base.xacro" />

Now that the URDFs are complete, let's configure the controllers. Let's create the following config file to define the controllers we are using. For this, let's go to our workspace, go inside the config folder we created, and create a controller config file, as shown here:

$ cd ~/chapter3_ws/src/robot_description/config/
$ gedit control.yaml

Now, copy the code that's available in this book's GitHub repository, https://github.com/PacktPublishing/ROS-Robotics-Projects-SecondEdition/blob/master/chapter_3_ws/src/robot_description/config/control.yaml, into the file. Now that we have completed our robot_base model, let's test it in Gazebo.

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

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