ROS教程 Gazebo仿真(1)--ros_control两轮差速控制_wx:pjcoder的博客-程序员宅基地

技术标签: 自动驾驶  ROS  

创建机器人描述

catkin_create_pkg  robot_description  urdf  xacro  gazebo_ros gazebo_ros_control  gazebo_plugins

URDF

robot_base.xacro

<robot name="robot_base" xmlns:xacro="http://www.ros.org/wiki/xacro">

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

    <material name="black">
        <color rgba="0.0 0.0 0.0 1.0" />
    </material>

    <xacro:property name="base_footprint_radius" value="0.001" />
    <xacro:property name="base_link_radius" value="0.1" /> 
    <xacro:property name="base_link_length" value="0.08" />
    <xacro:property name="earth_space" value="0.015" /> 
    <xacro:property name="base_link_m" value="0.5" />


    <link name="base_footprint">
      <visual>
        <geometry>
          <sphere radius="${base_footprint_radius}" />
        </geometry>
      </visual>
    </link>

    <link name="base_link">
      <visual>
        <geometry>
          <cylinder radius="${base_link_radius}" length="${base_link_length}" />
        </geometry>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <material name="yellow">
          <color rgba="0.5 0.3 0.0 0.5" />
        </material>
      </visual>
      <collision>
        <geometry>
          <cylinder radius="${base_link_radius}" length="${base_link_length}" />
        </geometry>
        <origin xyz="0 0 0" rpy="0 0 0" />
      </collision>
      <xacro:cylinder_inertial_matrix m="${base_link_m}" r="${base_link_radius}" h="${base_link_length}" />

    </link>


    <joint name="base_link2base_footprint" type="fixed">
      <parent link="base_footprint" />
      <child link="base_link" />
      <origin xyz="0 0 ${earth_space + base_link_length / 2 }" />
    </joint>
    <gazebo reference="base_link">
        <material>Gazebo/Yellow</material>
    </gazebo>


    <xacro:property name="wheel_radius" value="0.0325" />
    <xacro:property name="wheel_length" value="0.015" />
    <xacro:property name="wheel_m" value="0.05" /> 


    <xacro:macro name="add_wheels" params="name flag">
      <link name="${name}_wheel">
        <visual>
          <geometry>
            <cylinder radius="${wheel_radius}" length="${wheel_length}" />
          </geometry>
          <origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
          <material name="black" />
        </visual>
        <collision>
          <geometry>
            <cylinder radius="${wheel_radius}" length="${wheel_length}" />
          </geometry>
          <origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
        </collision>
        <xacro:cylinder_inertial_matrix m="${wheel_m}" r="${wheel_radius}" h="${wheel_length}" />

      </link>

      <joint name="${name}_wheel2base_link" type="continuous">
        <parent link="base_link" />
        <child link="${name}_wheel" />
        <origin xyz="0 ${flag * base_link_radius} ${-(earth_space + base_link_length / 2 - wheel_radius) }" />
        <axis xyz="0 1 0" />
      </joint>

      <gazebo reference="${name}_wheel">
        <material>Gazebo/Red</material>
      </gazebo>

    </xacro:macro>
    <xacro:add_wheels name="left" flag="1" />
    <xacro:add_wheels name="right" flag="-1" />

    <xacro:property name="support_wheel_radius" value="0.0075" />
    <xacro:property name="support_wheel_m" value="0.03" /> 


    <xacro:macro name="add_support_wheel" params="name flag" >
      <link name="${name}_wheel">
        <visual>
            <geometry>
                <sphere radius="${support_wheel_radius}" />
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="black" />
        </visual>
        <collision>
            <geometry>
                <sphere radius="${support_wheel_radius}" />
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
        </collision>
        <xacro:sphere_inertial_matrix m="${support_wheel_m}" r="${support_wheel_radius}" />
      </link>

      <joint name="${name}_wheel2base_link" type="continuous">
          <parent link="base_link" />
          <child link="${name}_wheel" />
          <origin xyz="${flag * (base_link_radius - support_wheel_radius)} 0 ${-(base_link_length / 2 + earth_space / 2)}" />
          <axis xyz="1 1 1" />
      </joint>
      <gazebo reference="${name}_wheel">
        <material>Gazebo/Red</material>
      </gazebo>
    </xacro:macro>

    <xacro:add_support_wheel name="front" flag="1" />
    <xacro:add_support_wheel name="back" flag="-1" />


</robot>

camera.xacro

