TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
travesim Namespace Reference

Namespaces

 converter
 
 proto
 
 ros_side
 
 udp
 

Classes

class  AdapterConfigurer
 
class  EntityState
 Data structure to hold the state of a entity in the simulation. More...
 
class  FieldState
 Data structure to hold the field state. More...
 
class  ReplacerConfigurer
 ReplacerConfigurer class definition. More...
 
class  RobotCommand
 Data structure to hold the command for a robot. More...
 
class  RobotState
 Data structure to hold the state of a robot in the simulation. More...
 
class  TeamCommand
 Data structure to hold the command for a team. More...
 
class  TeamsConfigurer
 TeamsConfigurer class definition. More...
 
class  Vector2D
 Data structure to hold a two dimensional vector. More...
 
class  VisionConfigurer
 VisionConfigurer class definition. More...
 

Enumerations

enum  IPValidation { VALID, INVALID_FORMAT, INVALID_NUMBERS, OUT_OF_RANGE }
 Type used to validate a IP string. More...
 
enum  TeamsFormation { THREE_ROBOTS_PER_TEAM = 3, FIVE_ROBOTS_PER_TEAM = 5 }
 Formation of the teams. More...
 

Functions

bool ipv4_string_to_uint (std::string ip_string, uint *ip_uint)
 Converts a IPv4 in a string to a array of unsigned integers, where the most significant byte of the IP address is in the position 0 and the last significant in the position 3. More...
 
IPValidation check_valid_ip (std::string ip, std::string min_ip, std::string max_ip)
 Checks if a IP is valid and is in the specified range. More...
 
std::string get_error_msg (IPValidation error)
 Get the error msg based on the validation type. More...
 
std::ostream & operator<< (std::ostream &output, const ReplacerConfigurer &repl_conf)
 
std::ostream & operator<< (std::ostream &output, const TeamsConfigurer &teams_conf)
 
std::ostream & operator<< (std::ostream &output, const VisionConfigurer &vision_conf)
 
std::ostream & operator<< (std::ostream &output, const Vector2D &vector_2d)
 
std::ostream & operator<< (std::ostream &output, const EntityState &entity_state)
 
std::ostream & operator<< (std::ostream &output, const FieldState &field_state)
 
std::ostream & operator<< (std::ostream &output, const RobotState &robot_state)
 
std::ostream & operator<< (std::ostream &output, const RobotCommand &command)
 
std::ostream & operator<< (std::ostream &output, const TeamCommand &command)
 

Enumeration Type Documentation

◆ IPValidation

Type used to validate a IP string.

Enumerator
VALID 

Valid IP address

INVALID_FORMAT 

Wrong formatted IP string

INVALID_NUMBERS 

The numbers on the ip are not representable by 8 bits

OUT_OF_RANGE 

The IP is not in the specified range

Definition at line 37 of file configurers_utils.hpp.

37  {
38  VALID, /**< Valid IP address */
39  INVALID_FORMAT, /**< Wrong formatted IP string */
40  INVALID_NUMBERS, /**< The numbers on the ip are not representable by 8 bits */
41  OUT_OF_RANGE /**< The IP is not in the specified range */
42 };

◆ TeamsFormation

Formation of the teams.

Enumerator
THREE_ROBOTS_PER_TEAM 
FIVE_ROBOTS_PER_TEAM 

Definition at line 40 of file data_common.hpp.

Function Documentation

◆ check_valid_ip()

IPValidation travesim::check_valid_ip ( std::string  ip,
std::string  min_ip,
std::string  max_ip 
)

Checks if a IP is valid and is in the specified range.

Note
Expects IPv4 in the quad-dotted notation.
Parameters
ipIP string to be converted
min_ipMinimum IP interval value
max_ipMaximum IP interval value
Returns
IPValidation

Definition at line 75 of file configurers_utils.cpp.

