gazebo学习

  • 一、URDF与Gazebo基本集成流程
  • 二、URDF与Gazebo基本集成实操
    • 1.框架搭建
      • 1.1惯性矩阵相关函数
      • 1.2包含惯性矩阵函数的xacro文件
    • 2.小车底盘xacro文件
    • 3.相机xacro文件
    • 4.雷达xacro文件
    • 5.launch启动文件

一、URDF与Gazebo基本集成流程

创建功能包urdf02_gzebo,添加依赖urdfxacrogazebo_rosgazebo_ros_controlgazebo_plugins

在gazebo中显示一个盒状机器人。gazebo文件和urdf文件不同之处在于多了碰撞检测和惯性矩阵。碰撞检测collision的内容直接复制geometry和origin即可。另外颜色的设置与urdf不同,需要单独设置gazebo子标签。

建立一个demo01_helloworld.urdf文件。

<robot name="mycar"><link name="base_link"><visual><geometry><box size="0.5 0.2 0.1" /></geometry><origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" /><material name="yellow"><color rgba="0.5 0.3 0.0 1" /></material></visual><collision><geometry><box size="0.5 0.2 0.1" /></geometry><origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" /></collision><inertial><origin xyz="0 0 0" /><mass value="6" /><inertia ixx="1" ixy="0" ixz="0" iyy="1" iyz="0" izz="1" /></inertial></link><gazebo reference="base_link"><material>Gazebo/Red</material></gazebo>
</robot>

建立一个demo01_helloworld.launch启动文件

<launch><!-- 将 Urdf 文件的内容加载到参数服务器 --><param name="robot_description" textfile="$(find urdf02_gazebo)/urdf/demo01_helloworld.urdf" /><!-- 启动 gazebo --><include file="$(find gazebo_ros)/launch/empty_world.launch" /><!-- 在 gazebo 中显示机器人模型 --><node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description"  />
</launch>

roslaunch urdf02_gazebo demo01_helloworld.launch启动命令。

二、URDF与Gazebo基本集成实操

1.框架搭建

1.1惯性矩阵相关函数

建立一个head.xacro文件,保存惯性矩阵相关内容,如下:

<robot name="base" 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>

1.2包含惯性矩阵函数的xacro文件

car.urdf.xacro

<robot name="mycar" xmlns:xacro="http://wiki.ros.org/xacro"><xacro:include filename="head.xacro"/><xacro:include filename="demo05_car_base.urdf.xacro"/><xacro:include filename="demo06_camera.urdf.xacro"/><xacro:include filename="demo07_lidar.urdf.xacro"/>
</robot>

2.小车底盘xacro文件

demo05_car_base.urdf.xacro

<robot name="my_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>

3.相机xacro文件

demo06_camera.urdf.xacro

<robot name="my_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>

4.雷达xacro文件

demo07_lidar.urdf.xacro

<robot name="my_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/Green</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>

5.launch启动文件

roslaunch urdf02_gazebo demo02_car.launch

<launch><!-- 将 Urdf 文件的内容加载到参数服务器 --><param name="robot_description" command="$(find xacro)/xacro $(find urdf02_gazebo)/urdf/car.urdf.xacro" /><!-- 启动 gazebo --><include file="$(find gazebo_ros)/launch/empty_world.launch" /><!-- 在 gazebo 中显示机器人模型 --><node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description"  />
</launch>

