当前位置:网站首页>URDF_Xcaro
URDF_Xcaro
2022-07-27 02:19:00 【2021 Nqq】
文章目录
roscore
rosrun xacro xacro demo01_helloworld.urdf.xacro
rosrun xacro xacro demo01_helloworld.urdf.xacro > demo01_helloworld.urdf 由xacro文件生成urdf文件
Xacro 语法
属性
属性定义
属性调用
算术运算
<robot name = "mycar" xmlns:xacro = "http://wiki.ros.org/xacro">
<!-- 1. 属性定义 属性名称,属性的值-->
<xacro:property name = "PI" value = "3.1415927" />
<xacro:property name = "radius" value = "0.03" />
<!-- 2. 属性调用 -->
<myUsrPropertyxxx name = "${PI}" />
<myUsrPropertyxxx name = "${radius}" />
<!-- 3. 算术运算 -->
<myUsrPropertyxxx result = "${PI / 2}" />
<myUsrPropertyxxx result = "${radius * 2}" />
</robot>
宏
宏定义
宏调用
<robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- 1. 宏的定义 参数1 参数2-->
<xacro:macro name = "getSum" params = "num1 num2">
<result value = "${num1 + num2}" />
</xacro:macro>
<!-- 2. 宏的调用 -->
<xacro:getSum num1 = "1" num2 = "5" />
</robot>
文件包含
<robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- 演示文件包含 -->
<xacro:include filename = "demo02_field.urdf.xacro" />
<xacro:include filename = "demo03_macro.urdf.xacro" />
</robot>
Xacro 实例
roslaunch urdf01_rviz demo06_car_base.launch
底盘launch文件 demo06_car_base.launch
<launch>
<!-- 1. 在参数服务器中载入URDF 建议用第二种方式-->
<!-- <param name = "robot_description" textfile = "$(find urdf01_rviz)/urdf/xacro/demo05_car_base.urdf" /> -->
<param name = "robot_description" command = "$(find xacro)/xacro $(find urdf01_rviz)/urdf/xacro/demo05_car_base.urdf.xacro" />
<!-- 2. 启动rviz -->
<node pkg = "rviz" type = "rviz" name = "rviz" args = "-d $(find urdf01_rviz)/config/show_mycar.rviz"/>
<!-- 3. 添加关节状态发布节点 -->
<node pkg = "joint_state_publisher" type = "joint_state_publisher" name = "joint_state_publisher" />
<!-- 4. 添加机器人状态发布节点 -->
<node pkg = "robot_state_publisher" type = "robot_state_publisher" name = "robot_state_publisher" />
<!-- 5. 关节运动控制节点 -->
<node pkg = "joint_state_publisher_gui" type = "joint_state_publisher_gui" name = "joint_state_publisher_gui" />
</launch>
底盘xacro文件 demo05_car_base.urdf.xacro
<robot name = "mycar" xmlns:xacro = "http://wiki.ros.org/xacro">
<xacro:property name = "footprint_radius" value = "0.001" />
<!-- 1. 添加 base_footprint -->
<link name = "base_footprint">
<visual>
<geometry>
<sphere radius = "${footprint_radius}" />
</geometry>
</visual>
</link>
<!-- 2. 添加底盘 -->
<!-- 形状: 底盘为圆柱状,半径 0.1m,高 0.08m 离地间距: 0.015m -->
<xacro:property name = "base_radius" value = "0.1" />
<xacro:property name = "base_length" value = "0.08" />
<xacro:property name = "lidi_space" value = "0.015" />
<xacro:property name = "base_joint_z" value = "${(base_length) / 2 + lidi_space}" />
<!-- 2-1 link -->
<link name = "base_link">
<visual>
<geometry>
<cylinder radius = "0.1" length = "0.08" />
</geometry>
<origin xyz = "0 0 0" rpy = "0 0 0"/>
<material name = "baselink_color">
<color rgba = "1 0.5 0.2 0.5" />
</material>
</visual>
</link>
<!-- 2-2 joint 半个车体的高度0.08m/2+0.015m-->
<joint name = "link2footprint" type = "fixed">
<parent link = "base_footprint" />
<child link = "base_link" />
<!-- 关节z上的设置 = 车体高度/2 + 离地高度 -->
<origin xyz = "0 0 0.055" rpy = "0 0 0" />
</joint>
<!-- 3. 添加驱动轮 -->
<!-- 形状: 圆柱 半径: 0.0325m 长度: 0.015m -->
<!-- 属性 -->
<xacro:property name = "wheel_radius" value = "0.0325" />
<xacro:property name = "wheel_length" value = "0.015" />
<xacro:property name = "PI" value = "3.1415927" />
<!-- 注意: 结果是负数 -->
<xacro:property name = "wheel_joint_z" value = "${(base_length / 2 + lidi_space - wheel_radius) * (-1)}" />
<!-- wheel_name: left或right flag: 1 或 -1 -->
<!-- 宏定义 -->
<xacro:macro name = "wheel_func" params = "wheel_name flag">
<!-- 3-1 link -->
<link name = "${wheel_name}_wheel">
<visual>
<geometry>
<cylinder radius = "${wheel_radius}" length = "${wheel_length}" />
</geometry>
<!-- 正常情况下圆柱面朝上,这里驱动轮在左右,需要修改欧拉角,沿x轴翻滚90度,约为1.57弧度 -->
<origin xyz = "0 0 0" rpy = "${PI / 2} 0 0"/>
<material name = "wheel_color">
<color rgba = "0 0 0 0.3" />
</material>
</visual>
</link>
<!-- 3-2 joint 关节 -->
<joint name = "${wheel_name}2link" type = "continuous">
<parent link = "base_link" />
<child link = "${wheel_name}_wheel" />
<!-- x: 0 无偏移 y: 0.1 车体半径 z: 0.04 + 0.015 - 0.0325 = 0.055 - 0.0325 = 0.0225,在下面为负数 关节高度 = 车体高度 / 2 + 离地间距 - 车轮半径 -->
<origin xyz = "0 ${0.1 * flag} ${wheel_joint_z}" rpy = "0 0 0" />
<!-- 转动时绕Y轴 -->
<axis xyz = "0 1 0" />
</joint>
</xacro:macro>
<!-- 调用才生效 -->
<xacro:wheel_func wheel_name = "left" flag = "1" />
<xacro:wheel_func wheel_name = "right" flag = "-1" />
<!-- 4. 添加万向轮 -->
<!-- 形状: 球 半径: 0.0075m -->
<!-- 属性 -->
<xacro:property name = "small_wheel_radius" value = "0.0075" />
<!-- 关节高度: 车体高度 / 2 + 离地间距 - 万向轮半径 = 0.04 + 0.015 - 0.0075 / 2 = 0.0475 -->
<xacro:property name = "small_joint_z" value = "${(base_length / 2 + lidi_space - small_wheel_radius) * (-1)}" />
<!-- 宏 -->
<xacro:macro name = "small_wheel_func" params = "small_wheel_name flag" >
<!-- 4-1 link -->
<link name = "${small_wheel_name}_wheel">
<visual>
<geometry>
<sphere radius = "${small_wheel_radius}" />
</geometry>
<origin xyz = "0 0 0" rpy = "0 0 0"/>
<material name = "wheel_color">
<color rbga = "0 0 0 0.3" />
</material>
</visual>
</link>
<!-- 4-2 joint -->
<joint name = "${small_wheel_name}2link" type = "continuous">
<parent link = "base_link" />
<child link = "${small_wheel_name}_wheel" />
<!-- x: 0.08 小于半径 y: 0 z: 0.04 + 0.015 - 0.0075 = 0.0475 -->
<origin xyz = "${0.08 * flag} 0 ${small_joint_z}" rpy = "0 0 0" />
<!-- 转动时绕Y轴 -->
<axis xyz = "0 1 0" />
</joint>
</xacro:macro >
<!-- 调用 -->
<xacro:small_wheel_func small_wheel_name = "front" flag = "1" />
<xacro:small_wheel_func small_wheel_name = "back" flag = "-1" />
</robot>
Xacro 实操
在前面小车底盘基础之上,添加摄像头和雷达传感器
摄像头xacro文件 demo06_car_camera.urdf.xacro
<robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- 摄像头部件 -->
<!-- 1. 参数 -->
<!-- 参数: 连杆属性: 厚度(x方向)、宽度(y方向)、高度(z方向) 关节属性: x y z 偏移量,z偏移量 = 底盘高度的一半+摄像头高度的一半 -->
<xacro:property name = "camera_length" value = "0.02" /> <!-- 厚度(x)-->
<xacro:property name = "camera_width" value = "0.05" /> <!-- 宽度(y)-->
<xacro:property name = "camera_height" value = "0.05" /> <!-- 高度(z)-->
<xacro:property name = "joint_camera_x" value = "0.08" /> <!-- 关节(x)-->
<xacro:property name = "joint_camera_y" value = "0" /> <!-- 关节(y)-->
<xacro:property name = "joint_camera_z" value = "${base_length / 2 + camera_height / 2}" /> <!-- 关节(z)-->
<!-- 2. 设计连杆关节 -->
<!-- 2-1 link -->
<link name = "camera">
<visual>
<geometry>
<box size = "${camera_length} ${camera_width} ${camera_height}" />
</geometry>
<material name = "black">
<color rgba = "0 0 0 0.8" />
</material>
</visual>
</link>
<!-- 2-2 关节 -->
<joint name = "camera2base" type = "fixed">
<parent link = "base_link" />
<child link = "camera" />
<origin xyz = "${joint_camera_x} ${joint_camera_y} ${joint_camera_z}" rpy = "0 0 0" />
</joint>
</robot>
雷达xacro文件 demo07_car_laser.urdf.xacro
<robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- 雷达部件 -->
<!-- 参数 -->
<!-- 1. 支架 支架尺寸: 半径 高度 关节偏移量: x y z 2. 雷达 支架尺寸: 半径 高度 关节偏移量: x y z -->
<xacro:property name = "support_radius" value = "0.01" />
<xacro:property name = "support_length" value = "0.15" />
<xacro:property name = "laser_radius" value = "0.03" />
<xacro:property name = "laser_length" value = "0.05" />
<xacro:property name = "joint_support_x" value = "0" />
<xacro:property name = "joint_support_y" value = "0" />
<!-- joint1 z = 车体高度 / 2 + 支架高度 / 2 -->
<xacro:property name = "joint_support_z" value = "${base_length / 2 + support_length / 2}" />
<xacro:property name = "joint_laser_x" value = "0" />
<xacro:property name = "joint_laser_y" value = "0" />
<!-- joint2 z = 支架高度 / 2 + 雷达高度 / 2 -->
<xacro:property name = "joint_laser_z" value = "${support_length / 2 + laser_length / 2}" />
<!-- 1. 支架 -->
<link name = "support">
<visual>
<geometry>
<cylinder radius = "${support_radius}" length = "${support_length}" />
</geometry>
<material name = "yellow">
<color rgba = "0.8 0.5 0 0.5" />
</material>
</visual>
</link>
<joint name = "support2base" type = "fixed">
<parent link = "base_link" />
<child link = "support" />
<origin xyz = "${joint_support_x} ${joint_support_y} ${joint_support_z}" rpy = "0 0 0"/>
</joint>
<!-- 2. 雷达 固定-->
<link name = "laser">
<visual>
<geometry>
<cylinder radius = "${laser_radius}" length = "${laser_length}" />
</geometry>
<material name = "black">
<color rgba = "0 0 0 0.5" />
</material>
</visual>
</link>
<joint name = "laser2support" type = "fixed">
<parent link = "support" />
<child link = "laser" />
<origin xyz = "${joint_laser_x} ${joint_laser_y} ${joint_laser_z}" rpy = "0 0 0"/>
</joint>
</robot>
组合底盘、摄像头、雷达xacro文件 car.urdf.xacro
<robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- 包含底盘、摄像头、雷达的xacro文件 -->
<xacro:include filename = "demo05_car_base.urdf.xacro" />
<xacro:include filename = "demo06_car_camera.urdf.xacro" />
<xacro:include filename = "demo07_car_laser.urdf.xacro" />
</robot>
launch文件 car.launch
<launch>
<!-- 1. 在参数服务器中载入URDF 建议用第二种方式-->
<!-- <param name = "robot_description" textfile = "$(find urdf01_rviz)/urdf/xacro/demo05_car_base.urdf" /> -->
<param name = "robot_description" command = "$(find xacro)/xacro $(find urdf01_rviz)/urdf/xacro/car.urdf.xacro" />
<!-- 2. 启动rviz -->
<node pkg = "rviz" type = "rviz" name = "rviz" args = "-d $(find urdf01_rviz)/config/show_mycar.rviz"/>
<!-- 3. 添加关节状态发布节点 -->
<node pkg = "joint_state_publisher" type = "joint_state_publisher" name = "joint_state_publisher" />
<!-- 4. 添加机器人状态发布节点 -->
<node pkg = "robot_state_publisher" type = "robot_state_publisher" name = "robot_state_publisher" />
<!-- 5. 关节运动控制节点 -->
<node pkg = "joint_state_publisher_gui" type = "joint_state_publisher_gui" name = "joint_state_publisher_gui" />
</launch>
边栏推荐
- How to conduct 360 assessment
- Member array and pointer in banyan loan C language structure
- 百融榕树数据模型
- OC message mechanism
- mysql底层数据结构
- The new version of Alibaba Seata finally solves the idempotence, suspension and empty rollback problems of TCC mode
- 03.获取网页源代码
- 基于OpenCV的轮廓检测(1)
- Food chain (day 79)
- Volatile keyword and its function
猜你喜欢

