当前位置: 首页 > news >正文

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.

相关文章:

ros2机器人在gazebo中移动方案

原文连接Gazebo - Docs: Moving the robot (gazebosim.org) 很重要的地方&#xff1a;使用虚拟机运行Ubuntu的时候&#xff0c;需要关闭”加速3D图形“的那个选项&#xff0c;否则gazebo无法正常显示。 Moving the robot&#xff08;使用命令移动机器人示例&#xff09; In t…...

学习Java第74天,Ajax简介

什么是ajax AJAX Asynchronous JavaScript and XML&#xff08;异步的 JavaScript 和 XML&#xff09;。 AJAX 不是新的编程语言&#xff0c;而是一种使用现有标准的新方法。 AJAX 最大的优点是在不重新加载整个页面的情况下&#xff0c;可以与服务器交换数据并更新部分网页…...

【Java面试题】在Java中String,Stringbuffer,StringBuilder的区别?

Hi i,m JinXiang ⭐ 前言 ⭐ 本篇文章主要介绍在Java中String&#xff0c;Stringbuffer&#xff0c;StringBuilder的区别以及部分理论知识 &#x1f349;欢迎点赞 &#x1f44d; 收藏 ⭐留言评论 &#x1f4dd;私信必回哟&#x1f601; &#x1f349;博主收将持续更新学习记录…...

让AIGC成为你的智能外脑,助力你的工作和生活

人工智能成为智能外脑 在当前的科技浪潮中&#xff0c;人工智能技术正在以前所未有的速度改变着我们的生活和工作方式。其中&#xff0c;AIGC技术以其强大的潜力和广泛的应用前景&#xff0c;正在引领着这场革命。 AIGC技术是一种基于人工智能的生成式技术&#xff0c;它可以通…...

ubuntu12.04 源

替换 /etc/apt/sources.list deb http://old-releases.ubuntu.com/ubuntu precise main restricted universe multiverse deb http://old-releases.ubuntu.com/ubuntu precise-security main restricted universe multiverse deb http://old-releases.ubuntu.com/ubu…...

openssl数据压缩

介绍 数据压缩是将原有数据通过某种压缩算法计算得到相对数据量小的过程。这种过程是可逆的&#xff0c;即能通过压缩后的数据恢复出原数据。数据压缩能够节省存储空间&#xff0c;减轻网络负载。 在即需要加密又需要压缩的情况下&#xff0c;必须先压缩再加密&#xff0c;次…...

SQLturning:定位连续值范围起点和终点

在上一篇blog说到&#xff0c;如何去优化查询连续值范围&#xff0c;没看过的朋友&#xff0c;上篇blog链接[在此]。(https://blog.csdn.net/weixin_42575078/article/details/135067645?spm1001.2014.3001.5501) 那么今天来说说怎么将连续的数据合并&#xff0c;然后返回合并…...

饥荒Mod 开发(十七):手动保存和加载,无限重生

饥荒Mod 开发(十六)&#xff1a;五格装备栏 饥荒Mod 开发(十八)&#xff1a;Mod 添加配置选项 饥荒游戏会自动保存&#xff0c;本来是一个好的机制&#xff0c;但是当角色死亡的时候存档会被删除&#xff0c;又要从头开始&#xff0c;有可能一不小心玩了很久的档就直接给整没了…...

Skywalking系列之最新版9.2.0-JavaAgent本地构建

