【Moveit】step或stl文件转urdf,并添加到机械臂上

【Moveit】step或stl文件转urdf,并添加到机械臂上

ROS专门提供了一种机器人建模方法——URDF,用来描述机器人外观、性能等各方面属性。所以我们需要将别的描述格式转换成URDF,才能在ROS中使用。

1. 安装sw_urdf_exporter插件

参考官方给出的wiki page:sw_urdf_exporter/Tutorials
我们需要给solideworks下载一个插件,插件地址为:SolidWorks to URDF Exporter,其github的release为:https://github.com/ros/solidworks_urdf_exporter/releases

注意solideworks的版本不能过高,这个插件支持solidworks的版本为(2018SP5~2021),我们安装的时候可以直接下载这个.exe可执行文件即可,然后默认安装

Image

2. 导出urdf

具体的操作可以参考这个视频:[ROS] Solidworks导出urdf

然后按照教程中的方式进行导出即可。这里我导出了一个夹爪,如下所示

Image

导出的结果会生成一个ROS的功能包,其目录结果如下

.
├── CMakeLists.txt
├── config
│   └── joint_names_gripper_urdf3.yaml
├── export.log
├── launch
│   ├── display.launch
│   └── gazebo.launch
├── meshes
│   └── base_link.STL
├── package.xml
├── textures
└── urdf
    ├── gripper_urdf3.csv
    └── gripper_urdf3.urdf

5 directories, 9 files

我们可以使用其display.launch来查看模型是否正确,但是首先得使用catkin_make来进行编译一下,我的显示结果如下

roslaunch gripper_urdf display.launch

打开rviz之后,我们需要手动添加RobotModel,添加完毕后即可显示

Image

显示的效果如下:

Image

3. 将夹爪连接到机械臂上

在导出的功能包中最重要的内容是meshs目录中的.stl文件,这是我们夹爪的模型外观,还有就是urdf目录中的gripper_urdf3.urdf文件,这个是根据.stl模型文件生成的ROS下的URDF机器人描述文件,我们可以复制其中的部分,然后将其粘贴到我们的机械臂的URDF中。

值得注意的是,link-joint-link是urdf的基本结构,示意如下

Image

我们在编写joint时,需要指定其类型,一共有这么四种类型可以指定

Image

夹爪的基座相对于机械臂是固定的,所以我们在指定夹爪的基座到机械臂的末端的这个joint的时候,一定要选择fixed类型,具体可以这么写

	<joint name="gripper_joint" type="fixed">
	    <origin rpy="0 0 0" xyz="0 0 0.107" />	#xyz rpy是你的夹爪相对于机械臂的姿态
	    <parent link="wrist3_Link" />	#改为你的机械臂的最后一个link
	    <child link="arm_hand_link0" /> #改为你的gripper的base link
	    <axis xyz="0 0 0" />
	</joint>

在定义完这个joint之后,我们就可以将之前生成的URDF中的内容复制到其中,如下是我生成的内容

    </joint>
    <link name="arm_hand_link0">
        <inertial>
            <origin xyz="-2.12153840077004E-06 9.05398824170634E-05 0.0527906490348432" rpy="0 0 0" />
            <mass value="0.113713405635938" />
            <inertia ixx="5.00996061302902E-05" ixy="3.81710319217012E-10" ixz="2.12328984939388E-10" iyy="5.98637675434999E-05" iyz="-3.29078206892533E-08" izz="6.10777596321381E-05" />
        </inertial>
        <visual>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <geometry>
                <mesh filename="package://frcobot_description/meshes/fr5/collision/hand_1.STL" />
            </geometry>
            <material name="">
                <color rgba="0.792156862745098 0.819607843137255 0.933333333333333 1" />
            </material>
        </visual>
        <collision>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <geometry>
                <mesh filename="package://frcobot_description/meshes/fr5/collision/hand_1.STL" />
            </geometry>
        </collision>
    </link>
    <transmission name="trans_j1">
        <type>transmission_interface/SimpleTransmission</type>
        <joint name="j1">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
        </joint>
        <actuator name="j1_motor">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
    </transmission>
    <transmission name="trans_j2">
        <type>transmission_interface/SimpleTransmission</type>
        <joint name="j2">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
        </joint>
        <actuator name="j2_motor">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
    </transmission>
    <transmission name="trans_j3">
        <type>transmission_interface/SimpleTransmission</type>
        <joint name="j3">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
        </joint>
        <actuator name="j3_motor">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
    </transmission>
    <transmission name="trans_j4">
        <type>transmission_interface/SimpleTransmission</type>
        <joint name="j4">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
        </joint>
        <actuator name="j4_motor">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
    </transmission>
    <transmission name="trans_j5">
        <type>transmission_interface/SimpleTransmission</type>
        <joint name="j5">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
        </joint>
        <actuator name="j5_motor">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
    </transmission>
    <transmission name="trans_j6">
        <type>transmission_interface/SimpleTransmission</type>
        <joint name="j6">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
        </joint>
        <actuator name="j6_motor">
            <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
    </transmission>
    <gazebo>
        <plugin name="gazebo_ros_control">
            <robotNamespace>/</robotNamespace>
        </plugin>
    </gazebo>

