当前位置: 首页 > article >正文

ros2-6.4.4 两轮差速控制机器人的问题

遇到一个问题。本节开始尝试在gazebo中仿真上一节构建的模型。

先贴一下现象,启动launch之后,gazebo显示正常移动。但是在rviz中查看就是有问题的:

fixedframe:选择odom.显示添加机器人,按topic 选择。提示:

no transform from left wheel to odom

No transform from [right_wheel_link] to [odom]

可以通过键盘控制小车移动,对比视频:不能显示小车两个轮子TF转动。

如果 fixedframe切回base_link ,在rviz显示是正常的,轮子部件都在。

在gazebo显示正常

TF tree对比视频不太一样,视频里面左右轮子right_wheel_link都是在 base_footprint下。

 

关键代码:

启动脚本

import launch
import launch.launch_description_sources
import launch_ros
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    # 获取功能包默认路径
    urdf_tutorial_path = get_package_share_directory('fishbot_description')
    default_model_path = urdf_tutorial_path + '/urdf/fishbot/fish_robot.urdf.xacro'
    default_world_path = urdf_tutorial_path + '/world/custom_room.world'
    # 为 Launch 声明参数
    action_declare_arg_mode_path = launch.actions.DeclareLaunchArgument(
        name='model', default_value=str(default_model_path),
        description='加载模型文件的绝对路径')
    # 获取文件内容生成新的参数
    robot_description = launch_ros.parameter_descriptions.ParameterValue(
        launch.substitutions.Command(
            ['xacro ', launch.substitutions.LaunchConfiguration('model')]),
        value_type=str)
    # 状态发布节点
    robot_state_publisher_node = launch_ros.actions.Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        parameters=[{'robot_description': robot_description}]
    )


    # 通过 IncludeLaunchDescription 包含另外一个 launch 文件
    launch_gazebo = launch.actions.IncludeLaunchDescription(
        launch.launch_description_sources.PythonLaunchDescriptionSource([get_package_share_directory(
            'gazebo_ros'), '/launch', '/gazebo.launch.py']),
      	# 传递参数
        launch_arguments=[('world', default_world_path),('verbose','true')]
    )
    #请求gazebo 加载机器人
    action_spawn_entity = launch_ros.actions.Node(
        package= 'gazebo_ros',
        executable='spawn_entity.py',
        arguments=['-topic', '/robot_description','-entity', 'fishbot']
    )

    return launch.LaunchDescription([
        action_declare_arg_mode_path,
        robot_state_publisher_node,
        launch_gazebo,
        action_spawn_entity,
    ])

定义模型

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="fishbot">
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/base.urdf.xacro" />
    <!-- 传感器组件 -->
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/imu.urdf.xacro" />
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/laser.urdf.xacro" />
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/camera.urdf.xacro" />
    <!-- 执行器组件 -->
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/actuator/wheel.urdf.xacro" />
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/actuator/caster.urdf.xacro" />
    <!--gazebo插件-->
    <xacro:include filename="$(find fishbot_description)/urdf/fishbot/plugins/gazebo_control_plugin.xacro" />
    
    <xacro:base_xacro length="0.12" radius="0.1" />
    <!-- 传感器 -->
    <xacro:imu_xacro xyz="0 0 0.02" />
    <xacro:laser_xacro xyz="0 0 0.10" />
    <xacro:camera_xacro xyz="0.10 0 0.075" />
       <!-- 执行器主动轮+从动轮 -->
    <xacro:wheel_xacro wheel_name="left_wheel" xyz="0 0.10 -0.06" />
    <xacro:wheel_xacro wheel_name="right_wheel" xyz="0 -0.10 -0.06" />
    <xacro:caster_xacro caster_name="front_caster" xyz="0.08 0.0 -0.076" />
    <xacro:caster_xacro caster_name="back_caster" xyz="-0.08 0.0 -0.076" />

    <xacro:gazebo_control_plugin />
</robot>

