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下。

关键代码:

启动脚本

python 复制代码
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 复制代码
<?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 复制代码
<?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 复制代码
<?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>
相关推荐
xwz小王子6 分钟前
CMU卡内基梅隆大学「软体机器人动态手旋转笔」
机器人·动态旋转
xwz小王子1 小时前
斯坦福大学李飞飞教授团队ARCap: 利用增强现实反馈收集高质量的人类示教以用于机器人学习
学习·机器人·ar
滴滴哒哒答答2 小时前
《自动驾驶与机器人中的SLAM技术》ch10:自动驾驶车辆的实时定位系统
人工智能·机器人·自动驾驶
Mr.Winter`5 小时前
轨迹优化 | 基于贝塞尔曲线的无约束路径平滑与粗轨迹生成(附ROS C++/Python仿真)
人工智能·机器人·自动驾驶·ros·几何学·ros2·轨迹优化
天天讯通11 小时前
AI语音机器人大模型是什么?
人工智能·机器人
SkyXZ~17 小时前
地瓜机器人RDK Studio使用入门教程
人工智能·嵌入式硬件·物联网·目标检测·ubuntu·机器学习·机器人
CubeMars1 天前
Duke Humanoid:利用被动动力学实现节能双足机器人
机器人
bohu831 天前
ros2-6.4.4 两轮差速控制机器人(问题解决)
机器人·ros2·gazebo·rviz·二轮差速控制
IPdodo全球网络服务1 天前
Outlook注册时机器人验证无法通过的原因及解决方法
机器人·outlook