urdf实践:圆形机器人小车

我们进行搭建一个机器人小车的模型实践。

机器人的参数如下:底盘为圆柱形,半径为10cm,高8cm,四轮由两个驱动轮和两个万向支撑轮组成,两个驱动轮半径为3.25cm,轮胎宽度为1.5cm,两个万向轮为球状,半径为0.75cm,底盘离地间距为1.5cm(与万向轮直径一致)。

编写.urdf文件:

<robot name="practice">
 
    <link name="base_footprint">
        <visual>
            <geometry>
                <sphere radius="0.0001" />
            </geometry>
        </visual>
    </link>

    <link name="base_link">
        <visual>
            <geometry>
                <cylinder radius="0.1" length="0.08" />
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="orange">
                <color rgba="0.99 0.6 0.0625 0.5" />
            </material>
        </visual>
    </link>

    <link name="left_wheel">
        <visual>
            <geometry>
                <cylinder radius="0.0325" length="0.015" />
            </geometry>
            <material name="black">
                <color rgba="0 0 0 1" />
            </material>
            <origin xyz="0 0 0" rpy="1.5708 0 0" />
        </visual>
    </link>

    <link name="right_wheel">
        <visual>
            <geometry>
                <cylinder radius="0.0325" length="0.015" />
            </geometry>
            <material name="black">
                <color rgba="0 0 0 1" />
            </material>
            <origin xyz="0 0 0" rpy="1.5708 0 0" />
        </visual>
    </link>


    <link name="front_wheel">
        <visual>
            <geometry>
                <sphere radius="0.0075" />
            </geometry>
            <material name="black">
                <color rgba="0 0 0 1" />
            </material>
        </visual>
    </link>

    <link name="back_wheel">
        <visual>
            <geometry>
                <sphere radius="0.0075" />
            </geometry>
            <material name="black">
                <color rgba="0 0 0 1" />
            </material>
        </visual>
    </link>

    <joint name="link2footprint" type="fixed">
        <parent link="base_footprint" />
        <child link="base_link" />
        <origin xyz="0 0 0.055" rpy="0 0 0" />
    </joint>

    <joint name="left2link" type="continuous">
        <parent link="base_link" />
        <child link="left_wheel" />
        <origin xyz="0 0.1075 -0.0225" rpy="0 0 0" />
        <!--  The y=the radius of the base_link ; the z = the radius of the wheel - (the height of the base_link/2 + the distance to the ground ) -->
        <axis xyz="0 1 0" />
    </joint>

     <joint name="right2link" type="continuous">
        <parent link="base_link" />
        <child link="right_wheel" />
        <origin xyz="0 -0.1075 -0.0225" rpy="0 0 0" />
        <!--  The y = - the radius of the base_link ; the z = the radius of the wheel - (the height of the base_link/2 + the distance to the ground ) -->
        <axis xyz="0 1 0" />
    </joint>

    <joint name="front2link" type="continuous">
        <parent link="base_link" />
        <child link="front_wheel" />
        <origin xyz="0.08 0 -0.0475" rpy="0 0 0" />
        <axis xyz="0 1 0" />
    </joint>

<joint name="back2link" type="continuous">
        <parent link="base_link" />
        <child link="back_wheel" />
        <origin xyz="-0.08 0 -0.0475" rpy="0 0 0" />
        <axis xyz="0 1 0" />
    </joint>

</robot>

PS:注意,轮子的joint中origin.xyz的z数值取值为=车轮半径-(底盘高度的一半+底盘离地高度),这个数值应该是负值。

注意各种车轮的位置和轴的位置以及正负数值。

然后我们再编写.launch文件

<launch>
    <param name="robot_description" textfile="$(find urdf01_rviz)/urdf/urdf/demo05_practice01.urdf" />
    <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" />
    <node pkg="joint_state_publisher" type="joint_state_publisher" name="joint_state_publisher" />
    <node pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" name="joint_state_publisher_gui" />
    <node pkg="rviz" type="rviz" name="rviz" />
</launch>

然后我们配置环境变量,再roslaunch运行程序。

--------------------------------------------------------------------------------

接下来提供两个urdf工具:

check_urdf [filename]:检查复杂的urdf1文件是否存在语法问题:

如果语法编写正确,那我们会在终端中有如下信息:

robot name is: practice
---------- Successfully Parsed XML ---------------
root Link: base_footprint has 1 child(ren)
    child(1):  base_link
        child(1):  back_wheel
        child(2):  front_wheel
        child(3):  left_wheel
        child(4):  right_wheel

如果有语法错误则会主动报错显示;

urdf_to_graphiz [filename]  :查看urdf模型结构,显示不同link的层级关系,它会在.urdf文件存在的文件夹中生成一个.gv文件和一个pdf文件,可以清晰查看这个关系,由于是图像,会比较便于理解。

注意:使用这些工具之前,需要安装工具,安装命令为:sudo apt install liburdfom-tools。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一段 C++ 代码,包含了几个语句,主要功能是订阅ROS话题,加载URDF模型,并获取ROS节点的命名空间。 具体来说,这段代码中: - `if (orientation_from_imu_)` 表示如果满足条件 `orientation_from_imu_`,则执行下面的语句。这里的 `orientation_from_imu_` 是一个成员变量,可能是一个布尔类型的变量。 - `imu_subscriber_ = nh->subscribe<sensor_msgs::Imu>("imu/data", 1, &StateEstimation::imu_callback_, this);` 表示创建了一个 ROS 订阅者对象 `imu_subscriber_`,订阅了名为 "imu/data" 的话题,并指定了回调函数 `&StateEstimation::imu_callback_`。其中,`nh` 是一个 ROS 节点句柄,用于创建 ROS 订阅者对象;`1` 表示订阅话题的队列长度为 1;`this` 表示回调函数的对象是当前对象。 - `base_.setGaitConfig(gait_config_);` 表示调用对象 `base_` 的成员函数 `setGaitConfig()`,并将参数 `gait_config_` 传递给该函数。这里的 `base_` 可能是一个对象。 - `champ::URDF::loadFromServer(base_, nh);` 表示调用 `champ::URDF` 命名空间中的静态成员函数 `loadFromServer()`,并将 `base_` 和 `nh` 作为参数传递给该函数。这个函数的作用是从 ROS 参数服务器中加载 URDF 模型,然后将模型设置到 `base_` 对象中。 - `joint_names_ = champ::URDF::getJointNames(nh);` 表示调用 `champ::URDF` 命名空间中的静态成员函数 `getJointNames()`,并将 `nh` 作为参数传递给该函数。这个函数的作用是从 ROS 参数服务器中获取机器人关节名称列表,并将结果保存到 `joint_names_` 变量中。 - `node_namespace_ = ros::this_node::getNamespace();` 表示调用 ROS API 中的 `ros::this_node::getNamespace()` 函数,获取当前节点的命名空间,并将结果保存到 `node_namespace_` 变量中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值