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.rhkb.cn/news/220857.html

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

相关文章

小新Air-14 Plus 2021款AMD ACN版(82L7)原装出厂Win11系统镜像

LENOVO联想笔记本开箱状态原厂Windows11系统包 链接&#xff1a;https://pan.baidu.com/s/1D_sYCJAtOeUu9RbTIXgI3A?pwd96af 提取码&#xff1a;96af 联想小新AIR14笔记本电脑原厂系统自带所有驱动、出厂主题壁纸、Office办公软件、联想电脑管家等预装程序 所需要工具&am…

OpenAI 疑似正在进行 GPT-4.5 灰度测试!

‍ 大家好&#xff0c;我是二狗。 今天&#xff0c;有网友爆料OpenAI疑似正在进行GPT-4.5灰度测试&#xff01; 当网友询问ChatGPT API调用查询模型的确切名称是什么时&#xff1f; ChatGPT的回答竟然是 gpt-4.5-turbo。 也有网友测试之后发现仍然是GPT-4模型。 这是有网友指…

飞天使-k8s-知识点1-kubernetes架构简述

文章目录 名词功能要点 k8s核心要素CNCF 云原生框架简介k8s组建介绍 名词 CI 持续集成, 自动化构建和测试&#xff1a;通过使用自动化构建工具和自动化测试套件&#xff0c;持续集成可以帮助开发人员自动构建和测试他们的代码。这样可以快速检测到潜在的问题&#xff0c;并及早…

[ CTF ]【天格】战队WriteUp-第七届“强网杯”全国安全挑战赛

第七届“强网杯”全国安全挑战赛 2023.12.16~2023.12.17 文章目录 【Misc】Pyjail ! Its myFILTER !!!easyfuzz谍影重重2.0签到Pyjail ! Its myRevenge !!!server_8F6C72124774022B.py 问卷调查 【Reverse】ezre 【Web】happygame 【强网先锋】石头剪刀布TrieSpeedUpezreez_fmt…

Gazebo11更新安装

ROS Melodic版本安装的是Gazebo9&#xff0c;Gazebo 最新版本是11 dpkg -l | grep gazebo 出现的是 gazebo9 相关的插件&#xff0c;需要卸载全部插件。 sudo apt-get remove gazebo9 gazebo9-common gazebo9-plugin-base libgazebo9:amd64 libgazebo9-dev:amd64 ros-melodic…

SpringCloud源码探析(十二)-基于SpringBoot开发自定义中间件

1.概述 中间件是一种介于操作系统和应用软件之间&#xff0c;为应用软件提供服务功能的软件&#xff0c;按功能划分有消息中间件&#xff08;Kafka、RocketMQ&#xff09;、通信中间件&#xff08;RPC通信中间件&#xff0c;dubbo等&#xff09;&#xff0c;应用服务器等。中间…

什么是 DDoS ?如何识别DDoS?怎么应对DDOS攻击

什么是DDOS攻击 DDoS攻击&#xff08;Distributed Denial of Service Attack&#xff09;即分布式拒绝服务攻击&#xff0c;是一种利用分布式网络来发起大量的请求&#xff0c;占用目标服务器或网络资源的攻击行为。这种攻击方式可以瘫痪目标系统&#xff0c;导致其无法正常提供…

每日一题,二维平面

给你 二维 平面上两个 由直线构成且边与坐标轴平行/垂直 的矩形&#xff0c;请你计算并返回两个矩形覆盖的总面积。 每个矩形由其 左下 顶点和 右上 顶点坐标表示&#xff1a; 第一个矩形由其左下顶点 (ax1, ay1) 和右上顶点 (ax2, ay2) 定义。 第二个矩形由其左下顶点 (bx1, …

vscode颜色主题插件one dark Pro安装

1.点击扩展图标→搜索“one dark Pro”→第一个点击安装 2.安装成功后&#xff0c;不要忘了点击设置颜色主题 3.看下效果&#xff1a;

如何获取光标在 textarea 中的位置

如何获取光标在 textarea 中的位置 这里的位置不是指光标所在的字符数位置&#xff0c;而是相对 textarea 的向上向左的大体像素位置。 你可以通过 textarea.selectionStart() 来获取光标在 textarea 文本中的字符位置&#xff0c;比如在第几个字符上。 一、如何获取大体的像…

YOLOv5改进 | 注意力篇 | DiverseBranchBlock(DBB)多元分支模块(有效涨点)

一、本文介绍 本文带来的改进机制是YOLOv5模型与多元分支模块&#xff08;Diverse Branch Block&#xff09;的结合&#xff0c;Diverse Branch Block (DBB) 是一种用于增强卷积神经网络性能的结构重新参数化技术。这种技术的核心在于结合多样化的分支&#xff0c;这些分支具有…

eclipse中基于maven构建的web项目pom.xml中指定的jar包无法发布到tomcat中

eclipse运行maven web项目报错&#xff1a; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 信息: Star…

vp与vs联合开发-通过FrameGrabber连接相机

添加控件 1.CogRecordDisplay 控件 用于显示图像 初始化相机对象方法 //启动窗体时 调用初始化相机方法 //封装相机关闭方法 //窗体关闭时 调用相机关闭方法 拍照 设置采图事件 // 保存图像 设置曝光按钮事件 1.可变参数

C++刷题 -- KMP算法

C刷题 – KMP算法 文章目录 C刷题 -- KMP算法1.算法讲解2.算法实现 https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string/description/ 1.算法讲解 KMP算法是一种字符串匹配算法&#xff0c;当出现字符串不匹配时&#xff0c;可以记录一部分之…

2024 年 8 个顶级开源 LLM(大语言模型)

如果没有所谓的大型语言模型&#xff08;LLM&#xff09;&#xff0c;当前的生成式人工智能革命就不可能实现。LLM 基于 transformers&#xff08;一种强大的神经架构&#xff09;是用于建模和处理人类语言的 AI 系统。它们之所以被称为“大”&#xff0c;是因为它们有数亿甚至…

Python tkinter 初探Toplevel控件搭建父子窗口

目录 Toplevel控件搭建父子窗口 最简明的父子窗口框架 改进一&#xff1a;屏蔽和开放按钮 改进二&#xff1a;子窗口始终在主窗口之上 改进三&#xff1a;增加子窗口的关闭协议 改进四&#xff1a;使子窗口长获焦点 总结 Toplevel控件搭建父子窗口 最近&#xff0c;用P…

EasyExcel合并相同内容单元格及动态标题功能的实现

一、最初版本 导出的结果&#xff1a; 对应实体类代码&#xff1a; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ContentLoopMerge; import com.al…

【TB作品】51单片机,具有报时报温功能的电子钟

2.具有报时报温功能的电子钟 一、功能要求: 1.显示室温。 2.具有实时时间显示。 3.具有实时年月日显示和校对功能。 4.具有整点语音播报时间和温度功能。 5.定闹功能,闹钟音乐可选。 6.操作简单、界面友好。 二、设计建议: 1.单片机自选(C51、STM32或其他单片机)。 2.时钟日历芯…

第十七章 爬虫scrapy登录与中间件2

文章目录 数据盘区太快会报错&#xff0c;setting中配置延迟 连接提取器

深度学习记录--矩阵维数

如何识别矩阵的维数 如下图 矩阵的行列数容易在前向和后向传播过程中弄错&#xff0c;故写这篇文章来提醒易错点 顺便起到日后查表改错的作用 本文仅作本人查询参考(摘自吴恩达深度学习笔记)