75  {
76  uint ip_uint[IPV4_NUM_OF_BYTES] = {0};
77  uint min_ip_uint[IPV4_NUM_OF_BYTES] = {0};
78  uint max_ip_uint[IPV4_NUM_OF_BYTES] = {0};
79 
80  // Check formats
81  if (!ipv4_string_to_uint(ip, ip_uint)) {
83  }
84 
85  if (!ipv4_string_to_uint(min_ip, min_ip_uint)) {
87  }
88 
89  if (!ipv4_string_to_uint(max_ip, max_ip_uint)) {
91  }
92 
93  // Check numbers
94  for (uint i = 0; i < IPV4_NUM_OF_BYTES; i++) {
95  if (ip_uint[i] > 0xFF) {
97  }
98 
99  if (min_ip_uint[i] > 0xFF) {
101  }
102 
103  if (max_ip_uint[i] > 0xFF) {
105  }
106  }
107 
108  // Check range
109  uint32_t ip_num = 0;
110  uint32_t max_num = 0;
111  uint32_t min_num = 0;
112 
113  for (uint8_t i = 0; i < IPV4_NUM_OF_BYTES; i++) {
114  ip_num = ip_num << 8;
115  ip_num += ip_uint[i];
116  min_num = min_num << 8;
117  min_num += min_ip_uint[i];
118  max_num = max_num << 8;
119  max_num += max_ip_uint[i];
120  }
121 
122  if ((ip_num < min_num) || (ip_num > max_num)) {
124  }
125 
126  return IPValidation::VALID;
127 }
bool ipv4_string_to_uint(std::string ip_string, uint *ip_uint)
Converts a IPv4 in a string to a array of unsigned integers, where the most significant byte of the I...
#define IPV4_NUM_OF_BYTES

References INVALID_FORMAT, INVALID_NUMBERS, IPV4_NUM_OF_BYTES, ipv4_string_to_uint(), OUT_OF_RANGE, and VALID.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_error_msg()

std::string travesim::get_error_msg ( IPValidation  error)

Get the error msg based on the validation type.

Parameters
errorWhich error to get the message
Returns
std::string representing the error

Definition at line 129 of file configurers_utils.cpp.

129  {
130  switch (error) {
132  return "The IP string is wrong formatted.";
133  }
134 
136  return "The numbers on the ip are not representable by 8 bits.";
137  }
138 
140  return "The IP is not in the specified range. Hover over the parameterto see the range.";
141  }
142 
143  default: {
144  return "No error.";
145  }
146  }
147 }

References INVALID_FORMAT, INVALID_NUMBERS, and OUT_OF_RANGE.

Here is the caller graph for this function:

◆ ipv4_string_to_uint()

bool travesim::ipv4_string_to_uint ( std::string  ip_string,
uint *  ip_uint 
)

Converts a IPv4 in a string to a array of unsigned integers, where the most significant byte of the IP address is in the position 0 and the last significant in the position 3.

Note
Expects IPv4 in the quad-dotted notation.
Parameters
ip_stringIPv4 string to be converted
ip_uintPointer where to store the converted IPv4
Returns
true if the conversion was successful, false otherwise

Definition at line 27 of file configurers_utils.cpp.

27  {
28  std::stringstream ip_stream(ip_string);
29 
30  char dot;
31 
32  if (ip_stream.rdbuf()->in_avail() == 0) {
33  return false;
34  } else {
35  ip_stream >> ip_uint[0];
36 
37  if (ip_stream.fail()) {
38  return false;
39  }
40  }
41 
42  for (uint i = 1; i < IPV4_NUM_OF_BYTES; i++) {
43  if (ip_stream.rdbuf()->in_avail() == 0) {
44  return false;
45  } else {
46  ip_stream >> dot;
47 
48  if (ip_stream.fail()) {
49  return false;
50  }
51 
52  if (dot != '.') {
53  return false;
54  }
55  }
56 
57  if (ip_stream.rdbuf()->in_avail() == 0) {
58  return false;
59  } else {
60  ip_stream >> ip_uint[i];
61 
62  if (ip_stream.fail()) {
63  return false;
64  }
65  }
66  }
67 
68  if (ip_stream.rdbuf()->in_avail() != 0) {
69  return false;
70  }
71 
72  return true;
73 }
#define IPV4_NUM_OF_BYTES

References IPV4_NUM_OF_BYTES.

Here is the caller graph for this function:

◆ operator<<() [1/9]

std::ostream& travesim::operator<< ( std::ostream &  output,
const FieldState field_state 
)

Definition at line 24 of file field_state.cpp.

