TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
ros_side.test.cpp
Go to the documentation of this file.
1 /**
2  * @file converter.test.cpp
3  * @author Felipe Gomes de Melo <felipe.gomes@thunderatz.org>
4  * @brief
5  * @date 04/2021
6  *
7  * @copyright MIT License - Copyright (c) 2021 ThundeRatz
8  *
9  */
10 
11 #include <ros/ros.h>
12 #include <ros/console.h>
13 #include <gtest/gtest.h>
14 #include <gazebo_msgs/ModelState.h>
15 #include <geometry_msgs/Vector3.h>
16 #include <iostream>
17 
21 
22 TEST(vector2d_to_vector3, convert_from_vector2d)
23 {
24  travesim::Vector2D vector2d(2, 4);
25 
26  geometry_msgs::Vector3 vector3 = travesim::converter::Vector2D_to_Vector3(&vector2d);
27 
28  EXPECT_DOUBLE_EQ(vector3.x, 2);
29  EXPECT_DOUBLE_EQ(vector3.y, 4);
30 }
31 
32 TEST(vector2d_to_vector3, convert_from_vector3)
33 {
34  geometry_msgs::Vector3 vector3;
35 
36  vector3.x = 3;
37  vector3.y = -7;
38 
40 
41  EXPECT_DOUBLE_EQ(vector2d.x, 3);
42  EXPECT_DOUBLE_EQ(vector2d.y, -7);
43 }
44 
45 TEST(robot_state_to_model_state, model_name)
46 {
47  travesim::RobotState robot_state;
48 
49  EXPECT_EQ(travesim::converter::RobotState_to_ModelState(&robot_state).model_name, "yellow_team/robot_0");
50 
51  robot_state.id = 2;
52 
53  EXPECT_EQ(travesim::converter::RobotState_to_ModelState(&robot_state).model_name, "yellow_team/robot_2");
54 
55  robot_state.is_yellow = false;
56  robot_state.id = 0;
57 
58  EXPECT_EQ(travesim::converter::RobotState_to_ModelState(&robot_state).model_name,
59  "blue_team/robot_0");
60 
61  robot_state.id = 1;
62 
63  EXPECT_EQ(travesim::converter::RobotState_to_ModelState(&robot_state).model_name,
64  "blue_team/robot_1");
65 }
66 
67 TEST(robot_state_to_model_state, angle_conversion)
68 {
69  travesim::RobotState robot_state;
70  robot_state.angular_position = -M_PI/3;
71 
72  gazebo_msgs::ModelState model_state = travesim::converter::RobotState_to_ModelState(&robot_state);
73 
74  EXPECT_DOUBLE_EQ(travesim::converter::ModelState_to_RobotState(&model_state).angular_position,
75  robot_state.angular_position);
76 }
77 
78 // Run all the tests that were declared with TEST()
79 int main(int argc, char** argv) {
80  testing::InitGoogleTest(&argc, argv);
81 
82  // ros::init(argc, argv, "tester");
83  // ros::NodeHandle nh;
84  return RUN_ALL_TESTS();
85 }
ROS vision receiver class definition.
travesim::Vector2D Vector3_to_Vector2D(geometry_msgs::Vector3 *vector3)
Function to convert geometry_msgs::Vector3 to travesim::Vector2D.
Definition: ros_side.cpp:34
TEST(vector2d_to_vector3, convert_from_vector2d)
Data structure to hold a two dimensional vector.
double x
Public attributes.
Robot state data structure.
Collection of data converters between ROS and local formats.
Data structure to hold the state of a robot in the simulation.
Definition: robot_state.hpp:23
double angular_position
Angular position in radinans.
geometry_msgs::Vector3 Vector2D_to_Vector3(Vector2D *vector2d)
Function to convert travesim::Vector2D to geometry_msgs::Vector3.
Definition: ros_side.cpp:43
travesim::RobotState ModelState_to_RobotState(gazebo_msgs::ModelState *model_state, bool is_yellow=true, int id=0)
Function to convert gazebo_msgs::ModelState to travesim::RobotState.
Definition: ros_side.cpp:78
gazebo_msgs::ModelState RobotState_to_ModelState(RobotState *robot_state, double z=DEFAULT_Z_VALUE_ROBOT)
Function to convert travesim::RobotState to gazebo_msgs::ModelState.
Definition: ros_side.cpp:108
int main(int argc, char **argv)
bool is_yellow
Public attributes.
Definition: robot_state.hpp:64