基本步骤参考:Solidworks导出URDF总结(Noetic)
本文只介绍不同之处。
将solidworks生成的文件夹(我这里为wuwei2)移动到/ws_moveit2/src.
修改CMakeLists.txt 确认project(wuwei2)为自己的名称。
cmake_minimum_required(VERSION 3.5)
project(wuwei2)find_package(ament_cmake REQUIRED)install(DIRECTORY images launch meshes rviz urdfDESTINATION share/${PROJECT_NAME}
)if(BUILD_TESTING)find_package(ament_lint_auto REQUIRED)ament_lint_auto_find_test_dependencies()
endif()ament_package()
修改package.xml:确认name为自己的名称。
wuwei2 1.0.0 URDF Description package for wuwei2
This package contains configuration data, 3D models and launch files
for wuwei2 robot
TODO BSD ament_cmake joint_state_publisher joint_state_publisher_gui robot_state_publisher rviz2 xacro ament_lint_auto ament_cmake
修改/launch/display.launch:确认get_package_share_path(‘wuwei2’),urdf_tutorial_path / 'urdf/wuwei2.urdf’为自己的名称。
from ament_index_python.packages import get_package_share_pathfrom launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition, UnlessCondition
from launch.substitutions import Command, LaunchConfigurationfrom launch_ros.actions import Node
from launch_ros.parameter_descriptions import ParameterValuedef generate_launch_description():urdf_tutorial_path = get_package_share_path('wuwei2')default_model_path = urdf_tutorial_path / 'urdf/wuwei2.urdf'default_rviz_config_path = urdf_tutorial_path / 'rviz/urdf.rviz'gui_arg = DeclareLaunchArgument(name='gui', default_value='true', choices=['true', 'false'],description='Flag to enable joint_state_publisher_gui')model_arg = DeclareLaunchArgument(name='model', default_value=str(default_model_path),description='Absolute path to robot urdf file')rviz_arg = DeclareLaunchArgument(name='rvizconfig', default_value=str(default_rviz_config_path),description='Absolute path to rviz config file')robot_description = ParameterValue(Command(['xacro ', LaunchConfiguration('model')]),value_type=str)robot_state_publisher_node = Node(package='robot_state_publisher',executable='robot_state_publisher',parameters=[{'robot_description': robot_description}])# Depending on gui parameter, either launch joint_state_publisher or joint_state_publisher_guijoint_state_publisher_node = Node(package='joint_state_publisher',executable='joint_state_publisher',condition=UnlessCondition(LaunchConfiguration('gui')))joint_state_publisher_gui_node = Node(package='joint_state_publisher_gui',executable='joint_state_publisher_gui',condition=IfCondition(LaunchConfiguration('gui')))rviz_node = Node(package='rviz2',executable='rviz2',name='rviz2',output='screen',arguments=['-d', LaunchConfiguration('rvizconfig')],)return LaunchDescription([gui_arg,model_arg,rviz_arg,joint_state_publisher_node,joint_state_publisher_gui_node,robot_state_publisher_node,rviz_node])
新建images文件夹。
新建rviz文件夹,并新建urdf.rviz:
Panels:- Class: rviz_common/DisplaysName: Displays- Class: rviz_common/ViewsName: Views
Visualization Manager:Class: ""Displays:- Class: rviz_default_plugins/GridName: GridValue: true- Alpha: 0.8Class: rviz_default_plugins/RobotModelDescription Source: TopicDescription Topic:Value: /robot_descriptionEnabled: trueName: RobotModelValue: true- Class: rviz_default_plugins/TFName: TFValue: trueGlobal Options:Fixed Frame: base_linkFrame Rate: 30Name: rootTools:- Class: rviz_default_plugins/MoveCameraValue: trueViews:Current:Class: rviz_default_plugins/OrbitDistance: 1.7Name: Current ViewPitch: 0.33Value: Orbit (rviz)Yaw: 5.5
Window Geometry:Height: 800Width: 1200
编译:
colcon build --packages-select wuwei2
. install/local_setup.bash
ros2 launch wuwei2 display.launch
效果:Robot Model滚动条可以显示转动移动效果。
https://github.com/ros/urdf_tutorial/tree/ros2
https://github.com/xiaoming-sun6/sw2urdf_ros2(尝试过,但是不显示模型)
https://zhuanlan.zhihu.com/p/465398486
https://blog.csdn.net/cxyhjl/article/details/120922447