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文件规范。

相关推荐
LS_learner9 小时前
小智机器人CMakeLists编译文件解析
嵌入式硬件·机器人
国货崛起9 小时前
波兰发布世界首个双足肌肉骨骼机器人,细节高度模拟人类生物特征
机器人
IT观察9 小时前
优艾智合获批广东省复合协作机器人工程技术研究中心
机器人
shichaog9 小时前
腿足机器人之十一- 深度强化学习
机器人
猫头虎-人工智能14 小时前
NVIDIA A100 SXM4与NVIDIA A100 PCIe版本区别深度对比:架构、性能与场景解析
gpt·架构·机器人·aigc·文心一言·palm
Leiditech__15 小时前
人工智能时代电子机器人静电问题及电路设计防范措施
人工智能·嵌入式硬件·机器人·硬件工程
JAMES费15 小时前
figure机器人技术架构的演进初探——Helix人形机器人控制的革新
架构·机器人
【云轩】18 小时前
基于STM32与BD623x的电机控制实战——从零搭建无人机/机器人驱动系统
stm32·机器人·无人机
AWS官方合作商1 天前
Amazon Lex:AI对话引擎重构企业服务新范式
人工智能·ai·机器人·aws
风口猪炒股指标2 天前
想象一个AI保姆机器人使用场景分析
人工智能·机器人·deepseek·深度思考