24  {
25  output << "TIME STEP: " << std::endl;
26  output << field_state.time_step << std::endl;
27 
28  output << "BALL STATE: " << std::endl;
29  output << field_state.ball << std::endl;
30 
31  output << "TEAM YELLOW STATE: " << std::endl;
32 
33  for (int i = 0; i < field_state.robots_per_team; i++) {
34  output << "ROBOT " << i << ":" << std::endl;
35  output << field_state.yellow_team[i] << std::endl;
36  }
37 
38  output << std::endl;
39 
40  output << "TEAM BLUE STATE: " << std::endl;
41 
42  for (int i = 0; i < field_state.robots_per_team; i++) {
43  output << "ROBOT " << i << ":" << std::endl;
44  output << field_state.blue_team[i] << std::endl;
45  }
46 
47  output << std::endl;
48 
49  return output;
50 }

References travesim::FieldState::ball, travesim::FieldState::blue_team, travesim::FieldState::robots_per_team, travesim::FieldState::time_step, and travesim::FieldState::yellow_team.

◆ operator<<() [2/9]

std::ostream& travesim::operator<< ( std::ostream &  output,
const RobotCommand command 
)

Definition at line 24 of file team_command.cpp.

24  {
25  output << std::fixed << std::setprecision(PRINTING_DECIMAL_PRECISION);
26 
27  output << "LEFT SPEED: " << std::setw(PRINTING_MIN_WIDTH) << command.left_speed << std::endl;
28  output << "RIGHT SPEED: " << std::setw(PRINTING_MIN_WIDTH) << command.right_speed;
29 
30  return output;
31 }
#define PRINTING_DECIMAL_PRECISION
Definition: data_common.hpp:22
#define PRINTING_MIN_WIDTH
Printing output configuration constants.
Definition: data_common.hpp:21

References travesim::RobotCommand::left_speed, PRINTING_DECIMAL_PRECISION, PRINTING_MIN_WIDTH, and travesim::RobotCommand::right_speed.

◆ operator<<() [3/9]

std::ostream& travesim::operator<< ( std::ostream &  output,
const Vector2D vector_2d 
)

Definition at line 33 of file entity_state.cpp.

33  {
34  output << std::fixed << std::setprecision(PRINTING_DECIMAL_PRECISION);
35 
36  output << "X: " << std::setw(PRINTING_MIN_WIDTH) << vector_2d.x << " | ";
37  output << "Y: " << std::setw(PRINTING_MIN_WIDTH) << vector_2d.y;
38 
39  return output;
40 }
#define PRINTING_DECIMAL_PRECISION
Definition: data_common.hpp:22
#define PRINTING_MIN_WIDTH
Printing output configuration constants.
Definition: data_common.hpp:21

References PRINTING_DECIMAL_PRECISION, PRINTING_MIN_WIDTH, travesim::Vector2D::x, and travesim::Vector2D::y.

◆ operator<<() [4/9]

std::ostream& travesim::operator<< ( std::ostream &  output,
const RobotState robot_state 
)

Definition at line 39 of file robot_state.cpp.

39  {
40  output << std::fixed << std::setprecision(PRINTING_DECIMAL_PRECISION);
41 
42  output << "TEAM YELLOW: " << robot_state.is_yellow << std::endl;
43  output << "ROBOT ID: " << robot_state.id << std::endl;
44 
45  output << "POSITION: ";
46  output << robot_state.position << " | ";
47  output << "THETA: "<< std::setw(PRINTING_MIN_WIDTH) << robot_state.angular_position << std::endl;
48 
49  output << "VELOCITY: ";
50  output << robot_state.velocity << " | ";
51  output << "THETA: "<< std::setw(PRINTING_MIN_WIDTH) << robot_state.angular_velocity << std::endl;
52 
53  return output;
54 }
#define PRINTING_DECIMAL_PRECISION
Definition: data_common.hpp:22
#define PRINTING_MIN_WIDTH
Printing output configuration constants.
Definition: data_common.hpp:21

References travesim::EntityState::angular_position, travesim::EntityState::angular_velocity, travesim::RobotState::id, travesim::RobotState::is_yellow, travesim::EntityState::position, PRINTING_DECIMAL_PRECISION, PRINTING_MIN_WIDTH, and travesim::EntityState::velocity.

◆ operator<<() [5/9]

std::ostream& travesim::operator<< ( std::ostream &  output,
const TeamCommand command 
)

