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