【机器人】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

分别在改包下面创建launch,meshes,rviz,urdf这四个文件夹

  • 在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
相关推荐
特立独行的猫a21 小时前
ROS 2 主流DDS中间件入门:Cyclone DDS 与 Fast DDS 完全指南
中间件·ros2·dds·fast dds·cyclone dds
米糕闯编程4 天前
鱼香ros2(二十二)机器人建模
机器人·碰撞·urdf·xacro·机器人质量与惯性
轻口味4 天前
启元无真机二开实战1:54 个接口能做什么、不能做什么——启元 Q1/T1 SDK 能力全景与版本矩阵
线性代数·矩阵·ros2·具身智能·启元机器人
热金鼠7 天前
2.ROS2 核心机制与命令行实操
ros2
DDSOFT_Howe8 天前
SOLIDWORKS PDM 多站点异地协同部署方案选型解析
solidworks·pdm·异地协同
七夜zippoe9 天前
启元 Q1 关节指令预检器:URDF 限位拦越界指令
ai·机器人·urdf·启元·关节
solidwork_s11 天前
SOLIDWORKS 2027 Electrical电气新功能汇总
运维·服务器·人工智能·solidworks
大雨歌12 天前
笛卡尔坐标 → 自然坐标(Frenet) 逐步推导全解 -2
ros2
米糕闯编程16 天前
鱼香ros2(十七)C++小海龟巡逻
开发语言·c++·机器人·ros2·服务·小海龟
solidwork_s17 天前
SOLIDWORKS 2027 Simulation仿真新功能汇总
人工智能·solidworks