<robot name="camera" xmlns:xacro="http://wiki.ros.org/xacro">

    <xacro:property name="camera_length" value="0.01" /> 
    <xacro:property name="camera_width" value="0.025" />
    <xacro:property name="camera_height" value="0.025" />
    <xacro:property name="camera_x" value="0.08" /> 
    <xacro:property name="camera_y" value="0.0" /> 
    <xacro:property name="camera_z" value="${base_link_length / 2 + camera_height / 2}" />

    <xacro:property name="camera_m" value="0.01" /> 


    <link name="camera">
        <visual>
            <geometry>
                <box size="${camera_length} ${camera_width} ${camera_height}" />
            </geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
            <material name="black" />
        </visual>
        <collision>
            <geometry>
                <box size="${camera_length} ${camera_width} ${camera_height}" />
            </geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
        </collision>
        <xacro:Box_inertial_matrix m="${camera_m}" l="${camera_length}" w="${camera_width}" h="${camera_height}" />
    </link>

    <joint name="camera2base_link" type="fixed">
        <parent link="base_link" />
        <child link="camera" />
        <origin xyz="${camera_x} ${camera_y} ${camera_z}" />
    </joint>
    <gazebo reference="camera">
        <material>Gazebo/Blue</material>
    </gazebo>
</robot>

laser.xacro

<robot name="laser" xmlns:xacro="http://wiki.ros.org/xacro">


    <xacro:property name="support_length" value="0.15" /> 
    <xacro:property name="support_radius" value="0.01" /> 
    <xacro:property name="support_x" value="0.0" />
    <xacro:property name="support_y" value="0.0" /> 
    <xacro:property name="support_z" value="${base_link_length / 2 + support_length / 2}" />

    <xacro:property name="support_m" value="0.02" />

    <link name="support">
        <visual>
            <geometry>
                <cylinder radius="${support_radius}" length="${support_length}" />
            </geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
            <material name="red">
                <color rgba="0.8 0.2 0.0 0.8" />
            </material>
        </visual>

        <collision>
            <geometry>
                <cylinder radius="${support_radius}" length="${support_length}" />
            </geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
        </collision>

        <xacro:cylinder_inertial_matrix m="${support_m}" r="${support_radius}" h="${support_length}" />

    </link>

    <joint name="support2base_link" type="fixed">
        <parent link="base_link" />
        <child link="support" />
        <origin xyz="${support_x} ${support_y} ${support_z}" />
    </joint>

    <gazebo reference="support">
        <material>Gazebo/White</material>
    </gazebo>


    <xacro:property name="laser_length" value="0.05" /> 
    <xacro:property name="laser_radius" value="0.03" /> 
    <xacro:property name="laser_x" value="0.0" />
    <xacro:property name="laser_y" value="0.0" />
    <xacro:property name="laser_z" value="${support_length / 2 + laser_length / 2}" /> 

    <xacro:property name="laser_m" value="0.1" /> 


    <link name="laser">
        <visual>
            <geometry>
                <cylinder radius="${laser_radius}" length="${laser_length}" />
            </geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
            <material name="black" />
        </visual>
        <collision>
            <geometry>
                <cylinder radius="${laser_radius}" length="${laser_length}" />
            </geometry>
            <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
        </collision>
        <xacro:cylinder_inertial_matrix m="${laser_m}" r="${laser_radius}" h="${laser_length}" />
    </link>

    <joint name="laser2support" type="fixed">
        <parent link="support" />
        <child link="laser" />
        <origin xyz="${laser_x} ${laser_y} ${laser_z}" />
    </joint>
    <gazebo reference="laser">
        <material>Gazebo/Black</material>
    </gazebo>
</robot>

inertia.xacro 惯性矩阵


<robot name="inertia" xmlns:xacro="http://wiki.ros.org/xacro">
    <!-- Macro for inertia matrix -->
    <xacro:macro name="sphere_inertial_matrix" params="m r">
        <inertial>
            <mass value="${m}" />
            <inertia ixx="${2*m*r*r/5}" ixy="0" ixz="0"
                iyy="${2*m*r*r/5}" iyz="0" 
                izz="${2*m*r*r/5}" />
        </inertial>
    </xacro:macro>

    <xacro:macro name="cylinder_inertial_matrix" params="m r h">
        <inertial>
            <mass value="${m}" />
            <inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0"
                iyy="${m*(3*r*r+h*h)/12}" iyz = "0"
                izz="${m*r*r/2}" /> 
        </inertial>
    </xacro:macro>

    <xacro:macro name="Box_inertial_matrix" params="m l w h">
       <inertial>
               <mass value="${m}" />
               <inertia ixx="${m*(h*h + l*l)/12}" ixy = "0" ixz = "0"
                   iyy="${m*(w*w + l*l)/12}" iyz= "0"
                   izz="${m*(w*w + h*h)/12}" />
       </inertial>
   </xacro:macro>
</robot>

launch

<launch>
    <!-- 将 Urdf 文件的内容加载到参数服务器 -->
    <param name="robot_description" command="$(find xacro)/xacro $(find robot_description)/urdf/robot_car.xacro" />
    <!-- 启动 gazebo -->
    <include file="$(find gazebo_ros)/launch/empty_world.launch">
   	<arg name="world_name" value="$(find robot_description)/worlds/box_house.world" />
    </include>

    <!-- 在 gazebo 中显示机器人模型 -->
    <node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description"  />
