26、ROS机器人编程:OpenManipulator Chain的建模与可视化

ROS机器人编程:OpenManipulator Chain的建模与可视化

1. OpenManipulator Chain简介

OpenManipulator Chain是一种具有基本形式的机械臂,其末端执行器是由3D打印框架制成的线性夹爪。它的设计文件可在Onshape上获取,源代码可从ROBOTIS GitHub下载。该源代码支持ROS、Arduino和Processing,以及Gazebo和MoveIt! 软件包。此外,OpenManipulator Chain与TurtleBot3 Waffle和Waffle Pi机械兼容,具有扩展功能以弥补自由度不足的潜力。

在使用相关工具前,需要安装以下ROS软件包:

sudo apt-get install ros-kinetic-ros-controllers ros-kinetic-gazebo* ros-kinetic-moveit* ros-kinetic-dynamixel-sdk ros-kinetic-dynamixel-workbench-toolbox ros-kinetic-robotis-math ros-kinetic-industrial-core
2. 简单机械臂的URDF建模

在查看OpenManipulator Chain的URDF之前,先创建一个由三个关节和四个连杆组成的简单机械臂的URDF。操作步骤如下:
1. 创建 testbot_description 软件包并创建 urdf 文件夹:

cd ~/catkin_ws/src
catkin_create_pkg testbot_description urdf
cd testbot_description
mkdir urdf
cd urdf
  1. 使用编辑器创建 testbot.urdf 文件并输入以下内容:
<?xml version="1.0" ?>
<robot name="testbot">
  <material name="black">
    <color rgba="0.0 0.0 0.0 1.0"/>
  </material>
  <material name="orange">
    <color rgba="1.0 0.4 0.0 1.0"/>
  </material>
  <link name="base"/>
  <joint name="fixed" type="fixed">
    <parent link="base"/>
    <child link="link1"/>
  </joint>
  <link name="link1">
    <collision>
      <origin xyz="0 0 0.25" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 0.5"/>
      </geometry>
    </collision>
    <visual>
      <origin xyz="0 0 0.25" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 0.5"/>
      </geometry>
      <material name="black"/>
    </visual>
    <inertial>
      <origin xyz="0 0 0.25" rpy="0 0 0"/>
      <mass value="1"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
    </inertial>
  </link>
  <joint name="joint1" type="revolute">
    <parent link="link1"/>
    <child link="link2"/>
    <origin xyz="0 0 0.5" rpy="0 0 0"/>
    <axis xyz="0 0 1"/>
    <limit effort="30" lower="-2.617" upper="2.617" velocity="1.571"/>
  </joint>
  <link name="link2">
    <collision>
      <origin xyz="0 0 0.25" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 0.5"/>
      </geometry>
    </collision>
    <visual>
      <origin xyz="0 0 0.25" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 0.5"/>
      </geometry>
      <material name="orange"/>
    </visual>
    <inertial>
      <origin xyz="0 0 0.25" rpy="0 0 0"/>
      <mass value="1"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
    </inertial>
  </link>
  <joint name="joint2" type="revolute">
    <parent link="link2"/>
    <child link="link3"/>
    <origin xyz="0 0 0.5" rpy="0 0 0"/>
    <axis xyz="0 1 0"/>
    <limit effort="30" lower="-2.617" upper="2.617" velocity="1.571"/>
  </joint>
  <link name="link3">
    <collision>
      <origin xyz="0 0 0.5" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
    </collision>
    <visual>
      <origin xyz="0 0 0.5" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 1"/>
      </geometry>
      <material name="black"/>
    </visual>
    <inertial>
      <origin xyz="0 0 0.5" rpy="0 0 0"/>
      <mass value="1"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
    </inertial>
  </link>
  <joint name="joint3" type="revolute">
    <parent link="link3"/>
    <child link="link4"/>
    <origin xyz="0 0 1.0" rpy="0 0 0"/>
    <axis xyz="0 1 0"/>
    <limit effort="30" lower="-2.617" upper="2.617" velocity="1.571"/>
  </joint>
  <link name="link4">
    <collision>
      <origin xyz="0 0 0.25" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 0.5"/>
      </geometry>
    </collision>
    <visual>
      <origin xyz="0 0 0.25" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 0.5"/>
      </geometry>
      <material name="orange"/>
    </visual>
    <inertial>
      <origin xyz="0 0 0.25" rpy="0 0 0"/>
      <mass value="1"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
    </inertial>
  </link>
