【机器人】ROS2配置solidworks模型转换的URDF文件

🙇‍♀ 安装solidworks_urdf插件

地址

在添加过点和坐标系后,点击工具->tools(在最下面)

如何转为URDF请看这个视频点击

☕ 为ROS2配置

安装相关依赖

复制代码
sudo apt install ros-humble-joint-state-publisher-gui
sudo apt install ros-humble-xacro

solidworks导出的URDF文件是ROS1 版本的,所以要改装为ROS2

在你的工作空间src目录中新建一个C++的功能包

bash 复制代码
ros2 pkg create looraysbot_model --build-type ament_cmake --license Apache-2.0

分别在改包下面创建launchmeshesrvizurdf这四个文件夹

  • launch文件夹下创建 文件 [display.launch.py](<http://display.launch.py/>) ,插入一下代码
bash 复制代码
from ament_index_python.packages import get_package_share_path

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition, UnlessCondition
from launch.substitutions import Command, LaunchConfiguration

from launch_ros.actions import Node
from launch_ros.parameter_descriptions import ParameterValue

def generate_launch_description():
    urdf_tutorial_path = get_package_share_path('looraysbot_model')
    default_model_path = urdf_tutorial_path / 'urdf/looraysbot_model.urdf'
    default_rviz_config_path = urdf_tutorial_path / 'rviz/looraysbot_model.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_gui
    joint_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
    ])

ctrl+f搜索looraysbot_model,并替换为你的包名称,其他不变

  • 将solidworks生成的urdf包中的meshes 文件夹下的所有stl文件复制到你的对应文件夹下
  • 和solidworks生成的urdf包中的urdf文件夹下的所有文件直接复制到你的对应文件夹下

可以执行urdf_to_graphviz looraysbot_model.urdf 生成pdf(要在终端进入urdf目录下)

CMakeLists.txt配置

bash 复制代码
cmake_minimum_required(VERSION 3.8)
project(looraysbot_model)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_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 files
  set(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 files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()

ctrl+f搜索looraysbot_model,并替换为你的包名称,其他不变

package.xml配置

bash 复制代码
<?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>looraysbot_model</name>
  <version>0.0.0</version>
  <description>
    <p>URDF Description package for looraysbot_model</p>
    <p>This package contains configuration data, 3D models and launch files
      for looraysbot_model robot</p>
  </description>
  <maintainer email="rqtz@todo.todo">rqtz</maintainer>
  <license>Apache-2.0</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

ctrl+f搜索looraysbot_model,并替换为你的包名称,其他不变(其实这个文件不改也不影响)

🥦rviz2配置

打开rviz2,按照上图所示,配置完成后保存并将其保存到该包下的rviz目录中

🦐 运行并显示URDF模型

执行编译colcon build后,更新环境变量

bash 复制代码
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树的pdf

复制代码
ros2 run tf2_tools view_frames
相关推荐
小手智联老徐4 小时前
ROS2:Humble 安装详解(Ubuntu 22.04)
ros2·humble·colcon
rqtz9 小时前
【机器人】ROS2 功能包创建与 CMake 编译链路探秘
机器人·cmake·ros2
maxmaxma1 天前
ROS2机器人少年创客营:Python第三课
开发语言·python·机器人·ros2
小手智联老徐1 天前
ROS2 :Node 与 Topic 初探(Python)
ros2
kyle~3 天前
ROS2 --- WaitSet(等待集) 等待实体就绪,管理执行回调函数
大数据·c++·机器人·ros2
Stack Overflow?Tan903 天前
linux ubuntu22.04安装ROS2humble完整版的流程
linux·docker·ros2
maxmaxma3 天前
ROS2 机器人 少年创客营:Day 9
机器人·ros2
kyle~3 天前
导航---Small-GICP重定位算法
c++·机器人·ros2·导航
G果4 天前
ros2工程 debug(vscode)
c++·ide·vscode·编辑器·bug·debug·ros2