ROS创建机器人的urd模型、rviz可视化

  • Post author:
  • Post category:其他


先说一下我的文件夹结构

这样你就容易理解我后边的步骤

创建工作空间

mkdir -p ~/ros_testurdf/src
cd ~/ros_testurd/src
catkin_init_workspace
cd ..
catkin_make

在工作空间中创建功能包

cd ~/ros_testurdf/src
catkin_create_pkg custom_urdf roscpp urdf tf rviz geometry_msgs
cd ..
catkin_make
echo "source ~/ros_testurdf/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

向功能包添加机器人的urdf模型

roscd custom_urdf
mkdir rviz
mkdir launch
mkdir urdf && cd urdf
gedit four_wheels_car.urdf



four_wheels_car.urdf

文件添加如下的内容:

<?xml version="1.0" ?>
<robot name="four_wheels_car" xmlns:xacro="http://ros.org/wiki/xacro">
    <link name="base_link">
        <visual>
            <geometry>
                <box size="0.2 .3 .1"/>
            </geometry>
            <origin rpy="0 0 0" xyz="0 0 0.05"/>
            <material name="white">
                <color rgba="1 1 1 1"/>
            </material>
        </visual>
    </link>

    <joint name="wheel01_joint" type="fixed">
        <parent link="base_link"/>
        <child link="wheel01_link"/>
        <origin xyz = " 0 0 0" rpy = "0 0 0"/>
    </joint>
    <link name="wheel01_link">
        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.05"/>
            </geometry>
            <origin rpy="0 1.57 0" xyz="0.1 0.1 0"/>
            <material name="black">
                <color rgba="0 0 0 1"/>
            </material>
        </visual>
    </link>

    <joint name="wheel02_joint" type="fixed">
        <parent link="base_link"/>
        <child link="wheel02_link"/>
        <origin xyz = "0 0 0" rpy = "0 0 0"/>
    </joint>
    <link name="wheel02_link">
        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.05"/>
            </geometry>
            <origin rpy="0 1.57 0" xyz="-0.1 0.1 0"/>
            <material name="black"/>
        </visual>
    </link>

    <joint name="wheel03_joint" type="fixed">
        <parent link="base_link"/>
        <child link="wheel03_link"/>
        <origin xyz = "0 0 0" rpy = "0 0 0"/>
    </joint>
    <link name="wheel03_link">
        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.05"/>
            </geometry>
            <origin rpy="0 1.57 0" xyz="0.1 -0.1 0"/>
            <material name="black"/>
        </visual>
    </link>

    <joint name="wheel04_joint" type="fixed">
        <parent link="base_link"/>
        <child link="wheel04_link"/>
        <origin xyz = "0 0 0" rpy = "0 0 0"/>
    </joint>
    <link name="wheel04_link">
        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.05"/>
            </geometry>
            <origin rpy="0 1.57 0" xyz="-0.1 -0.1 0"/>
            <material name="black"/>
        </visual>
    </link>

</robot>

保存文件并退出.

编写launch启动文件

roscd custom_urdf/launch
gedit view_car.launch

输入如下的内容,保存并退出:

<launch>
    <arg name = "model"/>
    <param name = "robot_description" textfile = "$(find custom_urdf)/urdf/four_wheels_car.urdf"/>
    <param name = "use_gui" value = "true"/>

    <node name = "joint_state_publisher"
          pkg = "joint_state_publisher"
          type = "joint_state_publisher"/>

    <node name = "robot_state_publisher"
          pkg = "robot_state_publisher"
          type = "state_publisher"/>

    <node name = "rviz"
          pkg = "rviz"
          type = "rviz"
          args = "-d $(find custom_urdf)/rviz/urdf.rviz"
          required = "true"/>
</launch>

启动节点,通过rviz查看机器人模型()

roslaunch custom_urdf view_car.launch

最后结果

最后可以参考几个链接


ROS学习之路08:创建机器人的urdf(xacro)模型并通过rviz可视化_将自己创建的机器人urdf模型,改写成xacro形式的模型并在rviz中_小强的机器人工坊的博客-CSDN博客


ROS(五):使用rviz及urdf文件建模_奔跑的林小川的博客-CSDN博客



版权声明:本文为qq_43683669原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。