从零开始,自己搭建一个autonomous mobile robot做gazebo仿真(1):mobile robot建模与添加差速控制器

news2024/9/22 19:31:09

这样一个简单的mobile robot模型

 首先写xacro文件,创建 link joint transmission

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="whill_modelc" >

    <xacro:property name="PI" value="3.1415926"/>

    <link name="base_link">
        <visual>
            <geometry>
                <sphere radius="0.001" />
            </geometry>
        </visual>
    </link>

    <link name="base_floor">
        <visual>
            <geometry>
                <box size="0.600 0.400 0.050"/>
            </geometry>
            <material name="grey">
                <color rgba="0.5 0.5 0.5 1.0"/>
            </material>
        </visual>

        <collision>
            <geometry>
                <box size="0.600 0.400 0.050"/>
            </geometry>
        </collision>

        <inertial>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <mass value="40" />
            <inertia ixx="1.0"  ixy="0.0"   ixz="0.0"
                                iyy="1.0"   iyz="0.0"
                                            izz="1.0" />
        </inertial>
    </link>

    <joint name="base_body_joint" type="fixed">
        <parent link="base_link" />
        <child link="base_floor" />
        <origin xyz="0.3 0 0.0" rpy="0 0 0"/>
    </joint>


    <link name="footrest_link">
        <collision>
            <geometry>
                <box size="0.250 0.260 0.050"/>
            </geometry>
        </collision>
        <visual>
            <geometry>
                <box size="0.250 0.260 0.050"/>
            </geometry>
            <material name="grey">
                <color rgba="0.5 0.5 0.5 1.0"/>
            </material>
        </visual>
        <inertial>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <mass value="1" />
            <inertia ixx="1.0"  ixy="0.0"   ixz="0.0"
                                iyy="1.0"   iyz="0.0"
                                            izz="1.0" />
        </inertial>
    </link>

    <joint name="footrest_joint" type="fixed">
        <parent link="base_floor" />
        <child link="footrest_link" />
        <origin xyz="0.320 0 0" rpy="0 0 0"/>
    </joint>

    <link name="left_wheel_link">
        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
            <material name="black" />
        </visual>

        <collision>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
        </collision> 

        <inertial>
            <mass value="0.500"/>
            <inertia ixx="0.0013541667" ixy="0" ixz="0" iyy="0.0013541667" iyz="0" izz="0.0025"/>
        </inertial>
    </link>


    <joint name="leftWheel" type="continuous">
        <parent link="base_floor" />
        <child link="left_wheel_link" />
        <origin xyz="-0.3 0.245 0" rpy="${-PI / 2} 0.0 0.0" />
        <axis xyz="0 0 1" />
    </joint>


    <link name="right_wheel_link">
        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="black" />
        </visual>
        <collision>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
            <origin xyz="0 0 0" rpy="0.0 0.0 0.0" />
        </collision>
        
        <inertial>
            <mass value="0.500"/>
            <inertia ixx="0.0013541667" ixy="0" ixz="0" iyy="0.0013541667" iyz="0" izz="0.0025"/>
        </inertial>
    </link>

    <joint name="rightWheel" type="continuous">
        <parent link="base_floor" />
        <child link="right_wheel_link" />
        <origin xyz="-0.3 -0.245 0" rpy="${-PI / 2} 0.0 0.0" />
        <axis xyz="0 0 1" />
    </joint>


    <link name="frontwheel_left">
        <collision>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
        </collision>

        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
            <material name="black" />
        </visual>

        <inertial>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <mass value="1.0" />
            <inertia ixx="1.0"  ixy="0.0"   ixz="0.0"
                                iyy="1.0"   iyz="0.0"
                                            izz="1.0" />
        </inertial>
    </link>
    
    <joint name="frontwheel_left_joint" type="fixed">
        <parent link="base_floor" />
        <child link="frontwheel_left" />
        <origin xyz="0.3 -0.245 0" rpy="1.57 0 0" />
        <axis xyz="0 0 1" />
    </joint>



    <link name="frontwheel_right">
        <collision>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
        </collision>

        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
            <material name="black" />
        </visual>

        <inertial>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <mass value="1.0" />
            <inertia ixx="1.0"  ixy="0.0"   ixz="0.0"
                                iyy="1.0"   iyz="0.0"
                                            izz="1.0" />
        </inertial>    
    </link>

    <joint name="frontwheel_right_joint" type="fixed">
        <parent link="base_floor" />
        <child link="frontwheel_right"/>
        <origin xyz="0.3 0.245 0" rpy="1.57 0 0" />
        <axis xyz="0 0 -1" />
    </joint>


    <!-- ===============  Transmission =============== -->

    <transmission name="right_wheel_trans">
        <type>transmission_interface/SimpleTransmission</type>
        <joint name="rightWheel">
            <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
        </joint>
        <actuator name="right_wheel_motor">
            <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
            <mechanicalReduction>30</mechanicalReduction>
        </actuator>
    </transmission>

    <transmission name="left_wheel_trans">
        <type>transmission_interface/SimpleTransmission</type>
        <joint name="leftWheel">
            <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
        </joint>
        <actuator name="left_wheel_motor">
            <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
            <mechanicalReduction>30</mechanicalReduction>
        </actuator>
    </transmission>

    <gazebo reference="base_floor">
        <selfCollide>true</selfCollide>
        <mu1 value="0.05" />
        <mu2 value="0.05" />
    </gazebo>

    <gazebo reference="sensor_arm_link">
        <selfCollide>true</selfCollide>
        <mu1 value="0.05" />
        <mu2 value="0.05" />
    </gazebo>

    <gazebo reference="rearwheel_right">
        <selfCollide>true</selfCollide>
        <mu1 value="1.0" />
        <mu2 value="1.0" />
    </gazebo>

    <gazebo reference="rearwheel_left">
        <selfCollide>true</selfCollide>
        <mu1 value="1.0" />
        <mu2 value="1.0" />
    </gazebo>

    <gazebo reference="frontwheel_right">
        <selfCollide>true</selfCollide>
        <mu1 value="0.0" />
        <mu2 value="0.0" />
    </gazebo>

    <gazebo reference="frontwheel_left">
        <selfCollide>true</selfCollide>
        <mu1 value="0.0" />
        <mu2 value="0.0" />
    </gazebo>

