【机器人】ROS2配置solidworks模型转换的URDF文件
♀ 安装solidworks_urdf插件地址在添加过点和坐标系后点击工具-tools(在最下面)如何转为URDF请看这个视频点击☕ 为ROS2配置安装相关依赖sudo apt install ros-humble-joint-state-publisher-gui sudo apt install ros-humble-xacrosolidworks导出的URDF文件是ROS1版本的所以要改装为ROS2在你的工作空间src目录中新建一个C的功能包ros2 pkg create looraysbot_model --build-type ament_cmake--licenseApache-2.0分别在改包下面创建launchmeshesrvizurdf这四个文件夹在launch文件夹下创建 文件[display.launch.py](http://display.launch.py/)插入一下代码from ament_index_python.packagesimportget_package_share_path from launchimportLaunchDescription from launch.actionsimportDeclareLaunchArgument from launch.conditionsimportIfCondition, UnlessCondition from launch.substitutionsimportCommand, LaunchConfiguration from launch_ros.actionsimportNode from launch_ros.parameter_descriptionsimportParameterValue def generate_launch_description(): urdf_tutorial_pathget_package_share_path(looraysbot_model)default_model_pathurdf_tutorial_path /urdf/looraysbot_model.urdfdefault_rviz_config_pathurdf_tutorial_path /rviz/looraysbot_model.rvizgui_argDeclareLaunchArgument(namegui,default_valuetrue,choices[true,false],descriptionFlag to enable joint_state_publisher_gui)model_argDeclareLaunchArgument(namemodel,default_valuestr(default_model_path),descriptionAbsolute path to robot urdf file)rviz_argDeclareLaunchArgument(namervizconfig,default_valuestr(default_rviz_config_path),descriptionAbsolute path to rviz config file)robot_descriptionParameterValue(Command([xacro , LaunchConfiguration(model)]),value_typestr)robot_state_publisher_nodeNode(packagerobot_state_publisher,executablerobot_state_publisher,parameters[{robot_description:robot_description}])# Depending on gui parameter, either launch joint_state_publisher or joint_state_publisher_guijoint_state_publisher_nodeNode(packagejoint_state_publisher,executablejoint_state_publisher,conditionUnlessCondition(LaunchConfiguration(gui)))joint_state_publisher_gui_nodeNode(packagejoint_state_publisher_gui,executablejoint_state_publisher_gui,conditionIfCondition(LaunchConfiguration(gui)))rviz_nodeNode(packagerviz2,executablerviz2,namerviz2,outputscreen,arguments[-d, LaunchConfiguration(rvizconfig)],)returnLaunchDescription([gui_arg, model_arg, rviz_arg, joint_state_publisher_node, joint_state_publisher_gui_node, robot_state_publisher_node, rviz_node])按ctrlf搜索looraysbot_model并替换为你的包名称其他不变将solidworks生成的urdf包中的meshes文件夹下的所有stl文件复制到你的对应文件夹下和solidworks生成的urdf包中的urdf文件夹下的所有文件直接复制到你的对应文件夹下可以执行urdf_to_graphviz looraysbot_model.urdf生成pdf(要在终端进入urdf目录下)CMakeLists.txt配置cmake_minimum_required(VERSION3.8)project(looraysbot_model)if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHESClang)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)install(DIRECTORY launch meshes urdf rviz DESTINATION share/${PROJECT_NAME})if(BUILD_TESTING)find_package(ament_lint_auto REQUIRED)# the following line skips the linter which checks for copyrights# comment the line when a copyright and license is added to all source filesset(ament_cmake_copyright_FOUND TRUE)# the following line skips cpplint (only works in a git repo)# comment the line when this package is in a git repo and when# a copyright and license is added to all source filesset(ament_cmake_cpplint_FOUND TRUE)ament_lint_auto_find_test_dependencies()endif()ament_package()按ctrlf搜索looraysbot_model并替换为你的包名称其他不变package.xml配置?xmlversion1.0??xml-modelhrefhttp://download.ros.org/schema/package_format3.xsdschematypenshttp://www.w3.org/2001/XMLSchema?packageformat3namelooraysbot_model/nameversion0.0.0/versiondescriptionpURDF Description packageforlooraysbot_model/ppThis package contains configuration data, 3D models and launch filesforlooraysbot_model robot/p/descriptionmaintaineremailrqtztodo.todorqtz/maintainerlicenseApache-2.0/licensebuildtool_dependament_cmake/buildtool_dependtest_dependament_lint_auto/test_dependtest_dependament_lint_common/test_dependexportbuild_typeament_cmake/build_type/export/package按ctrlf搜索looraysbot_model并替换为你的包名称其他不变(其实这个文件不改也不影响)rviz2配置打开rviz2,按照上图所示配置完成后保存并将其保存到该包下的rviz目录中 运行并显示URDF模型执行编译colcon build后更新环境变量ros2 launch looraysbot_model display.launch.py执行成功安装tf树sudo apt install ros-humble-rqt-tf-tree rm -rf ~/.config/ros.org/rqt_gui.ini生成当前tf树的pdfros2 run tf2_tools view_frames
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2487904.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!