C++入门 ros中urdf整合rviz

一、 开发环境

ubuntu20.04

ros版本noetic

参考视频

https://www.bilibili.com/video/BV1Ci4y1L7ZZ/?p=52\&spm_id_from=333.1007.top_right_bar_window_history.content.click\&vd_source=4cd1b6f268e2a29a11bea5d2568836ee

二、 编写launch文件

在功能包下面创建launch文件夹(launch文件夹和src文件夹并列),在launch文件夹中创建chassis.launch文件

chassis.launch

xml 复制代码
<launch>

    <!-- 在参数服务器载入urdf文件 -->
    <param name="robot_description" textfile="$(find urdf_rviz)/urdf/urdf/chassis.urdf" />
    <!-- 启动RVIZ -->
    <node pkg="rviz" type="rviz" name="rviz" args="-d $(find urdf_rviz)/config/chassis.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>

三、 编写urdf文件

chassis.urdf

cpp 复制代码
<robot name="chassis">
    <!-- 参考点 -->
    <link name="base_footprint">
        <visual>
            <geometry>
                <!-- 单位:米-->
                <sphere radius="0.001"/>
            </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="baselink_color">
                <color rgba="1.0 0.5 0.2 0.5"/>
            </material>
        </visual>
    </link>
    <joint name="base_link2base_footprint" type="fixed">
        <parent link="base_footprint" />
        <child link="base_link"/>
        <!-- 0.055 = 0.08/2+0.015  0.015是离地距离 -->
        <origin xyz="0 0 0.055" rpy="0 0 0"/>
    </joint>


    <!-- 驱动轮-->
    <!-- 半径3.25cm 宽1.5cm-->
    <link name="left_wheel">
        <visual>
            <geometry>
                <cylinder radius="0.0325" length="0.015" />
            </geometry>
            <origin xyz="0 0 0" rpy="1.5705 0 0" />
            <material name="black">
                <color rgba="0.0 0.0 0.0 1.0" />
            </material>
        </visual>
    </link>

    <joint name="left_wheel2base_link" type="continuous">
        <parent link="base_link" />
        <child link="left_wheel" />
        <!-- -0.0225 = 0.0325 - 0.055 -->
        <origin xyz="0 0.1 -0.0225" />
        <!-- 可以沿Y轴旋转 -->
        <axis xyz="0 1 0" />
    </joint>

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

    <joint name="right_wheel2base_link" type="continuous">
        <parent link="base_link" />
        <child link="right_wheel" />
        <origin xyz="0 -0.1 -0.0225" />
        <!-- 可以沿Y轴旋转 -->
        <axis xyz="0 1 0" />
    </joint>

    <!-- 万向轮-->
    <link name="front_wheel">
        <visual>
            <geometry>
                <sphere radius="0.0075" />
            </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="front_wheel2base_link" type="continuous">
        <parent link="base_link" />
        <child link="front_wheel" />
        <!-- 0.0925 = 0.1 - 0.0075 -->
        <!-- -0.0475 = 0.0075 - 0.055 -->
        <origin xyz="0.0925 0 -0.0475" />
        <axis xyz="1 1 1" />
    </joint>

    <link name="back_wheel">
        <visual>
            <geometry>
                <sphere radius="0.0075" />
            </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="back_wheel2base_link" type="continuous">
        <parent link="base_link" />
        <child link="back_wheel" />
        <origin xyz="-0.0925 0 -0.0475" />
        <axis xyz="1 1 1" />
    </joint>
</robot>

四、 运行截图

相关推荐
岁忧33 分钟前
(LeetCode 面试经典 150 题) 200. 岛屿数量(深度优先搜索dfs || 广度优先搜索bfs)
java·c++·leetcode·面试·go·深度优先
一枝小雨41 分钟前
【OJ】C++ vector类OJ题
数据结构·c++·算法·leetcode·oj题
一枝小雨42 分钟前
【C++】Vector完全指南:动态数组高效使用
开发语言·c++·笔记·vector·学习笔记·std库
buyutang_1 小时前
C/C++ Linux系统编程:线程控制详解,从线程创建到线程终止
linux·c语言·c++·学习
Qiang_san2 小时前
GNU Make | C/C++项目自动构建入门
c语言·c++·gnu
源代码•宸2 小时前
Leetcode—2749. 得到整数零需要执行的最少操作数【中等】(__builtin_popcountl)
c++·经验分享·算法·leetcode·位运算
芒果敲代码2 小时前
单一职责原则(SRP)
c++·单一职责原则
ComputerInBook3 小时前
C++编程语言:标准库:第37章——正则表达式(Bjarne Stroustrup)
开发语言·c++·正则表达式
青草地溪水旁3 小时前
C/C++中的可变参数 (Variadic Arguments)函数机制
c语言·c++·可变参数
汉克老师3 小时前
第十四届蓝桥杯青少组C++选拔赛[2023.2.12]第二部分编程题(1、求和)
c++·蓝桥杯·蓝桥杯c++·c++蓝桥杯