</robot>
3. URDF标签解析
  • <material> 标签 :用于描述连杆的颜色和纹理信息。例如:
<material name="black">
  <color rgba="0.0 0.0 0.0 1.0"/>
</material>
<material name="orange">
  <color rgba="1.0 0.4 0.0 1.0"/>
</material>
  • <link> 标签 :描述连杆的名称、大小、重量和惯性等信息,包含 <collision> <visual> <inertial> 子标签。
    • <collision> :设置连杆的碰撞计算信息。
    • <visual> :设置连杆的可视化信息。
    • <inertial> :设置连杆的惯性信息。
<link name="link1">
  <collision>
    <origin xyz="0 0 0.25" rpy="0 0 0"/>
    <geometry>
      <box size="0.1 0.1 0.5"/>
    </geometry>
  </collision>
  <visual>
    <origin xyz="0 0 0.25" rpy="0 0 0"/>
    <geometry>
      <box size="0.1 0.1 0.5"/>
    </geometry>
    <material name="black"/>
  </visual>
  <inertial>
    <origin xyz="0 0 0.25" rpy="0 0 0"/>
    <mass value="1"/>
    <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
  </inertial>
</link>
  • <joint> 标签 :描述关节的名称、类型以及连接的连杆,还可以设置关节的运动限制。
<joint name="joint2" type="revolute">
  <parent link="link2"/>
  <child link="link3"/>
  <origin xyz="0 0 0.5" rpy="0 0 0"/>
  <axis xyz="0 1 0"/>
  <limit effort="30" lower="-2.617" upper="2.617" velocity="1.571"/>
</joint>
4. 模型检查与可视化
  • 检查URDF语法错误和连接关系
check_urdf testbot.urdf

如果文件语法和逻辑正确,将输出连杆的连接关系。
- 生成模型的图形表示

urdf_to_graphiz testbot.urdf

运行该命令后会生成 *.gv 文件和 *.pdf 文件,通过PDF查看器可以查看连杆和关节的关系。
- 使用RViz可视化模型
1. 创建 testbot.launch 文件:

cd ~/catkin_ws/src/testbot_description
mkdir launch
cd launch
gedit testbot.launch
2. 在`testbot.launch`文件中输入以下内容:
<launch>
  <arg name="model" default="$(find testbot_description)/urdf/testbot.urdf" />
  <arg name="gui" default="True" />
  <param name="robot_description" textfile="$(arg model)" />
  <param name="use_gui" value="$(arg gui)"/>
  <node pkg="joint_state_publisher" type="joint_state_publisher" name="joint_state_publisher"/>
  <node pkg="robot_state_publisher" type="state_publisher" name="robot_state_publisher"/>
</launch>
3. 运行`testbot.launch`和RViz:
roslaunch testbot_description testbot.launch
rviz

在RViz中,选择 base 作为固定框架,添加 RobotModel TF 显示,调整机器人模型的 Alpha 值约为0.3,即可查看连杆的形状和关节的关系。通过调整 joint_state_publisher 节点的GUI滑块,可以控制RViz中的虚拟机器人。

5. OpenManipulator Chain的URDF建模
  • 下载源代码
cd ~/catkin_ws/src
git clone https://github.com/ROBOTIS-GIT/open_manipulator.git
cd ~/catkin_ws && catkin_make
cd ~/catkin_ws/src/
git clone https://github.com/ROBOTIS-GIT/turtlebot3.git
git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
cd ~/catkin_ws && catkin_make
  • 查看OpenManipulator文件夹结构
cd ~/catkin_ws/src/open_manipulator
ls

主要文件夹包括:
| 文件夹名称 | 说明 |
| ---- | ---- |
| Arduino | Arduino库 |
| open_manipulator | 元软件包 |
| open_manipulator_description | 建模软件包 |
| open_manipulator_dynamixel_ctrl | Dynamixel控制软件包 |
| open_manipulator_gazebo | Gazebo软件包 |
| open_manipulator_moveit | MoveIt!软件包 |
| open_manipulator_msgs | 消息软件包 |
| open_manipulator_position_ctrl | 位置控制软件包 |
| open_manipulator_with_tb3 | OpenManipulator和TurtleBot3软件包 |

  • 查看建模软件包的配置
roscd open_manipulator_description/urdf
ls
roscd open_manipulator_description/launch
ls
  • 查看材料信息文件 materials.xacro
roscd open_manipulator_description/urdf
gedit materials.xacro