注意这里的package://需要更改为你存放这个urdf的包的名字,我这里是将其复制了一份,统一放置在了fr_description这个包中了,请将这里修改为你的放置路径。

4. 使用moveit_setup_assistant配置功能包

修改完毕后,我们就可以使用moveit_setup_assisatant来配置或者修改功能包了,

roslaunch moveit_setup_assistant setup_assistant.launch

如下所示,我们能看到夹爪正确地显示了

Image

Reference

[1]机械臂urdf模型修改及功能包配置

<think>好的,用户想了解如何从零开始搭建一个与ROS1兼容的机械。我需要结合提供的引用信息来构建一个详细的教程。首先,根据引用[4],用户提到了从三维模型导出URDF,所以第一步应该是创建机械的3D模型,将其换为URDF格式。可能需要使用SolidWorks其他CAD软件,然后导出为STEP文件,再换为URDF。接下来,安装ROS1环境是基础,引用[1]提到了ROS的基本知识,可能需要指导用户安装ROS Noetic,设置工作空间。 然后,配置URDF文件是关键步骤。引用[4]中提到了UR3机械的例子,用户需要正确配置关节和连杆,添加传感器和传输标签。可能需要引用ROS的官方文档引用[3]中的mycobot_ros项目作为参考。接下来,搭建控制框架部分,引用[3]提到使用MoveIt和Gazebo进行仿真,所以需要指导用户安装MoveIt和配置控制器,比如使用ros_control插件,以及启动Gazebo进行验证。 调试和测试部分,可能需要使用RViz和Gazebo来可视化机械测试简单的运动规划。引用[2]中的ROS2案例虽然是用ROS2,但原理类似,可以适当参考。最后,实际应用部分,引用[1]和[3]都提到了与真实硬件对接,可能需要指导用户编写控制节点和集成传感器数据。 需要注意用户提到的ROS1兼容性,所以所有步骤都要基于ROS1的版本,比如使用Noetic。同时,要确保LaTeX格式正确,行内公式用$...$,独立公式用$$...$$,且生成相关问题。检查引用标记是否正确添加,例如在提到URDF换和MoveIt时引用对应的资料。最后,生成的相关问题要围绕机械搭建的扩展内容,如URDF优化、MoveIt配置、仿真测试和真实硬件对接等。</think>### 从零搭建与ROS1兼容的机械教程 #### 1. **机械三维建模与URDF生成** - **步骤1:创建3D模型** 使用SolidWorks、Blender等工具设计机械模型,确保包含关节、连杆等基本结构。保存为`.step``.stl`格式[^4]。 *示例命令:* ```bash # 在Blender中导出模型为URDF兼容格式 ``` - **步骤2:生成URDF文件** 使用`sw_urdf_exporter`插件(SolidWorks)`blender_urdf`工具将模型换为URDF格式。 *关键配置:* ```xml <link name="base_link"> <inertial> <mass value="1.0"/> <origin xyz="0 0 0.5"/> </inertial> </link> <joint name="joint1" type="revolute"> <parent link="base_link"/> <child link="link1"/> </joint> ``` 引用:URDF需定义关节运动范围、坐标系和惯性参数[^4]。 --- #### 2. **ROS1环境配置** - **安装ROS Noetic** 参考官方文档安装ROS1 Noetic版本,创建Catkin工作空间: ```bash sudo apt-get install ros-noetic-desktop-full mkdir -p ~/catkin_ws/src && cd ~/catkin_ws && catkin_make ``` - **配置URDF依赖包** 安装`urdf_tutorial`和`xacro`包以解析URDF文件: ```bash sudo apt-get install ros-noetic-urdf ros-noetic-xacro ``` --- #### 3. **机械控制框架搭建** - **步骤1:集成MoveIt!框架** 使用MoveIt! Setup Assistant生成机械配置包: ```bash roslaunch moveit_setup_assistant setup_assistant.launch ``` 引用:MoveIt!提供运动规划、碰撞检测等功能[^3]。 - **步骤2:添加Gazebo仿真插件** 在URDF添加Gazebo控制器接口: ```xml <gazebo> <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so"> <robotNamespace>/my_arm</robotNamespace> </plugin> </gazebo> ``` 引用:Gazebo可实现物理仿真和传感器模拟[^2]。 --- #### 4. **调试与验证** - **启动RViz可视化** 通过RViz验证机械模型和运动规划: ```bash roslaunch my_arm_moveit_config demo.launch ``` - **Gazebo仿真测试** 加载机械到Gazebo环境测试关节控制: ```bash roslaunch my_arm_gazebo my_arm_world.launch ``` --- #### 5. **真实硬件对接(可选)** - **配置ROS驱动** 根据硬件接口(如Arduino、STM32)编写ROS节点,订阅`/joint_states`话题。 *示例代码片段:* ```cpp ros::Subscriber sub = nh.subscribe("/joint_commands", 10, jointCallback); ``` - **集成传感器数据** 通过`tf`发布机械坐标系,融合IMU摄像头数据[^1]。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值