ros2机器人在gazebo中移动方案

这篇具有很好参考价值的文章主要介绍了ros2机器人在gazebo中移动方案。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

ros2机器人在gazebo中移动方案,ros2,gazebo,ros,机器人

很重要的地方:使用虚拟机运行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.

<plugin
    filename="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.

ros2机器人在gazebo中移动方案,ros2,gazebo,ros,机器人

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.文章来源地址https://www.toymoban.com/news/detail-792131.html

到了这里,关于ros2机器人在gazebo中移动方案的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【ROS2机器人入门到实战】RVIZ2可视化移动机器人模型

    当前平台文章汇总地址:ROS2机器人从入门到实战 获取完整教程及配套资料代码,请关注公众号鱼香ROS获取 教程配套机器人开发平台:两驱版| 四驱版 为方便交流,搭建了机器人技术问答社区:地址 fishros.org.cn 大家好,我是小鱼,上一节讲完joint和link,我们来把我们上面定义

    2024年02月03日
    浏览(45)
  • Gazebo-Ros搭建小车和场景并运行slam算法进行建图4--为机器人添加运动控制器控制其移动

    1.要想机器人小车在gazebo中运动还需要为其添加运动插件 在文章3中的my_robot2.urdf 最下边(前边)添加如下部分: ​ 这里使用的二轮差速控制,选择对应的插件libgazebo_ros_diff_drive.so 添加上述部分,文章3中的my_robot2.urdf 更新为 --完整代码如下: 2.使用turtlebot3中的控制机器人的

    2023年04月11日
    浏览(97)
  • 【ROS2机器人入门到实战】ROS2话题入门

    当前平台文章汇总地址:ROS2机器人从入门到实战 获取完整教程及配套资料代码,请关注公众号鱼香ROS获取 教程配套机器人开发平台:两驱版| 四驱版 为方便交流,搭建了机器人技术问答社区:地址 fishros.org.cn 话题是ROS2中最常用的通信方式之一,话题通信采取的是订阅发布

    2024年02月04日
    浏览(66)
  • 【ROS2机器人入门到实战】ROS2节点介绍

    当前平台文章汇总地址:ROS2机器人从入门到实战 获取完整教程及配套资料代码,请关注公众号鱼香ROS获取 教程配套机器人开发平台:两驱版| 四驱版 为方便交流,搭建了机器人技术问答社区:地址 fishros.org.cn ROS2中每一个节点也是只负责一个单独的模块化的功能(比如一个

    2024年02月06日
    浏览(57)
  • 【ROS2机器人入门到实战】ROS2服务入门

    当前平台文章汇总地址:ROS2机器人从入门到实战 获取完整教程及配套资料代码,请关注公众号鱼香ROS获取 教程配套机器人开发平台:两驱版| 四驱版 为方便交流,搭建了机器人技术问答社区:地址 fishros.org.cn 大家好,帅鱼又蹬蹬蹬的游回来了。本节小鱼将要带大家一起了解

    2024年02月07日
    浏览(61)
  • 【ROS2机器人入门到实战】ROS2接口介绍

    当前平台文章汇总地址:ROS2机器人从入门到实战 获取完整教程及配套资料代码,请关注公众号鱼香ROS获取 教程配套机器人开发平台:两驱版| 四驱版 为方便交流,搭建了机器人技术问答社区:地址 fishros.org.cn 本节小鱼将会带你学习认识一个新的概念,叫做interface,即接口。

    2024年02月05日
    浏览(52)
  • 【ROS2机器人入门到实战】2.ROS与ROS2对比

    当前平台文章汇总地址:ROS2机器人从入门到实战 获取完整教程及配套资料代码,请关注公众号鱼香ROS获取 教程配套机器人开发平台:两驱版| 四驱版 为方便交流,搭建了机器人技术问答社区:地址 fishros.org.cn 经过上一节的学习,相信你已经对ROS和ROS2的发展有了一定的了解

    2024年02月04日
    浏览(48)
  • 【ROS2机器人入门到实战】4.ROS2初体验

    当前平台文章汇总地址:ROS2机器人从入门到实战 获取完整教程及配套资料代码,请关注公众号鱼香ROS获取 教程配套机器人开发平台:两驱版| 四驱版 为方便交流,搭建了机器人技术问答社区:地址 fishros.org.cn 通过几个简单的小例子来体验ROS2软件库和工具集。 游戏内容:很

    2024年02月04日
    浏览(73)
  • 【ROS2机器人入门到实战】3.动手安装ROS2

    当前平台文章汇总地址:ROS2机器人从入门到实战 获取完整教程及配套资料代码,请关注公众号鱼香ROS获取 教程配套机器人开发平台:两驱版| 四驱版 为方便交流,搭建了机器人技术问答社区:地址 fishros.org.cn 到了这一节,终于可以开始安装ROS2了。安装ROS2本来是一件比较麻

    2024年02月13日
    浏览(59)
  • 【ROS2机器人入门到实战】

    当前平台文章汇总地址:ROS2机器人从入门到实战 获取完整教程及配套资料代码,请关注公众号鱼香ROS获取 教程配套机器人开发平台:两驱版| 四驱版 为方便交流,搭建了机器人技术问答社区:地址 fishros.org.cn 第 1 章 ROS2介绍与安装 基础篇-Linux基础 1.Linux与Ubuntu系统介绍 2.在

    2024年02月16日
    浏览(56)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包