0
$\begingroup$

I am new to ROS2 and am currently working on getting a basic simulation going using Gazebo/ROS2 Humble. My robot's urdf works as expected on rviz when I use joint state publisher to control the wheels. However, when I try using the differential drive plugin rviz doesn't seem to work properly. I don't see the /odom or /cmd_vel topics on ros topic list, and I also don't see the diff_drive node on rqt_graph. I believe this is why the wheels of my robot on rviz aren't working correctly.

There was another very similar question but even when I implemented that I had the same issue as before. I don't believe that it is related to formatting or wrongly naming any tags (outside of the plugin's gazebo tags) since everything works when I run it using joint state publisher.

Question - Why are the /odom and /cmd_vel topics, and the diff_drive node not showing up, and is this why the wheels are not showing up correctly on rviz?

my_robot.urdf.xacro - Main urdf file that I reference in the launch file

 <?xml version="1.0"?> <robot name="my_robot" xmlns:xacro="http://www.ros.org/wiki/xacro"> <xacro:include filename="common_properties.xacro" /> <xacro:include filename="mobile_base.xacro" /> <xacro:include filename="mobile_base_gazebo.xacro" /> </robot> 

mobile_base.xacro - Creates links and joints

<?xml version="1.0"?> <robot xmlns:xacro="http://www.ros.org/wiki/xacro"> <xacro:property name="base_length" value="0.6" /> <xacro:property name="base_width" value="0.4" /> <xacro:property name="base_height" value="0.2" /> <xacro:property name="wheel_radius" value="0.1" /> <xacro:property name="wheel_length" value="0.05" /> <link name="base_footprint" /> <link name="base_link"> <visual> <geometry> <box size="${base_length} ${base_width} ${base_height}" /> </geometry> <origin xyz="0 0 ${base_height / 2.0}" rpy="0 0 0" /> <material name="blue" /> </visual> <collision> <geometry> <box size="${base_length} ${base_width} ${base_height}" /> </geometry> <origin xyz="0 0 ${base_height / 2.0}" rpy="0 0 0" /> </collision> <xacro:box_inertia m="5.0" l="${2*base_length}" w="${2*base_width}" h="${2*base_height}" xyz="0 0 ${base_height / 2.0}" rpy="0 0 0" /> </link> <xacro:macro name="wheel_link" params="prefix"> <link name="${prefix}_wheel_link"> <visual> <geometry> <cylinder radius="${wheel_radius}" length="${wheel_length}" /> </geometry> <origin xyz="0 0 0" rpy="${pi / 2.0} 0 0" /> <material name="grey" /> </visual> <collision> <geometry> <cylinder radius="${wheel_radius}" length="${wheel_length}" /> </geometry> <origin xyz="0 0 0" rpy="${pi / 2.0} 0 0" /> </collision> <xacro:cylinder_inertia m="1.0" r="${2*wheel_radius}" h="${2*wheel_length}" xyz="0 0 0" rpy="${pi / 2.0} 0 0" /> </link> </xacro:macro> <xacro:wheel_link prefix="right" /> <xacro:wheel_link prefix="left" /> <link name="caster_wheel_link"> <visual> <geometry> <sphere radius="${wheel_radius / 2.0}" /> </geometry> <origin xyz="0 0 0" rpy="0 0 0" /> <material name="grey" /> </visual> <collision> <geometry> <sphere radius="${wheel_radius / 2.0}" /> </geometry> <origin xyz="0 0 0" rpy="0 0 0" /> </collision> <xacro:sphere_inertia m="0.5" r="${2*wheel_radius / 2.0}" xyz="0 0 0" rpy="0 0 0" /> </link> <joint name="base_joint" type="fixed"> <parent link="base_footprint" /> <child link="base_link" /> <origin xyz="0 0 ${wheel_radius}" rpy="0 0 0"/> </joint> <joint name="base_right_wheel_joint" type="continuous"> <parent link="base_link" /> <child link="right_wheel_link" /> <origin xyz="${-base_length / 4.0} ${-(base_width + wheel_length) / 2.0} 0" rpy="0 0 0" /> <axis xyz="0 1 0" /> </joint> <joint name="base_left_wheel_joint" type="continuous"> <parent link="base_link" /> <child link="left_wheel_link" /> <origin xyz="${-base_length / 4.0} ${(base_width + wheel_length) / 2.0} 0" rpy="0 0 0" /> <axis xyz="0 1 0" /> </joint> <joint name="base_caster_wheel_joint" type="fixed"> <parent link="base_link" /> <child link="caster_wheel_link" /> <origin xyz="${base_length / 3.0} 0 ${-wheel_radius / 2.0}" rpy="0 0 0" /> </joint> </robot> 

mobile_base_gazebo.xacro

<?xml version="1.0"?> <robot xmlns:xacro="http://www.ros.org/wiki/xacro"> <gazebo reference="base_link"> <material>Gazebo/Blue</material> </gazebo> <gazebo reference="right_wheel_link"> <material>Gazebo/Grey</material> </gazebo> <gazebo reference="left_wheel_link"> <material>Gazebo/Grey</material> </gazebo> <gazebo reference="caster_wheel_link"> <material>Gazebo/Grey</material> <mu1 value="0.1" /> <mu2 value="0.1" /> </gazebo> <gazebo> <plugin name="diff_drive" filename="libgazebo_ros_diff_drive.so"> <ros> <!--<namespace>/</namespace>--> </ros> <update_rate>30</update_rate> <!-- wheels --> <left_joint>base_right_wheel_joint</left_joint> <right_joint>base_left_wheel_joint</right_joint> <!-- kinematics --> <wheel_separation>0.45</wheel_separation> <wheel_diameter>0.2</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> </robot> 

Launch File

<launch> <let name="urdf_path" value="$(find-pkg-share my_robot_description)/urdf/my_robot.urdf.xacro" /> <let name="rviz_config_path" value="$(find-pkg-share my_robot_bringup)/rviz/urdf_config.rviz" /> <node pkg="robot_state_publisher" exec="robot_state_publisher"> <param name="robot_description" value="$(command 'xacro $(var urdf_path)')" /> </node> <include file="$(find-pkg-share gazebo_ros)/launch/gazebo.launch.py"> <arg name="world" value="$(find-pkg-share my_robot_bringup)/worlds/test_world.world" /> </include> <node pkg="gazebo_ros" exec="spawn_entity.py" args="-topic robot_description -entity my_robot" /> <node pkg="rviz2" exec="rviz2" output="screen" args="-d $(var rviz_config_path)" /> </launch> 

Rviz error

enter image description here

ROS2 topic list and rqt_graph

enter image description here

$\endgroup$
2
  • $\begingroup$ Is the plugin loaded correctly? Any console outputs, and is the plugin shown in the gazebo UI? $\endgroup$ Commented Sep 25, 2024 at 7:13
  • $\begingroup$ @ChristophFroehlich I don't see any console outputs other than what is shown when I run the launch file (rviz error image). The plugin shows up on Gazebo, so I believe it is loaded correctly. I didn't do anything to load the plugin other than include the gazebo tag for diff drive in mobile_base_gazebo.xacro, not sure if there was something else that needed to be done. $\endgroup$ Commented Sep 26, 2024 at 2:31

1 Answer 1

0
$\begingroup$

I was able to find a fix. During my ROS2 setup I had apparently never installed gazebo plugins:

sudo apt-get install ros-humble-gazebo-plugins 

So, although the diff_drive node showed up on gazebo under the robot model, the plugin was never installed.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.