ros2+gazebo建立机器人

Building your own robot

In this tutorial we will learn how to build our own robot in SDFormat. We will build a simple two wheeled robot.本文用SDF文件建立一个2轮机器人

You can find the finished SDF file for the tutorial here.SDF文件点击下载

What is SDF

SDFormat (Simulation Description Format), sometimes abbreviated as SDF, is an XML format that describes objects and environments for robot simulators, visualization, and control.

SDF格式文件是一个用来描述仿真时候的各种配置的文件

Building a world

We will start by building a simple world and then build our robot in it. Open a new file called building_robot.sdf and copy the following code to it.

<?xml version="1.0" ?>
<sdf version="1.10"><world name="car_world"><physics name="1ms" type="ignored"><max_step_size>0.001</max_step_size><real_time_factor>1.0</real_time_factor></physics><pluginfilename="gz-sim-physics-system"name="gz::sim::systems::Physics"></plugin><pluginfilename="gz-sim-user-commands-system"name="gz::sim::systems::UserCommands"></plugin><pluginfilename="gz-sim-scene-broadcaster-system"name="gz::sim::systems::SceneBroadcaster"></plugin><light type="directional" name="sun"><cast_shadows>true</cast_shadows><pose>0 0 10 0 0 0</pose><diffuse>0.8 0.8 0.8 1</diffuse><specular>0.2 0.2 0.2 1</specular><attenuation><range>1000</range><constant>0.9</constant><linear>0.01</linear><quadratic>0.001</quadratic></attenuation><direction>-0.5 0.1 -0.9</direction></light><model name="ground_plane"><static>true</static><link name="link"><collision name="collision"><geometry><plane><normal>0 0 1</normal></plane></geometry></collision><visual name="visual"><geometry><plane><normal>0 0 1</normal><size>100 100</size></plane></geometry><material><ambient>0.8 0.8 0.8 1</ambient><diffuse>0.8 0.8 0.8 1</diffuse><specular>0.8 0.8 0.8 1</specular></material></visual></link></model></world>
</sdf>

Save the file, navigate to the directory where you saved the file and launch the simulator:

gz sim building_robot.sdf

Note: You can name your file any name and save it anywhere on your computer.

You should see an empty world with just a ground plane and a sun light. Check World demo to learn how to build your own world.

Building a model

Under the </model> tag we will add our robot model as follows:

Defining the model

<model name='vehicle_blue' canonical_link='chassis'><pose relative_to='world'>0 0 0 0 0 0</pose>

Here we define the name of our model vehicle_blue, which should be a unique name among its siblings (other tags or models on the same level). Each model may have one link designated as the canonical_link, the implicit frame of the model is attached to this link. If not defined, the first <link> will be chosen as the canonical link. The <pose> tag is used to define the position and orientation of our model and the relative_to attribute is used to define the pose of the model relative to any other frame. If relative_to is not defined, the model's <pose> will be relative to the world.

Let's make our pose relative to the world. The values inside the pose tag are as follows: <pose>X Y Z R P Y</pose>, where the X Y Z represent the position of the frame and R P Y represent the orientation in roll pitch yaw. We set them to zeros which makes the two frames (the model and the world) identical.

Every model is a group of links (can be just one link) connected together with joints.

Chassis

    <link name='chassis'><pose relative_to='__model__'>0.5 0 0.4 0 0 0</pose>

We define the first link, the chassis of our car and it's pose relative to the model.

Inertial properties

    <inertial> <!--inertial properties of the link mass, inertia matix--><mass>1.14395</mass><inertia><ixx>0.095329</ixx><ixy>0</ixy><ixz>0</ixz><iyy>0.381317</iyy><iyz>0</iyz><izz>0.476646</izz></inertia></inertial>

Here we define the inertial properties of the chassis like the <mass> and the <inertia> matrix. The values of the inertia matrix for primitive shapes can be calculated using this tool.

