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>
        <plugin
            filename="gz-sim-physics-system"
            name="gz::sim::systems::Physics">
        </plugin>
        <plugin
            filename="gz-sim-user-commands-system"
            name="gz::sim::systems::UserCommands">
        </plugin>
        <plugin
            filename="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.mfbz.cn/a/244092.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

电脑和手机中的日历提醒怎么进行同步

作为一名忙碌的现代人&#xff0c;我常常需要在电脑和手机上记录各种日程和提醒。然而&#xff0c;我发现电脑和手机“日历提醒无法同步”是一个令人头疼的问题。如果我在电脑中添加了一个提醒&#xff0c;但是我没有把它同步到我的手机上&#xff0c;那么当我离开电脑时&#…

关于shell的面试题小练习(三道)

目录 第一题&#xff1a;&#xff08;关于内存&#xff09; 第一步&#xff1a;需了解使用的大纲命令 第二步过滤取得具体所需的值 第三步&#xff1a;具体执行步骤及命令 1&#xff09;安装邮件软件 2&#xff09;编辑脚本 方法一&#xff1a;脚本编辑1 方法二&#x…

玩转 K8s 权限控制:RBAC + kubeconfig 搞定 kubectl 权限管理那些事

1. 先抛需求 当一个 K8s 集群需要被多个租户共享时&#xff0c;就涉及到了权限问题&#xff0c;比如你是管理员&#xff0c;这时候你会面临着“给每个用户分配一个 Namespace”类似的需求。 更进一步&#xff0c;可能你需要限制特定用户只能够对集群进行特定的操作&#xff0c;…

Dialogue Transformers:如何解决医学大模型【偏离主诉和没抓住核心】,建立抗干扰的能力,使得发现用户问题会一追到底?

Dialogue Transformers&#xff1a;实现抗干扰能力的对话模型 抗干扰能力基于 Transformer 的实现技术优化目标 抗干扰能力 前置知识&#xff1a;从【注意力机制】开始&#xff0c;到【Transformer】的零基础【大模型】系列 Dialogue Transformers 论文地址&#xff1a;https:/…

如何用CHAT写复习教案?

近日天气恶劣&#xff0c;好多地方的学校都停课了&#xff0c;改为线上学习&#xff0c;那作为老师&#xff0c;如何安排好线上的教学方案呢&#xff1f;下面小编分享下朋友用CHATGPT写的这份复习教案。 问CHAT&#xff1a;一年级语文上册复习计划教案 CHAT回复&#xff1a;教…

网络安全事件分级指南

文章目录 一、特别重大网络安全事件符合下列情形之一的&#xff0c;为特别重大网络安全事件&#xff1a;通常情况下&#xff0c;满足下列条件之一的&#xff0c;可判别为特别重大网络安全事件&#xff1a; 二、重大网络安全事件符合下列情形之一且未达到特别重大网络安全事件的…

HarmonyOS--基础组件Text

Text组件 可以包含Span子组件。 接口 Text(content? : string | Resource) string: Text(我是ttttt) Resource: Text($r(app.string.aaaaaa)) 先找限定词目录&#xff0c;找不到内容 找base目录 属性 除支持通用属性外&#xff0c;还支持以下属性&#xff1a; 名称 参数…

工厂设备数据采集如何更高效?

​随着工业4.0时代的到来&#xff0c;工厂设备数据采集变得越来越重要。然而&#xff0c;在实际的生产环境中&#xff0c;工厂设备数据采集面临着诸多痛点和难点。本文将分析这些痛点和难点&#xff0c;并介绍如何解决这些问题&#xff0c;提高工厂设备数据采集的效率。 一、工…

Linux 线程池源码剖析

1 了解线程池 1-1线程池的概述 由一个任务队列和一组处理队列的线程组成。一旦工作进程需要处理某个可能“阻塞”的操作,不用自己操作,将其作为一个任务放到线程池的队列,接着会被某个空闲线程提取处理。 1-2线程池的组件 任务 待处理的工作,通常由标识、上下文和处理…

xilinx 产品系列分类

1. 按照产品代数&#xff0c;分为6代&#xff0c;7代&#xff0c;ultrascale&#xff0c;ultrascale&#xff0c;Versal。6代是较早的器件&#xff0c;现在基本是7代及之后的产品&#xff0c;最新的一代是Versal&#xff0c;网上很多说法提到7系列也即是7代&#xff0c;在第二章…

