ros2+gazebo建立机器人

news2024/11/16 23:42:01

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.coloradmin.cn/o/1309735.html

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

相关文章

Redis持久化AOF详解

基础面试题 什么是AOF AOF&#xff08;Append-Only File&#xff09;用于将Redis服务器收到的写操作追加到日志文件&#xff0c;通过该机制可以保证服务器重启后依然可以依靠日志文件恢复数据。 它的工作过程大抵分为以下几步&#xff1a; 收到客户端的写入命令(例如SET、DE…

Unity中Shader URP 简介

文章目录 前言一、URP&#xff08;Universal Render Pipeline&#xff09;由名字可知&#xff0c;这是一个 通用的 渲染管线1、Universal&#xff08;通用性&#xff09;2、URP的由来 二、Build-in Render Pipeline&#xff08;内置渲染管线&#xff09;1、LWRP&#xff08;Lig…

escapeshellarg参数绕过和注入的问题

escapeshellcmd escapeshellcmd(string $command): string command--要转义的命令。 escapeshellcmd() 对字符串中可能会欺骗 shell 命令执行任意命令的字符进行转义。 此函数保证用户输入的数据在传送到 exec() 或 system() 函数&#xff0c;或者 执行操作符 之前进行转义。 …

如何排查线上问题的?

其他系列文章导航 Java基础合集数据结构与算法合集 设计模式合集 多线程合集 分布式合集 ES合集 文章目录 其他系列文章导航 文章目录 前言 一、预警层面 1.1 做好监控告警 1.2 定位报警层面 二、近期版本 2.1 判断最近有没有发版本 2.2 回归最近的版本 三、日志告警…

国际语音通知系统有哪些功能?

支持动态呼叫及语音播报通知 支持根据企业需求自定义语音通知内容&#xff0c;并可实现批量外呼&#xff0c;同时支持中文、英语、日语等其他国家语言。系统还可以根据不同的通知需求设置不同的呼叫策略&#xff0c;如设置外呼的启动时间段、呼叫间隔频率、呼叫次数、以及接通…

计网 - 白话TCP 三次握手过程

文章目录 概述TCP协议头的格式TCP Finite State Machine (FSM) 状态机三次握手如何在 Linux 系统中查看 TCP 状态 概述 每一个抽象层建立在低一层提供的服务上&#xff0c;并且为高一层提供服务。 我们需要知道 TCP在网络OSI的七层模型中的第四层——Transport层 -----------…

同城线下社交搭子,同城圈子交友系统

简介:打破传统耗时耗力的交友模式&#xff0c;实现1对1,点对点的快速即时交友模式&#xff0c;线上线下 整合&#xff0c;可在线查看状态以及距离远近&#xff0c;可自行设置每单的收益提成以及代理的分佣提成。 结构: TINKPHP框架 公众号H5;系统开源&#xff0c;方便二次开发…

【PostgreSQL】从零开始:(三)PgAdmin4下载与安装

【PostgreSQL】从零开始:&#xff08;三&#xff09;PgAdmin4下载与安装 pgAdmin简介liunx下部署通过yum部署pgAdmin4&#xff08;6.21&#xff09;1.安装依赖包2.永久停止防火墙3.配置pgadmin4项目源4.下载并安装pgAdmin45.执行初始化命令6.访问我们的网站 liunx下通过python方…

TCP/IP详解——ARP 协议

文章目录 一、ARP 协议1. ARP 数据包格式2. ARP 工作过程3. ARP 缓存4. ARP 请求5. ARP 响应6. ARP 代理7. ARP 探测IP冲突8. ARP 协议抓包分析9. ARP 断网攻击10. 总结 一、ARP 协议 ARP&#xff08;Address Resolution Protocol&#xff09;协议工作在网络层和数据链路层之间…

RLC防孤岛负载测试的操作和维护

孤岛现象是指当电网因故障或停电而与主电网断开连接时&#xff0c;某些部分仍然保持供电的现象。这种情况下&#xff0c;如果电力系统的保护设备不能及时检测到孤岛并切断供电&#xff0c;可能会导致严重的安全事故。因此&#xff0c;进行RLC防孤岛负载测试对于确保电力系统的安…

