创建URDF模型——解决无法运行launch文件、功能包无法定位、global status error、无模型显示现象等问题

创建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">
&lt;link name="base_link"&gt;
		&lt;visual&gt;
 	&lt;origin xyz=" 0 0 0" rpy="0 0 0" /&gt;
 	 &lt;geometry&gt;
	  		&lt;cylinder length="0.005" radius="0.13"/&gt;
	&lt;/geometry&gt;
	&lt;material name="yellow"&gt;
 	 	&lt;color rgba="1 0.4 0 1"/&gt;
		 &lt;/material&gt;
 	&lt;/visual&gt;
 &lt;/link&gt;

&lt;joint name="base_left_motor_joint" type="fixed"&gt;
 		 &lt;origin xyz="-0.055 0.075 0" rpy="0 0 0" /&gt;
  		 &lt;parent link="base_link"/&gt;
  		 &lt;child link="left_motor" /&gt;
&lt;/joint&gt;

&lt;link name="left_motor"&gt;
   		&lt;visual&gt;
	&lt;origin xyz="0 0 0" rpy="1.5707 0 0" /&gt;
	&lt;geometry&gt;
    		&lt;cylinder radius="0.02" length = "0.08"/&gt;
	&lt;/geometry&gt;
	&lt;material name="gray"&gt;
    	&lt;color rgba="0.75 0.75 0.75 1"/&gt;
  &lt;/material&gt;
  &lt;/visual&gt;

</link>

&lt;joint name="left_wheel_joint" type="continuous"&gt;
	&lt;origin xyz="0 0.0485 0" rpy="0 0 0 "/&gt;
	&lt;parent link="left_motor"/&gt;
  	&lt;child link="left_wheel_link"/&gt;
 	&lt;axis xyz="0 1 0"/&gt;
  &lt;/joint&gt;

&lt;link name="left_wheel_link"&gt;
 		 &lt;visual&gt;
	 &lt;origin xyz="0 0 0" rpy="1.5707 0 0" /&gt;
	 &lt;geometry&gt;
    		&lt;cylinder radius="0.033" length = "0.017"/&gt;
 	 &lt;/geometry&gt;
	 &lt;material name="white"&gt;
    	 &lt;color rgba="1 1 1 0.9"/&gt;
	 &lt;/material&gt;
  		 &lt;/visual&gt;
  &lt;/link&gt;

&lt;joint name="base_right_motor_joint" type="fixed"&gt;
  			&lt;origin xyz="-0.055 -0.075 0" rpy="0 0 0" /&gt;
  			&lt;parent link="base_link"/&gt;
 		        &lt;child link="right_motor" /&gt;
&lt;/joint&gt;

&lt;link name="right_motor"&gt;
    	&lt;visual&gt;
	&lt;origin xyz="0 0 0" rpy="1.5707 0 0" /&gt;
	&lt;geometry&gt;
   				 &lt;cylinder radius="0.02" length = "0.08"/&gt;
 	&lt;/geometry&gt;
 	&lt;material name="gray"&gt;
    	&lt;color rgba="0.75 0.75 0.75 1"/&gt;
	&lt;/material&gt;
 		&lt;/visual&gt;
  &lt;/link&gt;
  
&lt;joint name="right_wheel_joint" type="continuous"&gt;
		&lt;origin xyz="0 -0.0485 0" rpy="0 0 0 "/&gt;
		&lt;parent link="right_motor"/&gt;
		&lt;child link="right_wheel_link"/&gt;
		&lt;axis xyz="0 1 0"/&gt;
&lt;/joint&gt;

&lt;link name="right_wheel_link"&gt;
 		 &lt;visual&gt;
	 &lt;origin xyz="0 0 0" rpy="1.5707 0 0" /&gt;
	 &lt;geometry&gt;
    		&lt;cylinder radius="0.033" length = "0.017"/&gt;
	 &lt;/geometry&gt;
	 &lt;material name="white"&gt;
	 &lt;color rgba="1 1 1 0.9"/&gt;
	 &lt;/material&gt;
  		 &lt;/visual&gt;
&lt;/link&gt;

&lt;joint name="front_castor_joint" type="fixed"&gt;
 		 &lt;origin xyz="0.1135 0 -0.0165" rpy="0 0 0" /&gt;
 		 &lt;parent link="base_link"/&gt;
  		 &lt;child link="front_castor_link" /&gt;
  		 &lt;axis xyz= "0 1 0"/&gt;
&lt;/joint&gt;

&lt;link name="front_castor_link"&gt;
  			&lt;visual&gt;
		&lt;origin xyz="0 0 0" rpy="1.5707 0 0" /&gt;
		 &lt;geometry&gt;
  			 &lt;sphere radius="0.0165"/&gt;
		 &lt;/geometry&gt;
		 &lt;material name="black"&gt;
    		 &lt;color rgba="0 0 0 0.95"/&gt;
		&lt;/material&gt;
  		&lt;/visual&gt;
&lt;/link&gt;

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

在这里插入图片描述
完成建模

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值