</launch>

box_house.world 接: https://pan.baidu.com/s/1T17RWZF1DMeb6FhLc8a2tQ 密码: ka98

下面配置ros_control

<robot name="move" xmlns:xacro="http://wiki.ros.org/xacro">

    <xacro:macro name="joint_trans" params="joint_name">
        <transmission name="${joint_name}_trans">
            <type>transmission_interface/SimpleTransmission</type>
            <joint name="${joint_name}">
                <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
            </joint>
            <actuator name="${joint_name}_motor">
                <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
                <mechanicalReduction>1</mechanicalReduction>
            </actuator>
        </transmission>
    </xacro:macro>


    <xacro:joint_trans joint_name="left_wheel2base_link" />
    <xacro:joint_trans joint_name="right_wheel2base_link" />


    <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>left_wheel2base_link</leftJoint>
            <rightJoint>right_wheel2base_link</rightJoint> 
            <wheelSeparation>${base_link_radius * 2}</wheelSeparation> 
            <wheelDiameter>${wheel_radius * 2}</wheelDiameter> 
            <broadcastTF>1</broadcastTF>
            <wheelTorque>30</wheelTorque>
            <wheelAcceleration>1.8</wheelAcceleration>
            <commandTopic>cmd_vel</commandTopic> 
            <odometryFrame>odom</odometryFrame> 
            <odometryTopic>odom</odometryTopic> 
            <robotBaseFrame>base_footprint</robotBaseFrame> 
        </plugin>
    </gazebo>

</robot>

robt_car.xacro 整合ros_control

<robot name="robot_car" xmlns:xacro="http://wiki.ros.org/xacro">
    <xacro:include filename="inertia.xacro" />    
    <xacro:include filename="robot_base.xacro" />
    <xacro:include filename="camera.xacro" />
    <xacro:include filename="laser.xacro" />
    <xacro:include filename="gazebo/move.xacro" />
</robot>

要点

两轮差速配置文件中需要注意的是 这几个参数

<xacro:joint_trans joint_name="left_wheel2base_link" />
<xacro:joint_trans joint_name="right_wheel2base_link" />
<leftJoint>left_wheel2base_link</leftJoint>
<rightJoint>right_wheel2base_link</rightJoint> 
 <wheelSeparation>${base_link_radius * 2}</wheelSeparation> 
<wheelDiameter>${wheel_radius * 2}</wheelDiameter>

一定要对应好urdf中的配置 如果配置错误有些情况下没有错误提示
在这里插入图片描述

rostopic list
/clock
/cmd_vel
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/set_link_state
/gazebo/set_model_state
/joint_states
/odom
/rosout
/rosout_agg
/tf

存在/cmd_vel 和 /odom 等话题 说明配置成功
让它原地打转

rostopic pub -r 10 /cmd_vel geometry_msgs/Twist '{linear: {x: 0.2, y: 0, z: 0}, angular: {x: 0, y: 0, z: 0.5}}'

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43928944/article/details/115899503

智能推荐

Missing URI template variable 'employeeNumber' for method parameter of type String_Exrick的博客-程序员宅基地

使用SpringMVC参数注解@PathVariable时出错提示:Missing URI template variable 'employeeNumber' for method parameter of type String@RequestMapping(value = "/findUserByEmployeeNumber/{EmployeeNumber}",method = Request

【VUE】vue+element开发中的问题汇总(更新中……)_Sòrry╮的博客-程序员宅基地

目录校验时弹出英文提示校验时弹出英文提示问题:校验未填时会显示英文,点击其他位置触发blur校验后,显示正常解决方法:将此项el-form-item上的required或required="true"删除

【回顾】手机淘宝推荐系统实战_智能推荐系统的博客-程序员宅基地

写在前面:昨天给大家分享了《文章推荐系统电子书》,有粉丝朋友问下载链接在那里,已经上传到省时查报告小程序中,到详情页点击下方菜单复制下载链接即可,以后公众号中分享的所有文档都会传..._淘宝系统手淘推荐

bt4linux安装网卡驱动,BT4网卡支持列表_三盒草莓的博客-程序员宅基地

e 54g] 802.11g Wireless LAN Controller (rev 02)可以监控,无法注入Motorola WN825G v2驱动 : bcm43xx芯片组 : Broadcom 4306可以监控,注入未测试,估计和其它Broadcom网卡一样无法注入NetGear MA401驱动 : HostAP芯片组 : Prism 2你必须加载HostAP驱动进行注入.NetGear ..._怎么在bt4安装ar9285无线网卡linux驱动

分享一些有趣的 Web APIs_二俊89757的博客-程序员宅基地

