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

Replacer adapter execution file. More...

#include <queue>
#include <memory>
#include <ros/ros.h>
#include <ros/console.h>
#include <gazebo_msgs/ModelStates.h>
#include "travesim_adapters/ros/replacer_sender.hpp"
#include "travesim_adapters/protobuf/replacer_receiver.hpp"
#include "travesim_adapters/data/converter/ros_side.hpp"
#include "travesim_adapters/configurers/replacer_configurer.hpp"
Include dependency graph for replacer_adapter.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Replacer adapter execution file.

Author
Felipe Gomes de Melo felip.nosp@m.e.go.nosp@m.mes@t.nosp@m.hund.nosp@m.eratz.nosp@m..org
Lucas Haug lucas.nosp@m..hau.nosp@m.g@thu.nosp@m.nder.nosp@m.atz.o.nosp@m.rg
Date
06/2021

Definition in file replacer_adapter.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file replacer_adapter.cpp.

27  {
28  ros::init(argc, argv, "replacer_adapter");
29  ros::NodeHandle nh;
30 
31  // Get config
32  travesim::ReplacerConfigurer replacer_configurer;
33 
34  int32_t receiver_port = replacer_configurer.get_port();
35  std::string receiver_address = replacer_configurer.get_address();
36 
37  bool specific_source = replacer_configurer.get_specific_source();
38 
39  // Initialize sender, receivers and commands
40  travesim::ros_side::ReplacerSender replacer_sender;
41  travesim::proto::ReplacerReceiver replacer_receiver(receiver_address, receiver_port, specific_source);
42 
43  // Define data structures
44  travesim::ros_side::state_vector_t model_state_vector;
45  std::queue<std::shared_ptr<travesim::EntityState>> states_queue;
46 
47  // Start
48  ROS_INFO_STREAM("Replacer adapter config:" << std::endl << replacer_configurer);
49 
50  while (ros::ok()) {
51  bool received_new_msg = replacer_receiver.receive(&states_queue);
52 
53  if (received_new_msg) {
54  replacer_sender.send_command(travesim::ros_side::PAUSE);
55 
56  while (!states_queue.empty()) {
57  std::shared_ptr<travesim::RobotState> state = std::dynamic_pointer_cast<travesim::RobotState>(
58  states_queue.front());
59 
60  gazebo_msgs::ModelState gazebo_state_msg;
61 
62  if (state != nullptr) {
63  gazebo_state_msg = travesim::converter::RobotState_to_ModelState(state.get());
64  } else {
65  gazebo_state_msg = travesim::converter::EntityState_to_ModelState(states_queue.front().get());
66  }
67 
68  model_state_vector.push_back(gazebo_state_msg);
69 
70  states_queue.pop();
71  }
72 
73  replacer_sender.set_models_state(&model_state_vector);
74 
76 
77  model_state_vector.clear();
78  }
79 
80  if (replacer_configurer.get_reset()) {
81  // Get config
82  receiver_port = replacer_configurer.get_port();
83  receiver_address = replacer_configurer.get_address();
84 
85  specific_source = replacer_configurer.get_specific_source();
86 
87  // Reconfigure receiver
88  replacer_receiver.set_receiver_endpoint(receiver_address, receiver_port);
89  replacer_receiver.force_specific_source(specific_source);
90  replacer_receiver.reset();
91 
92  // Show config
93  ROS_INFO_STREAM("Replacer adapter config:" << std::endl << replacer_configurer);
94  }
95 
96  ros::spinOnce();
97  }
98 }
std::string get_address(void)
Get the replacer configured address.
bool send_command(simulation_command_t command)
Send command to gazebo.
bool get_specific_source(void)
Get the specific_source config.
bool set_models_state(state_vector_t *model_states)
Set state of multiple entities.
bool get_reset(void)
Get the reset config.
std::vector< gazebo_msgs::ModelState > state_vector_t
Helper type to set the states of multiple entites at once.
uint16_t get_port(void)
Get the replacer configured port.
Replacer receiver class with UDP and protobuf.
ReplacerConfigurer class definition.
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
gazebo_msgs::ModelState EntityState_to_ModelState(EntityState *entity_state, double z=DEFAULT_Z_VALUE_BALL)
Function to convert travesim::EntityState to gazebo_msgs::ModelState.
Definition: ros_side.cpp:86

References travesim::converter::EntityState_to_ModelState(), travesim::proto::ReplacerReceiver::force_specific_source(), travesim::ReplacerConfigurer::get_address(), travesim::ReplacerConfigurer::get_port(), travesim::AdapterConfigurer< AdapterConfigType >::get_reset(), travesim::ReplacerConfigurer::get_specific_source(), travesim::ros_side::PAUSE, travesim::proto::ReplacerReceiver::receive(), travesim::proto::ReplacerReceiver::reset(), travesim::ros_side::RESUME, travesim::converter::RobotState_to_ModelState(), travesim::ros_side::ReplacerSender::send_command(), travesim::ros_side::ReplacerSender::set_models_state(), and travesim::proto::ReplacerReceiver::set_receiver_endpoint().

Here is the call graph for this function: