当前位置:   article > 正文

ros小车模型_ros差速小车模型

ros差速小车模型

autolabor

1.urdf文件格式及指令

geometry标签下的文件指令

<link name ="base_link">
        <visual>
            <!--1.形状-->
            <geometry>
                    <!--lifangti -->
                    <!-- <box size ="0.3 0.2 0.1" /> -->
                    <!--圆柱-->
                    <!-- <cylinder radius="0.1" length="0.2" /> -->
                    <!-- 球体 -->
                    <!-- <sphere radius="1"/> -->
                    <!-- 皮肤 -->
                    <mesh filename= "package://urdf01_rviz/meshes/autolabor_mini.stl"/>
            </geometry>
            <!--2.偏移量-->

            <!-- xyz rpy倾斜弧度 -->
            <origin xyz="0 0 0" rpy="1.57 0 1.57" />
            <!-- 3.颜色 -->
            <!-- 0~1范围内   红 绿 兰 透明度 -->
            <material name ="car_color">
                <color rgba ="0 0 1 1" />
            </material>
        </visual>

    </link>
  • 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

launch文件

<launch>

    <!-- 在参数服务器启用urdf文件,设置参数 -->
    <param name="robot_description" textfile="$(find urdf01_rviz)/urdf/urdf/demo02_link.urdf" />

    <!-- 启动 rviz -->
    <node pkg="rviz" type="rviz" name="rviz" args="-d $(find urdf01_rviz)/config/show_mycar.rviz" />

</launch>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

joint指令

<robot name ="mycar">
<!-- footprint -->
<link name ="base_footprint">
        <visual>
            <!--1.形状-->
            <geometry>
                    <!--lifangti -->
                    <box size ="0.001 0.001 0.001" />
            </geometry>
            <!--2.偏移量-->
            <!-- xyz rpy倾斜弧度 -->
            <material name ="car_color">
                <color rgba ="0.5 0 1 0.5" />
            </material>
        </visual>
    </link>
    



<!-- 1/底盘 -->
    <link name ="base_link">
        <visual>
            <!--1.形状-->
            <geometry>
                    <!--lifangti -->
                    <box size ="0.3 0.2 0.1" />
            </geometry>
            <!--2.偏移量-->
            <!-- xyz rpy倾斜弧度 -->
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name ="car_color">
                <color rgba ="0.5 0 1 0.5" />
            </material>
        </visual>
    </link>
    
<!-- 2/摄像头link -->
    <link name ="camera">
        <visual>
            <!--1.形状-->
            <geometry>
                    <!--lifangti -->
                    <box size ="0.02 0.05 0.05" />
            </geometry>
            <origin xyz="0 0 0.025" rpy="0 0 0" />
            <material name ="camera_color">
                <color rgba ="0 0.5 0.5 1" />
            </material>
        </visual>
    </link>
    <!-- base_link与base_footprint -->
     <joint name ="link2footprint" type="fixed">
<!-- 父极link -->
        <parent link ="base_footprint"/>
<!-- 子集link -->
        <child link ="base_link"/>
<!-- 设置偏移量 -->
        <origin xyz ="0 0 0.05" rpy ="0 0 0"/>
    </joint>

<!-- 3/关节 -->
    <joint name ="camera2base" type="continuous">
<!-- 父极link -->
        <parent link ="base_link"/>
<!-- 子集link -->
        <child link ="camera"/>
<!-- 设置偏移量 -->
        <origin xyz ="0.12 0 0.05" rpy ="0 0 0"/>
<!-- 设置关节旋转参考的坐标轴 -->
        <axis xyz ="0 0 1"/>

    </joint>
</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

launch

<launch>

    <!-- 在参数服务器启用urdf文件,设置参数 -->
    <param name="robot_description" textfile="$(find urdf01_rviz)/urdf/urdf/demo03_joint.urdf" />

    <!-- 关节状态/机器人状态-->
    <node pkg="rviz" type="rviz" name="rviz" args="-d $(find urdf01_rviz)/config/show_mycar.rviz" />
    <node pkg="joint_state_publisher" type="joint_state_publisher" name="joint_state_publisher"/>
    <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher"/>
    <node pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" name="joint_state_publisher_gui"/>


</launch>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

base_footprint 使得长方体地面可接触到坐标系的0 0 0 位置。

2.xacro使用及指令

为实现代码复用

ry@ry-vpc:~/demo05_ws/src/urdf01_rviz/urdf/xacro$ rosrun xacro xacro demo01_helloworld.xacro > demo01_helloworld.urdf
  • 1

生成urdf文件

