13 #include <ros/console.h> 21 #define BUFFER_SIZE 1024U 30 bool force_specific_source) {
32 std::unique_ptr<udp::UnicastReceiver>(
new udp::UnicastReceiver(receiver_address, receiver_port));
43 }
catch (std::exception& e) {
44 ROS_ERROR_STREAM(
"Replacer receiver: " << e.what());
50 fira_message::sim_to_ref::Packet packet_data;
53 if (packet_data.has_replace()) {
54 for (
const auto& robot_replacement : packet_data.replace().robots()) {
56 p_replament_queue->push(std::make_shared<RobotState>(robot_state));
59 if (packet_data.replace().has_ball()) {
60 const fira_message::sim_to_ref::BallReplacement ball = packet_data.replace().ball();
62 p_replament_queue->push(std::make_shared<EntityState>(ball_state));
73 this->
unicast_receiver->set_receiver_endpoint(receiver_address, receiver_port);
83 }
catch (std::exception& e) {
84 ROS_ERROR_STREAM(
"Replacer receiver: " << e.what());
89 const fira_message::sim_to_ref::BallReplacement* p_ball_pb_msg) {
92 ball_state.
position.
x = p_ball_pb_msg->x();
93 ball_state.
position.
y = p_ball_pb_msg->y();
94 ball_state.
velocity.
x = p_ball_pb_msg->vx();
95 ball_state.
velocity.
y = p_ball_pb_msg->vy();
101 const fira_message::sim_to_ref::RobotReplacement* p_robot_pb_msg) {
104 robot_state.
is_yellow = p_robot_pb_msg->yellowteam();
105 robot_state.
id = p_robot_pb_msg->position().robot_id();
107 robot_state.
position.
x = p_robot_pb_msg->position().x();
108 robot_state.
position.
y = p_robot_pb_msg->position().y();
111 robot_state.
velocity.
x = p_robot_pb_msg->position().vx();
112 robot_state.
velocity.
y = p_robot_pb_msg->position().vy();
double angular_velocity
Angular velocity in rad/s.
Vector2D velocity
Velocity in m/s.
double x
Public attributes.
EntityState ball_rplcmt_pb_to_entity_state(const fira_message::sim_to_ref::BallReplacement *p_ball_pb_msg)
Convert a BallReplacement protobuf message to a EntityState.
Data structure to hold the state of a robot in the simulation.
double angular_position
Angular position in radinans.
Receiver class using UDP in unicast mode.
Replacer receiver with UDP and protobuf.
Vector2D position
Position in meters.
ReplacerReceiver(const std::string receiver_address, const short receiver_port, bool force_specific_source=false)
Construct a new ReplacerReceiver object.
void force_specific_source(bool force_specific_source)
Set wheter to enable any source or source specific multicast. True for specific source,...
bool is_yellow
Public attributes.
bool receive(std::queue< std::shared_ptr< EntityState >> *p_replament_queue)
Receive the replacement commands.
Data structure to hold the state of a entity in the simulation.
void reset(void)
Reset the receiver.
RobotState robot_rplcmt_pb_to_robot_state(const fira_message::sim_to_ref::RobotReplacement *p_robot_pb_msg)
Convert a RobotReplacement protobuf message to a RobotState.
std::unique_ptr< udp::UnicastReceiver > unicast_receiver
void set_receiver_endpoint(const std::string receiver_address, const short receiver_port)
Set the receiver endpoint.