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;从而…

Java自动化测试系列[v1.0.0][多种数据驱动实现附源码]

数据驱动测试是自动化测试中一种重要的设计模式&#xff0c;这种设计模式可以将测试数据和测试代码分开&#xff0c;实现数据与代码解耦&#xff0c;与此同时还能够实现一次任务中使用不同的数据来执行执行相同的测试脚本&#xff0c;因此它会使得我们的代码层次结构清晰&#…

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

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

天空卫士协助蒙牛打造数据安全堡垒

“真正的世界领先不光是看规模和销量&#xff0c;还要看给行业、给消费者、给这个世界带来更多的价值与贡献。” ——蒙牛总裁 卢敏放蒙牛集团1999年成立于内蒙古自治区&#xff0c;总部位于呼和浩特&#xff0c;是全球乳业八强。除中国内地外&#xff0c;蒙牛产品还进入了东南…

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

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

LDO的工作原理

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

前端加密后端校验(MD5)

前端加密后端校验&#xff08;MD5&#xff09; 因为md5是RSA数据安全公司开发的一种单向散列算法&#xff0c;非可逆&#xff0c;相同的明文产生相同的密文。因此校验可以比较加密之后的密文是否相同。 前端 md5 加密工具类&#xff08;js&#xff09;: https://pan.baidu.…

Java8中的流如何正确使用?

Java 8引入的流&#xff08;Stream&#xff09;是一种强大而灵活的处理数据集合的方式。流提供了一种声明性的编程风格&#xff0c;使得对数据的操作更为简洁和可读。以下是一些关于如何正确使用Java 8中的流的建议&#xff1a; 创建流&#xff1a; 使用Collection接口的stream…

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

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

信息收集 - 端口

端口 -简介 端口是计算机网络中用于标识特定应用程序或服务的数字标识符。当计算机之间进行通信时,数据传输通过端口进行。每个端口都有一个唯一的数字值,范围从0到65535。 端口分为三类: 知名端口(Well-known Ports):范围从0到1023,这些端口通常被系统或公共服务使用。…

2. 运算符和表达式

2. 运算符和表达式 ​ 在Java中&#xff0c;使用算术运算符、-、*、/表示加、减、乘、除运算。 ​ 当参与/运算时&#xff0c;两个操作数都是整数时&#xff0c;表示整除法&#xff1b;否则表示浮点除法。 ​ 整数的求余操作&#xff08;取模&#xff09;用%表示。例如&…

求解器的可行解存在一个允许的误差范围

在模型计算中&#xff0c;由于浮点计算的存在&#xff0c;包括数学建模当中常用的大M法等&#xff0c;都可能会使得结果存在轻微偏离预期的情况。然而&#xff0c;对于一些一定范围内的轻微偏移&#xff0c;我们常常是能够接受的&#xff0c;因为这些轻微的偏移能通过简单的调整…

听力句子100

[ 30 ] Now, you are going to be working on / writing a series of music lessons / for very young children. 现在&#xff0c;你将为年幼的孩子们编写一系列音乐课程 As before, youll be basing / the degin of your lessons / on the existing research / into how c…

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

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 级别的…