该文件定义了未来机械臂可视化所需的颜色。
- 查看OpenManipulator Chain的URDF文件 open_manipulator_chain.xacro

roscd open_manipulator_description/urdf
gedit open_manipulator_chain.xacro

使用xacro可以减少URDF文件的重复代码,提高代码管理效率。
- <transmission> 标签 :用于与ROS-Control交互,建立关节和执行器之间的关系。

<transmission name="tran1">
  <type>transmission_interface/SimpleTransmission</type>
  <joint name="joint1">
    <hardwareInterface>PositionJointInterface</hardwareInterface>
  </joint>
  <actuator name="motor1">
    <hardwareInterface>PositionJointInterface</hardwareInterface>
    <mechanicalReduction>1</mechanicalReduction>
  </actuator>
</transmission>
  • 可视化OpenManipulator Chain的URDF文件
roslaunch open_manipulator_description open_manipulator_chain_rviz.launch

通过以上步骤,我们可以完成简单机械臂和OpenManipulator Chain的URDF建模和可视化,为后续的机器人开发和控制奠定基础。

ROS机器人编程:OpenManipulator Chain的建模与可视化(续)

6. 深入理解OpenManipulator Chain URDF文件

OpenManipulator Chain的URDF文件使用了xacro来简化代码,提高可维护性。我们已经了解了其基本结构和一些关键标签,下面进一步剖析其细节。

6.1 xacro的使用优势

xacro允许我们定义变量和宏,避免代码的重复编写。例如,在 open_manipulator_chain.xacro 中,我们可以定义圆周率变量:

<xacro:property name="pi" value="3.141592654" />

还可以通过 xacro:include 指令引入其他文件,如材料信息文件和Gazebo配置文件:

<xacro:include filename="$(find open_manipulator_description)/urdf/open_manipulator_chain.gazebo.xacro" />
<xacro:include filename="$(find open_manipulator_description)/urdf/materials.xacro" />

这样可以将不同功能的代码分开管理,使代码更加清晰和易于维护。

6.2 <transmission> 标签详解

<transmission> 标签是与ROS - Control交互的关键。它定义了关节和执行器之间的关系,允许我们选择不同的控制输入(如力、速度、位置)。

<transmission name="tran1">
  <type>transmission_interface/SimpleTransmission</type>
  <joint name="joint1">
    <hardwareInterface>PositionJointInterface</hardwareInterface>
  </joint>
  <actuator name="motor1">
    <hardwareInterface>PositionJointInterface</hardwareInterface>
    <mechanicalReduction>1</mechanicalReduction>
  </actuator>
</transmission>
  • <type> :指定传动方法的类型,这里使用 transmission_interface/SimpleTransmission
  • <joint> :配置关节信息,指定关节名称和硬件接口类型。
  • <actuator> :设置执行器信息,包括硬件接口类型和机械减速比。
6.3 OpenManipulator Chain的结构

OpenManipulator Chain由四个关节(电机)和五个连杆组成,线性夹爪由两个连杆和一个关节(电机)组成。除了线性夹爪的关节类型为棱柱关节(prismatic)外,其他关节和连杆的描述与之前的示例类似。

7. 可视化与调试流程总结

为了更清晰地展示整个可视化和调试的流程,我们可以用mermaid流程图来表示:

graph LR
    classDef startend fill:#F5EBFF,stroke:#BE8FED,stroke-width:2px
    classDef process fill:#E5F6FF,stroke:#73A6FF,stroke-width:2px
    classDef decision fill:#FFF6CC,stroke:#FFBC52,stroke-width:2px

    A([开始]):::startend --> B(安装ROS软件包):::process
    B --> C(创建简单机械臂URDF):::process
    C --> D(检查URDF语法和连接关系):::process
    D --> E{是否正确}:::decision
    E -- 是 --> F(生成模型图形表示):::process
    E -- 否 --> C
    F --> G(创建launch文件):::process
    G --> H(运行launch文件和RViz):::process
    H --> I(可视化和调试):::process
    I --> J(下载OpenManipulator Chain源代码):::process
    J --> K(查看文件夹结构和配置):::process
    K --> L(查看材料和URDF文件):::process
    L --> M(可视化OpenManipulator Chain URDF):::process
    M --> N([结束]):::startend

具体步骤如下:
1. 安装ROS软件包 :确保所需的ROS软件包已安装。

