TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
vision_sender_example.cpp File Reference

Example on how to use the VisionSender with protobuf. More...

#include <iostream>
#include <string>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/text_format.h>
#include "travesim_adapters/protobuf/vision_sender.hpp"
Include dependency graph for vision_sender_example.cpp:

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

Example on how to use the VisionSender with protobuf.

Author
Lucas Haug lucas.nosp@m..hau.nosp@m.g@thu.nosp@m.nera.nosp@m.tz.or.nosp@m.g
Date
04/2021

Definition in file vision_sender_example.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 24 of file vision_sender_example.cpp.

24  {
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.
Vector2D position
Position in meters.
Vision sender class with UDP and protobuf.
std::vector< EntityState > blue_team
Definition: field_state.hpp:51

References travesim::FieldState::ball, travesim::FieldState::blue_team, travesim::proto::VisionSender::field_state_to_env_pb_msg(), travesim::EntityState::position, travesim::EntityState::velocity, travesim::Vector2D::x, travesim::Vector2D::y, and travesim::FieldState::yellow_team.

Here is the call graph for this function: