使用Gazebo建模
// 创建包的步骤
// 1. 创建文件夹
// 2. 创建src子文件夹
catkin_init_workspace
catkin_make
source devel/setup.bash
// 3. 进入src子文件夹
// 4. 创建小车模型的包
catkin_create_pkg my_car roscpp rospy std_msgs urdf xacro
touch my_car.urdf
建模时需要注意坐标间的关系, 尤其是要区分Link和Joint模块中的坐标
xyz: x y z方向的偏移量(即坐标位置)
rpy: rpy角,绕定轴x-y-z旋转角
Link中的坐标是指相对于其质心的位置,如果不设置,则默认为相对于质心无偏移。
Jiont的坐标用来描述child(wheel)相对于Parent(base_link)间的坐标变换。
<link name="right_front_wheel">
<visual>
<geometry>
<cylinder length=".05" radius="0.05"/>
</geometry>
<material name="black">
<color rgba="0 0 0 1"/>
</material>
</visual>
</link>
// 默认相较于质心无偏移
<joint name="right_front_wheel_joint" type="continuous">
<axis xyz="0 0 1"/>
<parent link="base_link"/>
<child link="right_front_wheel"/>
<origin rpy="0 1.57075 0" xyz="0.15 0.15 -0.05"/>
// wheel相较于base_link的坐标变换
<limit effort="100" velocity="100"/>
<joint_properties damping="0.0" friction="0.0"/>
</joint>
模型建好后,创建launch文件夹,创建launch文件
<launch>
<param name="robot_description" textfile="$(find my_car)/urdf/my_car.urdf"/>
<!--set parameter gui-->
<param name = "use_gui" value = "true"/>
<!--run node joint-state-pub,publish joint_state-->
<node name="joint_state_publisher_gui" pkg = "joint_state_publisher_gui" type = "joint_state_publisher_gui" />
<!--run node robot_state_publisher, publish tf-->
<node name="robot_state_publisher" pkg = "robot_state_publisher" type = "robot_state_publisher" />
<!--run rviz-->
<node name="rviz" pkg = "rviz" type = "rviz" args = "-d $(find my_car)/config/my_car_urdf.rviz" />
</launch>
当第一次launch时,rviz会报错
这时需要add—>robot model
Fixed Frame 里改为base_link
为了避免每次重复修改,将此时的设置保存在config文件夹中