【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模型修改及功能包配置

在使用Foxy版本的ROS中,你可以使用以下步骤将.stl文件换为URDF文件: 1. 首先,确保你已经安装了ROS Foxy和相关的软件包。你可以使用以下命令来安装相应的软件包: ```bash sudo apt install ros-foxy-urdfdom-py sudo apt install ros-foxy-urdf-parser-py ``` 2. 创建一个用于存储URDF文件的工作空间,进入该工作空间: ```bash mkdir -p urdf_conversion_ws/src cd urdf_conversion_ws/src ``` 3. 创建一个URDF进入该包的目录: ```bash ros2 pkg create --build-type ament_python urdf_conversion_pkg cd urdf_conversion_pkg ``` 4. 在`urdf_conversion_pkg`包的`urdf_conversion_pkg`目录中创建一个Python脚本,例如`convert_stl_to_urdf.py`,编辑该脚本: ```python #!/usr/bin/env python3 import os from urdf_parser_py.urdf import URDF from urdf_parser_py.xml_reflection.basics import Vector3, Quaternion from urdf_parser_py.xml_reflection import set_attributes def convert_stl_to_urdf(stl_file_path, urdf_file_path): # 创建一个URDF对象 urdf = URDF() # 设置URDF中的各个组件 # 设置模型名称 urdf.name = "my_robot" # 设置根链接 root_link = urdf.create_link() root_link.name = "base_link" # 设置链接的几何形状 geometry = urdf.create_geometry() geometry.type = "mesh" geometry.filename = stl_file_path # 设置链接的原点和姿态 origin = urdf.create_origin() origin.position = Vector3(0, 0, 0) origin.rotation = Quaternion(0, 0, 0, 1) # 将几何形状、原点和姿态添加到链接中 link = urdf.create_link() link.name = "link" link.visual.geometry = geometry link.visual.origin = origin link.inertial.origin = origin # 将链接添加到根链接中 root_link.add_child(link) # 将根链接添加URDF模型中 urdf.add_link(root_link) # 将URDF模型保存到文件urdf.save(urdf_file_path) if __name__ == "__main__": stl_file_path = "/path/to/your/stl/file.stl" urdf_file_path = "/path/to/save/urdf/file.urdf" convert_stl_to_urdf(stl_file_path, urdf_file_path) ``` 请将`/path/to/your/stl/file.stl`替换为你的实际.stl文件的路径,将`/path/to/save/urdf/file.urdf`替换为你想要保存URDF文件的路径。 5. 添加可执行权限构建工作空间: ```bash chmod +x convert_stl_to_urdf.py cd ../.. colcon build ``` 6. 运行脚本进行换: ```bash . install/setup.bash ros2 run urdf_conversion_pkg convert_stl_to_urdf.py ``` 以上步骤将把.stl文件换为URDF文件保存在指定的路径中。请确保你的.stl文件是有效的,且包含正确的几何信息。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

木心

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

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

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

打赏作者

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

抵扣说明:

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

余额充值