</robot>

创建xcaro模型时,下面几个地方要注意:

(1)

车轮是一个cylinder link,

<link name="right_wheel_link">
        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="black" />
        </visual>
        <collision>
            <geometry>
                <cylinder length="0.05" radius="0.1325"/>
            </geometry>
            <origin xyz="0 0 0" rpy="0.0 0.0 0.0" />
        </collision>

link的局部坐标系原点在这个物体的形心右手坐标系

<joint name="rightWheel" type="continuous">
        <parent link="base_floor" />
        <child link="right_wheel_link" />
        <origin xyz="-0.3 -0.245 0" rpy="${-PI / 2} 0.0 0.0" />
        <axis xyz="0 0 1" />
    </joint>

车轮在跟父link连接的时候,放在父link局部坐标系中-0.3 -0.245 0这个位置,然后绕child link自己的X轴转-90度(rpy=-pi/2 0 0),也就是这样转下来,原来的z轴转到原来的y轴位置

<axis xyz="0 0 1" />

这句话的意思是,这个物体绕自己的z轴旋转(注意z轴已经有刚才的 rpy命令移动了) 。

注意左右车轮的z轴正向要是一致的,否则会出现,你给往前走的指令,robot旋转,你给旋转的指令,robot反而向前走直线!

transmission是给车轮绑定一个gazebo中的电机

然后在transmission下面加入一个双轮差速控制器

<gazebo>
        <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
            <rosDebugLevel>Debug</rosDebugLevel>
            <publishWheelTF>true</publishWheelTF>
            <robotNamespace>/</robotNamespace>
            <publishTf>1</publishTf>
            <publishWheelJointState>true</publishWheelJointState>
            <alwaysOn>true</alwaysOn>
            <updateRate>100.0</updateRate>
            <legacyMode>true</legacyMode>
            <leftJoint>leftWheel</leftJoint> <!-- 左轮 -->
            <rightJoint>rightWheel</rightJoint> <!-- 右轮 -->
            <wheelSeparation>0.49</wheelSeparation> <!-- 车轮间距 -->
            <wheelDiameter>0.265</wheelDiameter> <!-- 车轮直径 -->
            <broadcastTF>false</broadcastTF>
            <wheelTorque>30</wheelTorque>
            <wheelAcceleration>1.8</wheelAcceleration>
            <commandTopic>cmd_vel</commandTopic> <!-- 运动控制话题 -->
            <odometryFrame>odom</odometryFrame> 
            <odometryTopic>odom</odometryTopic> <!-- 里程计话题 -->
            <robotBaseFrame>base_link</robotBaseFrame> <!-- 根坐标系 -->
        </plugin>
    </gazebo>

在给双轮差速器发送控制指令的时候,topic是robotNamespace+commandTopic,具体来说,robotNamespace是 / ,commandTopic是 cmd_vel,那就要发送 /cmd_vel,如果robotNamespace是 /robot,那就要发送 /robot/cmd_vel