轮子定义:

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
   <xacro:include filename="$(find fishbot_description)/urdf/fishbot/common_inertia.xacro" />
    <xacro:macro name="wheel_xacro" params="wheel_name xyz">
        <link name="${wheel_name}_link">
            <visual>
                <origin xyz="0 0 0" rpy="1.57079 0 0" />
                <geometry>
                    <cylinder length="0.04" radius="0.032" />
                </geometry>
                <material name="yellow">
                    <color rgba="1.0 1.0 0.0 0.8"/>
                </material>
            </visual>
           <collision>
                <origin xyz="0 0 0" rpy="1.57079 0 0" />
                <geometry>
                    <cylinder length="0.04" radius="0.032" />
                </geometry>
                <material name="yellow">
                    <color rgba="1.0 1.0 0.0 0.8"/>
                </material>
            </collision>
             <xacro:cylinder_inertia m="0.1" h="0.04" r="0.032"/>
        </link>
        <gazebo reference="${wheel_name}_link">
            <mu1 value="20.0" />
            <mu2 value="20.0" />
            <kp value="1000000000.0" />
            <kd value="1.0" />
        </gazebo>

        <joint name="${wheel_name}_joint" type="continuous">
            <parent link="base_link" />
            <child link="${wheel_name}_link" />
            <origin xyz="${xyz}" />
            <!--轮子绕那个轴旋转-->
            <axis xyz="0 1 0" />
        </joint>
    </xacro:macro>
</robot>

差速控制:

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
    <xacro:macro name="gazebo_control_plugin">
        <gazebo>
            <plugin name='diff_drive' filename='libgazebo_ros_diff_drive.so'>
                <ros>
                    <namespace>/</namespace>
                    <remapping>cmd_vel:=cmd_vel</remapping>
                    <remapping>odom:=odom</remapping>
                </ros>
                <update_rate>30</update_rate>
                <!-- wheels -->
                <left_joint>left_wheel_joint</left_joint>
                <right_joint>right_wheel_joint</right_joint>
                <!-- kinematics -->
                <wheel_separation>0.2</wheel_separation>
                <wheel_diameter>0.064</wheel_diameter>
                <!-- limits -->
                <max_wheel_torque>20</max_wheel_torque>
                <max_wheel_acceleration>1.0</max_wheel_acceleration>
                <!-- output -->
                <publish_odom>true</publish_odom>
                <publish_odom_tf>true</publish_odom_tf>
                <publish_wheel_tf>true</publish_wheel_tf>

                <odometry_frame>odom</odometry_frame>
                <robot_base_frame>base_footprint</robot_base_frame>
            </plugin>
        </gazebo>
   </xacro:macro>
</robot>


http://www.kler.cn/a/502868.html

相关文章:

  • 如何提高自动化测试覆盖率和效率
  • 2025 年 UI 大屏设计新风向
  • 银河麒麟服务器操作系统桌面任务栏网络图标消失问题
  • 【ArcGIS微课1000例】0137:色彩映射表转为RGB全彩模式
  • JVM:ZGC详解(染色指针,内存管理,算法流程,分代ZGC)
  • 关于Java数组操作函数
  • MATLAB编程实用技巧深度解析
  • 1Hive概览
  • Redis 3 种特殊数据类型
  • CentOS 8 如何安装java与mysql
  • MySQL 最新数据库查询指南
  • springMVC百宝箱
  • [免费]SpringBoot+Vue新能源汽车充电桩管理系统【论文+源码+SQL脚本】
  • 《AI模型格局演变:Claude、Gemini Flash与OpenAI的技术角力》
  • python 3个线程轮流打印A、B、C
  • ElasticSearch 认识和安装ES
  • Mysql--架构篇--存储引擎InnoDB(内存结构,磁盘结构,存储结构,日志管理,锁机制,事务并发控制等)
  • 【深度学习】SAB:空间注意力
  • 【深度学习】数据操作入门
  • web-app uniapp监测屏幕大小的变化对数组一行展示数据作相应处理
  • vue3+ts的<img :src=““ >写法
  • Unity搭配VS Code使用
  • 基于“大型园区”网络设计
  • LeetCode 3270.求出数字答案:每位分别计算 或 for循环
  • 重回C语言之老兵重装上阵(三)C语言储存类
  • 【Uniapp-Vue3】@import导入css样式及scss变量用法与static目录