Definition at line 41 of file team_command.cpp.

41  {
42  output << std::fixed << std::setprecision(PRINTING_DECIMAL_PRECISION);
43 
44  for (int i = 0; i < command.robots_per_team; i++) {
45  output << "ROBOT " << i << ":" << std::endl;
46  output << command.robot_command[i] << std::endl;
47  output << std::endl;
48  }
49 
50  return output;
51 }
#define PRINTING_DECIMAL_PRECISION
Definition: data_common.hpp:22

References PRINTING_DECIMAL_PRECISION, travesim::TeamCommand::robot_command, and travesim::TeamCommand::robots_per_team.

◆ operator<<() [6/9]

std::ostream& travesim::operator<< ( std::ostream &  output,
const VisionConfigurer vision_conf 
)

Definition at line 53 of file vision_configurer.cpp.

53  {
54  output << "Vision Endpoint: " << vision_conf.config.multicast_address;
55  output << ":" << vision_conf.config.multicast_port << std::endl;
56  output << "Reset: " << ((vision_conf.config.reset || vision_conf.reconfigured) ? "True" : "False") << std::endl;
57 
58  return output;
59 }

References travesim::AdapterConfigurer< AdapterConfigType >::config, and travesim::AdapterConfigurer< AdapterConfigType >::reconfigured.

◆ operator<<() [7/9]

std::ostream& travesim::operator<< ( std::ostream &  output,
const EntityState entity_state 
)

Definition at line 56 of file entity_state.cpp.

56  {
57  output << std::fixed << std::setprecision(PRINTING_DECIMAL_PRECISION);
58 
59  output << "POSITION: ";
60  output << entity_state.position << " | ";
61  output << "THETA: "<< std::setw(PRINTING_MIN_WIDTH) << entity_state.angular_position << std::endl;
62 
63  output << "VELOCITY: ";
64  output << entity_state.velocity << " | ";
65  output << "THETA: "<< std::setw(PRINTING_MIN_WIDTH) << entity_state.angular_velocity << std::endl;
66 
67  return output;
68 }
#define PRINTING_DECIMAL_PRECISION
Definition: data_common.hpp:22
#define PRINTING_MIN_WIDTH
Printing output configuration constants.
Definition: data_common.hpp:21

References travesim::EntityState::angular_position, travesim::EntityState::angular_velocity, travesim::EntityState::position, PRINTING_DECIMAL_PRECISION, PRINTING_MIN_WIDTH, and travesim::EntityState::velocity.

◆ operator<<() [8/9]

std::ostream& travesim::operator<< ( std::ostream &  output,
const ReplacerConfigurer repl_conf 
)

Definition at line 58 of file replacer_configurer.cpp.

58  {
59  output << "Replacer Endpoint: " << repl_conf.config.replacer_address;
60  output << ":" << repl_conf.config.replacer_port << std::endl;
61  output << "Specific Source: " << (repl_conf.config.specific_source ? "True" : "False") << std::endl;
62  output << "Reset: " << ((repl_conf.config.reset || repl_conf.reconfigured) ? "True" : "False") << std::endl;
63 
64  return output;
65 }

References travesim::AdapterConfigurer< AdapterConfigType >::config, and travesim::AdapterConfigurer< AdapterConfigType >::reconfigured.

◆ operator<<() [9/9]

std::ostream& travesim::operator<< ( std::ostream &  output,
const TeamsConfigurer teams_conf 
)

Definition at line 69 of file teams_configurer.cpp.

69  {
70  output << "Yellow Team Endpoint: " << teams_conf.config.yellow_team_address;
71  output << ":" << teams_conf.config.yellow_team_port << std::endl;
72  output << "Blue Team Endpoint: " << teams_conf.config.blue_team_address;
73  output << ":" << teams_conf.config.blue_team_port << std::endl;
74  output << "Specific Source: " << (teams_conf.config.specific_source ? "True" : "False") << std::endl;
75  output << "Reset: " << ((teams_conf.config.reset || teams_conf.reconfigured) ? "True" : "False") << std::endl;
76 
77  return output;
78 }

References travesim::AdapterConfigurer< AdapterConfigType >::config, and travesim::AdapterConfigurer< AdapterConfigType >::reconfigured.