<robot name ="mycar" xmlns:xacro ="http://wiki.ros.org/xacro">

    <xacro:property name ="footprint_radius" value ="0.001" />
    <link name ="base_footprint">
        <visual>
            <!--1.形状-->
            <geometry>
                    <sphere radius="${footprint_radius}" />
            </geometry>
        </visual>
    </link>
    <!-- <xacro:property name ="base_radius" value="0.1" /> -->
    <xacro:property name ="base_length" value="0.1" />


    <xacro:property name ="lidi" value="0.015" />
    <xacro:property name ="base_joint_2" value="${base_length /2+lidi}" />

    <link name ="base_link">
        <visual>
            <!--1.形状-->
            <geometry>
                    <!--lifangti -->
                    <box size ="0.3 0.2 0.1" />
                    <!-- <cylinder radius="${base_radius}" length="${base_length}" /> -->
            </geometry>
            <!--2.偏移量-->
            <!-- xyz rpy倾斜弧度 -->
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name ="car_color">
                <color rgba ="0.5 0 1 0.5" />
            </material>
        </visual>
    </link>
        <!-- base_link与base_footprint -->
     <joint name ="link2footprint" type="fixed">
<!-- 父极link -->
        <parent link ="base_footprint"/>
<!-- 子集link -->
        <child link ="base_link"/>
<!-- 设置偏移量 -->
        <origin xyz ="0 0 ${base_joint_2}" rpy ="0 0 0"/>
    </joint>

</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

完成后导出urdf文件,在launch文件中修改

    <!-- 在参数服务器启用urdf文件,设置参数 -->
    <param name="robot_description" textfile="$(find urdf01_rviz)/urdf/xacro/demo05_car_base.urdf" />

  • 1
  • 2
  • 3
<!-- 左右轮-->
        <xacro:macro name="wheel_func" params="wheel_name flag">

            <link name ="${wheel_name}_wheel">
                <visual>
                    <geometry>
                        <cylinder radius="0.0325" length="0.015"/>
                    </geometry>
                    <origin xyz ="0 0 0" rpy="${PI/2} 0 0"/>


                    <material name ="wheel_color">
                        <color rgba="0 0 0 0.3"/>
                    </material>
                </visual>
            </link>

            <joint name ="${wheel_name}2link" type="continuous">
                <parent link ="base_link"/>
                <child link ="${wheel_name}_wheel"/>

                <origin xyz="0 ${0.1*flag} ${wheel_joint_z}" rpy ="0 0 0"/>
                <axis xyz ="0 1 0"/>
    </joint>
        </xacro:macro>

        <xacro:wheel_func wheel_name="left" flag="1"/>
        <xacro:wheel_func wheel_name="right" flag="-1"/> 


  • 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

万向轮

         [ERROR] [1657868037.145190151]: Failed to build tree: child link [back] of joint [back2base_link] not found

  • 1
  • 2

   </xacro:macro>

        <xacro:wheel_func wheel_name="left" flag="1"/>
        <xacro:wheel_func wheel_name="right" flag="-1"/> 

        <!-- 万向轮 -->
        <xacro:property name="small_wheel_radius" value="0.0075"/>
        <xacro:property name ="small_joint_z" value="${(base_length/2+lidi-small_wheel_radius)*-1}"/>


        <xacro:macro name ="small_wheel_func" params ="small_wheel_name flag">

        <!-- 添加万向轮(支撑轮) -->
    <!--
        参数
            形状: 球体
            半径: 0.75 cm
            颜色: 黑色

        关节设置:
            x = 自定义(底盘半径 - 万向轮半径) = 0.1 - 0.0075 = 0.0925(cm)
            y = 0
            z = 底盘长度 / 2 + 离地间距 / 2 = 0.08 / 2 + 0.015 / 2 = 0.0475 
            axis= 1 1 1

    -->
    <link name="${small_wheel_name}_wheel">
        <visual>
            <geometry>
                <sphere radius="${small_wheel_radius}" />
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="black">
                <color rgba="0.0 0.0 0.0 1.0" />
            </material>
        </visual>
    </link>
    <joint name="${small_wheel_name}2base_link" type="continuous">
        <parent link="base_link" />
        <child link="${small_wheel_name}_wheel" />
        <origin xyz="${0.08*flag} 0 ${small_joint_z}" rpy="0 0 0" />

        <!-- <origin xyz="-0.0925 0 -0.0475" /> -->
        <axis xyz="1 1 1" />
    </joint>
</xacro:macro>
        <xacro:small_wheel_func small_wheel_name="front" flag="1"/>
        <xacro:small_wheel_func small_wheel_name="back" flag="-1"/>

  • 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


## 雷达