sudo apt-get install ros-kinetic-ros-controllers ros-kinetic-gazebo* ros-kinetic-moveit* ros-kinetic-dynamixel-sdk ros-kinetic-dynamixel-workbench-toolbox ros-kinetic-robotis-math ros-kinetic-industrial-core
  1. 创建简单机械臂URDF :按照前面的步骤创建 testbot.urdf 文件。
  2. 检查URDF语法和连接关系
check_urdf testbot.urdf
  1. 生成模型图形表示
urdf_to_graphiz testbot.urdf
  1. 创建launch文件 :创建 testbot.launch 文件并配置相关参数。
  2. 运行launch文件和RViz
roslaunch testbot_description testbot.launch
rviz
  1. 可视化和调试 :在RViz中进行可视化和调试。
  2. 下载OpenManipulator Chain源代码
cd ~/catkin_ws/src
git clone https://github.com/ROBOTIS-GIT/open_manipulator.git
cd ~/catkin_ws && catkin_make
cd ~/catkin_ws/src/
git clone https://github.com/ROBOTIS-GIT/turtlebot3.git
git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
cd ~/catkin_ws && catkin_make
  1. 查看文件夹结构和配置 :查看相关文件夹和文件的配置。
cd ~/catkin_ws/src/open_manipulator
ls
roscd open_manipulator_description/urdf
ls
roscd open_manipulator_description/launch
ls
  1. 查看材料和URDF文件 :查看 materials.xacro open_manipulator_chain.xacro 文件。
roscd open_manipulator_description/urdf
gedit materials.xacro
roscd open_manipulator_description/urdf
gedit open_manipulator_chain.xacro
  1. 可视化OpenManipulator Chain URDF
roslaunch open_manipulator_description open_manipulator_chain_rviz.launch
8. 注意事项和常见问题

在进行URDF建模和可视化的过程中,可能会遇到一些问题,以下是一些注意事项和常见问题的解决方法:

问题 解决方法
URDF语法错误 使用 check_urdf 命令检查语法错误,仔细检查标签的拼写和格式。
模型在RViz中显示异常 检查 launch 文件的配置,确保 robot_description 参数正确指向URDF文件。
无法找到相关软件包 确保所需的ROS软件包已正确安装,使用 rosdep install 命令安装依赖项。
可视化效果不佳 调整RViz中的显示参数,如透明度、颜色等。
9. 总结与展望

通过本文,我们详细介绍了如何使用URDF对简单机械臂和OpenManipulator Chain进行建模和可视化。从创建基本的URDF文件到使用xacro简化代码,再到使用RViz进行可视化和调试,我们逐步深入了解了整个过程。

在后续的开发中,我们可以基于这些模型进行更复杂的机器人控制和规划任务,如运动规划、路径规划等。同时,我们还可以结合其他ROS工具和库,进一步扩展机器人的功能。

希望本文能帮助你更好地理解和掌握ROS机器人编程中的URDF建模和可视化技术,为你的机器人开发之旅提供有力的支持。

内容概要:本文档介绍了基于3D FDTD(时域有限差分)方法在MATLAB平台上对微带线馈电的矩形天线进行仿真分析的技术方案,重点在于模拟超MATLAB基于3D FDTD的微带线馈矩形天线分析[用于模拟超宽带脉冲通过线馈矩形天线的传播,以计算微带结构的回波损耗参数]宽带脉冲信号通过天线结构的传播过程,并计算微带结构的回波损耗参数(S11),以评估天线的匹配性能和辐射特性。该方法通过建立三维电磁场模型,精确求解麦克斯韦方程组,适用于高频电磁仿真,能够有效分析天线在宽频带内的响应特性。文档还提及该资源属于一个涵盖多个科研方向的综合性MATLAB仿真资源包,涉及通信、信号处理、电力系统、机器学习等多个领域。; 适合人群:具备电磁场微波技术基础知识,熟悉MATLAB编程及数值仿真的高校研究生、科研人员及通信工程领域技术人员。; 使用场景及目标:① 掌握3D FDTD方法在天线仿真中的具体实现流程;② 分析微带天线的回波损耗特性,优化天线设计参数以提升宽带匹配性能;③ 学习复杂电磁问题的数值建模仿真技巧,拓展在射频无线通信领域的研究能力。; 阅读建议:建议读者结合电磁理论基础,仔细理解FDTD算法的离散化过程和边界条件设置,运行并调试提供的MATLAB代码,通过调整天线几何尺寸和材料参数观察回波损耗曲线的变化,从而深入掌握仿真原理工程应用方法。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值