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

Example to read data published from VSSReplacer. More...

#include <queue>
#include <memory>
#include <iostream>
#include "travesim_adapters/protobuf/replacer_receiver.hpp"
Include dependency graph for replacer_receiver_example.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Example to read data published from VSSReplacer.

Author
Lucas Haug lucas.nosp@m..hau.nosp@m.g@thu.nosp@m.nera.nosp@m.tz.or.nosp@m.g
Lucas Schneider lucas.nosp@m..sch.nosp@m.neide.nosp@m.r@th.nosp@m.unera.nosp@m.tz.o.nosp@m.rg
Date
05/2021

Definition in file replacer_receiver_example.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 24 of file replacer_receiver_example.cpp.

24  {
25  const std::string receiver_address = "127.0.0.1";
26  const short receiver_port = 20011;
27 
28  std::queue<std::shared_ptr<travesim::EntityState>> states_queue;
29 
30  try {
31  travesim::proto::ReplacerReceiver replacer_receiver(receiver_address, receiver_port, true);
32 
33  while (true) {
34  bool received_new_msg = replacer_receiver.receive(&states_queue);
35 
36  if (received_new_msg) {
37  while (!states_queue.empty()) {
38  std::shared_ptr<travesim::RobotState> state = std::dynamic_pointer_cast<travesim::RobotState>(
39  states_queue.front());
40 
41  if (state != nullptr) {
42  std::cout << *state;
43  } else {
44  std::cout << "BALL" << std::endl;
45  std::cout << *states_queue.front();
46  }
47 
48  states_queue.pop();
49 
50  std::cout << std::endl;
51  }
52  }
53  }
54  } catch (std::exception& e) {
55  std::cerr << "Exception: " << e.what() << "\n";
56  }
57 
58  return 0;
59 }
Replacer receiver class with UDP and protobuf.

References travesim::proto::ReplacerReceiver::receive().

Here is the call graph for this function: