TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
vision_sender_example.cpp
Go to the documentation of this file.
1 /**
2  * @file vision_sender_example.cpp
3  *
4  * @author Lucas Haug <lucas.haug@thuneratz.org>
5  *
6  * @brief Example on how to use the VisionSender with protobuf
7  *
8  * @date 04/2021
9  *
10  * @copyright MIT License - Copyright (c) 2021 ThundeRatz
11  */
12 
13 #include <iostream>
14 #include <string>
15 #include <google/protobuf/util/json_util.h>
16 #include <google/protobuf/text_format.h>
17 
19 
20 /*****************************************
21  * Main Function
22  *****************************************/
23 
24 int main() {
25  const short multicast_port = 30001;
26  const std::string multicast_address_str = "239.255.0.1";
27 
28  travesim::proto::VisionSender my_sender(multicast_address_str, multicast_port);
29 
30  travesim::FieldState field_state;
31 
32  field_state.ball.position.x = 2.4;
33  field_state.ball.velocity.y = 0.7;
34  field_state.yellow_team[0].angular_velocity = 1.54;
35  field_state.blue_team[2].angular_position = 3.14;
36 
37  fira_message::sim_to_ref::Environment env_data = my_sender.field_state_to_env_pb_msg(&field_state);
38 
39  std::string buffer;
40 
41  google::protobuf::util::JsonPrintOptions options;
42  options.add_whitespace = true;
43  options.always_print_primitive_fields = true;
44 
45  google::protobuf::util::MessageToJsonString(env_data, &buffer, options);
46 
47  std::cout << buffer;
48 
49  return 0;
50 }
EntityState ball
Field entities.
Definition: field_state.hpp:48
Data structure to hold the field state.
Definition: field_state.hpp:25
std::vector< EntityState > yellow_team
Definition: field_state.hpp:50
Vector2D velocity
Velocity in m/s.
double x
Public attributes.
Vision data sender with UDP and protobuf.
Vector2D position
Position in meters.
Vision sender class with UDP and protobuf.
static fira_message::sim_to_ref::Environment field_state_to_env_pb_msg(FieldState *p_field_state)
Convert a FieldState object to a Environment protobuf message object.
std::vector< EntityState > blue_team
Definition: field_state.hpp:51
int main()