下一步写luanch文件

<launch>

  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>

  <!-- We resume the logic in empty_world.launch -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="debug" value="$(arg debug)" />
    <arg name="gui" value="$(arg gui)" />
    <arg name="paused" value="$(arg paused)"/>
    <arg name="use_sim_time" value="$(arg use_sim_time)"/>
    <arg name="headless" value="$(arg headless)"/>
  </include>

  <!-- Load the URDF into the ROS Parameter Server -->
  <param name="robot_description" command="$(find xacro)/xacro '$(find ros_whill)/xacro/modelc.xacro'" /> 


  <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
  args="-urdf -model whill_modelc -param robot_description"/> 

  <!-- 运行joint_state_publisher节点,发布机器人的关节状态  -->
  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
  
  <!-- 运行robot_state_publisher节点,发布tf  -->
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher">
    <remap from="/joint_states" to="/whill_modelc/joint_states" />
  </node>

 
</launch>

用rqt发送控制指令,rviz可视化,rviz可视化的时候,注意 Fixed Frame是odom

不然就会看到,robot在rviz中不动,odom坐标系在往后退

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1398192.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Unity导出Android项目踩坑记录

导出的时候需要注意以下地方的配置&#xff1a; 1、buildSetting-> 设置ExportProject 2、buildsetting ->playerSetting ->设置IL2CPP 3、设置ndk edit->preferences->external tools->ndk 如果unity的ndk版本和android项目里的ndk版本不一致会报错&…

尝试着在Stable Diffusion里边使用SadTalker进行数字人制作

首先需要标明的是&#xff0c;我这里是图片说话类型&#xff0c;而且是看了知识星球AI破局俱乐部大航海数字人手册进行操作的。写下这篇文章是防止我以后遗忘。 我使用的基础软件是Stable Diffusion&#xff0c;SadTalker是作为插件放进来的&#xff0c;需要注意的是这对自己的…

Swagger + Knife4j 接口文档的整合

Swagger 接口文档的整合&#xff1a; 引入依赖&#xff08;Swagger 或 Knife4j&#xff09;。自定义 Swagger 配置类。定义需要生成接口文档的代码位置&#xff08;Controller&#xff09;。注意&#xff1a;线上环境不要把接口暴露出去&#xff01;&#xff01;&#xff01;可…

统计学-R语言-6.1

文章目录 前言参数估计的原理总体、样本和统计量点估计区间估计评价估计量的标准有效性 总体均值的区间估计一个总体均值的估计&#xff08;大样本&#xff09;一个总体均值的估计&#xff08;小样本估计&#xff09; 练习 前言 本篇文章将开始介绍参数估计的相关知识。 参数估…

【超实用】用Python语言实现定时任务的八个方法,建议收藏!

在日常工作中,我们常常会用到需要周期性执行的任务,一种方式是采用 Linux 系统自带的 crond 结合命令行实现。另外一种方式是直接使用Python。接下来整理的是常见的Python定时任务的八种实现方式。 利用while True: + sleep()实现定时任务 位于 time 模块中的 sleep(secs) 函…

【ARM Cortex-M 系列 1.1 -- Cortex-M33 与 M4 差异 详细介绍】

请阅读【嵌入式开发学习必备专栏 之 Cortex-Mx 专栏】 文章目录 背景Cortex-M33 与 M4 差异Cortex-M33Cortex-M4关系和差异举例说明 背景 在移植 RT-Thread 到 瑞萨RA4M2&#xff08;Cortex-M33&#xff09;上时&#xff0c;遇到了hardfault 问题&#xff0c;最后使用了Cortex…

物理层网路设备

目录 一、物理层网络设备-中继器 二、物理层网络设备-集线器 三、在物理层扩展局域网 一、物理层网络设备-中继器 中继器的介绍&#xff1a; 线路上传输的信号功率由于存在损耗会逐渐衰减&#xff0c;衰减到一定程度时信号失真会导致接收错误。中继器就是为解决这一问题而…

小埋公司的IPO方案的题解

目录 原题描述&#xff1a; 题目描述 输入格式 输出格式 输出格式 样例 #1 样例输入 #1 样例输出 #1 样例 #2 样例输入 #2 样例输出 #2 提示 题目大意&#xff1a; 主要思路&#xff1a; 但是but 代码code&#xff1a; 时间限制: 500ms 空间限制: 65536kB 原题…

Wayfair 开启2024年的裁员模式

周五的时候 Wayfair 的 CEO 公开信中表示&#xff0c;将削减 1650 个工作岗位。 通篇读下来的意思就是公司目前还是非常健康的状态&#xff0c;新冠导致的在线购物激增让 Wayfair 在短时间内的销售从 90 亿美元增加到 180 亿美元。 几乎是翻倍了&#xff0c;而且这个让 Wayfai…

