Robot Game  v1.0
Research Track part 1 - Assignment
rg_services.cpp File Reference

A collection of services for the controller. More...

#include "ros/ros.h"
#include "ros/console.h"
#include "geometry_msgs/Point.h"
#include "geometry_msgs/Vector3.h"
#include "geometry_msgs/Twist.h"
#include "robot_game/rg_check_srv.h"
#include "robot_game/rg_get_target_srv.h"
#include "robot_game/rg_get_vel_srv.h"
#include <cmath>
#include <cstdlib>
#include <ctime>

Go to the source code of this file.

Macros

#define TOLERANCE   0.1f
 
#define K   (1.f)
 

Functions

double compute_eucledian_distance (geometry_msgs::Point P1, geometry_msgs::Point P2)
 Eucledian distance between two points. More...
 
double rand_range (double min, double max)
 Generate a random value within a given range. More...
 
bool rg_check_target_callback (robot_game::rg_check_srv::Request &initpos, robot_game::rg_check_srv::Response &r)
 Service - check target. More...
 
bool rg_get_target_callback (robot_game::rg_get_target_srv::Request &limits, robot_game::rg_get_target_srv::Response &target)
 Service - get a new random target. More...
 
bool rg_get_velocity_callback (robot_game::rg_get_vel_srv::Request &initpos, robot_game::rg_get_vel_srv::Response &vel)
 Service - generate a twist command. More...
 
int main (int argc, char **argv)
 Ask for services, topics, and initialise the node. More...
 

Detailed Description

A collection of services for the controller.

Author
Francesco Ganci (S4143910)
Version
1.0
Date
2021-06-25

This file contains the three services the controller needs in order to work:

  • get target randomly generate a new target
  • check target check if the target is reached or not
  • get velocity generate the gelocity for approaching the goal

Definition in file rg_services.cpp.

Macro Definition Documentation

◆ K

#define K   (1.f)

the speed at which the robot reaches its position.

Definition at line 38 of file rg_services.cpp.

◆ TOLERANCE

#define TOLERANCE   0.1f

minimum distance from the target for considering it reached

Definition at line 35 of file rg_services.cpp.

Function Documentation

◆ compute_eucledian_distance()

double compute_eucledian_distance ( geometry_msgs::Point  P1,
geometry_msgs::Point  P2 
)

Eucledian distance between two points.

Parameters
P1the start point of the vector
P2the final point of the vector
Returns
double the eucledian distance of (P2-P1)

Definition at line 51 of file rg_services.cpp.

◆ main()

int main ( int  argc,
char **  argv 
)

Ask for services, topics, and initialise the node.

Definition at line 159 of file rg_services.cpp.

◆ rand_range()

double rand_range ( double  min,
double  max 
)

Generate a random value within a given range.

Parameters
minthe minimum number (included)
maxthe maximum number (include)
Returns
a random number in [min, max]

Definition at line 64 of file rg_services.cpp.

◆ rg_check_target_callback()

bool rg_check_target_callback ( robot_game::rg_check_srv::Request &  initpos,
robot_game::rg_check_srv::Response &  r 
)

Service - check target.

Parameters
initposX and Xt
ris the target reached?
Returns
true if the lenght of (X - Xt) is less than the TOLERANCE
false if the distance is greater than the TOLERANCE

The function simply takes the distance between actual position and target, and compares this with the TOLERACE. If the distance is less than the TOLERANCE, the target is considered to be reached.

Definition at line 88 of file rg_services.cpp.

◆ rg_get_target_callback()

bool rg_get_target_callback ( robot_game::rg_get_target_srv::Request &  limits,
robot_game::rg_get_target_srv::Response &  target 
)

Service - get a new random target.

Parameters
limitsbounds within to take the target
targetthe respose of the server, the target

Definition at line 104 of file rg_services.cpp.

◆ rg_get_velocity_callback()

bool rg_get_velocity_callback ( robot_game::rg_get_vel_srv::Request &  initpos,
robot_game::rg_get_vel_srv::Response &  vel 
)

Service - generate a twist command.

Parameters
initposX and Xt
velthe return of the server, the Twist

Definition at line 131 of file rg_services.cpp.