【ROS2】solidworks2021导出IRB52机器人的urdf,导入到coppeliasim和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="[email protected]">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

Guess you like

Origin blog.csdn.net/cxyhjl/article/details/120922447