建模实践1 —— 手写装有kinova机械臂的husky地面无人车的xacro模型
1.在catkin_ws/src下,创建功能包2.添加底盘3.添加base_footprint4.添加前左轮5.添加前右轮6.添加后左轮7.添加后右轮8.添加上底盘9.添加user_rail_link10.添加前保险杠11.添加前保险杠加长12.添加后保险杠13.添加后保险杠加长14.添加顶板15.在顶板前后分别添加坐标系16.检查xacro模型整体结构
1.在catkin_ws/src下,创建功能包
catkin_create_pkg my_description urdf xacro
在功能包中建立urdf、meshes、launch、config这四个文件夹,分别用于存放特定的文件 接下来编写my.urdf文件
2.添加底盘
<?xml version
="1.0"?>
<robot name
="my_robot" xmlns
:xacro
="http://ros.org/wiki/xacro">
<!--
<link name
="base_link">
<visual
>
<origin xyz
="0 0 0" rpy
="0 0 0" />
<geometry
>
<mesh filename
="package://my_description/meshes/base_link.dae" />
</geometry
>
</visual
>
</link
>
</robot
>
编写display_my_urdf.launch文件
<launch
>
<!-- 设置机器人模型路径参数
-->
<param name
="robot_description" textfile
="$(find my_description)/urdf/my.urdf" />
<!-- 运行joint_state_publisher节点,发布机器人的关节状态
-->
<node name
="joint_state_publisher_gui" pkg
="joint_state_publisher_gui" type
="joint_state_publisher_gui" />
<!-- 运行robot_state_publisher节点,发布tf
-->
<node name
="robot_state_publisher" pkg
="robot_state_publisher" type
="robot_state_publisher" />
<!-- 运行rviz可视化界面
-->
<node name
="rviz" pkg
="rviz" type
="rviz" args
="-d $(find marm_description)/config/marm_urdf.rviz" required
="true" />
</launch
>
编译工作空间后在rviz中查看
roslaunch marm_description display_marm_urdf
.launch
3.添加base_footprint
这个link就是上一篇博客中述及的“机器人映射到地面投影的一个坐标系,一般坐标系的原点都位于地面,方便后续做一些导航、建模相关工作”
<!--
<link name
="base_footprint"/>
<joint name
="base_footprint_joint" type
="fixed">
<origin xyz
="0 0 ${wheel_vertical_offset - wheel_radius}" rpy
="0 0 0" />
<parent link
="base_link" />
<child link
="base_footprint" />
</joint
>
在此之前,还需要定义一些husky的属性,包括底盘尺寸、车轮安装位置、车轮参数:
<!--
<xacro
:property name
="base_x_size" value="0.98740000" />
<xacro
:property name
="base_y_size" value="0.57090000" />
<xacro
:property name
="base_z_size" value="0.24750000" />
<!--
<xacro
:property name
="wheelbase" value="0.5120" />
<xacro
:property name
="track" value="0.5708" />
<xacro
:property name
="wheel_vertical_offset" value="0.03282" />
<!--
<xacro
:property name
="wheel_length" value="0.1143" />
<xacro
:property name
="wheel_radius" value="0.1651" />
【启动rviz运行时报错】
[ERROR
] [1601879476.512976966]: Unable to parse component
[$
{wheel_vertical_offset
] to a
double (while parsing a vector value
)
[ERROR
] [1601879476.513133986]: Malformed parent origin element
for joint
[base_footprint_joint
]
[ERROR
] [1601879476.513180875]: joint xml is
not initialized correctly
[robot_state_publisher
-3] process has died
[pid
17781, exit code
255, cmd
/opt
/ros
/kinetic
/lib
/robot_state_publisher
/robot_state_publisher __name
:=robot_state_publisher __log
:=/home
/hjs
/.ros
/log
/5d1643cc
-06d4
-11eb
-b10d
-3cf862e0843b
/robot_state_publisher
-3.log
].
log file
: /home
/hjs
/.ros
/log
/5d1643cc
-06d4
-11eb
-b10d
-3cf862e0843b
/robot_state_publisher
-3*.log
无法将分量[$ {wheel_vertical_offset]解析为双精度(解析向量值时) 关节[base_footprint_joint]的父代原始元素格式错误
就是解析不了这句含有数学表达式的代码:
$
{wheel_vertical_offset
- wheel_radius
}
然而xacro是支持“使用属性”的啊,暂时还没有找到解决办法,只好计算器计算一下了,有待后续发现是哪里设置错误了;
将${wheel_vertical_offset - wheel_radius}替换为 -0.13228 ,在rviz中查看:
4.添加前左轮
<!--
<link name
="front_left_wheel_link">
<visual
>
<origin xyz
="0 0 0" rpy
="0 0 0" />
<geometry
>
<mesh filename
="package://my_description/meshes/wheel.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="${wheel_prefix}_wheel" type
="continuous">
<origin xyz
="0.256 0.2854 0.03282" rpy
="0 0 0" />
<parent link
="base_link"/>
<child link
="front_left_wheel_link"/>
<xacro
:insert_block name
="joint_pose"/>
<axis xyz
="0 1 0" rpy
="0 0 0" />
</joint
>
在rviz中查看:
5.添加前右轮
<!--
<link name
="front_right_wheel_link">
<visual
>
<origin xyz
="0 0 0" rpy
="0 0 0" />
<geometry
>
<mesh filename
="package://my_description/meshes/wheel.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="front_right_wheel" type
="continuous">
<origin xyz
="0.256 -0.2854 0.03282" rpy
="0 0 0" />
<parent link
="base_link"/>
<child link
="front_right_wheel_link"/>
<xacro
:insert_block name
="joint_pose"/>
<axis xyz
="0 1 0" rpy
="0 0 0" />
</joint
>
6.添加后左轮
<!--
<link name
="rear_left_wheel_link">
<visual
>
<origin xyz
="0 0 0" rpy
="0 0 0" />
<geometry
>
<mesh filename
="package://my_description/meshes/wheel.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="rear_left_wheel" type
="continuous">
<origin xyz
="-0.256 0.2854 0.03282" rpy
="0 0 0" />
<parent link
="base_link"/>
<child link
="rear_left_wheel_link"/>
<xacro
:insert_block name
="joint_pose"/>
<axis xyz
="0 1 0" rpy
="0 0 0" />
</joint
>
7.添加后右轮
<!--
<link name
="rear_right_wheel_link">
<visual
>
<origin xyz
="0 0 0" rpy
="0 0 0" />
<geometry
>
<mesh filename
="package://my_description/meshes/wheel.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="rear_right_wheel" type
="continuous">
<origin xyz
="-0.256 -0.2854 0.03282" rpy
="0 0 0" />
<parent link
="base_link"/>
<child link
="rear_right_wheel_link"/>
<xacro
:insert_block name
="joint_pose"/>
<axis xyz
="0 1 0" rpy
="0 0 0" />
</joint
>
8.添加上底盘
<!--
<link name
="top_chassis_link">
<visual
>
<origin xyz
="0 0 0" rpy
="0 0 0" />
<geometry
>
<mesh filename
="package://my_description/meshes/top_chassis.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="top_chassis_joint" type
="fixed">
<parent link
="base_link" />
<child link
="top_chassis_link" />
</joint
>
可见top_chassis_link和base_link的坐标系相同
9.添加user_rail_link
<!--
<link name
="user_rail_link">
<visual
>
<geometry
>
<mesh filename
="package://my_description/meshes/user_rail.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="user_rail" type
="fixed">
<origin xyz
="0.272 0 0.245" rpy
="0 0 0" />
<parent link
="base_link" />
<child link
="user_rail_link" />
</joint
>
10.添加前保险杠
<!--
<link name
="front_bumper_link">
<visual
>
<geometry
>
<mesh filename
="package://my_description/meshes/bumper.dae" />
</geometry
>
</visual
>
</link
>
<!-- Attach front bumper
-->
<joint name
="front_bumper" type
="fixed">
<origin xyz
="0.48 0 0.091" rpy
="0 0 0" />
<parent link
="base_link" />
<child link
="front_bumper_link" />
</joint
>
11.添加前保险杠加长
<!--
<link name
="front_bumper_extension_link">
<visual
>
<geometry
>
<mesh filename
="package://my_description/meshes/bumper_extension.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="front_bumper_extension" type
="fixed">
<origin xyz
="0.48 0 0.091" rpy
="0 0 0" />
<parent link
="base_link" />
<child link
="front_bumper_extension_link" />
</joint
>
12.添加后保险杠
<!--
<link name
="rear_bumper_link">
<visual
>
<geometry
>
<mesh filename
="package://my_description/meshes/bumper.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="rear_bumper" type
="fixed">
<origin xyz
="-0.48 0 0.091" rpy
="0 0 3.14159" />
<parent link
="base_link" />
<child link
="rear_bumper_link" />
</joint
>
13.添加后保险杠加长
<!--
<link name
="rear_bumper_extension_link">
<visual
>
<geometry
>
<mesh filename
="package://my_description/meshes/bumper_extension.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="rear_bumper_extension" type
="fixed">
<origin xyz
="-0.48 0 0.091" rpy
="0 0 3.14159" />
<parent link
="base_link" />
<child link
="rear_bumper_extension_link" />
</joint
>
14.添加顶板
<!--
<link name
="top_plate_link">
<visual
>
<origin xyz
="0 0 0" rpy
="0 0 0" />
<geometry
>
<mesh filename
="package://my_description/meshes/top_plate.dae" />
</geometry
>
</visual
>
</link
>
<joint name
="top_plate_joint" type
="fixed">
<parent link
="base_link" />
<child link
="top_plate_link"/>
<origin xyz
="0.0812 0 0.245" rpy
="0 0 0"/>
</joint
>
15.在顶板前后分别添加坐标系
<!--
<link name
="top_plate_front_link"/>
<link name
="top_plate_rear_link"/>
<!-- Top plate front link
-->
<joint name
="top_plate_front_joint" type
="fixed">
<parent link
="top_plate_link" />
<child link
="top_plate_front_link"/>
<origin xyz
="0.36367 0 0.00639" rpy
="0 0 0"/>
</joint
>
<!-- Top plate rear link
-->
<joint name
="top_plate_rear_joint" type
="fixed">
<parent link
="top_plate_link" />
<child link
="top_plate_rear_link"/>
<origin xyz
="-0.36633 0 0.00639" rpy
="0 0 0"/>
</joint
>
看一下现在的TF树吧!
16.检查xacro模型整体结构
进入xacro文件夹下
urdf_to_graphiz my
.urdf
.xacro
至此,husky地面无人车终于整理完毕了!通过自己从头到尾建立模型,可以说现在对husky的任何一个joint或者link都了如指掌,将官方的转化为自己的。