【ROS2】solidworks2021导出IRB52机器人的urdf,导入到coppeliasim和RViz2

本文详细介绍了如何从Solidworks2021导出ABB IRB52机器人的URDF模型,并将其成功导入到Coppeliasim和ROS2的RViz2环境中。过程中涉及了Solidworks中对模型的处理、URDF导出的注意事项、后处理步骤以及在ROS2环境中的配置和启动。通过修改CMakeLists.txt、package.xml和创建launch文件,使得模型能在RViz2中正确显示。此外,还提供了启动示例和所需的关键配置文件内容。

原文链接 【ROS2】solidworks2021导出IRB52机器人的urdf,导入到coppeliasim和RViz2

原文有视频演示。本文无。

图片

Solidworks中机器人模型

图片

urdf导入到Coppeliasim-截图

图片

urdf在RViz2中显示-截图

笔记

一、下载机器人模型 

    从网络上(https://new.abb.com/products/robotics/zh/industrial-robots/irb-52)下载的ABB机器人step格式模型,solidworks加载后得到SLDASM文件,之后,对模型进行“解散子装配体”、“生成新子装配体”、“浮动”、“重命名树项目”一系列操作。

图片

二、Solidworks导出urdf注意事项

     对于相对复杂的串联机械臂,需要创建每个关节的转轴(参考几何体-基准轴),导出urdf时,设置关节位置和关节转轴方向可以先自动生成,第一次导出可能失败,这时候就需要自己指定参考坐标系和参考轴。可以利用第一次导出urdf生成的参考坐标系和参考轴,也可以自己建立关节转轴和关节位置坐标系。

图片

图片

三、导出urdf后处理

      导出的urdf可以通过插件URDF import导入到coppeliasim。对其增加非线程脚本和操作球、target\tip ,设置关节属性后,就可以演示了。

图片

图片

    但是要想在RViz2中显示,就有点麻烦。最新的urdf导出插件生成的包符合ROS1中使用的格式,但是要想在ROS2中使用需要做很多修改。

urdf导出包时记得修改包名。本例为irb52_urdf。将包拷贝到Ubuntu20.04系统中自己已创建的ROS2工作空间中,本例为“~/ws_moveit2/src”。

修改CMakeLists.txt,改为如下内容:

cmake_minimum_required(VERSION 3.5)project(irb52_urdf)
# Default to C99if(NOT CMAKE_C_STANDARD)  set(CMAKE_C_STANDARD 99)endif()
# Default to C++14if(NOT CMAKE_CXX_STANDARD)  set(CMAKE_CXX_STANDARD 14)endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")  add_compile_options(-Wall -Wextra -Wpedantic)endif()
# find dependenciesfind_package(ament_cmake REQUIRED)# uncomment the following section in order to fill in# further dependencies manually.# find_package(<dependency> REQUIRED)
if(BUILD_TESTING)  find_package(ament_lint_auto REQUIRED)  # the following line skips the linter which checks for copyrights  # uncomment the line when a copyright and license is not present in all source files  #set(ament_cmake_copyright_FOUND TRUE)  # the following line skips cpplint (only works in a git repo)  # uncomment the line when this package is not in a git repo  #set(ament_cmake_cpplint_FOUND TRUE)  ament_lint_auto_find_test_dependencies()endif()

install(DIRECTORY  meshes urdf textures config launch rviz   DESTINATION share/${PROJECT_NAME}/)ament_package()

修改package.xml​​​​​​​

<?xml version="1.0"?><?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?><package format="3">  <name>irb52_urdf</name>  <version>0.1.0</version>  <description>IRB52_URDF</description>  <maintainer email="chenxiaoyong0016@126.com">cxy</maintainer>  <license>BSD</license>
  <buildtool_depend>ament_cmake</buildtool_depend>
  <test_depend>ament_lint_auto</test_depend>  <test_depend>ament_lint_common</test_depend>
  <exec_depend>joint_state_publisher</exec_depend>  <exec_depend>joint_state_publisher_gui</exec_depend>  <exec_depend>robot_state_publisher</exec_depend>  <exec_depend>rviz2</exec_depend>  <exec_depend>xacro</exec_depend>  <export>    <build_type>ament_cmake</build_type>  </export></package>

新建launch目录,在其内新建文件display.launch.py,写入内容:​​​​​​​

import osfrom ament_index_python.packages import get_package_share_directoryfrom launch import LaunchDescriptionfrom launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescriptionfrom launch.conditions import IfConditionfrom launch.launch_description_sources import PythonLaunchDescriptionSourcefrom launch.substitutions import LaunchConfiguration, PythonExpressionfrom launch_ros.actions import Node
def generate_launch_description():    # Get the launch directory    bringup_dir = get_package_share_directory('irb52_urdf')    launch_dir = os.path.join(bringup_dir, 'launch')
    # Launch configuration variables specific to simulation    rviz_config_file = LaunchConfiguration('rviz_config_file')    use_robot_state_pub = LaunchConfiguration('use_robot_state_pub')    use_joint_state_pub = LaunchConfiguration('use_joint_state_pub')    use_rviz = LaunchConfiguration('use_rviz')    urdf_file= LaunchConfiguration('urdf_file')        declare_rviz_config_file_cmd = DeclareLaunchArgument(        'rviz_config_file',        default_value=os.path.join(bringup_dir, 'rviz', 'urdf.rviz'),        description='Full path to the RVIZ config file to use')      declare_use_robot_state_pub_cmd = DeclareLaunchArgument(        'use_robot_state_pub',        default_value='True',        description='Whether to start the robot state publisher')    declare_use_joint_state_pub_cmd = DeclareLaunchArgument(        'use_joint_state_pub',        default_value='True',        description='Whether to start the joint state publisher')    declare_use_rviz_cmd = DeclareLaunchArgument(        'use_rviz',        default_value='True',        description='Whether to start RVIZ')
    declare_urdf_cmd = DeclareLaunchArgument(        'urdf_file',        default_value=os.path.join(bringup_dir, 'urdf', 'irb52_urdf.urdf'),        description='Whether to start RVIZ') 
    start_robot_state_publisher_cmd = Node(        condition=IfCondition(use_robot_state_pub),        package='robot_state_publisher',        executable='robot_state_publisher',        name='robot_state_publisher',        output='screen',        #parameters=[{'use_sim_time': use_sim_time}],        arguments=[urdf_file])        start_joint_state_publisher_cmd = Node(        condition=IfCondition(use_joint_state_pub),        package='joint_state_publisher_gui',        executable='joint_state_publisher_gui',        name='joint_state_publisher_gui',        output='screen',        arguments=[urdf_file])        rviz_cmd = Node(        condition=IfCondition(use_rviz),        package='rviz2',        executable='rviz2',        name='rviz2',        arguments=['-d', rviz_config_file],        output='screen')              # Create the launch description and populate    ld = LaunchDescription()
    # Declare the launch options    ld.add_action(declare_rviz_config_file_cmd)    ld.add_action(declare_urdf_cmd)    ld.add_action(declare_use_robot_state_pub_cmd)    ld.add_action(declare_use_joint_state_pub_cmd)    ld.add_action(declare_use_rviz_cmd)

    # Add any conditioned actions    ld.add_action(start_joint_state_publisher_cmd)    ld.add_action(start_robot_state_publisher_cmd)    ld.add_action(rviz_cmd)
    return ld   

新建rviz目录,目录内新建urdf.rviz文件,内容如下:​​​​​​​

Panels:  - Class: rviz_common/Displays    Name: Displays  - Class: rviz_common/Views    Name: ViewsVisualization Manager:  Class: ""  Displays:    - Class: rviz_default_plugins/Grid      Name: Grid      Value: true    - Alpha: 0.8      Class: rviz_default_plugins/RobotModel      Description Source: Topic      Description Topic:        Value: /robot_description      Enabled: true      Name: RobotModel      Value: true    - Class: rviz_default_plugins/TF      Name: TF      Value: true  Global Options:    Fixed Frame: base_link    Frame Rate: 30  Name: root  Tools:    - Class: rviz_default_plugins/MoveCamera  Value: true  Views:    Current:      Class: rviz_default_plugins/Orbit      Distance: 1.7      Name: Current View      Pitch: 0.33      Value: Orbit (rviz)      Yaw: 5.5Window Geometry:  Height: 800  Width: 1200

三、ros2指令-构建和安装,获取安装,启动demo​​​​​​​

cxy@ubuntu:~/ws_moveit2$colcon build --packages-select irb52_urdfcxy@ubuntu:~/ws_moveit2$ . install/local_setup.bashcxy@ubuntu:~/ws_moveit2$ ros2 launch irb52_urdf display.launch.py

运行后,修改透明度

图片

参考:

https://github.com/ros/urdf_tutorial/tree/ros2 

https://index.ros.org/packages/#foxy

https://new.abb.com/products/robotics/zh/

https://new.abb.com/products/robotics/zh/industrial-robots/irb-52

https://wiki.ros.org/sw_urdf_exporter

https://github.com/benbongalon/ros2-urdf-tutorial/blob/master/urdf_tutorial/README.md

<think>好的,用户想将ABB IRB120机械臂的SW(SolidWorks)文件转换为ROS兼容的URDF格式。首先,我需要回忆一下相关的步骤工具。通常,SolidWorks模型转换到URDF需要使用插件,比如sw_urdf_exporter。不过记得这个插件可能在不同版本的SolidWorks中有不同的兼容性,可能需要确认用户使用的SolidWorks版本是否支持。 接下来,用户提到的IRB120是ABB的工业机器人,结构可能比较复杂,包含多个连杆关节。转换过程中需要注意每个连杆的质量、惯性矩阵、坐标系对齐等问题。可能需要提醒用户仔细检查每个关节的旋转轴父子关系是否正确,否则生成的URDF在仿真中会出现问题,比如关节运动方向错误或者模型坍塌。 然后,用户可能需要安装SolidWorksURDF导出插件。步骤大致是:在SolidWorks中打开装配体,确保每个部件正确命名约束,然后使用插件生成URDF。这里需要分步骤说明,比如如何定义每个关节的类型(旋转、固定等),如何设置坐标系原点,以及如何调整质量属性。如果插件导出URDF不准确,可能需要手动编辑XML文件,调整参数。 另外,用户提到想导入到CoppeliaSimRViz2。可能需要提醒用户,URDF导出后还需要生成对应的mesh文件路径,确保在ROS环境中能够正确加载模型。此外,可能需要使用check_urdf工具验证URDF文件的正确性,避免语法错误。 用户可能需要示例代码,比如一个简单的URDF结构,或者如何编写launch文件在RViz中显示模型。此外,常见问题比如关节名称不匹配、坐标系错误、惯性参数缺失等,都需要在回答中提及解决方案。 最后,考虑到用户可能遇到的问题,比如插件安装失败、导出后模型部件缺失或位置错误,需要提供排查步骤,比如检查SolidWorks的装配约束是否正确,或者手动调整URDF中的linkjoint定义。同时,引用相关的教程或文档,比如ROS官方关于URDF的教程,或者之前提到的站内引用,帮助用户进一步查阅资料。</think>### SolidWorks模型转URDF完整流程 #### 一、环境准备 1. 安装SolidWorks 2019-2023任一版本(建议2020以上) 2. 安装sw_urdf_exporter插件[^1] ```bash # 通过ROS获取插件 sudo apt install ros-${ROS_DISTRO}-sw-urdf-exporter ``` 3. 确认机械臂装配体满足: - 所有零件已完全约束 - 运动副已正确定义 - 坐标系对齐机械臂基座 #### 二、关键导出步骤 1. 在SolidWorks中打开IRB120装配体 2. 通过`工具 > 导出URDF`启动向导 3. 关节类型映射示例: ```xml <!-- 旋转关节定义 --> <joint name="joint1" type="revolute"> <parent link="base_link"/> <child link="link1"/> <axis xyz="0 0 1"/> <limit lower="-3.14" upper="3.14"/> </joint> ``` 4. 坐标系对齐规则: $$ T_{parent}^{child} = \begin{bmatrix} R & p \\ 0 & 1 \end{bmatrix} $$ 其中$R$为旋转矩阵,$p$为位置向量 #### 三、后处理优化 1. 添加物理属性: ```xml <inertial> <mass value="2.5"/> <inertia ixx="0.1" ixy="0" ixz="0" iyy="0.1" iyz="0" izz="0.1"/> </inertial> ``` 2. 验证URDF结构: ```bash check_urdf irb120.urdf ``` 3. 坐标转换修正(如需): ```python # 使用tf2进行坐标系转换 import tf_transformations as tf tf.quaternion_from_euler(np.pi/2, 0, 0) ``` #### 四、CoppeliaSim适配 1. 转换URDF为TTM格式: ```lua simURDF.import('irb120.urdf', {collisionMode=1}) ``` 2. 动力学参数调整: ```lua sim.setObjectFloatParam(handle, sim.shapefloatparam_mass, 2.5) ```
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值