```xml

<robot name ="mycar" xmlns:xacro ="http://wiki.ros.org/xacro">
    <!-- 参数 -->
  <!-- 支架尺寸,关节偏移量
  雷达尺寸,雷达关节偏移量 -->
<xacro:property name="support_radius" value="0.01"/>
<xacro:property name="support_length" value="0.15"/>
<xacro:property name="laser_radius" value="0.03"/>
<xacro:property name="laser_length" value="0.05"/>

<xacro:property name="joint_support_x" value="0"/>
<xacro:property name="joint_support_y" value="0"/>
<xacro:property name="joint_support_z" value="${base_length/2+laser_length/2}"/>
<!-- 车体高度/2+支架高度/2 -->

<xacro:property name="joint_laser_x" value="0"/>
<xacro:property name="joint_laser_y" value="0"/>
<xacro:property name="joint_laser_z" value="${support_length/2+laser_length/2}"/>
<!-- 支架高副/2+雷达高度/2 -->


    <!-- 雷达支架 -->
    <link name="support">
        <visual>
            <geometry>
                <cylinder radius="${support_radius}"  length="${support_length}" />
            </geometry>
            <material name="yellow">
                <color rgba="0.8 0.5 0 0.5"/>

            </material>
        </visual>
    </link>

    <joint name="support2base" type="fixed">

        <parent link ="base_link"/>
        <child link ="support"/>
        <origin xyz="${joint_support_x} ${joint_support_y} ${joint_support_z}" rpy="0 0 0"/>

    </joint>
    
    <!-- 雷达自身 -->
    <link name="laser">
        <visual>
            <geometry>
                <cylinder radius="${laser_radius}"  length="${laser_length}" />
            </geometry>
            <material name="pink">
                <color rgba="0.8 0.5 0 0.5"/>

            </material>
        </visual>
    </link>

    <joint name="laser2support" type="fixed">

        <parent link ="support"/>
        <child link ="laser"/>
        <origin xyz="${joint_laser_x} ${joint_laser_y} ${joint_laser_z}" rpy="0 0 0"/>

    </joint>

</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

## 相机

```xml
```cpp
<robot name ="mycar" xmlns:xacro ="http://wiki.ros.org/xacro">

<!-- 参数 -->
    <xacro:property name="camera_length" value="0.02"/>   <!-- 厚度 -->
    <xacro:property name="camera_width" value="0.05"/>
    <xacro:property name="camera_height" value="0.05"/>
    <xacro:property name="joint_camera_x" value="0.08"/>
    <xacro:property name="joint_camera_y" value="0"/>
    <xacro:property name="joint_camera_z" value="${base_length /2+camera_height/2}"/>


<!-- 设计连杆和关节 -->
    <link name="camera">
        <visual>
            <geometry>
                <box size="${camera_length} ${camera_width} ${camera_height}"/>

            </geometry>
            <material name ="black">
                <color rgba="0 0 0 0.8"/>

            </material>
        </visual>
    </link>

    <joint name="camera2base" type="fixed">
        <parent link="base_link"/>
        <child link="camera"/>
        <origin xyz="${joint_camera_x} ${joint_camera_y} ${joint_camera_z}" rpy="0 0 0"/>
    </joint>

</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
<robot name ="mycar" xmlns:xacro ="http://wiki.ros.org/xacro">
<!-- 包含底盘 摄像头与雷达的xacro文件 -->
<xacro:include filename="demo05_car_base.urdf.xacro"/>
<xacro:include filename="demo06_car_camera.urdf.xacro"/>
<xacro:include filename="demo07_car_laser.urdf.xacro"/>


</robot>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在这里插入图片描述

launch运行xacro文件报错

RLException: Invalid <param> tag: Cannot load command parameter [robot_description]: command [['/opt/ros/noetic/lib/xacro/xacro', '/home/ry/demo05_ws/src/urdf01_rviz/urdf/xacro/car.urdf.xacro']] returned with code [2]. 

Param xml is <param name="robot_description" command="$(find xacro)/xacro  $(find urdf01_rviz)/urdf/xacro/car.urdf.xacro"/>
The traceback for the exception was written to the log file
  • 1
  • 2
  • 3
  • 4

因为是noetic版本的问题,

<arg name="model" default="$(find carsim_discription)/urdf/model.urdf"/>
<param name="robot_description" command="$(find xacro)/xacro $(arg model)" />

  • 1
  • 2
  • 3

上述两行代码我用了还是报错。
将car.xacro集成的文件通过rosrun xacro 命令转换为urdf文件也是一种方式,再在launch文件中引用urdf文件,也是解决launch文件调用xacro时报错的问题的一种方法。

<param name="robot_description" textfile="$(find urdf01_rviz)/urdf/xacro/car.urdf" />//在launch文件中这么写
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/642815
推荐阅读
相关标签
  

闽ICP备14008679号