Ask Your Question

Why can't my URDF be like my SDF in rviz?

asked 2021-08-13 14:28:55 -0500

kak13 gravatar image

updated 2022-03-25 17:41:10 -0500

lucasw gravatar image

So, basically...I learned that ROS2 foxy does not support SDF with plugins and ROS2. So, I had to re-update one for URDF instead of SDF. I made SDF enitrely from Gazebo11.

So, the question is why can't I put wheels on the box? Take a look at this URDF code:

<?xml version="1.0"?>
<robot name="my_robot" xmlns:xacro="">

  <!-- Define robot constants -->
  <xacro:property name="base_width" value="0.2159"/>
  <xacro:property name="base_length" value="0.1524"/>
  <xacro:property name="base_height" value="0.10795"/>

  <xacro:property name="wheel_radius" value="0.0325"/>
  <xacro:property name="wheel_width" value="0.02"/>
  <xacro:property name="wheel_ygap" value="0.088"/>
  <xacro:property name="wheel_zoff" value="0.05"/>
  <xacro:property name="wheel_xoff" value="0.1"/>

  <xacro:property name="caster_xoff" value="0.14"/>

 <!-- Robot Base -->
  <link name="base_link">
    <box size="0.2159 0.1524 0.10795"/>
      <material name="Cyan">
    <color rgba="0 1.0 1.0 1.0"/>

  <!-- Robot Footprint -->
  <link name="base_footprint"/>

  <joint name="base_joint" type="fixed">
    <parent link="base_link"/>
    <child link="base_footprint"/>
    <origin xyz="0.0 0.0 ${-(wheel_radius+wheel_zoff)}" rpy="0 0 0"/>

    <!-- Wheels -->
  <xacro:macro name="wheel" params="prefix x_reflect y_reflect">
    <link name="${prefix}_link">
    <origin xyz="0 0 0" rpy="${pi/2} 0 0"/>
        <cylinder radius="${wheel_radius}" length="${wheel_width}"/>
    <material name="Gray">
      <color rgba="0.5 0.5 0.5 1.0"/>

    <joint name="${prefix}_joint" type="continuous">
      <parent link="base_link"/>
      <child link="${prefix}_link"/>
      <origin xyz="${x_reflect*wheel_xoff} ${y_reflect*(base_width/6+wheel_ygap)} ${-wheel_zoff}" rpy="0 0 0"/>
      <axis xyz="0 1 0"/>

  <xacro:wheel prefix="drivewhl_rl" x_reflect="-1" y_reflect="1" />
  <xacro:wheel prefix="drivewhl_rr" x_reflect="-1" y_reflect="-1" />
  <xacro:wheel prefix="drivewhl_fl" x_reflect="1" y_reflect="1" />
  <xacro:wheel prefix="drivewhl_fr" x_reflect="1" y_reflect="-1" /> 


The model look like this

image description

As for my SDF code and picture like this:

        <link name='chassis'>
        <pose>0 0 .1 0 0 0</pose>
        <collision name='collision'>
              <size>0.2159 0.1524 0.10795</size>

        <visual name='visual'>
              <size>0.2159 0.1524 0.10795</size>

    <link name="front_left_wheel">
    <pose>0.1 0.088 0.05 0 1.5707 1.5707</pose>
    <collision name="collision">
    <visual name="visual">
          <length> ...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-08-16 08:00:45 -0500

Delb gravatar image

The wheels aren't attached to the box on your urdf because this formula is wrong :

y_reflect*(base_width/6+wheel_ygap) = +/- 0.12398333333

The correct way to calculate y_wheel is :

y_wheel =  y_reflect * (base_length/2 + wheel_width/2) = +/- 0.0862

Which is almost equal to your wheel_ygap (0.088) which is the same value for the link you've defined in the sdf file :

<pose>0.1 0.088 0.05 0 1.5707 1.5707</pose>
edit flag offensive delete link more


Oh my god! You have a beautiful soul!

It worked! (for some reason, it wouldn't let me upload the image but its literally same as SDF now)

I have another question if you don't mind :)

How do you set variable in urdf for ros to control single joint using python?

kak13 gravatar image kak13  ( 2021-08-16 10:55:56 -0500 )edit

Glad it worked. If you have another question you should create a new one to explain your issue, what you want to achieve and what you've tried so far.

Delb gravatar image Delb  ( 2021-08-17 02:22:45 -0500 )edit

Your Answer

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

Add Answer

Question Tools



Asked: 2021-08-13 14:28:55 -0500

Seen: 98 times

Last updated: Aug 16 '21