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

相关推荐
人类发明了工具14 小时前
【机器人-激光雷达】点云时间运动补偿
算法·机器人
bd_jc18 小时前
ubuntu24.04 ros2 rosdep相关
ros2·ubuntu24.04
金智维科技官方1 天前
RPA财务机器人为企业高质量发展注入动能
人工智能·机器人·rpa·财务
沫儿笙1 天前
安川机器人tag焊接怎么节省保护气
人工智能·物联网·机器人
xwz小王子1 天前
Science Robotics 综述 | 超材料机器人:重塑“体”与“智”的未来!
机器人·超材料
强化学习与机器人控制仿真1 天前
RSL-RL:开源人形机器人强化学习控制研究库
开发语言·人工智能·stm32·神经网络·机器人·强化学习·模仿学习
xwz小王子1 天前
【Adv.Sci.】北京航空航天大学【一个切向灵敏的触觉传感器揭示了杆滑机制,增强了机器人触觉感知】
机器人·触觉感知
ModestCoder_2 天前
ROS Bag与导航数据集技术指南
开发语言·人工智能·自然语言处理·机器人·具身智能
Mr.Winter`2 天前
基于Proto3和单例模式的系统参数配置模块设计(附C++案例实现)
c++·人工智能·单例模式·机器人
中國龍在廣州3 天前
现在人工智能的研究路径可能走反了
人工智能·算法·搜索引擎·chatgpt·机器人