Visual and collision

    <visual name='visual'><geometry><box><size>2.0 1.0 0.5</size></box></geometry><!--let's add color to our link--><material><ambient>0.0 0.0 1.0 1</ambient><diffuse>0.0 0.0 1.0 1</diffuse><specular>0.0 0.0 1.0 1</specular></material></visual>

As the name suggests, the <visual> tag is responsible for how our link will look. We define the shape of our link inside the <geometry> tag as a <box> (cuboid) and then specify the three dimensions (in meters) of this box inside the <size> tag. Then, inside the <material> tag we define the material of our link. Here we defined the <ambient><diffuse> and <specular> colors in a set of four numbers red/green/blue/alpha each in range [0, 1].

        <collision name='collision'><geometry><box><size>2.0 1.0 0.5</size></box></geometry></collision></link>
</model>

The <collision> tag defines the collision properties of the link, how our link will react with other objects and the effect of the physics engine on it.

Note<collision> can be different from the visual properties, for example, simpler collision models are often used to reduce computation time.

After copying all the parts above into the world file in order, run the world again:

gz sim building_robot.sdf

Our model should look like this:

car chassis

In the top left toolbar, click the Translate icon, then select your model. You should see three axes like this:

model_axis

These are the axes of our model where red is the x-axis, green is the y-axis and blue is the z-axis.

Left wheel

Let's add wheels to our robot. The following code goes after the </link> tag and before the </model> tag. All the links and joints belonging to the same model should be defined before the </model>.

<link name='left_wheel'><pose relative_to="chassis">-0.5 0.6 0 -1.5707 0 0</pose><inertial><mass>1</mass><inertia><ixx>0.043333</ixx><ixy>0</ixy><ixz>0</ixz><iyy>0.043333</iyy><iyz>0</iyz><izz>0.08</izz></inertia></inertial>

We defined the name of our link left_wheel and then defined its <pose> relative_to the chassis link. The wheel needed to be placed on the left to the back of the chassis so that's why we chose the values for pose as -0.5 0.6 0. Also, our wheel is a cylinder, but on its side. That's why we defined the orientation value as -1.5707 0 0 which is a -90 degree rotation around the x-axis (the angles are in radians). Then we defined the inertial properties of the wheel, the mass and the inertia matrix.

Visualization and Collision

    <visual name='visual'><geometry><cylinder><radius>0.4</radius><length>0.2</length></cylinder></geometry><material><ambient>1.0 0.0 0.0 1</ambient><diffuse>1.0 0.0 0.0 1</diffuse><specular>1.0 0.0 0.0 1</specular></material></visual><collision name='collision'><geometry><cylinder><radius>0.4</radius><length>0.2</length></cylinder></geometry></collision>
</link>

The <visual> and the <collision> properties are similar to the previous link, except the shape of our link has the shape of <cylinder> that requires two attributes: the <radius> and the <length> of the cylinder. Save the file and run the world again, our model should look like this:

this

Right wheel

<!--The same as left wheel but with different position-->
<link name='right_wheel'><pose relative_to="chassis">-0.5 -0.6 0 -1.5707 0 0</pose> <!--angles are in radian--><inertial><mass>1</mass><inertia><ixx>0.043333</ixx><ixy>0</ixy><ixz>0</ixz><iyy>0.043333</iyy><iyz>0</iyz><izz>0.08</izz></inertia></inertial><visual name='visual'><geometry><cylinder><radius>0.4</radius><length>0.2</length></cylinder></geometry><material><ambient>1.0 0.0 0.0 1</ambient><diffuse>1.0 0.0 0.0 1</diffuse><specular>1.0 0.0 0.0 1</specular></material></visual><collision name='collision'><geometry><cylinder><radius>0.4</radius><length>0.2</length></cylinder></geometry></collision>
</link>

The right wheel is similar to the left wheel except for its position.

Defining an arbitrary frame

As of SDF 1.7 (Fortress uses SDF 1.8), we can define arbitrary frames. It takes two attributes:

  • name: the name of the frame
  • attached_to: the name of the frame or the link to which this frame is attached.

