ros学习

news/2025/2/3 21:08:36/

1创建工作空间

catkin_init_workspace 将文件夹初始化成ros文件

编译工作空间catkin_make

vi ~/.bashrc
加入环境变量bashrc一下在任何终端都生效

catkin_create_pkg learning_communication通讯机制 std_msgs数据结构 rospy roscpp
catkin_create_pkg mbot_description urdf:xacro
创建相应文件
2创建urdf模型
Config中配置rviz文件 rviz自己的文件不用管

Urdf中写代码编模型,检查urdf模型
在这里插入图片描述

在launch文件夹中创建launch文件

roslaunch car_base.launch启动查看模型

3改写urdf模型
Urdf改xacro

将之前urdf的launch文件声明一下是xacro

启动launch文件roslaunch rbot_base.launch

看到xacro文件模型与urdf模型相同,但xacro模型方便编写
4搭建gazebo物理模型
在xacro基础上加入惯性参数和碰撞属性

标准刚体

添加gazebo标签

添加gazebo控制插件

配置gazebo的launch文件

配置实际环境并保存world文件

5配置仿真雷达、move_base、gmapping文件并进行建图导航
在xacro文件中加入激光雷达仿真配置

配置建图导航文件

Move_base与gmapping都是固定功能包可根据自己需求更改相应的配置,并配置好yaml文件
启动launch文件进行建图 也可不用move base直接用键盘

rosrun map_server map_saver -f car_gmapping 保存地图
配置导航launch文件

启动launch文件进行导航

6 rviz配置

下面这两个为膨胀半径和amcl点

Urdf

<?xml version="1.0" ?>
<link name="base_link"><visual><origin xyz="0 0 0" rpy="0 0 0"/><geometry><cylinder length="0.05" radius="0.20"/></geometry><material name="yellow"><color rgba="1 0.4 0 1"/></material></visual>
</link>






**<link name="radar_link"><visual><origin xyz="0 0 0" rpy="0 0 0" /><geometry><cylinder radius="0.03" length = "0.04"/></geometry><material name="black"><color rgba="0 0 0 0.95"/></material></visual>
</link>**<joint name="left_wheel_joint" type="continuous"><origin xyz="0 0.21 -0.02" rpy="0 0 0"/><parent link="base_link"/><child link="left_wheel_link"/><axis xyz="0 1 0"/>
</joint><link name="left_wheel_link"><visual><origin xyz="0 0 0" rpy="1.5707 0 0" /><geometry><cylinder radius="0.05" length = "0.025"/></geometry><material name="white"><color rgba="1 1 1 0.9"/></material></visual>
</link><joint name="right_wheel_joint" type="continuous"><origin xyz="0 -0.21 -0.02" rpy="0 0 0"/><parent link="base_link"/><child link="right_wheel_link"/><axis xyz="0 1 0"/>
</joint><link name="right_wheel_link"><visual><origin xyz="0 0 0" rpy="1.5707 0 0" /><geometry><cylinder radius="0.06" length = "0.025"/></geometry><material name="white"><color rgba="1 1 1 0.9"/></material></visual>
</link><joint name="front_caster_joint" type="continuous"><origin xyz="0.18 0 -0.0475" rpy="0 0 0"/><parent link="base_link"/><child link="front_caster_link"/><axis xyz="0 1 0"/>
</joint><link name="front_caster_link"><visual><origin xyz="0 0 0" rpy="0 0 0"/><geometry><sphere radius="0.0225" /></geometry><material name="black"><color rgba="0 0 0 0.95"/></material></visual>
</link><joint name="back_caster_joint" type="continuous"><origin xyz="-0.18 0 -0.0475" rpy="0 0 0"/><parent link="base_link"/><child link="back_caster_link"/><axis xyz="0 1 0"/>
</joint><link name="back_caster_link"><visual><origin xyz="0 0 0" rpy="0 0 0"/><geometry><sphere radius="0.0225" /></geometry><material name="black"><color rgba="0 0 0 0.95"/></material></visual>
</link>

Xacro

