• 小鱼送你个URDF模板|省出来时间过七夕


    之前小鱼做了一键安装,节省了不少小伙伴的时间来追求爱情,成功脱单 今年七夕小鱼没啥好送的,送你一个URDF模板,

    地址在: https://fishros.com/d2lros2/#/humble/codebook/urdf/xacro

    原文如下

    URDF默认格式是纯文本的,我们并不能在其中加入计算公式和定义,用URDF定义一个机器人模型会导致整个文件非常冗长,使用Xacro工具可以解决这个问题。

    Xacro是urdf的定义和生成工具,你按照Xacro提供的方式定义可以复用的模型描述块,之后就可以直接调用这些描述,最后使用xacro指令生成最终的urdf模型了。

    1.添加模板

    小鱼这里提供了常用的xacro描述定义的代码块,你可以直接引入的你的工程里进行使用。

    在你的功能包里新建xacro_template.xacro文件,复制粘贴下面的内容到其中。

    
    <robot xmlns:xacro="http://ros.org/wiki/xacro" xmlns:fishros="http://fishros.com">
      <xacro:macro name="box_inertia" params="m w h d">
        <inertial>
          <origin xyz="0 0 0" rpy="${pi/2} 0 ${pi/2}"/>
          <mass value="${m}"/>
          <inertia ixx="${(m/12) * (h*h + d*d)}" ixy="0.0" ixz="0.0" iyy="${(m/12) * (w*w + d*d)}" iyz="0.0" izz="${(m/12) * (w*w + h*h)}"/>
        inertial>
      xacro:macro>
    
      <xacro:macro name="cylinder_inertia" params="m r h">
        <inertial>
          <origin xyz="0 0 0" rpy="${pi/2} 0 0" />
          <mass value="${m}"/>
          <inertia ixx="${(m/12) * (3*r*r + h*h)}" ixy = "0" ixz = "0" iyy="${(m/12) * (3*r*r + h*h)}" iyz = "0" izz="${(m/2) * (r*r)}"/>
        inertial>
      xacro:macro>
    
      <xacro:macro name="sphere_inertia" params="m r">
        <inertial>
          <mass value="${m}"/>
          <inertia ixx="${(2/5) * m * (r*r)}" ixy="0.0" ixz="0.0" iyy="${(2/5) * m * (r*r)}" iyz="0.0" izz="${(2/5) * m * (r*r)}"/>
        inertial>
      xacro:macro>
    
      <xacro:macro name="sphere_visual" params="r origin_r origin_p origin_y">
        <visual>
          <origin xyz="0 0 0" rpy="${origin_r} ${origin_p} ${origin_y}"/>
          <geometry>
              <sphere radius="${r}"/>
          geometry>
          <material name="blue">
            <color rgba="0.0 0.0 0.8 1.0"/>
          material> 
        visual>
      xacro:macro>
    
    <xacro:macro name="sphere_collision" params="r origin_r origin_p origin_y">
        <collision>
          <origin xyz="0 0 0" rpy="${origin_r} ${origin_p} ${origin_y}"/>
          <geometry>
              <sphere radius="${r}"/>
          geometry>
            <material name="green">
                <color rgba="0.0 0.8 0.0 1.0"/>
            material>
        collision>
    xacro:macro>
    
    
    <xacro:macro name="box_visual" params="w d h origin_r origin_p origin_y">
        <visual>
          <origin xyz="0 0 0" rpy="${origin_r} ${origin_p} ${origin_y}"/>
          <geometry>
              <box size="${w} ${d} ${h}" />
          geometry>
          <material name="blue">
            <color rgba="0.0 0.0 0.8 1.0"/>
          material> 
        visual>
    xacro:macro>
    
    <xacro:macro name="box_collision" params="w d h origin_r origin_p origin_y">
        <collision>
          <origin xyz="0 0 0" rpy="${origin_r} ${origin_p} ${origin_y}"/>
          <geometry>
              <box size="${w} ${d} ${h}" />
          geometry>
            <material name="green">
                <color rgba="0.0 0.8 0.0 1.0"/>
            material>
        collision>
    xacro:macro>
    
    
    <xacro:macro name="cylinder_visual" params="r h origin_r origin_p origin_y">
        <visual>
          <origin xyz="0 0 0" rpy="${origin_r} ${origin_p} ${origin_y}"/>
          <geometry>
             <cylinder length="${h}" radius="${r}"/>
          geometry>
          <material name="blue">
            <color rgba="0.0 0.0 0.8 1.0"/>
          material> 
        visual>
    xacro:macro>
    
    
    <xacro:macro name="cylinder_collision" params="r h origin_r origin_p origin_y">
        <collision>
          <origin xyz="0 0 0" rpy="${origin_r} ${origin_p} ${origin_y}"/>
          <geometry>
             <cylinder length="${h}" radius="${r}"/>
          geometry>
          <material name="blue">
            <color rgba="0.0 0.0 0.8 1.0"/>
          material> 
        collision>
    xacro:macro>
    
    
    robot>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102

    2.使用模板生成URDF

    接着你可以新建你的机器人模型描述文件,比如fishbot.urdf.xacro,之后你就可以在你的描述文件中调用小鱼提供的模板,快速的定义机器人。

    比如创建一个正方体的base_link,并导入惯性矩阵。

    
    <robot name="fishbot" xmlns:xacro="http://ros.org/wiki/xacro">
      <xacro:include filename="xacro_template.xacro" />
    
      <link name="base_link">
        <xacro:box_visual w="0.809" d="0.5" h="0.1" origin_r="0" origin_p="0" origin_y="0"/>
        <xacro:box_collision w="0.809" d="0.5" h="0.1" origin_r="0" origin_p="0" origin_y="0"/>
        <xacro:box_inertia m="1.0" w="0.809" d="0.5" h="0.1"/>
      link>
    
    robot>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    上面w,d,h,代表长宽高,m代表质量。 用于引入小鱼提供的模板。

    接着我们就可以通过xacro指令将其变成正常的urdf,打开终端,进入fishbot.urdf.xacro同级目录,输入指令xacro fishbot.urdf.xacro -o fishbot.urdf,即可生成fishbot.urdf,正常生成后的内容如下。

    
    
    
    
    
    <robot name="fishbot" xmlns:fishros="http://fishros.com">
      <link name="base_link">
        <visual>
          <origin rpy="0 0 0" xyz="0 0 0"/>
          <geometry>
            <box size="0.809 0.5 0.1"/>
          geometry>
          <material name="blue">
            <color rgba="0.0 0.0 0.8 1.0"/>
          material>
        visual>
        <collision>
          <origin rpy="0 0 0" xyz="0 0 0"/>
          <geometry>
            <box size="0.809 0.5 0.1"/>
          geometry>
          <material name="green">
            <color rgba="0.0 0.8 0.0 1.0"/>
          material>
        collision>
        <inertial>
          <origin rpy="1.5707963267948966 0 1.5707963267948966" xyz="0 0 0"/>
          <mass value="1.0"/>
          <inertia ixx="0.021666666666666667" ixy="0.0" ixz="0.0" iyy="0.07537341666666666" iyz="0.0" izz="0.055373416666666675"/>
        inertial>
      link>
    robot>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    这就是xacro的神奇之处,将短短的三行定义根据规则生成长长的URDF,关于xacro的详细使用可以参考 http://ros.org/wiki/xacro 。

  • 相关阅读:
    【云原生 · DevOps】DevOps 解决方案
    21、设计模式之备忘录模式(Memento)
    Django搭建一个简易GPT网站
    面试题-5
    基于人工蜂群算法的新型概率密度模型的无人机路径规划(Matlab代码实现)
    安卓期中汇总回顾
    原博客迁移
    python协程入门实战详解
    flume安装
    windows设置自启动服务使用winsw
  • 原文地址:https://blog.csdn.net/qq_27865227/article/details/126165643