分享一些有趣的 Web APIsWeb API 简介MDN 文档:https://developer.mozilla.org/zh-CN/docs/Web/API在使用 JavaScript 编写 Web 应用时,有许多 Web API 可供调用。一些有趣的 Web APIsElement.scrollIntoViewMDN 文档:https://developer.mozilla.org/zh-CN/docs/Web/API/Element/scrollIntoView定义:Elem

Android 字体国际化适配方法以及源码解析_SvenWang_的博客-程序员宅基地

起源由于我们公司的app,支持多国语言,所以就导致了 同样的文案,但是长度不同,就会出现适配的问题,因为 中文 是 字表义,外文是 音表义。 今天就用8.0新特新来解决这个问题。适配前是这样的在固定的宽高就会出现适配的问题,在之前博客中也写过解决方案 多语言适配,让text自动改变大小 但现在谷歌已经完全解决了该问题,我们就直接用谷歌的了。适配方法只支持最低版本是26的方法 android

随便推点

Intel PAUSE指令变化影响到MySQL的性能,该如何解决?_innodb_sync_spin_loops_美团技术团队的博客-程序员宅基地

MySQL得益于其开源属性、成熟的商业运作、良好的社区运营以及功能的不断迭代与完善,已经成为互联网关系型数据库的标配。可以说,X86服务器、Linux作为基础设施,跟MySQL一起构建了互联网数据存储服务的基石,三者相辅相成。本文将分享一个工作中的实践案例:因Intel PAUSE指令周期的迭代,引发了MySQL的性能瓶颈,美团MySQL DBA团队如何基于这三者来一步步进行分析、定位和优化。希望..._innodb_sync_spin_loops

YApi初识及安装_yapi mongo地址_相守之路的博客-程序员宅基地

YApi在开始使用 YApi 之前,我们先来熟悉一下 YApi 的网站结构,这将让你快速了解YApi。登录与注册想要使用 YApi ,首先要注册账号。首页登录后进入首页,首页展示了分组与项目。此时你作为新用户,没有任何分组与项目的权限,因此只能搜索、浏览 “公开项目” 的接口,如果在首页找不到任何项目,请联系管理员将你加入对应项目。首页头部展示了当前所在的位置、搜索框、新建项目、查看文档和用户信息。首页左侧展示分组信息,“分组”是“项目”的集合,只有超级管理员可以管理分组。首页右侧是分_yapi mongo地址

qq飞车手游忘记哪个区了服务器也没显示,qq飞车手游大区查询方法,轻松几步让你知道你是哪个区..._weixin_39791446的博客-程序员宅基地

相信在座的小伙伴有很多人喜欢玩《qq飞车》这款游戏,是不是这款游戏给你带来了很多快乐呢,但是现在有很多小伙伴忘记以前是哪个区的了,下面我们就说说qq飞车手游大区查询方法,希望对你有帮助。qq飞车手游怎么看自己在哪个区 所在区查看方法1、首先玩家打开游戏,选择QQ或者微信登录,在游戏登录界面输入账号!这时会在登录界面出现服务前推荐选项!2、不要直接点击进入游戏,找到进入游戏上方的换区选项,在选择服务...

Sublime Text3无法输入中文的问题_sublimetext3 怎么输入不了中文_没-昵称的博客-程序员宅基地

依次执行如下命令1 sudo apt-get update &amp;&amp; sudo apt-get upgrade2 git clone https://github.com/lyfeyaj/sublime-text-imfix.git3 cd sublime-text-imfix4 ./sublime-imfix以下内容转自 http://blog.x228.com/archive..._sublimetext3 怎么输入不了中文

java代码, eclipse连接数据库_Evewyf的博客-程序员宅基地

java代码, eclipse连接数据库eclipse 连接 MySQL 数据库的基本操作1.jar文件java代码要想操作数据库需要引入jar文件jar文件是eclipse连接数据库的驱动文件.jar文件可在网上自行搜索下载. jar包下载地址:https://mvnrepository.com2 eclipse中导入jar包eclipse中新建项目,直接把jar包...

表格识别1-使用python-opencv实现表格识别_python 识别图像内表格结果_我想问问天的博客-程序员宅基地

path是要写入的文件路径,data是数据if index!项目地址,觉得还可以点点star,fork啥的哈。2.不过这个介绍是说完了大致流程,其实过程中还有遇到很多坑,直接运行github的项目有可能跑出的结果和我不一样,那是因为一个是要下载tesseract的中文数据集,第二是这个里面数学和几个文字竟然识别不出来,需要手动给tesseract增加一些训练集。这个增加训练数据集应该后面会再出一篇文章。3.弄完这个表格识别,准备在看下图片矫正和去除水印,复杂的表格识别也会使用到的。_python 识别图像内表格结果

推荐文章

热门文章

相关标签