Characteristics and determination scheme of Worthington pectinase

Kettle读取按行分割的文件

A new paradigm of distributed deep learning programming: Global tensor

深圳家具展首日,金可儿展位三大看点全解锁!

477-82(236、61、47、74、240、93)

Feitengtengrui d2000 won the "top ten hard core technologies" award of Digital China

Basic concept and essence of Architecture

Mysql database related operations

On the first day of Shenzhen furniture exhibition, the three highlights of Jin Ke'er booth were unlocked!

Characteristics and determination scheme of Worthington pectinase
随机推荐
架构基本概念和架构本质
Kettle读取按行分割的文件
Technology vane | interpretation of cloud native technology architecture maturity model
How to interact with the server when the client sends an SQL message
MySQL has a nonexistent error
Implementation of API short message gateway based on golang
Wechat applet generation Excel
Docker creates MySQL 8.x container and supports Mac and arm architecture chips
C language force deduction question 43 string multiplication. Optimized vertical
Basic concept and essence of Architecture
Ring counting (Northern Polytechnic machine test questions) (day 83)
It's confirmed that the registration of soft exam in the second half of 2022 will start in August
Briefly sort out the dualpivotquicksort
代码回滚,你真的理解吗?
Realization of regular hexagon map with two-dimensional array of unity
面试题:String类中三种实例化对象的区别
How to optimize MySQL
Vector to SVG method
NLP hotspots from ACL 2022 onsite experience
C语言力扣第43题之字符串相乘。优化竖式