ros2/ros 4轮2驱机器人xacro/urdf文件示例代码

这个实验中最重要的是:colcon build 之后要记得source install/setup.bash.否则修改的文件是不会更新的。知道了吧

html 复制代码
<robot name="half" xmlns:xacro="http://wiki.ros.org/wiki/xacro">
  <xacro:property name="PI" value="3.1415926"/><!--定义一个变量PI,后边用来调用的-->
  <xacro:property name="base_footprint_radius" value="0.001"/>
  <xacro:property name="base_radius" value="0.1"/>
  <xacro:property name="base_length" value="0.08"/>
  <xacro:property name="ground_clearance" value="0.015"/>
  <material name="black">
    <color rgba="0.3 0.3 0.0 0.5"/>
  </material>    <!--注意了这个不能少-->
  <link name="base_footprint">
    <visual>
      <geometry>
          <sphere radius="${base_footprint_radius}"/>
      </geometry>
    </visual>
  </link>
  <link name="base">
    <visual>
      <geometry>
        <cylinder radius="${base_radius}" length="${base_length}"/>
      </geometry>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <material name="yellow">
        <color rgba="0.3 0.3 0.0 0.5"/>
      </material>
    </visual>
  </link>
  <joint name="base2base_footprint" type="fixed">
    <parent link="base_footprint"/>
    <child link="base"/>
    <origin xyz="0 0 ${ground_clearance+base_length/2}"/>
  </joint>
  <xacro:property name="wheel_radius" value="0.0325"/>
  <xacro:property name="wheel_length" value="0.015"/>
  <xacro:macro name="add_wheel" params="name flag">
    <link name="${name}_wheel">
      <visual>
        <geometry>
          <cylinder radius="${wheel_radius}" length="${wheel_length}"/>
        </geometry>
        <origin xyz="0.0 0.0 0.0" rpy="${PI/2} 0 0"/>
        <material name="black"/>
      </visual>
    </link>
    <joint name="${name}_wheel2base" type="continuous">
      <parent link="base"/>
      <child link="${name}_wheel"/>
      <origin xyz="0 ${flag*base_radius} ${-(ground_clearance+base_length/2-wheel_radius)}"/>
      <axis xyz="0 1 0"/>
    </joint>
  </xacro:macro>
  <xacro:add_wheel name="left" flag="1"/>
  <xacro:add_wheel name="right" flag="-1"/>
  <xacro:property name="support_wheel_radius" value="0.0075">
  </xacro:property>
  <xacro:macro name="add_support_wheel" params="name flag">
    <link name="${name}_wheel">
      <visual>
        <geometry>
            <sphere radius="${support_wheel_radius}"/>
        </geometry>
        <origin xyz="0 0 0" rpy="0.0 0.0 0.0"/>
        <material name="black">
        </material>
      </visual>
    </link>
    <joint name="${name}_wheel2base" type="continuous">
      <parent link="base"/>
      <child link="${name}_wheel"/>
      <origin xyz="${flag*(base_radius-support_wheel_radius)} 0 ${-(base_length/2+ground_clearance/2)}"/>
      <axis xyz="1 1 1"/>
    </joint>
  </xacro:macro>
  <xacro:add_support_wheel name="front" flag="1"/>
  <xacro:add_support_wheel name="back" flag="-1"/>
</robot>

上述代码中的:<material name="black">

<color rgba="0.3 0.3 0.0 0.5"/>

</material>

这段代码不能少,(虽然说少了也可以,但是不正常了)

不少之后没有任何错误,说明符合urdf文件,xacro文件规范。

相关推荐
房开民19 小时前
使用海康机器人相机SDK实现基本参数配置(C语言示例)
c语言·数码相机·机器人
南山二毛19 小时前
机器人控制器开发(导航算法——导航栈关联坐标系)
人工智能·架构·机器人
猫头虎1 天前
2025最新超详细FreeRTOS入门教程:第一章 FreeRTOS移植到STM32
stm32·单片机·嵌入式硬件·机器人·硬件架构·freertos·嵌入式实时数据库
xwz小王子1 天前
Nature Machine Intelligence 基于强化学习的磁性微型机器人自主三维位置控制
机器人·微型机器人
IoT砖家涂拉拉1 天前
从“找新家”到“走向全球”,布尔云携手涂鸦智能开启机器人新冒险
人工智能·机器人·ai助手·ai智能体·ai机器人
纪元A梦1 天前
贪心算法应用:机器人路径平滑问题详解
贪心算法·机器人
陈敬雷-充电了么-CEO兼CTO1 天前
具身智能模拟器:解决机器人实机训练场景局限与成本问题的创新方案
大数据·人工智能·机器学习·chatgpt·机器人·具身智能
KlipC1 天前
特斯拉“宏图计划4.0”发布!马斯克:未来80%价值来自机器人
机器人
点云SLAM2 天前
PyTorch 中.backward() 详解使用
人工智能·pytorch·python·深度学习·算法·机器学习·机器人
vickycheung32 天前
基于RK3576的机房巡检机器人应用解决方案
机器人