ros2机器人在gazebo中移动方案

原文连接Gazebo - Docs: Moving the robot (gazebosim.org)

很重要的地方:使用虚拟机运行Ubuntu的时候,需要关闭”加速3D图形“的那个选项,否则gazebo无法正常显示。

Moving the robot(使用命令移动机器人示例)

In this tutorial we will learn how to move our robot. We will use the robot we built in the Build your own robot tutorial. You can download the robot from here. You can also find the finished world of this tutorial here.

What is a plugin

To make our robot move we will use the diff_drive plugin. But before doing so let's answer the question "What is a plugin?" A plugin is a chunk of code that is compiled as a shared library and inserted into the simulation. Plugins make us control many aspects of the simulation like world, models, etc.

Diff_drive plugin

diff_drive plugin helps us control our robot, specifically a robot that can be differentially driven. Let's setup the plugin on our robot. Open the building_robot.sdf and add the following code within the vehicle_blue model tags.

<pluginfilename="gz-sim-diff-drive-system"name="gz::sim::systems::DiffDrive"><left_joint>left_wheel_joint</left_joint><right_joint>right_wheel_joint</right_joint><wheel_separation>1.2</wheel_separation><wheel_radius>0.4</wheel_radius><odom_publish_frequency>1</odom_publish_frequency><topic>cmd_vel</topic>
</plugin>

The <plugin> tag has two attributes, filename which takes the library file name and name which takes the name of the plugin. In the <left_joint> and <right_joint> tags we define the joints which connect the left and the right wheel with the body of the robot, in our case left_wheel_joint and right_wheel_joint<wheel_separation> takes the distance between the two wheels. Our robot has its left_wheel at 0.6 m and the right_wheel at -0.6 m in y-axis with respect to the chassis, so the wheel_separation is 1.2 m. <wheel_radius> takes the radius of the wheel which was defined in the <radius> tag under the wheel link. <odom_publish_frequency> sets the frequency at which the odometry is published at /model/vehicle_blue/odometrycmd_vel is the input <topic> to the DiffDrive plugin.

Topics and Messages

Now our model is ready. We just need to send commands (messages) to it. These messages will be published (sent) on the cmd_vel topic defined above.

A topic is simply a name for grouping a specific set of messages or a particular service. Our model will subscribe (listen) to the messages sent on the cmd_vel topic.

Launch the robot world:

gz sim building_robot.sdf

In another terminal let's send a message to to our robot:

gz topic -t "/cmd_vel" -m gz.msgs.Twist -p "linear: {x: 0.5}, angular: {z: 0.05}"

Now you should have your robot moving in the simulation.

Note: Don't forget to press the play button in the simulation.

The command specifies the topic to publish to after the -t option. After the -m we specify the message type. Our robot expects messages of type Twist which consists of two components, linear and angular. After the -p option we specify the content (value) of the message: linear speed x: 0.5 and angular speed z: 0.05.

Hint: You can know what every topic option does using this command: gz topic -h

For more information about Topics and Messages in Gazebo check the Transport library tutorials

Moving the robot using the keyboard(使用按键遥控机器人示例)

Instead of sending messages from the terminal we will send messages using the keyboard keys. To do so we will add two new plugins: KeyPublisher and TriggeredPublisher.

KeyPublisher

KeyPublisher is an gz-gui plugin that reads the keyboard's keystrokes and sends them on a default topic /keyboard/keypress. Let's try this plugin as follows:

  • In one terminal type

    gz sim building_robot.sdf

  • In the top right corner click on the plugins dropdown list (vertical ellipsis), click the Key Publisher.

  • In another terminal type

    gz topic -e -t /keyboard/keypress

The last command will display all messages sent on /keyboard/keypress topic.

In the Gazebo window press different keys and you should see data (numbers) on the terminal where you run the gz topic -e -t /keyboard/keypress command.

KeyPublisher

We want to map these keystrokes into messages of type Twist and publish them to the /cmd_vel topic which our model listens to. The TriggeredPublisher plugin will do this.

Triggered Publisher

The TriggeredPublisher plugin publishes a user specified message on an output topic in response to an input message that matches user specified criteria. Let's add the following code under the <world> tag:

<!-- Moving Forward-->
<plugin filename="gz-sim-triggered-publisher-system"name="gz::sim::systems::TriggeredPublisher"><input type="gz.msgs.Int32" topic="/keyboard/keypress"><match field="data">16777235</match></input><output type="gz.msgs.Twist" topic="/cmd_vel">linear: {x: 0.5}, angular: {z: 0.0}</output>
</plugin>

This code defines the triggered-publisher plugin. It accepts messages of type gz.msgs.Int32 on the /keyboard/keypress topic and if the value in the data field matches 16777235(Up arrow key) it outputs a Twist message on the cmd_vel topic with values x: 0.5z: 0.0.

Now launch building_robot.sdf then add the Key Publisher plugin and our robot should move forward as we press the Up arrow key ↑ (make sure you start the simulation by pressing the play button to see the robot move forward after pressing the Up arrow key).