Let's add a frame for our caster wheel as follows:

<frame name="caster_frame" attached_to='chassis'><pose>0.8 0 -0.2 0 0 0</pose>
</frame>

We gave our frame name caster_frame and attached it to the chassis link, then the <pose> tag to define the position and orientation of the frame. We didn't use the relative_to attribute so the pose is with respect to the frame named in the attached_to attribute, chassis in our case.

Caster wheel

<!--caster wheel-->
<link name='caster'><pose relative_to='caster_frame'/><inertial><mass>1</mass><inertia><ixx>0.016</ixx><ixy>0</ixy><ixz>0</ixz><iyy>0.016</iyy><iyz>0</iyz><izz>0.016</izz></inertia></inertial><visual name='visual'><geometry><sphere><radius>0.2</radius></sphere></geometry><material><ambient>0.0 1 0.0 1</ambient><diffuse>0.0 1 0.0 1</diffuse><specular>0.0 1 0.0 1</specular></material></visual><collision name='collision'><geometry><sphere><radius>0.2</radius></sphere></geometry></collision>
</link>

Our last link is the caster and its pose is with respect to the frame caster_frame we defined above. As you could notice we closed the pose tag without defining the position or the orientation; in this case the pose of the link is the same as (identity) the frame in relative_to.

In the <visual> and <collision> tags we defined a different shape <sphere> which requires the <radius> of the sphere.

We need to connect these links together; here comes the job of the <joint> tag. The joint tag connects two links together and defines how they will move with respect to each other. Inside the <joint> tag we need to define the two links to connect and their relations (way of movement).

Left wheel joint

<joint name='left_wheel_joint' type='revolute'><pose relative_to='left_wheel'/>

Our first joint is the left_wheel_joint. It takes two attributes: the name name='left_wheel_joint' and the type type='revolute'. the revolute type gives 1 rotational degree of freedom with joint limits. The pose of the joint is the same as the child link frame, which is the left_wheel frame.

    <parent>chassis</parent><child>left_wheel</child>

Every joint connects two links (bodies) together. Here we connect the chassis with the left_wheelchassis is the parent link and left_wheel is the child link.

    <axis><xyz expressed_in='__model__'>0 1 0</xyz> <!--can be defined as any frame or even arbitrary frames--><limit><lower>-1.79769e+308</lower>    <!--negative infinity--><upper>1.79769e+308</upper>     <!--positive infinity--></limit></axis>
</joint>

Here we define the axis of rotation. The axis of rotation can be any frame, not just the parent or the child link. We chose the y-axis with respect to the model frame so we put 1 in the y element and zeros in the others. For the revolute joint we need to define the <limits> of our rotation angle in the <lower> and <upper> tags.

Note: The angles are in radians.

Right wheel joint

The right_wheel_joint is very similar except for the pose of the joint. This joint connects the right_wheel with the chassis.

<joint name='right_wheel_joint' type='revolute'><pose relative_to='right_wheel'/><parent>chassis</parent><child>right_wheel</child><axis><xyz expressed_in='__model__'>0 1 0</xyz><limit><lower>-1.79769e+308</lower>    <!--negative infinity--><upper>1.79769e+308</upper>     <!--positive infinity--></limit></axis>
</joint>
Caster wheel joint

For the caster we need a different type of joint (connection). We used type='ball' which gives 3 rotational degrees of freedom.

<joint name='caster_wheel' type='ball'><parent>chassis</parent><child>caster</child>
</joint>

Conclusion

Run the world:

gz sim building_robot.sdf

It should look like this:

two_wheeled_robot

Hurray! We build our first robot. You can learn more details about SDFormat tags here. In the next tutorial we will learn how to move our robot around.

Video walk-through

A video walk-through of this tutorial is available from our YouTube channel: Gazebo tutorials: Building a robot.

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

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

相关文章

SQL排列组合