【MySQL】安装和配置mysql

环境&#xff1a;Centos 7 删除不需要的环境 查看是否有正在运行的服务&#xff1a; ps ajx |grep mysqlps ajx |grep mariadb切换为root用户&#xff0c; 如果存在有服务 systemctl stop mariadb.service 或者 systemctl stop mysqld查看系统下的mysql安装包并删除&#xf…

linux文本处理sed

sed常用命令详解 sed &#xff08;Stream EDitor&#xff09; a append&#xff0c;对文本追加&#xff0c;在指定行后面添加一行/多行文本c 取代&#xff0c;替换d Delete&#xff0c;删除匹配行i insert&#xff0c;表示插入文本&#xff0c;在指定行前添加一行/多行文本p …

工业磷酸行业分析:中国市场产能及消费发展研究

工业磷酸主要用于电镀工业、医药工业、磷酸盐工业及冶金工业等。磷酸蒸汽对皮肤有较强的腐蚀作用&#xff0c;工作人员应注意保护呼吸器官和皮肤。预计工业级磷酸一铵将在一定时期内保持供应趋紧的市场格局&#xff0c;其市场价格有望保持相对高位运行。 业磷酸纯品为无色透…

蛋白质的上位性效应及突变影响的范式

直接性上位效应 在这张图片中 &#xff1a; 1&#xff09;相互作用的氨基酸形成有利接触&#xff08;H和T具有H键相互作用&#xff09; 2&#xff09;H和P的空间叠加&#xff0c;属于不利的上位姓效应 3&#xff09;V和P具有更高的自由度&#xff0c;因此需要的能量更低&#…

fastapi-amis-admin快速创建一个后台管理系统增加音乐管理功能(3)

fastapi_amis_admin 是一个功能强大的框架&#xff0c;旨在帮助开发者在使用 FastAPI 进行 web 开发时&#xff0c;能够快速创建一个高效且易于管理的后台界面。通过结合 FastAPI 和 amis 的优势&#xff0c;fastapi_amis_admin 提供了一种简洁而高效的方式来构建和管理 web 应…

03进程基础-学习笔记

Process 进程 进程为操作系统的基本调度单位&#xff0c;占用系统资源(cpu,内存)完成特定任务&#xff0c;所有说进程是操作系统的标准执行单元 进程与程序的差别 程序是静态资源&#xff0c;存储与电脑磁盘中(disk磁盘资源)程序执行后会创建进程&#xff0c;负责完成功能&a…

软件测试(接口测试业务场景测试)

软件测试 手动测试 测试用例8大要素 编号用例名称&#xff08;标题&#xff09;模块优先级预制条件测试数据操作步骤预期结果 接口测试&#xff08;模拟http请求&#xff09; 接口用例设计 防止漏测方便分配工具&#xff0c;评估工作量和时间接口测试测试点 功能 单接口业…

计算机网络安全原理习题参考答案

1.9习题 一、单项选择题 1. ISO 7498-2从体系结构的角度描述了5种可选的安全服务&#xff0c;以下不属于这5种安全服务的是&#xff08;  D  &#xff09; A. 数据完整性   B. 身份鉴别   C. 授权控制   D. 数据报过滤 2. ISO 7498-2描述了8种特定的安全机制&…

漏洞复现-iDocview某接口存在任意文件读取漏洞(附漏洞检测脚本)

免责声明 文章中涉及的漏洞均已修复&#xff0c;敏感信息均已做打码处理&#xff0c;文章仅做经验分享用途&#xff0c;切勿当真&#xff0c;未授权的攻击属于非法行为&#xff01;文章中敏感信息均已做多层打马处理。传播、利用本文章所提供的信息而造成的任何直接或者间接的…

QT 入门

目录 QT 概述 QT5安装 QT环境介绍 编写第一个QT的程序 QT项目文件介绍 QT 概述 QT简介 QT是一个跨平台的C图形用户界面应用程序框架。它为程序开发者提供图形界面所需的所有功能。它是完全面向对象的&#xff0c;很容易扩展&#xff0c;并且允许真正地组件编程。 QT的发…