Unity vs Godot :哪个游戏引擎更适合你?

Unity vs Godot &#xff1a;哪个游戏引擎更适合你&#xff1f; 游戏引擎的选择对开发过程和最终产品质量有着重大影响。近年来&#xff0c;Godot和Unity这两款引擎受到广泛关注。本文将从多个维度对两者进行比较&#xff0c;以期为开发者提供正确的选择建议。 Godot和Unity都有…

[Error]连接iPhone调试时提示Failed to prepare the device for development.

环境&#xff1a; iPhone 7 Plus iOS 15.8 Xcode14.2 问题&#xff1a; 连接iPhone设备运行时&#xff0c;设备旁提示如下文案。 Failed to prepare the device for development. 这时强行点击运行按钮&#xff0c;会弹窗提示如下文案。 The run destination ZDMiPhone is n…

分类预测 | Matlab实现WOA(海象)-XGboost分类【24年新算法】基于海象优化算法(WOA)优化XGBoost的数据分类预测

分类预测 | Matlab实现WOA(海象)-XGboost分类【24年新算法】基于海象优化算法(WOA)优化XGBoost的数据分类预测 目录 分类预测 | Matlab实现WOA(海象)-XGboost分类【24年新算法】基于海象优化算法(WOA)优化XGBoost的数据分类预测分类效果基本描述程序设计参考资料 分类效果 基本…

第一篇【传奇开心果系列】beeware开发移动应用:轮盘抽奖移动应用

系列博文目录 beeware开发移动应用示例系列博文目录一、项目目标二、开发传奇开心果轮盘抽奖安卓应用编程思路三、传奇开心果轮盘抽奖安卓应用示例代码四、补充抽奖逻辑实现五、开发传奇开心果轮盘抽奖苹果手机应用编程思路六、开发传奇开心果轮盘抽奖苹果手机应用示例代码七、…

B站提示:“当前浏览器版本较低……”可行的解决方案(edge浏览器)

文章目录 问题研究和分析使用User-Agent Switcher for Chrome插件的解决方法使用userAgent switcher的解决方法 问题研究和分析 问题&#xff1a;使用最新版浏览器访问B站&#xff0c;首页总是有一条横幅提示&#xff1a;当前浏览器版本较低&#xff0c;为保证您的使用体验&am…

怎么用小程序将身份证转为结构化Excel?

随着科技的不断发展&#xff0c;我们的生活变得越来越智能化。现在&#xff0c;我们可以使用金鸣表格文字识别小程序来识别身份证并转为结构化的excel&#xff0c;并且可自动核对真伪&#xff0c;保留头像。金鸣表格文字识别小程序是一种基于人工智能技术的应用程序&#xff0c…

全开源多城市同城信息小程序源码(Laravel 框架),同城分类信息发布便民小程序系统【非DZ】

同城生活分类信息小程序&#xff0c;人才招聘、房产二手 多城市地区同城分类信息发布&#xff0c;商家入驻等功能 小程序前后端代码开源无加密&#xff0c;可进行二次开发 【源码运行要求】 1、需要已认证的微信小程序 2、已备案的域名及服务器空间 推荐使用宝塔面板LinuxPHP…

五、模 板

1 泛型编程 以往我们想实现一个通用的交换函数&#xff0c;可能是通过下面的方式来实现的&#xff1a; void Swap(int& left, int& right) {int temp left;left right;right temp; } void Swap(double& left, double& right) {double temp left;left ri…

luffy商城项目(一)

企业项目类型 # 1 面向互联网用户&#xff1a;商城类项目 -微信小程序商城 # 2 面向互联网用户&#xff1a;二手交易类的 -咸鱼 -转转 # 3 公司内部项目&#xff1a;python写的重点 -oa系统 -打卡系统工资核算系统 -第三方公司做的&#xff1a…

区间问题笔记

1、k倍区间 #include <iostream> #include<cmath> #include<vector> #include<algorithm> #include<stack> using namespace std;long long sum[100005]; // 前缀和数组 int cnt[100005]; // 记录sum[i]除k得到的余数的个数 int ans;int…

Python基本输入和输出

Python是一种高级编程语言&#xff0c;以其简洁易学和功能强大而闻名。在Python中&#xff0c;输入和输出是编程中至关重要的一部分&#xff0c;它们帮助程序与用户进行交互&#xff0c;以便获取输入并向用户显示输出。本文将重点介绍Python中的基本输入和输出&#xff0c;包括…