SQL排列组合 1、排列组合概述2、SQL排列组合2.1、排列2.2、组合3、SQL排列组合的应用1、排列组合概述 排列组合是针对离散数据常用的数据组织方法,本节将分别介绍排列、组合的SQL实现方法,并结合实例着重介绍通过组合对数据的处理 如何使用SQL实现排列与组合?本节将通过介绍…

nodejs微信小程序+python+PHP的驾照理论模拟考试系统-计算机毕业设计推荐

从角色上分为用户和管理员两部分&#xff0c;用户功能主要是在前台&#xff0c;主要内容首页&#xff0c;注册登录&#xff0c; 模拟考试&#xff0c;论坛&#xff0c;公告信息 &#xff0c;个人中心&#xff0c;考试记录&#xff0c;错图记录等功能&#xff0c;后台部分主要给…

REST与RPC = 面向对象和函数编程

REST 与 RPC 的争论&#xff1a; REST API ! HTTP 远程过程调用 作为开发人员&#xff0c;每当需要 API 时&#xff0c;我们常听到的一句话就是 "哦&#xff0c;我们可以为此开发一个 REST API"。好吧&#xff0c;这没什么不好。 但是&#xff0c; 如果需求是可操作…

【mysql】事务的基本特性和隔离级别?

1 基本特性 1.1 原子性(Atomicity) 原子性是指事务是一个不可分割的工作单位,事务中的操作要么全部成功,要么全部失败。比如在同一个事务中的SQL语句,要么全部执行成功,要么全部执行失败。 begin transaction; update account set money = money-100 where name = ‘张…

2037约瑟夫问题(C语言)

目录 一&#xff1a;问题 二&#xff1a;思路分析 三&#xff1a;代码 一&#xff1a;问题 二&#xff1a;思路分析 1.输出结果是按编号输出&#xff0c;所以要考虑数组&#xff0c;数组里面存的数是有编号的&#xff0c;所以把n个人放到数组中&#xff0c;让他们的编号也是…

案例057:基于微信小程序的马拉松报名系统

文末获取源码 开发语言&#xff1a;Java 框架&#xff1a;SSM JDK版本&#xff1a;JDK1.8 数据库&#xff1a;mysql 5.7 开发软件&#xff1a;eclipse/myeclipse/idea Maven包&#xff1a;Maven3.5.4 小程序框架&#xff1a;uniapp 小程序开发软件&#xff1a;HBuilder X 小程序…

SQL语法系统性学习,关卡式进阶-学习笔记

学习笔记-SQL语法系统性学习&#xff0c;关卡式进阶 笔记参考&#xff1a;作者鱼皮 关卡式Sql语句学习体验网站 &#xff0c;网站开源代码 如果想本地体验语法&#xff1a;1.下载大佬开源代码&#xff0c;运行前端项目&#xff08;推荐&#xff09;&#xff1b; 2.或是自己使…

[云原生] Docker 入门指南:镜像、容器、卷和网络解析

Docker 是一种流行的容器化平台&#xff0c;它以其强大的功能和易用性在软件开发和部署领域广受欢迎。本文将带领您逐步探索 Docker 中的四个核心概念&#xff1a;镜像、容器、卷和网络。通过了解这些概念的是什么、为什么以及如何使用&#xff0c;您将能够更好地理解和利用 Do…

strings

在Go语言中&#xff0c;strings 包提供了许多用于处理字符串的函数。以下是一些常见的用法&#xff1a; 字符串拼接&#xff1a; package mainimport ("fmt""strings" )func main() {str1 : "Hello"str2 : "World"result : strings.Jo…

