栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

ROS Gazebo仿真 控制Turtlebots实现扫地机器人算法

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ROS Gazebo仿真 控制Turtlebots实现扫地机器人算法

Wander_bot 1.Problem background

The aim of this assignment is to give you a way in to writing software for controlling a (simulated) robot using the Robot Operating System (ROS).
In this assignment you will create a ROS node to drive the robot around with a simple wanderer algorithm, very like a ‘Roomba’ robot vacuum cleaner. The robot should move forward until it reaches an obstacle, then rotate in the same position until the way ahead is clear, then move forward again and repeat.

2.Creating a wander_bot Package

In ROS, the programs organized as packages. So, we have to create a ROS package before writing any program. To create a ROS package, we have to give a name of the package,then the dependent packages which help to compile the programs inside the package.
For example, if your package has C++ program, you have to add ‘roscpp’ as dependency.
Before creating the package, first switch to the src folder.

$ cd ~/catkin_ws/src
$ catkin_create_pkg wander_bot roscpp rospy std_msgs

Figure 1 shows the output when we execute this command.

Figure 1. Creating the Package

3.Creating a Wander.h
#include "ros/ros.h"
#include "sensor_msgs/LaserScan.h"

class Wander
{
public:
    // Tunable parameters 
    const double FORWARD_SPEED = 0.5;
    double angular_velocity;    //Randomly get angular velocity  
    const double MIN_SCAN_ANGLE = -15.0 / 180 * M_PI;   //-15 degree rad
    const double MAX_SCAN_ANGLE = +15.0 / 180 * M_PI;
    // Should be smaller than sensor_msgs::LaserScan::range_max
    const float MIN_DIST_FROM_OBSTACLE = 0.5;   //Minimum distance from an object
    Wander();//Stopper();
   void startMoving();
private:
    ros::NodeHandle node;
    ros::Publisher commandPub; // Publisher to the robot~s velocity command topic
    ros::Subscriber laserSub;  // Subscriber to the robot~s laser scan topic
    bool keepMoving;           // Indicates whether the robot should continue moving ,0 or 1
    bool keepMoving0;       //keepMoving the previous state of
bool getRandom;             //When keepMoving it changes from 1 to 0    
//Indicates whether the robot should keep moving, 0 or 1
    void moveForward();
    void turnCorner();//
    void scanCallback(const sensor_msgs::LaserScan::ConstPtr &scan); //Ptr is pointer
};
4.Creating a Wander.cpp 5.Creating a ROS wander_bot Node
#include "Wander.h"
int main(int argc, char **argv)
{
    // Initiate new ROS node named wander_bot
    ros::init(argc, argv, "wander_bot");
    // Create new wander object
    Wander wander;
    // Start the movement
    wander.startMoving();
    return 0;
}
6.Editing the CMakeLists.txt File

After saving the two files in the wander_bot/src folder, the nodes need to be compiled to create the executable. To do this, we have to edit the CMakeLists.txt file, which is not too complicated. We need to add four lines of code to CMakeLists.txt.
Figure 2 shows the additional lines of code to insert (Line 128 - 129)

Figure 2. Changes to the CMakeLists.txt file (Line 128-129)

7.Building C++ Nodes

After saving CMakeLists.txt, we can build the source code. The command to build the nodes is catkin_make. Just switch to the workspace folder and execute the catkin_make command.
To switch to the catkin_ws folder, assume that the workspace is in the home folder.

$ cd ~/catkin_ws

Executing the catkin_make command to build the nodes

$ catkin_make --pkg wander_bot

If everything is correct, you get a message saying that the build was successful (see Figure 3).

Figure 3.Building Successful
So we have successfully built the nodes. Now what? We can execute these nodes, right? That is covered in the next section.

8.Creating Launch Files

    
    
    
    
    

The following is the command to execute this launch file. We can execute it from any terminal path.

$ roslaunch wander_bot wander_bot.launch

After the roslaunch command, use the package name and then the launch file name

Figure 4. Talker and Listener working together

9.Visualising a Computing Graph

The rqt_graph GUI tool visualises the ROS computation graph. Use any of the launch files that we created in the previous section.

$ roslaunch wonder_bot wonder_bot.launch

And in another terminal, run the following.

$ rqt_graph

Figure 5 shows the output of this GUI tool.

Figure 5. ROS Graph
Check the list of ROS topics in the system by using the following command.

$ rostopic list

Figure 6. Rostopic List

效果视频

wander

视频
代码下载链接

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/779026.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号