[ROS2] solidworks2021 exports the urdf of IRB52 robot and imports it into coppeliasim and RViz2

Posted by Simon180 on Sat, 23 Oct 2021 09:51:33 +0200

Original link   [ROS2] solidworks2021 exports the urdf of IRB52 robot and imports it into coppeliasim and RViz2

The original text has a video demonstration. This article has no.

Robot model in Solidworks

urdf import to Coppeliasim - screenshot

urdf display in rviz 2 - screenshot

note

1, Download robot model  

     From the network( https://new.abb.com/products/robotics/zh/industrial-robots/irb-52 )For the downloaded ABB Robot step format model, the SLDASM file is obtained after solidworks is loaded, and then a series of operations such as "dissolving sub assemblies", "generating new sub assemblies", "floating" and "renaming tree items" are performed on the model.

2, Solidworks export urdf considerations

      For the relatively complex series manipulator, it is necessary to create the rotation axis of each joint (reference geometry - reference axis). When exporting urdf, setting the joint position and joint rotation axis direction can be automatically generated first. The first export may fail. At this time, you need to specify the reference coordinate system and reference axis yourself. You can use the reference coordinate system and reference axis generated by exporting urdf for the first time, or you can establish the joint rotation axis and joint position coordinate system yourself.

3, Post processing of export urdf

      The exported urdf can be imported into coppeliasim through the plug-in URDF import. Add non threaded script, operation ball and target\tip  , After setting joint attributes, you can demonstrate.

     But it's a little troublesome to display in rviz 2. The package generated by the latest urdf export plug-in conforms to the format used in ROS1, but many modifications need to be made to be used in ROS2.

Remember to modify the package name when exporting the package from URDF. This example is irb52_urdf. Copy the package to the ROS2 workspace you have created in the Ubuntu 20.04 system. This example is "~ / ws_moveit2/src".

Modify CMakeLists.txt to read as follows:

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()

Modify 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>

Create a new launch directory, create a new file display.launch.py in it, and write the following contents:

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   

Create a new rviz directory and a new urdf.rviz file in the directory, as follows:

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

3, ros2 instruction - build and install, get installation, start 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

After running, modify the transparency

reference resources:

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

Topics: Robot ROS2