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

以GO1为例

1. CMakelists.txt更新语法

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 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文件

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编译包

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

在这里插入图片描述

5. 启动仿真

ros2 launch go1_description spawn_robot.launch.py

在这里插入图片描述

6. 最终效果

在这里插入图片描述

### 宇树科技机器狗Gazebo仿真教程 #### 一、准备工作 为了能够成功地对宇树科技的机器狗进行Gazebo仿真,需先完成一系列准备操作。这包括但不限于下载必要的ROS包以及配置工作空间。 确保已安装好ROS环境,并创建了一个名为`catkin_ws`的工作空间。接着,在该工作空间下的`src`目录中克隆所需的仓库,具体命令如下所示: ```bash cd ~/catkin_ws/src/ git clone https://github.com/unitreerobotics/unitree_ros.git git clone https://github.com/unitreerobotics/unitree_guide.git git clone https://github.com/unitreerobotics/unitree_ros_to_real.git ``` 之后编译整个项目以使新加入的内容生效[^4]。 #### 二、启动仿真环境 对于不同型号的宇树机器狗(如Go1, A1),其具体的启动参数可能有所差异。下面给出针对特定模型的一般化指导方针。 ##### 对于Go2型号: 通过指定相应的发射文件来初始化模拟器,同时设置机器人名称为`go2`: ```bash roslaunch unitree_guide gazeboSim.launch rname:=go2 ``` 此过程会加载预设的世界场景并让虚拟版的Go2出现在其中等待进一步控制指令输入[^1]。 ##### 针对其他系列比如A1: 除了基本相同的步骤外还需要额外定义世界名称(`wname`)参数用于选择不同的地形条件;另外还需单独运行一些辅助节点以便更好地管理姿态调整等功能: ```bash # 启动 Gazebo 仿真环境 roslaunch unitree_gazebo normal.launch rname:=a1 wname:=stairs_single # 初始化机器人位姿 rosrun unitree_controller unitree_servo # 让机器人回到原点位置 rosrun unitree_controller unitee_move_kinetic ``` 最后不要忘记开启手柄支持和服务端口监听等服务,这样才能实现更直观的人机交互体验[^3]。 #### 三、总结说明 上述流程涵盖了从零开始建立一个完整的基于Gazebo平台上的宇树四足行走机械装置仿真的全过程描述。值得注意的是实际应用过程中可能会遇到各种各样的挑战,因此建议读者朋友们多查阅官方文档或者社区论坛获取更多帮助和支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

具身小站

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值