<?xml version="1.0"?>
<!-- PROPERTY LIST -->
<xacro:property name="M_PI" value="3.1415926"/>
<xacro:property name="base_radius" value="0.2"/>
<xacro:property name="base_length" value="0.05"/>

<xacro:property name=“base_mass” value=“20” />

<xacro:property name="wheel_radius" value="0.05"/>
<xacro:property name="wheel_length" value="0.025"/>
<xacro:property name="wheel_joint_y" value="0.21"/>
<xacro:property name="wheel_joint_z" value="0.02"/>

<xacro:property name=“wheel_mass” value=“2” />

<xacro:property name="caster_radius" value="0.0225"/> <!-- wheel_radius - ( base_length/2 - wheel_joint_z) -->
<xacro:property name="caster_joint_x" value="0.18"/>

<xacro:property name=“caster_mass” value=“0.5” />

<xacro:property name=“radar_radius” value=“0.05”/>
<xacro:property name=“radar_length” value=“0.0001”/>
<xacro:property name=“radar_joint_x” value=“0.16”/>
<xacro:property name=“radar_joint_z” value=“0.03”/>
<xacro:property name=“radar_mass” value=“1” />
<xacro:property name=“radar_radius” value=“0.05”/>
<xacro:property name=“radar_length” value=“0.0001”/>
<xacro:property name=“radar_joint_x” value=“0.16”/>
<xacro:property name=“radar_joint_z” value=“0.03”/>
<xacro:property name=“radar_mass” value=“1” />
<xacro:property name=“radar_radius” value=“0.05”/>
<xacro:property name=“radar_length” value=“0.0001”/>
<xacro:property name=“radar_joint_x” value=“0.16”/>
<xacro:property name=“radar_joint_z” value=“0.03”/>
<xacro:property name=“radar_mass” value=“1” />
<xacro:property name=“radar_radius” value=“0.05”/>
<xacro:property name=“radar_length” value=“0.0001”/>
<xacro:property name=“radar_joint_x” value=“0.16”/>
<xacro:property name=“radar_joint_z” value=“0.03”/>
<xacro:property name=“radar_mass” value=“1” />
<xacro:property name=“radar_radius” value=“0.05”/>
<xacro:property name=“radar_length” value=“0.0001”/>
<xacro:property name=“radar_joint_x” value=“0.16”/>
<xacro:property name=“radar_joint_z” value=“0.03”/>
<xacro:property name=“radar_mass” value=“1” />
<xacro:property name=“radar_radius” value=“0.05”/>
<xacro:property name=“radar_length” value=“0.0001”/>
<xacro:property name=“radar_joint_x” value=“0.16”/>
<xacro:property name=“radar_joint_z” value=“0.03”/>
<xacro:property name=“radar_mass” value=“1” />
<xacro:property name=“radar_radius” value=“0.05”/>
<xacro:property name=“radar_length” value=“0.0001”/>
<xacro:property name=“radar_joint_x” value=“0.16”/>
<xacro:property name=“radar_joint_z” value=“0.03”/>
<xacro:property name=“radar_mass” value=“1” />
<xacro:property name=“radar_radius” value=“0.05”/>
<xacro:property name=“radar_length” value=“0.0001”/>
<xacro:property name=“radar_joint_x” value=“0.16”/>
<xacro:property name=“radar_joint_z” value=“0.03”/>