There is a demo explaining how the Triggered Publisher works.

Moving using arrow keys

To see what values are sent on the /keyboard/keypress topic when pressing the arrows we can use the --echo or -e option

  • Run the model in one terminal:

    gz sim building_robot.sdf

  • In the top right corner click on the plugins dropdown list (vertical ellipsis), click the Key Publisher.

  • In another terminal run the following command:

    gz topic -e -t /keyboard/keypress

Start pressing the arrows keys and see what values they give:

  • Left ← : 16777234
  • Up ↑ : 16777235
  • Right → : 16777236
  • Down ↓ : 16777237

We will add the Triggered publisher plugin for each arrow key. For example, the Down arrow:

<!-- Moving Backward-->
<plugin filename="gz-sim-triggered-publisher-system"name="gz::sim::systems::TriggeredPublisher"><input type="gz.msgs.Int32" topic="/keyboard/keypress"><match field="data">16777237</match></input><output type="gz.msgs.Twist" topic="/cmd_vel">linear: {x: -0.5}, angular: {z: 0.0}</output>
</plugin>

Map each arrow (key stroke) with the desired message (movement) as we did with the backward arrow:

  • Left ➞ 16777234 ➞ linear: {x: 0.0}, angular: {z: 0.5}
  • Up ➞ 16777235 ➞ linear: {x: 0.5}, angular: {z: 0.0}
  • Right ➞ 16777236 ➞ linear: {x: 0.0}, angular: {z: -0.5}
  • Down ➞ 16777237 ➞ linear: {x: -0.5}, angular: {z: 0.0}

Now it's your turn try to make the robot move using different keys.

In the next tutorial, you'll learn to create your own simulated world with SDF.

Video walk-through

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

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

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

相关文章

SpringBoot知识点回顾01

Spring是为了解决企业级应用开发的复杂性而创建的&#xff0c;简化开发。 Spring是如何简化Java开发的 为了降低Java开发的复杂性&#xff0c;Spring采用了以下4种关键策略&#xff1a; 1、基于POJO的轻量级和最小侵入性编程&#xff0c;所有东西都是bean&#xff1b; 2、通…

《JVM由浅入深学习【一】 2023-12-19》JVM由简入深学习提升

JVM由浅入深一&#xff08;类加载&#xff09; JVM的类加载1. java运行时是什么时候被加载的&#xff1f;2. JVM类加载过程大致阶段3. 父类与子类初始化各个类型顺序4. 什么是类加载器&#xff1f;6. 双亲委派机制 JVM的类加载 1. java运行时是什么时候被加载的&#xff1f; …

TikTok获客工具开发,这些代码不能少!

随着TikTok的全球影响力不断扩大&#xff0c;越来越多的企业和个人开始将目光投向这个短视频平台。 为了在竞争激烈的市场中脱颖而出&#xff0c;开发一款高效的TikTok获客工具成为了迫切的需求&#xff0c;而在开发过程中&#xff0c;掌握一些基础源代码是必不可少的。 本文…

虾皮ERP系统:提升电商企业管理效率和水平的利器

虾皮ERP&#xff08;Enterprise Resource Planning&#xff0c;企业资源规划&#xff09;系统是电商企业管理业务流程和资源的重要工具。通过整合企业的各种功能模块&#xff0c;如采购、销售、库存和财务等&#xff0c;虾皮ERP系统实现了数据共享和流程自动化&#xff0c;从而…

数据结构学习 Leetcode300最长递增子序列

是我在学习动态规划时遇到的一道题。 题目&#xff1a; 一共有两种解法&#xff1a; 动态规划贪心 二分&#xff08;很难理解&#xff0c;我还没完全懂。。。&#xff09; 解法一&#xff1a;动态规划 思路&#xff1a; 状态&#xff1a;nums的前i个数的最长递增子序列。dp…

量子登月计划!Infleqtion与日本JST研发中性原子量子计算机

​&#xff08;图片来源&#xff1a;网络&#xff09; 美国量子信息公司Infleqtion&#xff0c;已被日本科学技术振兴机构&#xff08;JST&#xff09;选定为“量子登月计划”唯一的外国量子计算合作伙伴。该计划旨在增强日本的量子技术能力&#xff0c;预计将在2050年之前对日…

LDO的工作原理

LDO&#xff0c;全称是低压差线性稳压器。LDO使用的是在线性区域内运行的晶体管或者场效应管。通过调节晶体管或场效应管两端的电压&#xff0c;产生经过调整过的输出电压。 但仅能使用在降压应用中&#xff0c;也就是输出电压必须小于输入电压。 LDO内部基本都是由4大部件构成…

翻译: 负责任的人工智能 Responsible AI