行为树保姆级教程(以机器人的任务规划为例

行为树 目录 什么是行为树(behavior tree)&#xff1f;行为树的相关术语 行为节点和控制节点不同类型的控制结点&#xff1a; 顺序节点选择节点并行节点装饰结点 机器人的例子&#xff1a;物体搜索 1&#xff1a;如果只存在一个地点A&#xff0c;那么行为树很简单&#xff0…

CSS第二天导读

1&#xff0c;Emmet语法 Emmet语法的前身是Zen coding&#xff0c;它使用缩写&#xff0c;来提高html / css 的编写速度&#xff0c;Vscode内部已经集成该语法 1.1&#xff0c;快速生成HTML结构语法 1.想要快速生成多个相同标签&#xff0c;加上*就可以了&#xff0c;比如 d…

物流实时数仓:数仓搭建(DWD)一

系列文章目录 物流实时数仓&#xff1a;采集通道搭建 物流实时数仓&#xff1a;数仓搭建 物流实时数仓&#xff1a;数仓搭建&#xff08;DIM&#xff09; 物流实时数仓&#xff1a;数仓搭建&#xff08;DWD&#xff09;一 文章目录 系列文章目录前言一、文件编写1.目录创建2.b…

iPhone 16 的电池供应可能来自印度

据英国《金融时报》报道&#xff0c;据报道&#xff0c;苹果已通知其供应链&#xff0c;包括中国德赛公司和台湾新普科技等电池供应商&#xff0c;其倾向于将 iPhone 16 的电池供应转移到印度。苹果鼓励供应商将现有产能迁往印度&#xff0c;以扩大该地区的生产规模。 鉴于电池…

Redis高级特性解析:持久化、主从复制与哨兵机制全面探讨

Redis持久化 RDB快照&#xff08;snapshot&#xff09; 在默认情况下&#xff0c; Redis 将内存数据库快照保存在名字为 dump.rdb 的二进制文件中。 你可以对 Redis 进行设置&#xff0c; 让它在“ N 秒内数据集至少有 M 个改动”这一条件被满足时&#xff0c; 自动保存…

Java使用Microsoft Entra微软 SSO 认证接入

1. Microsoft Entra Microsoft Entra ID 是基于云的标识和访问管理服务&#xff0c;可帮助员工访问外部资源。 示例资源包括 Microsoft 365、Azure 门户以及成千上万的其他 SaaS 应用程序。 Microsoft Entra ID 还可帮助他们访问你的企业 Intranet 上的应用等内部资源&#x…

2019年第八届数学建模国际赛小美赛B题数据中心冷出风口的设计解题全过程文档及程序

2019年第八届数学建模国际赛小美赛 B题 数据中心冷出风口的设计 原题再现&#xff1a; 这是数据中心空调设计面临的一个问题。在一些数据中心&#xff0c;计算机机柜是开放的&#xff0c;在一个房间里排列成三到四排。冷却后的空气通过主管进入房间&#xff0c;并分为三到四个…

神经网络中梯度消失 以及梯度爆炸的原因已解决办法

深度神经网络中的梯度消失和梯度爆炸是两个常见的问题&#xff0c;它们都会导致网络训练过程中的梯度无法有效传播或者传播过于剧烈&#xff0c;从而影响网络的收敛性和性能。下面将详细介绍这两个问题以及解决方案。 梯度消失问题&#xff1a; 梯度消失指的是在网络的深层结…

python相关工具代码之网络图片下载并显示出下载图片保存到的地址

# codingutf-8 from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * import time import random import os import urllib.request from bs4 import BeautifulSoup 信号传参类型 pyqtSignal() #无参数信号 pyq…

【华为数据之道学习笔记】5-2华为数据湖的特点

华为数据湖是逻辑上对内外部的结构化、非结构化的原始数据的逻辑汇聚。数据入湖要遵从6项入湖标准&#xff0c;基于6项标准保证入湖的质量&#xff0c;同时面向不同的消费场景提供两种入湖方式&#xff0c;满足数据消费的要求。经过近两年的数据湖建设&#xff0c;目前已经完成…

centos7安装和卸载MySQL8.0

一.卸载Mysql 1.关闭MySQL服务 systemctl stop mysqld 2.使用 rpm 命令查看已安装的安装包 rpm -qa|grep mysql 3.使用yum卸载安装的mysql yum remove mysql mysql-server mysql-libs mysql-server 4.查询剩余的安装包 rpm -qa|grep mysql 这里是我的centos7上的mysq…