创建URDF模型——解决无法运行launch文件、功能包无法定位、global status error、无模型显示现象等问题
$ cd ~/catkin_ws
$ catkin_make
~/catkin_ws$ source devel/setup.bash
- 1
- 2
- 3
创建mrobot_description 功能包
$ cd ~/catkin_ws/src
$ ~/catkin_ws/src$ catkin_create_pkg mrobot_description urdf xacro
- 1
- 2
创建四个文件夹urdf meshes launch config
$ mkdir -p ~/catkin_ws/src/mrobot_description/urdf
$ mkdir -p ~/catkin_ws/src/mrobot_description/meshes
$ mkdir -p ~/catkin_ws/src/mrobot_description/launch
$ mkdir -p ~/catkin_ws/src/mrobot_description/config
- 1
- 2
- 3
- 4
在urdf文件夹下编写mrobot_chassis.urdf文件
内容如下:
<?xml version="1.0" ?> <robot name="mrobot_chassis">
<link name="base_link"> <visual> <origin xyz=" 0 0 0" rpy="0 0 0" /> <geometry> <cylinder length="0.005" radius="0.13"/> </geometry> <material name="yellow"> <color rgba="1 0.4 0 1"/> </material> </visual> </link> <joint name="base_left_motor_joint" type="fixed"> <origin xyz="-0.055 0.075 0" rpy="0 0 0" /> <parent link="base_link"/> <child link="left_motor" /> </joint> <link name="left_motor"> <visual> <origin xyz="0 0 0" rpy="1.5707 0 0" /> <geometry> <cylinder radius="0.02" length = "0.08"/> </geometry> <material name="gray"> <color rgba="0.75 0.75 0.75 1"/> </material> </visual>
</link>
<joint name="left_wheel_joint" type="continuous">
<origin xyz="0 0.0485 0" rpy="0 0 0 "/>
<parent link="left_motor"/>
<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.033" length = "0.017"/>
</geometry>
<material name="white">
<color rgba="1 1 1 0.9"/>
</material>
</visual>
</link>
<joint name="base_right_motor_joint" type="fixed">
<origin xyz="-0.055 -0.075 0" rpy="0 0 0" />
<parent link="base_link"/>
<child link="right_motor" />
</joint>
<link name="right_motor">
<visual>
<origin xyz="0 0 0" rpy="1.5707 0 0" />
<geometry>
<cylinder radius="0.02" length = "0.08"/>
</geometry>
<material name="gray">
<color rgba="0.75 0.75 0.75 1"/>
</material>
</visual>
</link>
<joint name="right_wheel_joint" type="continuous">
<origin xyz="0 -0.0485 0" rpy="0 0 0 "/>
<parent link="right_motor"/>
<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.033" length = "0.017"/>
</geometry>
<material name="white">
<color rgba="1 1 1 0.9"/>
</material>
</visual>
</link>
<joint name="front_castor_joint" type="fixed">
<origin xyz="0.1135 0 -0.0165" rpy="0 0 0" />
<parent link="base_link"/>
<child link="front_castor_link" />
<axis xyz= "0 1 0"/>
</joint>
<link name="front_castor_link">
<visual>
<origin xyz="0 0 0" rpy="1.5707 0 0" />
<geometry>
<sphere radius="0.0165"/>
</geometry>
<material name="black">
<color rgba="0 0 0 0.95"/>
</material>
</visual>
</link>
</robot>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
urdf文件提供了一些命令工具,帮助检查和梳理模型文件
$ sudo apt-get install liburdfdom-tools
- 1
然后使用check_urdf命令对mrobot_chassis文件进行检查
~/catkin_ws/src/mrobot_description/urdf$ check_urdf mrobot_chassis.urdf
- 1
如果检查有什么问题的话,会报错,报错就是代码有问题,好好检查检查就行了
用urdf_to_graphiz来查看URDF模型的整体结构
$ urdf_to_graphiz mrobot_chassis.urdf
- 1
在rviz中显示模型
先在launch文件夹中mrobot_description/launch/display_mrobot_chassis_urdf.launch,具体代码如下
<launch>
<param name="robot_description" textfile="$(find mrobot_description)/urdf/mrobot_chassis.urdf" />
<param name="use_gui" value="true"/>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mrobot_description)/config/mrobot_urdf.rviz" required="true" />
</launch>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
在使用rviz之前先安装arbotix,在catkin_ws/src下
$ git clone https://github.com/vanadiumlabs/arbotix_ros.git
- 1
回到catkin_ws目录,用catkin_make,这样就安装好了arbotix,然后安装rbx_vol_1,在catkin_ws/src中
$ git clone https://github.com/pirobot/rbx1
- 1
同样回到catkin_ws目录,用catkin_make编译结束用
$ source /path/to/your/catkin_ws/devel/setup.bash
- 1
运行launch文件
$ roslaunch mrobot_description display_mrobot_chassis_urdf.launch
- 1
我运行后出现了如下的问题
因此需要安装两个功能包joint_state_publisher robot_state_publisher
但是输入命令时却无法定位软件包
因此需要从网上下载
首先是robot_state_publisher的下载,如果显示无法定位此文件,则重新填一遍秘钥
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
- 1
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
- 1
记住之后一定要更新一下软件包索引
sudo apt-get update
- 1
然后是joint_state_publisher功能包的下载
$ cd ~/catkin_ws/src
$ git clone https://github.com/ros/joint_state_publisher.git
- 1
- 2
再重新运行
$ roslaunch mrobot_description display_mrobot_chassis_urdf.launch
- 1
进入后但出现
GLOBAL STATUS ERROR 的现象
因此 使用新建终端
$ rosrun tf static_transform_publisher 0.0 0.0 0.0 0.0 0.0 0.0 map my_frame 100
- 1
但是此时模型 还是加载不出来
此时分两步
1.等rviz启动完毕之后先将FixedFrame改为base_link
2.再点击下方Add按钮,添加一个RobotModel
完成建模