<!-- Defining the colors used in this robot -->
<material name="yellow"><color rgba="1 0.4 0 1"/>
</material>
<material name="black"><color rgba="0 0 0 1"/>
</material>     
<xacro:macro name="sphere_inertial_matrix" params="m r"><inertial><mass value="${m}" /><inertia ixx="${2*m*r*r/5}" ixy="0" ixz="0"iyy="${2*m*r*r/5}" iyz="0" izz="${2*m*r*r/5}" /></inertial>
</xacro:macro><xacro:macro name="cylinder_inertial_matrix" params="m r h"><inertial><mass value="${m}" /><inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0"iyy="${m*(3*r*r+h*h)/12}" iyz = "0"izz="${m*r*r/2}" /> </inertial>
</xacro:macro><!-- Macro for robot wheel -->
<xacro:macro name="wheel" params="prefix reflect"><joint name="${prefix}_wheel_joint" type="continuous"><origin xyz="0 ${reflect*wheel_joint_y} ${-wheel_joint_z}" rpy="0 0 0"/><parent link="base_link"/><child link="${prefix}_wheel_link"/><axis xyz="0 1 0"/></joint><link name="${prefix}_wheel_link"><visual><origin xyz="0 0 0" rpy="${M_PI/2} 0 0" /><geometry><cylinder radius="${wheel_radius}" length = "${wheel_length}"/></geometry><material name="black" /></visual>
    <gazebo reference="${prefix}_wheel_link"><material>Gazebo/Black</material></gazebo><!-- Transmission is important to link the joints and the controller --><transmission name="${prefix}_wheel_joint_trans"><type>transmission_interface/SimpleTransmission</type><joint name="${prefix}_wheel_joint" ><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface></joint><actuator name="${prefix}_wheel_joint_motor"><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface><mechanicalReduction>1</mechanicalReduction></actuator></transmission></xacro:macro>

<xacro:macro name=“radar” params=“prefix reflect”>





    <link name="${prefix}_radar_link"><visual><origin xyz="0 0 0" rpy="0 0 0" /><geometry><cylinder radius="${radar_radius}" length = "${radar_length}"/></geometry><material name="red" /></visual>
    <gazebo reference="${prefix}_radar_link"><material>Gazebo/Blue</material></gazebo></xacro:macro>   <!-- Macro for robot caster -->
<xacro:macro name="caster" params="prefix reflect"><joint name="${prefix}_caster_joint" type="continuous"><origin xyz="${reflect*caster_joint_x} 0 ${-(base_length/2 + caster_radius)}" rpy="0 0 0"/><parent link="base_link"/><child link="${prefix}_caster_link"/><axis xyz="0 1 0"/></joint><link name="${prefix}_caster_link"><visual><origin xyz="0 0 0" rpy="0 0 0"/><geometry><sphere radius="${caster_radius}" /></geometry><material name="black" /></visual><collision><origin xyz="0 0 0" rpy="0 0 0"/><geometry><sphere radius="${caster_radius}" /></geometry></collision>      <sphere_inertial_matrix  m="${caster_mass}" r="${caster_radius}" /></link><gazebo reference="${prefix}_caster_link"><material>Gazebo/Black</material></gazebo>
</xacro:macro><xacro:macro name="mbot_base_gazebo"><link name="base_footprint"><visual><origin xyz="0 0 0" rpy="0 0 0" /><geometry><box size="0.001 0.001 0.001" /></geometry></visual></link>
false
    <joint name="base_footprint_joint" type="fixed"><origin xyz="0 0 ${base_length/2 + caster_radius*2}" rpy="0 0 0" />        <parent link="base_footprint"/><child link="base_link" /></joint><link name="base_link"><visual><origin xyz=" 0 0 0" rpy="0 0 0" /><geometry><cylinder length="${base_length}" radius="${base_radius}"/></geometry><material name="yellow" />
    <gazebo reference="base_link"><material>Gazebo/Orange</material></gazebo><wheel prefix="left" reflect="-1"/><wheel prefix="right" reflect="1"/><caster prefix="front" reflect="-1"/><caster prefix="back" reflect="1"/><radar prefix="back" reflect="1"/>
Debug true / 1 true true 100.0 true left_wheel_joint right_wheel_joint ${wheel_joint_y*2} ${2*wheel_radius} 1 30 1.8 cmd_vel odom odom base_footprint
</xacro:macro>

Gmapping.launch

<include file="$(find mbot_navigation)/launch/gmapping.launch"/><!-- 运行move_base节点 -->
<include file="$(find mbot_navigation)/launch/move_base.launch" /><!-- 运行rviz -->
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot.rviz" required="true" />

Mbot_move.launch

