宇树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="[email protected]">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. 最终效果

相关推荐
慕羽★3 天前
多无人车协同探索开源包启动文件介绍(上)
机器人·ros·gazebo·运动规划·rrt·多无人车·协同探索
go54631584654 天前
在 Simulink 里构建输水隧洞充水过程模型的基本步骤与思路
仿真
青云交8 天前
Java 大视界 -- Java 大数据在智慧交通自动驾驶仿真与测试数据处理中的应用(136)
java·大数据·自动驾驶·数据存储·仿真·智慧交通·测试数据处理
放羊郎15 天前
宇树人形机器人开源模型
模型·gazebo·人形机器人·宇树·go2·b2·h1
Perishell22 天前
XTDrone+Mavros+Gazebo仿真——配置与控制不同的无人机
无人机·px4·gazebo·xtdrone
一颗小树x25 天前
机器人学习模拟框架 robosuite (3) 机器人控制代码示例
机器人·仿真
放羊郎1 个月前
从零实现机器人自主避障
ubuntu·机器人·gazebo·turtlebot·burger
bohu832 个月前
ros2笔记-6.5 使用ros2_control驱动机器人
机器人·控制·ros2·gazebo·ros2_control
bohu832 个月前
ros2-6.4.4 两轮差速控制机器人的问题
机器人·gazebo·rviz·两轮差速控制