TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
entity_state.cpp
Go to the documentation of this file.
1 /**
2  * @file entity_state.cpp
3  *
4  * @brief Entity state data structure
5  *
6  * @author Lucas Haug <lucas.haug@thunderatz.org>
7  *
8  * @date 04/2021
9  */
10 
11 #include <cmath>
12 #include <iomanip>
15 
16 namespace travesim {
17 /*****************************************
18  * Vector2D Related
19  *****************************************/
20 
21 Vector2D::Vector2D(double x, double y) {
22  this->x = x;
23  this->y = y;
24 }
25 
26 void Vector2D::rotate(double theta) {
27  double old_x = this->x, old_y = this->y;
28 
29  this->x = cos(theta)*old_x + sin(theta)*old_y;
30  this->y = -sin(theta)*old_x + cos(theta)*old_y;
31 }
32 
33 std::ostream& operator <<(std::ostream& output, const Vector2D& vector_2d) {
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 }
41 
42 /*****************************************
43  * EntityState Related
44  *****************************************/
45 
47 }
48 
49 EntityState::EntityState(Vector2D position, double angular_position, Vector2D velocity, double angular_velocity) {
50  this->position = position;
51  this->angular_position = angular_position;
52  this->velocity = velocity;
53  this->angular_velocity = angular_velocity;
54 }
55 
56 std::ostream& operator <<(std::ostream& output, const EntityState& entity_state) {
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 }
69 }
Entity state data structure.
double angular_velocity
Angular velocity in rad/s.
EntityState()
Construct a new Entity State object.
Vector2D velocity
Velocity in m/s.
Common constants and types for the data structures.
Data structure to hold a two dimensional vector.
double x
Public attributes.
double angular_position
Angular position in radinans.
Vector2D position
Position in meters.
#define PRINTING_DECIMAL_PRECISION
Definition: data_common.hpp:22
void rotate(double theta)
Perform a counter-clockwise rotation of the vector.
Vector2D(double x=0, double y=0)
Construct a new Vector2D object.
std::ostream & operator<<(std::ostream &output, const ReplacerConfigurer &repl_conf)
Data structure to hold the state of a entity in the simulation.
#define PRINTING_MIN_WIDTH
Printing output configuration constants.
Definition: data_common.hpp:21