<!-- 运行地图服务器,并且加载设置的地图-->
<node name="map_server" pkg="map_server" type="map_server" args="$(find mbot_navigation)/maps/$(arg map)"/><!-- 运行move_base节点 -->
<include file="$(find mbot_navigation)/launch/move_base.launch"/><!-- 对于虚拟定位,需要设置一个/odom与/map之间的静态坐标变换 -->
<node pkg="tf" type="static_transform_publisher" name="map_odom_broadcaster" args="0 0 0 0 0 0 /map /odom 100" /><!-- 运行rviz -->
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot.rviz" required="true" />

http://www.ppmy.cn/news/93099.html

相关文章

测试覆盖率详解

一、背景介绍 在软件开发过程中&#xff0c;测试是非常关键的环节。为了保证软件的质量和可靠性&#xff0c;测试覆盖率成为了一个重要的指标。测试覆盖率是指在一定的测试环境下&#xff0c;已经对软件代码进行了多大程度的覆盖测试。 测试覆盖率是衡量测试工作的效果的重要依…

【Docker】- 03 Docker CI、CD(CI、CD、项目配置、环境部署)

Docker CI、CD&#xff08;CI、CD、项目配置、环境部署&#xff09; 1 CICD引言2 CI介绍3 搭建Gitlab服务器3.1 准备工作3.2 修改ssh的22端口3.3 编写docker-compose.yml 4 搭建GitlabRunner5 整合项目入门测试5.1 创建项目5.2 编写.gitlab-ci.yml5.3 将maven工程推送到gitlab中…

DAB-DETR代码学习笔记

先上一张整体架构图 &#xff1a; 代码地址&#xff1a;GitHub - IDEA-Research/DAB-DETR: [ICLR 2022] DAB-DETR: Dynamic Anchor Boxes are Better Queries for DETR 论文地址&#xff1a; https://arxiv.org/pdf/2201.12329.pdf 文章全名《DYNAMIC ANCHOR BOXES ARE BETTER …

C++的sort函数如何实现从大到小排序

C的sort函数如何实现从大到小排序 一、sort的基本用法1. 所在的头文件2. 包含的参数3. 时间复杂度 二、具体示例[USACO07DEC\]Bookshelf B题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1 提示代码示例 一、sort的基本用法 1. 所在的头文件 在 #include<algorithm…

【Python文本处理】基于运动路线记录GPX文件解析,心率、速度、时间、功率、踏频、海拔等参数的生成和更改

【Python文本处理】基于运动路线记录GPX文件解析&#xff0c;心率、速度、时间、功率、踏频、海拔等参数的生成和更改 GPX文件本身其实就是坐标、海拔、时间、心率等综合性的xml文件 如图&#xff1a; 海拔&#xff1a;ele 时间&#xff1a;time 心率&#xff1a;heartrate 功…

vue2源码

初始化环境 先 npm init -y 初始化 npm 环境。 然后执行 npm install rollup rollup-plugin-babel babel/core babel/preset-env --save-dev。 一般类库都是采用 rollup 打包&#xff0c;因为打包的体积会比 webpack 小很多&#xff0c;所以常用于打包 js 库。 rollup-plug…

【数据结构】顺序表---C语言版(数据结构开篇小菜,全网最详细!小白看一遍就学会!!!)

文章目录 &#x1f354;一、前言&#x1f35f;1. 什么是数据结构 &#x1f354;二、顺序表的概念----线性表&#x1f35f;1. 什么是线性表&#x1f35f;2. 顺序表与数组的区别 &#x1f354;三、顺序表详解&#x1f4a7; 静态顺序表&#x1f4a7; 动态顺序表&#x1f34e;创建动…

多看一眼多进步,python入门到放弃

python相关工具都安装完成后&#xff0c;就可以开始学习了&#xff0c;以下在pycharm中&#xff0c;以下学习内容来自b站边学习边整理的笔记&#xff0c;好记性不如赖笔头&#xff0c;多总结多记录&#xff0c;总是不错的 print()函数的使用 print函数可以输出哪些内容 &…