以柔克刚:软体机器人的柔性革命与无限可能

原创 | 文 BFT机器人 戳“精彩内容”不容错过 你知道什么是软体机器人吗&#xff1f;真的是表面所理解的那样&#xff0c;这个“机器人是软的&#xff1f;”。当然不是啦&#xff01;那下面小编将带你具体解读一下软体机器人的来源与发展。 软体机器人是一类由软体驱动材料构成…

seata的安装及基本使用

seata的安装及基本使用 安装注意事项1. 启动时需要带上seata所在服务器的地址和端口&#xff08;默认是8091&#xff09;2. seata的服务端配置文件application.yml中在配置nacos的namespace时&#xff0c;需要注意的是&#xff1a;对应的值是nacos中namespace的id, 而不是名称&…

3分钟打造私人微信ChatGPT助手:新手友好指南!

接上文&#xff1a; https://mp.weixin.qq.com/s/RCqX0rx7TEu1gIwHEBBWKQ 本文适用于小白用户&#xff0c;技术大佬勿入&#xff01; 前言 这里教大家如何快速的拥有一个属于自己的微信GPT助手 我个人其实不是这么部署的&#xff0c;但是为了方便小白用户&#xff0c;探索了一个…

【AI底层逻辑】——“数学华尔兹”之一元线性回归

一元线性回归模型想必大家都耳熟能详&#xff0c;这里不再赘述。但在使用python中机器学习包时一定见过类似模型评价参数的输出&#xff0c;这一章我们就讲一讲回归分析里一些模型评价概念&#xff01; 一、方差分析ANOVA 方差分析是一种用于确定线性回归模型中不同变量对目标…

Java版工程行业管理系统源码-专业的工程管理软件-提供一站式服务

鸿鹄工程项目管理系统 Spring CloudSpring BootMybatisVueElementUI前后端分离构建工程项目管理系统 项目背景 随着公司的快速发展&#xff0c;企业人员和经营规模不断壮大。为了提高工程管理效率、减轻劳动强度、提高信息处理速度和准确性&#xff0c;公司对内部工程管理的提…

数字孪生轻量化引擎——AMRT3D引擎

随着全球经济亟待复苏&#xff0c;作为科技发展主要需求技术之一&#xff0c;数字孪生已经成为全球多个国家重点布局行业。例如&#xff0c;美国工业互联网盟将数字孪生作为工业互联网落地的核心和关键&#xff0c;德国工业4.0参考架构将数字孪生作为重要内容。 数字孪生已经形…

【问题解决】将页面下载为PDF文件(前端实现)

在前端开发过程中&#xff0c;将html页面下载为pdf文件的思路&#xff1a;使用html2canvas和jsPDF两个库&#xff0c;大致流程就是首先使用html2canvas库将组件内容转换为图像&#xff0c;然后使用jsPDF库将图像生成为PDF文件。 安装html2canvas库 npm install html2canvas安…

联邦学习算法介绍-FedAvg详细案例-Python代码获取

联邦学习算法介绍-FedAvg详细案例-Python代码获取 一、联邦学习系统框架二、联邦平均算法&#xff08;FedAvg&#xff09;三、联邦随梯度下降算法 (FedSGD&#xff09;四、差分隐私随联邦梯度下降算法 (DP-FedSGD&#xff09;五、差分隐私联邦平均算法 (DP-FedAVG&#xff09;六…

word图片点击放大,word图片双击放大

网上自己搜了半天&#xff0c;都是顾左右而言他&#xff0c;直接实践一下。 干货就是&#xff1a;调整word视图为阅读模式&#xff0c;双机图片 就能放大查看&#xff0c;然后还会有一个 放大镜供点击放大到整个屏幕。 其实挺好理解的&#xff0c;word跟wps不同&#xff0c;w…

二十六、模型、视图、代理

二十六、模型、视图、代理 模型&#xff08;Model&#xff09; InterView框架中所有模型都基于抽象基类QAbstractItemModel类&#xff0c;此类由QAbstractListModel、QAbstractTableModel和QAbstractProxyModel类继承。 视图&#xff08;View&#xff09; InterView框架中的…
最新文章