ROS学习笔记7:gazebo搭建机器人学习相关推荐

  1. 《ROS理论与实践》学习笔记(九)机器人自主导航

    <ROS理论与实践>学习笔记(九)机器人自主导航 课程内容 ROS中的导航框架 导航框架中的关键功能包 move_base amcl 机器人自主导航案例 导航仿真 程序接口 move_ba ...

  2. 【学习笔记】ROS-移动机器人导航相关

    [学习笔记]ROS-移动机器人导航相关 一.定位 二.导航 1. move_base现存问题 三.可视化 1. Rviz显示机器人运动轨迹方法: 一.定位 二.导航 1. move_base现存问题 ...

  3. 深度学习(二)theano学习笔记(1)环境搭建

    theano学习笔记(1)环境搭建 原文地址:http://blog.csdn.net/hjimce/article/details/46654229 作者:hjimce 搭建theano实属不易,因 ...

  4. Redis运维和开发学习笔记(3)redis搭建集群

    Redis运维和开发学习笔记(3)redis搭建集群 文章目录 Redis运维和开发学习笔记(3)redis搭建集群 Redis集群搭建 Redis集群搭建 cp /etc/redis.d/redis ...

  5. websocket 获取连接id_Swoole学习笔记七:搭建WebSocket长连接 之 使用 USER_ID 作为身份凭证...

    Swoole学习笔记七:搭建WebSocket长连接 之 使用 USER_ID 作为身份凭证 2年前 阅读 3678 评论 0 喜欢 0 ### 0.前言 前面基本的WebSocket操作,我们基本都 ...

  6. Go学习笔记_环境搭建

    Go学习笔记_环境搭建 Go背景知识 go的特点(官网): Build fast, reliable, and efficient software at scale- Go is an open s ...

  7. 学习笔记1:搭建floodlight+mininet+sflow环境

    学习笔记1:搭建floodlight+mininet+sflow环境 浏览了大量的CSDN博客和师兄继承下来的学习笔记,自己想总结一下搭环境的过程,为以后给自己查看时候好整理 全部都在VM虚拟机中ub ...

  8. Vue学习笔记: Vue + Element-ui搭建后台管理系统模板

    Vue学习笔记: Vue + Element-ui搭建后台管理系统模板 技术:Vue + Element-ui 功能:后台管理系统基础模板,路由配置,加载页面进度条,请求响应拦截器的封装等 页面预览: ...

  9. React Native学习笔记一之搭建开发环境

    因为项目需要,今天开始正式学习React Native,先来搭建个开发环境 忐忑的心情 因为项目比较急,而且客户要求使用React Native开发,只能先学点基础然后在项目中使用的时候,边做边学了, ...

  10. AI Studio 飞桨 零基础入门深度学习笔记4-飞桨开源深度学习平台介绍

    AI Studio 飞桨 零基础入门深度学习笔记4-飞桨开源深度学习平台介绍 深度学习框架 深度学习框架优势 深度学习框架设计思路 飞桨开源深度学习平台 飞桨开源深度学习平台全景 框架和全流程工具 模 ...

最新文章

  1. Word2Vec揭秘: 这是深度学习中的一小步,却是NLP中的巨大跨越
  2. 手机长时间不用自动断网_不用蓝牙的感应音箱,只需百元!放上手机自动播放,媲美千元音质...
  3. Python 技术篇-利用pdfkit库实现html格式文件转换PDF文档实例演示
  4. 基于Xml 的IOC 容器-分配解析策略
  5. 如何让其他机器访问你的oracle数据库
  6. MVVM前后分离轻量级框架应用juicer和doT.js
  7. office 2003 下载
  8. word自带公式编辑_如何在word自带的公式编辑器中设置字体格式
  9. 基于QT5、C/S(客户端/服务器)架构的MiniQQ项目开发
  10. 屏幕刷新频率怎么更改?
  11. 阿里云服务器安装宝塔流程
  12. 人类计划软件测试,人类分裂了16种人格,测测你是哪一种?
  13. python的常用集成开发环境_【分享|10个超好用的Python集成开发环境推荐】- 环球网校...
  14. ajax 服务路由,Angular自定义服务路由
  15. window 10 禁用笔记本触摸板
  16. python求梅森尼数_梅森尼数
  17. ssm报错:No qualifying bean of type ‘com.hr.service.LoginService‘ available
  18. Oracle 查看 SQL执行计划
  19. XFOIL联合Matlab的翼型优化设计
  20. python not in range_python报“30 is not in range”的错误应该如何解决?

热门文章

  1. 前端生成二维码图片以及条形码图片
  2. 女性内分泌失调要小心
  3. CentOS 6安装教程(图文详解)
  4. 怎么选择外贸邮箱,收费企业邮箱大全
  5. 南华大学计算机考研真题,2021南华大学考研历年真题复习资料
  6. 微信小程序修改data,页面数据实时更新
  7. 线段树 从入门到进阶(超清晰,简单易懂)
  8. [UESTC878]温泉旅店
  9. 制作轮播图经验分享——element ui走马灯的使用(附源码,效果截图)
  10. 7-5 走楼梯升级版(PTA程序设计)