使用版本虚拟机ubuntu20.04noetic
目的:arbotix功能包,键盘驱动差速小车
launch文件代码
<launch>
<param name="robot_description" textfile ="$(find mbot_description)/urdf/mbot_body.urdf"/>
<!-- 设置GUI参数,显示关节控制插件 -->
<param name="use_gui" value="ture"/>
<!-- 运行joint_state_publisher节点,发布机器人的关节状态 -->
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher"/>
<!-- 运行robot_state_publisher节点,发布tf -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"/>
<!-- 可选:用于控制关节运动的节点 -->
<node pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" name="joint_state_publisher_gui" />
<!-- 运行rviz可视化界面 -->
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true"/>
</launch>
urdf文件(xacro文件转urdf)代码
<?xml version="1.0"?>
<robot name="mbot_body" xmlns:xacro="http://www.ros.org/wiki/xacro">
<!-- 属性参数 -->
<xacro:property name="M_PI" value="3.14159"/>
<xacro:property name="body_length" value="0.5"/>
<xacro:property name="body_width" value="0.3"/>
<xacro:property name="body_height" value="0.15"/>
<xacro:property name="motor_radius" value="0.03"/>
<xacro:property name="motor_length" value="0.04"/>
<xacro:property name="wheel_radius" value="0.08"/>
<xacro:property name="wheel_length" value="0.04"/>
<!-- 常用颜色定义-->
<material name = "white">
<color rgba = "1 1 1 1"/>
</material>
<material name = "red">
<color rgba = "1 0 0 1"/>
</material>
<material name = "green">
<color rgba = "0 1 0 1"/>
</material>
<material name = "blue">
<color rgba = "0 0 1 1"/>
</material>
<material name = "black">
<color rgba = "0 0 0 1"/>
</material>
<link name="base_link">
<visual>
<geometry>
<box size="${body_length} ${body_width} ${body_height}"/>
</geometry>
<origin rpy="0 0 0" xyz="0 0 0.0"/>
<material name="blue"/>
</visual>
</link>
<xacro:macro name="base" params="parent code x_loc y_loc z_loc">
<joint name="base_${code}_wheel_joint" type="fixed">
<origin xyz="${x_loc} ${y_loc} ${z_loc}" rpy="${M_PI/2} 0 0" />
<parent link="${parent}"/>
<child link="base_${code}_wheel_link" />
<axis xyz="0 0 1"/>
</joint>
<link name="base_${code}_wheel_link">
<!-- 声明对象的质量,转动惯量矩阵-->
<!-- <inertial>
<mass value="0.001" />
<origin xyz="0 0 0" />
<inertia ixx="0.0001" ixy="0.0" ixz="0.0"
iyy="0.0001" iyz="0.0"
izz="0.0001" />
</inertial> -->
<!-- 声明可视化属性,放置在link标签中-->
<visual>
<origin xyz=" 0 0 0 " rpy="0 0 0" /> <!-- 声明放置位置以及朝向,放置在visual标签中-->
<geometry> <!-- 声明形状,放置在visual标签中-->
<cylinder length="${wheel_length}" radius="${wheel_radius}"/>
</geometry>
<material name="black"/>
</visual>
<!-- 声明碰撞属性-->
<!-- <collision>
<origin xyz="0.0 0.0 0.0" rpy="0 0 0" />
<geometry>
<box size="0.01 0.01 0.07" />
</geometry>
</collision> -->
</link>
</xacro:macro>
<xacro:base parent="base_link" code="l" x_loc="0" y_loc="${body_width/2 + wheel_length/2 + motor_length/2}" z_loc="-${body_height/2 - motor_radius}"/>
<xacro:base parent="base_link" code="r" x_loc="0" y_loc="-${body_width/2 + wheel_length/2 + motor_length/2}" z_loc="-${body_height/2 - motor_radius}"/>
<!-- <joint name="kinect_joint" type="continuous"> -->
<joint name="kinect_joint" type="fixed">
<origin rpy="0 0 0" xyz="${body_length/2-0.02} 0 ${0.035+body_height/2}"/>
<parent link="base_link"/>
<child link="kinect_link"/>
<!--设置关节旋转参考的坐标轴-->
<!-- <axis xyz="0 0 1"/> -->
</joint>
<link name="kinect_link">
<visual>
<origin rpy="0 0 1.5708" xyz="0 0 0"/>
<geometry>
<mesh filename="package://mbot_description/meshes/kinect.dae"/>
</geometry>
</visual>
</link>
<!-- 定义电机的宏 1-左前轮 2-右前轮 3-右后轮 4-左后轮-->
<xacro:macro name="motor" params="parent number x_loc y_loc z_loc">
<joint name="motor_${number}_joint" type="fixed">
<origin xyz="${x_loc} ${y_loc} ${z_loc}" rpy="${M_PI/2} 0 0" />
<parent link="${parent}"/>
<child link="motor_${number}_link" />
</joint>
<link name="motor_${number}_link">
<!-- 声明对象的质量,转动惯量矩阵-->
<!-- <inertial>
<mass value="0.001" />
<origin xyz="0 0 0" />
<inertia ixx="0.0001" ixy="0.0" ixz="0.0"
iyy="0.0001" iyz="0.0"
izz="0.0001" />
</inertial> -->
<!-- 声明可视化属性,放置在link标签中-->
<visual>
<origin xyz="0 0 0 " rpy="0 0 0" /> <!-- 声明放置位置以及朝向,放置在visual标签中-->
<geometry> <!-- 声明形状,放置在visual标签中-->
<cylinder length="${motor_length}" radius="${motor_radius}"/>
</geometry>
<material name="white"/>
</visual>
<!-- 声明碰撞属性-->
<!-- <collision>
<origin xyz="0.0 0.0 0.0" rpy="0 0 0" />
<geometry>
<box size="0.01 0.01 0.07" />
</geometry>
</collision> -->
</link>
</xacro:macro>
<!-- 定义车轮的宏 1-左前轮 2-右前轮 3-右后轮 4-左后轮-->
<xacro:macro name="wheel" params="parent number x_loc y_loc z_loc">
<joint name="wheel_${number}_joint" type="fixed">
<origin xyz="${x_loc} ${y_loc} ${z_loc}" rpy="${M_PI/2} 0 0" />
<parent link="${parent}"/>
<child link="wheel_${number}_link" />
</joint>
<link name="wheel_${number}_link">
<!-- 声明对象的质量,转动惯量矩阵-->
<!-- <inertial>
<mass value="0.001" />
<origin xyz="0 0 0" />
<inertia ixx="0.0001" ixy="0.0" ixz="0.0"
iyy="0.0001" iyz="0.0"
izz="0.0001" />
</inertial> -->
<!-- 声明可视化属性,放置在link标签中-->
<visual>
<origin xyz=" 0 0 0 " rpy="0 0 0" /> <!-- 声明放置位置以及朝向,放置在visual标签中-->
<geometry> <!-- 声明形状,放置在visual标签中-->
<cylinder length="${wheel_length}" radius="${wheel_radius}"/>
</geometry>
<material name="black"/>
</visual>
<!-- 声明碰撞属性-->
<!-- <collision>
<origin xyz="0.0 0.0 0.0" rpy="0 0 0" />
<geometry>
<box size="0.01 0.01 0.07" />
</geometry>
</collision> -->
</link>
</xacro:macro>
<xacro:wheel parent="base_link" number="1" x_loc="${body_length/2 - wheel_radius}" y_loc="${body_width/2 + wheel_length/2 + motor_length/2}" z_loc="-${body_height/2 - motor_radius}"/>
<xacro:wheel parent="base_link" number="2" x_loc="${body_length/2 - wheel_radius}" y_loc="-${body_width/2 + wheel_length/2 + motor_length/2}" z_loc="-${body_height/2 - motor_radius}"/>
<xacro:wheel parent="base_link" number="3" x_loc="-${body_length/2 - wheel_radius}" y_loc="-${body_width/2 + wheel_length/2 + motor_length/2}" z_loc="-${body_height/2 - motor_radius}"/>
<xacro:wheel parent="base_link" number="4" x_loc="-${body_length/2 - wheel_radius}" y_loc="${body_width/2 + wheel_length/2 + motor_length/2}" z_loc="-${body_height/2 - motor_radius}"/>
<xacro:motor parent="base_link" number="1" x_loc="${body_length/2 - wheel_radius}" y_loc="${body_width/2}" z_loc="-${body_height/2 - motor_radius}"/>
<xacro:motor parent="base_link" number="2" x_loc="${body_length/2 - wheel_radius}" y_loc="-${body_width/2}" z_loc="-${body_height/2 - motor_radius}"/>
<xacro:motor parent="base_link" number="3" x_loc="-${body_length/2 - wheel_radius}" y_loc="-${body_width/2}" z_loc="-${body_height/2 - motor_radius}"/>
<xacro:motor parent="base_link" number="4" x_loc="-${body_length/2 - wheel_radius}" y_loc="${body_width/2}" z_loc="-${body_height/2 - motor_radius}"/>
</robot>