Ask Your Question
1

No /odom or /cmd_vel topics when using diff drive plugin

asked 2021-07-20 09:14:47 -0500

vertical_beef576 gravatar image

Hi, I have created a two wheeled model and have added the gazebo differential drive plugin to the urdf file. However, when I spawn the robot into gazebo and view the topics in a terminal (with "ros2 topic list") there isn't the /odom or /cmd_vel topics (which I would expect). How would I fix this and make the topics appear? Any help is much appreciated.

Below is my urdf code:

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="self balancing robot">
<xacro:property name="update_rate" value = "10"/>

<xacro:property name="layer_width" value="0.15"/>
<xacro:property name="layer_depth" value="0.1"/>
<xacro:property name="layer_height" value="0.003"/>
<xacro:property name="layer_mass" value="0.054"/>
<xacro:property name="layer_spacing" value="0.12"/>


<xacro:property name="rod_radius" value="0.005"/>
<xacro:property name="rod_length" value="0.25"/>
<xacro:property name="rod_mass" value="0.055"/>

<xacro:property name="motor_depth" value="0.041"/>
<xacro:property name="motor_width" value="0.041"/>
<xacro:property name="motor_height" value="0.041"/>
<xacro:property name="motor_mass" value="0.319"/>
<xacro:property name="motor_wheel_clearance" value="0.002"/>

<xacro:property name="wheel_mass" value="0.055"/>
<xacro:property name="wheel_radius" value="0.0415"/>
<xacro:property name="wheel_width" value="0.035"/>

<xacro:property name="first_layer_gap" value="${1/2*(layer_height+motor_height) + wheel_radius}"/>

<xacro:macro name="cuboid_inertia" params="mass depth width height">
<inertia ixx="${1/12 * mass * ((width * width) + (height * height))}" ixy="0" ixz="0" 
     iyy="${1/12 * mass * ((depth * depth) + (height * height))}" iyz="0" 
     izz="${1/12 * mass * ((width * width) + (depth * depth))}" />
</xacro:macro>

<xacro:macro name="wheel_inertia" params="mass radius length">
<inertia ixx="${1/12 * mass * (3 * (radius * radius) + (length * length))}" ixy="0" ixz="0" 
     iyy="${1/12 * mass * (3 * (radius * radius) + (length * length))}" iyz="0" 
     izz="${1/2 * mass * (radius * radius)}" />
</xacro:macro>

<xacro:macro name="rod_inertia" params="mass radius length">
<inertia ixx="${1/12 * mass * (3 * (radius * radius) + (length * length))}" ixy="0" ixz="0" 
     iyy="${1/2 * mass * (radius * radius)}" iyz="0" 
     izz="${1/12 * mass * (3 * (radius * radius) + (length * length))}" />
</xacro:macro>

<xacro:macro name="new_layer" params="number">
    <link name="layer_${number}">
        <visual>
            <geometry>
                <box size="${layer_depth} ${layer_width} ${layer_height}"/>
            </geometry>
        </visual>
        <collision>
            <geometry>
                <box size="${layer_depth} ${layer_width} ${layer_height}"/>
            </geometry>
        </collision>
        <inertial>
            <mass value="${layer_mass}"/>
            <origin xyz="0 0 ${first_layer_gap + (number * layer_spacing)}" rpy="0 0 0"/>
            <xacro:cuboid_inertia mass="${layer_mass}" depth="${layer_depth}" width="${layer_width}" height="${layer_height}"/>
        </inertial>
    </link>
</xacro:macro>

<xacro:macro name="new_wheel" params="left_or_right">
    <link name="${left_or_right}_wheel">
        <visual>
            <geometry>
                <cylinder length="${wheel_width}" radius="${wheel_radius}"/>
            </geometry>
        </visual>
        <collision>
            <geometry>
                <cylinder length="${wheel_width}" radius="${wheel_radius}"/>
            </geometry>
        </collision>
        <inertial>
            <mass value="${layer_mass}"/>
            <!--<origin xyz="0 0 0" rpy="0 0 0"/>-->
            <xacro:wheel_inertia mass="${wheel_mass}" radius="${wheel_radius ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-07-20 20:22:54 -0500

Youssef_Lah gravatar image

In this link you will find how to use many gazebo plugins for ROS2 including diff_drive.

Here is an example of how to use diff_drive in ROS2 that worked for me (I assume that you have a valid URDF):

<gazebo>
  <plugin name="diff_drive" filename="libgazebo_ros_diff_drive.so">
            <ros>
                <!--<namespace>/</namespace>-->
            </ros>

            <update_rate>30</update_rate>

            <!-- wheels -->
            <left_joint>wheel_left_joint</left_joint>
            <right_joint>wheel_right_joint</right_joint>

            <!-- kinematics -->
            <wheel_separation>0.6855600</wheel_separation>
            <wheel_diameter>0.4064000</wheel_diameter>

            <!-- limits -->
            <max_wheel_torque>20</max_wheel_torque>
            <max_wheel_acceleration>1.0</max_wheel_acceleration>

            <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_footprint</robot_base_frame>
        </plugin>
        </gazebo>
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2021-07-20 09:14:47 -0500

Seen: 36 times

Last updated: Jul 20