负责任的人工智能指的是以道德、值得信赖和社会负责任的方式开发和使用人工智能。许多开发者、企业和政府都关心这一点&#xff0c;并且一直在进行对话&#xff0c;也在努力确保人工智能的构建和使用是负责任的。由于对负责任的人工智能的所有这些关注和努力&#xff0c;我们在…

苏州和数荣获苏州市软件行业协会“杰出贡献理事单位”

2023年12月14日&#xff0c;苏州市软件行业协会第五届第五次理事会议在金螳螂大厦顺利召开。 苏州市工信局副局长万资平&#xff0c;苏州市工信局大数据处处长卢剑荣&#xff0c;苏州市工信局大数据处丁天龙&#xff0c;江苏省软件行业协会副秘书长夏冰莹&#xff0c;苏州市软…

【SpringBoot快速入门】(2)SpringBoot的配置文件与配置方式详细讲解

之前我们已经学习的Spring、SpringMVC、Mabatis、Maven&#xff0c;详细讲解了Spring、SpringMVC、Mabatis整合SSM的方案和案例&#xff0c;上一节我们学习了SpringBoot的开发步骤、工程构建方法以及工程的快速启动&#xff0c;从这一节开始&#xff0c;我们开始学习SpringBoot…

SpringSecurity深度解析与实践(1)

目录 引言1. SpringSecurity1.1 SpringSecurity简介1.2 SpringSecurity工作原理1.3.特点 2. SpringSecurity的快速使用总结 引言 SpringSecurity作为Spring框架中的一个重要组成部分&#xff0c;扮演着保护应用程序安全的重要角色。本文将深入探讨SpringSecurity的原理、使用方…

logging模块

【 一 】前言 logging 模块是 Python 中用于记录日志信息的标准库模块。通过使用 logging 模块&#xff0c;你可以在应用程序中设置日志记录以追踪代码执行、错误报告等信息。 debug : 打印全部的日志( notset 等同于 debug )info : 打印 info, warning, error, critical 级别的…

Playground AI刚刚推出了它的新宠儿——Playground V2,去试试?

每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗&#xff1f;订阅我们的简报&#xff0c;深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同&#xff0c;从行业内部的深度分析和实用指南中受益。不要错过这个机会&#xff0c;成为AI领…

react useState异步问题

1. useState执行后 不能立马拿到新的数据&#xff0c;下次更新绘图就可以拿到了 然后当执行完第一次render时候&#xff0c;比如去点击按钮啥的执行某个方法这个时候就可以拿到数据了 例子&#xff1a; const UseState () > { // 函数组件中没有this const [count, setCou…

vlan的通信(hcia)

有两种情况 第一种 vlanif的接口 VLANIF接口&#xff1a;VLANIF接口是一种三层的逻辑接口。在VLANIF接口上配置P地址 后&#xff0c;没备会在MAC地址表中添加VLANIF接口的MAC地址VD表项&#xff0c;并且为表项的 三层转发标志位置位。当报文的目的MAC地址匹配该表项后&a…

Linux-----17、软件包管理

# 软件包管理 # 1、软件包分类 # ㈠ 软件包类型 二进制包源码包 # ① 二进制包 什么是二进制包&#xff1f;有什么特点&#xff1f; 二进制包&#xff0c;指的是已经 1 好了的软件包&#xff0c;只需要直接安装就可以使用。二进制包&#xff0c;不需要编译&#xff0c;直接…

计算机msvcr120.dll文件丢失怎样修复,只需简单3步即可

在使用电脑过程中&#xff0c;我们经常会遇到一些错误提示&#xff0c;其中最常见的就是“缺少某个.dll文件”&#xff0c;“找不到msvcr120.dll文件”。那么&#xff0c;msvcr120.dll文件到底是什么呢&#xff1f;当我们遇到这个问题时应该如何解决呢&#xff1f;本文将详细介…

5252D 5G基站测试仪

01 5252D 5G基站测试仪 产品综述&#xff1a; 5252D多通道综测仪打破了信号发生器进行信号发射、频谱分析仪进行观看频域波形的测试方案&#xff0c;将信号收发融为一体&#xff0c;推动无线通信测试进入全新时代。其独具的多通道收发一体、高性能、全方位测试能力及直观操作…

凯斯西储大学轴承数据解读

文章目录 一、凯斯西储大学轴承数据基础知识&#xff1f;1.1 故障种类1.2 故障点尺寸&#xff08;单点故障&#xff09;1.3 载荷和转速 二、数据解读2.1 文件2.2 以12k Drive End Bearing Fault Data为例2.3 以&#xff08;0.007&#xff0c;inner race)为例。 3 Normal Baseli…

计算机组件操作系统BIOS的相关知识思维导图

&#x1f3ac; 艳艳耶✌️&#xff1a;个人主页 &#x1f525; 个人专栏 &#xff1a;《产品经理如何画泳道图&流程图》 ⛺️ 越努力 &#xff0c;越幸运 目录 一、运维实施工程师需要具备的知识 1、运维工程师、实施工程师是啥&#xff1f; 2、运维工程师、实施工…