宇树ROS1开源模型在ROS2中Gazebo中仿真

以GO1为例

1. CMakelists.txt更新语法

sh 复制代码
cmake_minimum_required(VERSION 3.8)
project(go1_description)
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)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(gazebo_ros REQUIRED)
find_package(xacro REQUIRED)

# 安装URDF和Xacro文件
install(DIRECTORY
  urdf/
  DESTINATION share/${PROJECT_NAME}/urdf
)

# 安装启动文件
install(DIRECTORY
  launch/
  DESTINATION share/${PROJECT_NAME}/launch
)

ament_package()

2. packge.xml更新语法

xml 复制代码
<?xml version="1.0"?>
<package format="3">
    <name>go1_description</name>
    <version>0.0.0</version>
    <description>The go1_description package</description>

    <maintainer email="laikago@unitree.cc">unitree</maintainer>
    <license>TODO</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>rclcpp</depend>
  <depend>std_msgs</depend>
  <depend>sensor_msgs</depend>
  <depend>gazebo_ros</depend>
  <depend>xacro</depend>

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

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

3. 新建launch文件

python 复制代码
import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import Command, LaunchConfiguration, PathJoinSubstitution
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
    pkg_path = get_package_share_directory('go1_description')
    
    # 使用xacro命令生成URDF
    xacro_file = os.path.join(pkg_path, 'xacro', 'robot.xacro')
    robot_description = Command(['xacro ', xacro_file])

    # 启动Gazebo
    gazebo = IncludeLaunchDescription(
        PythonLaunchDescriptionSource([os.path.join(
            get_package_share_directory('gazebo_ros'), 'launch', 'gazebo.launch.py'
        )])
    )

    # 发布机器人状态
    robot_state_publisher_node = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        output='both',
        parameters=[{'robot_description': robot_description}]
    )

    # 在Gazebo中生成实体
    spawn_entity = Node(
        package='gazebo_ros',
        executable='spawn_entity.py',
        arguments=['-topic', 'robot_description', '-entity', 'my_robot'],
        output='screen'
    )

    return LaunchDescription([
        DeclareLaunchArgument(
            'world',
            default_value='worlds/empty.world'
        ),
        gazebo,
        robot_state_publisher_node,
        spawn_entity,
    ])

4. colcon编译包

bash 复制代码
cd ~/suo/unitree_ros/robots/go1_description
colcon build --packages-select go1_description
source install/setup.bash

5. 启动仿真

bash 复制代码
ros2 launch go1_description spawn_robot.launch.py

6. 最终效果

相关推荐
Altair澳汰尔18 小时前
行业分享丨SimSolid 在汽车零部件开发中应用的可行性调研及实践
汽车·仿真·cae·多物理场仿真·simsolid
幽迷狂7 天前
AFSIM入门教程03.03:更新所有依赖库版本
c++·qt·仿真·osgearth·osg·军事·afsim
民乐团扒谱机10 天前
【微实验】弦振动 MATLAB 物理模型 动画仿真
matlab·动画·仿真·信号·声学·振动·
民乐团扒谱机12 天前
【微实验】圆周运动的正弦信号发生仿真及其衍生(三)
经验分享·matlab·仿真·信号与系统·声音·微实验
Altair澳汰尔13 天前
行业热点丨仿真历史数据难以使用?如何利用几何深度学习破局,加速汽车工程创新
人工智能·ai·汽车·数据治理·仿真·cae·physicsai
Freshman小白18 天前
Fluent自动化仿真(TUI命令脚本教程)
自动化·脚本·仿真
想要成为计算机高手20 天前
10. isaacsim4.2教程-RTX Lidar 传感器
数码相机·机器人·ros·仿真·具身智能·vla·isaacsim
想要成为计算机高手25 天前
9. isaacsim4.2教程-ROS加相机/CLOCK
人工智能·机器人·ros·仿真·具身智能·isaacsim
六六王1 个月前
仿真每日一练 | LS-Dyna模态分析
仿真·ansys·workbench·结构振动·有限元仿真·ls-dyna
进击的奶龙1 个月前
02VCS_使用教程
verilog·仿真·eda