MAC 10.15.7IDEA 2021.2skywalking-agent 9.2.0-SNAPSHOTJDK 17/21 (最新的代码要看最新的要求&#xff0c;注意不能使用JDK8&#xff0c;会构建失败)Maven 3.6.0 关于本地构建JavaAgent源码 1、获取源码&#xff0c;加载submodule 分步执行&#xff1a; git clone https:/…...

olap/clickhouse-编译器优化与向量化

本文主要结合15721和clickhouse源码来聊聊向量化&#xff0c;正好我最近也在用Eigen做算子加速&#xff0c;了解下还是有好处的。 提示编译器 提示编译器而不是复杂化简单的代码 什么时候使用汇编&#xff0c;什么时候使用SIMD&#xff1f;下面有几个基本原则&#xff1a; …...

RK3399平台开发系列讲解(内核入门篇)网络协议的分层

🚀返回专栏总目录 文章目录 一、应用层二、传输层三、网络层四、数据链路层(Data Link Layer)五、物理层沉淀、分享、成长,让自己和他人都能有所收获!😄 📢对于多数的应用和用户而言,使用互联网的一个基本要求就是数据可以无损地到达。用户通过应用进行网络通信࿰...

Idea远程debugger调试

当我们服务部署在服务器上&#xff0c;我们想要像在本地一样debug,就可以使用idea自带的Remote JVM Debug 创建Remote JVM Debug服务器启动jar打断点进入断点 当我们服务部署在服务器上&#xff0c;我们想要像在本地一样debug,就可以使用idea自带的 Remote JVM Debug) 创建Rem…...

MATLAB - Gazebo 仿真环境

系列文章目录 前言 机器人系统工具箱&#xff08;Robotics System Toolbox™&#xff09;为使用 Gazebo 模拟器可视化的模拟环境提供了一个界面。通过 Gazebo&#xff0c;您可以在真实模拟的物理场景中使用机器人进行测试和实验&#xff0c;并获得高质量的图形。 Gazebo 可在…...

selenium自动化webdriver下载及安装

1、确认浏览器的版本 在浏览器的地址栏&#xff0c;输入chrome://version/&#xff0c;回车后即可查看到对应版本 2、找到对应的chromedriver版本 2.1 114及之前的版本可以通过点击下载chromedriver,根据版本号&#xff08;只看大版本&#xff09;下载对应文件 2.2 116版本通过…...

网络基础介绍

1.网线制作 1.1 网线制作需要的工具 网线 网线钳 水晶头 测试仪 ​编辑 1.2 网线的标准 1.3 网线的做法 2.集线器&交换机&路由器的介绍 3.OSI七层模型 4.路由器的设置 4.1 常见的路由器设置地址 4.2 常见的路由器账号密码 4.3 登录路由器 设置访客网…...

Java中四种引用类型(强、软、弱、虚)

目录 引言 强引用&#xff08;Strong References&#xff09; 软引用&#xff08;Soft References&#xff09; 弱引用&#xff08;Weak References&#xff09; 虚引用&#xff08;Phantom References&#xff09; 引用类型的应用场景 总结 引言 Java中的引用类型是管理…...

【MyBatis学习笔记】MyBatis基础学习

MyBatis基础 MyBatis简介MyBatis特性MyBatis下载和其他持久化层技术对比 核心配置文件详解默认的类型别名 搭建MyBatis开发环境创建maven工程创建MyBatis的核心配置文件创建mapper接口创建MyBatis的映射文件通过junit测试功能加入log4j日志功能 MyBatis获取参数值的两种方式&am…...

还在为论文焦虑?免费AI写作大师帮你搞定

先来看1分钟的视频&#xff0c;对于要写论文的你来说&#xff0c;绝对有所值&#xff01; 还在为写论文焦虑&#xff1f;免费AI写作大师来帮你三步搞定 第一步&#xff1a;输入关键信息 第二步&#xff1a;生成大纲 稍等片刻后&#xff0c;专业大纲生成&#xff08;由于举例&am…...

3.10【窗口】窗口使用示例(窗口缩放 三)

五,从窗口所有者放大 要从窗口的所有者本身进行放大,可以将源图像矩形设置得比窗口小。可以想象我们在一张图片中选取一部分进行放大的操作。 屏幕使用默认位置 (0,0) 作为源矩形、窗口和显示器显示的左上角。要放大源图形的特定区域,必须设置源矩形的大小。 源矩形由这些…...

【机器学习】密度聚类:从底层手写实现DBSCAN

【机器学习】Building-DBSCAN-from-Scratch 概念代码数据导入实现DBSCAN使用样例及其可视化 补充资料 概念 DBSCAN&#xff08;Density-Based Spatial Clustering of Applications with Noise&#xff0c;具有噪声的基于密度的聚类方法&#xff09;是一种基于密度的空间聚类算…...

【网络】每天掌握一个Linux命令 - iftop

在Linux系统中&#xff0c;iftop是网络管理的得力助手&#xff0c;能实时监控网络流量、连接情况等&#xff0c;帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...

汽车生产虚拟实训中的技能提升与生产优化​

在制造业蓬勃发展的大背景下&#xff0c;虚拟教学实训宛如一颗璀璨的新星&#xff0c;正发挥着不可或缺且日益凸显的关键作用&#xff0c;源源不断地为企业的稳健前行与创新发展注入磅礴强大的动力。就以汽车制造企业这一极具代表性的行业主体为例&#xff0c;汽车生产线上各类…...

质量体系的重要

质量体系是为确保产品、服务或过程质量满足规定要求&#xff0c;由相互关联的要素构成的有机整体。其核心内容可归纳为以下五个方面&#xff1a; &#x1f3db;️ 一、组织架构与职责 质量体系明确组织内各部门、岗位的职责与权限&#xff0c;形成层级清晰的管理网络&#xf…...

如何理解 IP 数据报中的 TTL?

目录 前言理解 前言 面试灵魂一问&#xff1a;说说对 IP 数据报中 TTL 的理解&#xff1f;我们都知道&#xff0c;IP 数据报由首部和数据两部分组成&#xff0c;首部又分为两部分&#xff1a;固定部分和可变部分&#xff0c;共占 20 字节&#xff0c;而即将讨论的 TTL 就位于首…...

听写流程自动化实践,轻量级教育辅助

随着智能教育工具的发展&#xff0c;越来越多的传统学习方式正在被数字化、自动化所优化。听写作为语文、英语等学科中重要的基础训练形式&#xff0c;也迎来了更高效的解决方案。 这是一款轻量但功能强大的听写辅助工具。它是基于本地词库与可选在线语音引擎构建&#xff0c;…...

Angular微前端架构:Module Federation + ngx-build-plus (Webpack)

以下是一个完整的 Angular 微前端示例&#xff0c;其中使用的是 Module Federation 和 npx-build-plus 实现了主应用&#xff08;Shell&#xff09;与子应用&#xff08;Remote&#xff09;的集成。 &#x1f6e0;️ 项目结构 angular-mf/ ├── shell-app/ # 主应用&…...

【笔记】WSL 中 Rust 安装与测试完整记录

#工作记录 WSL 中 Rust 安装与测试完整记录 1. 运行环境 系统&#xff1a;Ubuntu 24.04 LTS (WSL2)架构&#xff1a;x86_64 (GNU/Linux)Rust 版本&#xff1a;rustc 1.87.0 (2025-05-09)Cargo 版本&#xff1a;cargo 1.87.0 (2025-05-06) 2. 安装 Rust 2.1 使用 Rust 官方安…...

JavaScript基础-API 和 Web API

在学习JavaScript的过程中&#xff0c;理解API&#xff08;应用程序接口&#xff09;和Web API的概念及其应用是非常重要的。这些工具极大地扩展了JavaScript的功能&#xff0c;使得开发者能够创建出功能丰富、交互性强的Web应用程序。本文将深入探讨JavaScript中的API与Web AP…...

免费PDF转图片工具

免费PDF转图片工具 一款简单易用的PDF转图片工具&#xff0c;可以将PDF文件快速转换为高质量PNG图片。无需安装复杂的软件&#xff0c;也不需要在线上传文件&#xff0c;保护您的隐私。 工具截图 主要特点 &#x1f680; 快速转换&#xff1a;本地转换&#xff0c;无需等待上…...

Python竞赛环境搭建全攻略

Python环境搭建竞赛技术文章大纲 竞赛背景与意义 竞赛的目的与价值Python在竞赛中的应用场景环境搭建对竞赛效率的影响 竞赛环境需求分析 常见竞赛类型&#xff08;算法、数据分析、机器学习等&#xff09;不同竞赛对Python版本及库的要求硬件与操作系统的兼容性问题 Pyth…...