Research Track 2  1.0
ROS file documentation assignment
Macros | Functions | Variables
rt2_robot_logic.cpp File Reference

Robotics control in a simulated environment. More...

#include <iostream>
#include <string>
#include <chrono>
#include <ctime>
#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
#include "sensor_msgs/LaserScan.h"
#include "actionlib_msgs/GoalID.h"
#include "move_base_msgs/MoveBaseActionGoal.h"
#include "move_base_msgs/MoveBaseActionFeedback.h"
Include dependency graph for rt2_robot_logic.cpp:

Macros

#define DIST   0.35
 Minimum distance from the wall with the driving assistance enabled.
 
#define POS_ERROR   0.5
 Position range error.
 
#define MAX_TIME   120000000
 Maximum time to reach a goal (microseconds)
 

Functions

void drivingAssistance (const sensor_msgs::LaserScan::ConstPtr &msg)
 Checks data from robot's laser scanner and, if the driving assistance is enabled, help the user not to crush the robot against a wall. More...
 
void currentStatus (const move_base_msgs::MoveBaseActionFeedback::ConstPtr &msg)
 Checks if the robot is on the goal position and, when there is a new goal, update the current Goal ID and save it in a global variable. More...
 
void currentGoal (const move_base_msgs::MoveBaseActionGoal::ConstPtr &msg)
 Checks the current goal position and saves its coordinates x and y in two global variables. More...
 
int main (int argc, char **argv)
 Initializes the node and starts the logic of the robot. More...
 

Variables

ros::Publisher pub_canc
 Publishes to /move_base/cancel.
 
ros::Publisher pub_vel
 Publishes to /cmd_vel.
 
float x_goal
 Current goal coordinate x.
 
float y_goal
 Current goal coordinate y.
 
int reached_goal = 0
 Number of reached goals.
 
int non_reached_goal = 0
 Number of not reached goals.
 
std::string id = ""
 Goal ID.
 
std::chrono::high_resolution_clock::time_point t_start
 Starting time goal reaching.
 
std::chrono::high_resolution_clock::time_point t_end
 Ending time goal reaching.
 

Detailed Description

Robotics control in a simulated environment.

Author
Simone Contorno (simon.nosp@m.e.co.nosp@m.ntorn.nosp@m.o@ou.nosp@m.tlook.nosp@m..it)
Version
1.0
Date
2022-03-25

Server parameters:

Parameters
key_flagdefines the type of keyboard input inserted by the user (output).
drive_flagdefines if the manual driving assistance is enabled or not (output).
goal_flagdefines if a goal is set or not (input & output).
print_flagdefines if the warning sentence, about a wall too close to the robot, has been printed or not (input & output).

Publishers to:
/move_base/cancel
/cmd_vel

Subscribers to:
/move_base/feedback
/move_base/goal
/scan

Description:
This node simulates the 'logic' of the robot.
Managing publishers, subscribers and server parameters it is able to avoid the crashing of the robot against a wall, if asked by the user, and register how many targets it reached and how many not.
A target is considered 'not reached' when the robot does not reach it within 2 minutes, then the goal is cancelled.

Function Documentation

◆ currentGoal()

void currentGoal ( const move_base_msgs::MoveBaseActionGoal::ConstPtr &  msg)

Checks the current goal position and saves its coordinates x and y in two global variables.

Parameters
msgdefines the goal position values.

◆ currentStatus()

void currentStatus ( const move_base_msgs::MoveBaseActionFeedback::ConstPtr &  msg)

Checks if the robot is on the goal position and, when there is a new goal, update the current Goal ID and save it in a global variable.

Parameters
msgdefines the robot position values.

◆ drivingAssistance()

void drivingAssistance ( const sensor_msgs::LaserScan::ConstPtr &  msg)

Checks data from robot's laser scanner and, if the driving assistance is enabled, help the user not to crush the robot against a wall.

Parameters
msgdefines the laser scanner values.

◆ main()

int main ( int  argc,
char **  argv 
)

Initializes the node and starts the logic of the robot.

Parameters
argc
argv
Returns
int

Subscriber on /move_base/feedback

Subscriber on /move_base/goal

Subscriber on /scan