ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
trafficparticipantconverter.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Daniel Heß - initial API and implementation
13  ********************************************************************************/
14 
15 #pragma once
16 #include "quaternion.h"
17 #include <adore_if_ros_msg/TrafficParticipantSet.h>
18 #include <adore_if_ros_msg/TrafficParticipantSimulation.h>
21 
22 namespace adore
23 {
24  namespace if_ROS
25  {
30  {
31  public:
35  void decodeTrafficParticipantDetection(const adore_if_ros_msg::TrafficParticipantDetection* msg,adore::env::traffic::Participant* object)
36  {
37  decodeTrafficParticipant(msg->data,object);
38  object->detection_by_sensor_ = msg->detection_by_sensor;
39  object->trackingID_ = msg->trackingID;
40  }
44  void encodeTrafficParticipantDetection(const adore::env::traffic::Participant& object,adore_if_ros_msg::TrafficParticipantDetection* msg)
45  {
46  encodeTrafficParticipant(object,&msg->data);
47  msg->detection_by_sensor = object.getDetectionBySensor();
48  msg->trackingID = object.getTrackingID();
49  }
53  void decodeTrafficParticipant(const adore_if_ros_msg::TrafficParticipant& data,adore::env::traffic::Participant* object)
54  {
55  object->acceleration_x_ = 0.0;
56  object->brakeLight_certainty_ = data.brakeLight_certainty;
57  object->brakeLightsOn_ = data.brakeLightOn;
58  object->center_(0) = data.motion_state.pose.pose.position.x;
59  object->center_(1) = data.motion_state.pose.pose.position.y;
60  object->center_(2) = data.motion_state.pose.pose.position.z;
61  object->classification_ = static_cast<adore::env::traffic::Participant::EClassification>(data.classification.type_id);
62  object->classification_certainty_ = data.classification_certainty;
63  object->existance_certainty_ = data.existance_certainty;
64  object->height_ = data.shape.dimensions[data.shape.BOX_Z];
65  object->highBeamCertainty_ = data.highBeam_certainty;
66  object->highBeamOn_ = data.highBeamOn;
67  object->leftIndicator_certainty_ = data.leftIndicator_certainty;
68  object->leftIndicatorOn_ = data.leftIndicatorOn;
69  object->length_ = data.shape.dimensions[data.shape.BOX_X];
70  object->lowBeamCertainty_ = data.lowBeam_certainty;
71  object->lowBeamOn_ = data.lowBeamOn;
72  object->observation_time_ = data.time;
73  object->rightIndicator_certainty_ = data.rightIndicator_certainty;
74  object->rightIndicatorOn_ = data.rightIndicatorOn;
75  object->v2xStationID_ = data.v2xStationID;
76  object->vx_ = data.motion_state.twist.twist.linear.x;
77  object->vy_ = data.motion_state.twist.twist.linear.y;
78  object->width_ = data.shape.dimensions[data.shape.BOX_Y];
80  object->yaw_ = qc.quaternionToHeading(data.motion_state.pose.pose);
81  object->yawrate_ = data.motion_state.twist.twist.angular.z;
82  }
86  void encodeTrafficParticipant(const adore::env::traffic::Participant& object,adore_if_ros_msg::TrafficParticipant* msg)
87  {
88  msg->time = object.observation_time_;
89  msg->brakeLight_certainty = object.brakeLight_certainty_;
90  msg->brakeLightOn = object.brakeLightsOn_;
91  msg->motion_state.pose.pose.position.x = object.center_(0);
92  msg->motion_state.pose.pose.position.y = object.center_(1);
93  msg->motion_state.pose.pose.position.z = object.center_(2);
94  msg->classification.type_id = (char) object.classification_;
95  msg->classification_certainty = object.classification_certainty_;
96  msg->existance_certainty = object.existance_certainty_;
97  msg->shape.dimensions.push_back(object.length_);
98  msg->shape.dimensions.push_back(object.width_);
99  msg->shape.dimensions.push_back(object.height_);
100  msg->highBeam_certainty = object.highBeamCertainty_;
101  msg->highBeamOn = object.highBeamOn_;
102  msg->leftIndicator_certainty = object.leftIndicator_certainty_;
103  msg->leftIndicatorOn = object.leftIndicatorOn_;
104  msg->lowBeam_certainty = object.lowBeamCertainty_;
105  msg->lowBeamOn = object.lowBeamOn_;
106  msg->motion_state.header.stamp.fromSec( object.observation_time_ );
107  msg->rightIndicator_certainty = object.rightIndicator_certainty_;
108  msg->rightIndicatorOn = object.rightIndicatorOn_;
109  msg->v2xStationID = object.v2xStationID_;
110  msg->motion_state.twist.twist.linear.x = object.vx_;
111  msg->motion_state.twist.twist.linear.y = object.vy_;
113  qc.setHeading(object.yaw_,msg->motion_state.pose.pose);
114  msg->motion_state.twist.twist.angular.z = object.yawrate_;
115  }
116  };
117 
119  {
120  public:
124  void operator()(adore_if_ros_msg::TrafficParticipantSetConstPtr msg,adore::env::traffic::TParticipantSet* set)
125  {
126  set->clear();
127  for(auto& entry:msg->data)
128  {
130  decodeTrafficParticipantDetection(&entry,&object);
131  set->push_back(object);
132  }
133  }
134  adore_if_ros_msg::TrafficParticipantSet operator()(const adore::env::traffic::TParticipantSet& set)
135  {
136  adore_if_ros_msg::TrafficParticipantSet msg;
137  for(auto& p:set)
138  {
139  adore_if_ros_msg::TrafficParticipantDetection pmsg;
141  msg.data.push_back(pmsg);
142  }
143  return msg;
144  }
145  };
146 
151  class TPSetMultiReader:public adore::mad::AReader<adore::env::traffic::TParticipantSet>
152  {
153  private:
155  bool changed_;
158  ros::Subscriber subscriber1_;
159  ros::Subscriber subscriber2_;
160  void receive1(adore_if_ros_msg::TrafficParticipantSetConstPtr msg)
161  {
162  TPSetConverter()(msg,&data1_);
163  initialized_=true;
164  changed_=true;
165  }
166  void receive2(adore_if_ros_msg::TrafficParticipantSetConstPtr msg)
167  {
168  TPSetConverter()(msg,&data2_);
169  initialized_=true;
170  changed_=true;
171  }
172  public:
173  TPSetMultiReader(ros::NodeHandle* n,const std::string& topic1, const std::string& topic2,int qsize)
174  :initialized_(false),changed_(false)
175  {
176  bool no_delay;
177  n->param("/tcp_no_delay", no_delay, false);
178  subscriber1_ = n->subscribe(topic1,qsize,&TPSetMultiReader::receive1,this,ros::TransportHints().tcpNoDelay(no_delay));
179  subscriber2_ = n->subscribe(topic2,qsize,&TPSetMultiReader::receive2,this,ros::TransportHints().tcpNoDelay(no_delay));
180  }
181  virtual bool hasData() const override
182  {
183  return initialized_;
184  }
185  virtual bool hasUpdate() const override
186  {
187  return changed_;
188  }
189  virtual void getData(adore::env::traffic::TParticipantSet& value) override
190  {
191  value.clear();
192  for(const auto& p: data1_)value.push_back(p);
193  for(const auto& p: data2_)value.push_back(p);
194  changed_ = false;
195  }
196  };
197 
198 
200  {
201  public:
206  adore_if_ros_msg::TrafficParticipantSimulation operator()(const adore::env::traffic::Participant& object)
207  {
208  adore_if_ros_msg::TrafficParticipantSimulation msg;
209  encodeTrafficParticipant(object,&msg.data);
210  msg.simulationID = object.getTrackingID();
211  return msg;
212  }
216  void operator()(adore_if_ros_msg::TrafficParticipantSimulationConstPtr msg,adore::env::traffic::Participant& object)
217  {
218  decodeTrafficParticipant(msg->data,&object);
219  object.trackingID_ = msg->simulationID;
220  }
224  void operator()(const adore_if_ros_msg::TrafficParticipantSimulation& msg,adore::env::traffic::Participant& object)
225  {
226  decodeTrafficParticipant(msg.data,&object);
227  object.trackingID_ = msg.simulationID;
228  }
229 
230  };
231 
233  {
234  public:
238  void operator()(adore_if_ros_msg::TrafficParticipantDetectionConstPtr msg,adore::env::traffic::Participant* object)
239  {
240  decodeTrafficParticipantDetection(msg.get(),object);
241  }
245  adore_if_ros_msg::TrafficParticipantDetection operator()(const adore::env::traffic::Participant& object)
246  {
247  adore_if_ros_msg::TrafficParticipantDetection msg;
249  return msg;
250  }
251  };
252 
254  {
255  public:
259  adore_if_ros_msg::TrafficParticipant operator()(const adore::env::traffic::Participant& object)
260  {
261  adore_if_ros_msg::TrafficParticipant msg;
262  encodeTrafficParticipant(object,&msg);
263  return msg;
264  }
265  };
266  }
267 }
Definition: trafficparticipantconverter.h:233
void operator()(adore_if_ros_msg::TrafficParticipantDetectionConstPtr msg, adore::env::traffic::Participant *object)
Definition: trafficparticipantconverter.h:238
adore_if_ros_msg::TrafficParticipantDetection operator()(const adore::env::traffic::Participant &object)
Definition: trafficparticipantconverter.h:245
Definition: trafficparticipantconverter.h:254
adore_if_ros_msg::TrafficParticipant operator()(const adore::env::traffic::Participant &object)
Definition: trafficparticipantconverter.h:259
Definition: trafficparticipantconverter.h:119
adore_if_ros_msg::TrafficParticipantSet operator()(const adore::env::traffic::TParticipantSet &set)
Definition: trafficparticipantconverter.h:134
void operator()(adore_if_ros_msg::TrafficParticipantSetConstPtr msg, adore::env::traffic::TParticipantSet *set)
Definition: trafficparticipantconverter.h:124
TPSetMultiReader reads two ros topics and combines data from both.
Definition: trafficparticipantconverter.h:152
ros::Subscriber subscriber2_
Definition: trafficparticipantconverter.h:159
void receive2(adore_if_ros_msg::TrafficParticipantSetConstPtr msg)
Definition: trafficparticipantconverter.h:166
virtual bool hasUpdate() const override
Definition: trafficparticipantconverter.h:185
bool initialized_
Definition: trafficparticipantconverter.h:154
adore::env::traffic::TParticipantSet data2_
Definition: trafficparticipantconverter.h:157
TPSetMultiReader(ros::NodeHandle *n, const std::string &topic1, const std::string &topic2, int qsize)
Definition: trafficparticipantconverter.h:173
virtual void getData(adore::env::traffic::TParticipantSet &value) override
Definition: trafficparticipantconverter.h:189
void receive1(adore_if_ros_msg::TrafficParticipantSetConstPtr msg)
Definition: trafficparticipantconverter.h:160
adore::env::traffic::TParticipantSet data1_
Definition: trafficparticipantconverter.h:156
bool changed_
Definition: trafficparticipantconverter.h:155
virtual bool hasData() const override
Definition: trafficparticipantconverter.h:181
ros::Subscriber subscriber1_
Definition: trafficparticipantconverter.h:158
Definition: trafficparticipantconverter.h:200
void operator()(const adore_if_ros_msg::TrafficParticipantSimulation &msg, adore::env::traffic::Participant &object)
Definition: trafficparticipantconverter.h:224
void operator()(adore_if_ros_msg::TrafficParticipantSimulationConstPtr msg, adore::env::traffic::Participant &object)
Definition: trafficparticipantconverter.h:216
adore_if_ros_msg::TrafficParticipantSimulation operator()(const adore::env::traffic::Participant &object)
Definition: trafficparticipantconverter.h:206
Definition: trafficparticipantconverter.h:30
void decodeTrafficParticipant(const adore_if_ros_msg::TrafficParticipant &data, adore::env::traffic::Participant *object)
Definition: trafficparticipantconverter.h:53
void encodeTrafficParticipantDetection(const adore::env::traffic::Participant &object, adore_if_ros_msg::TrafficParticipantDetection *msg)
Definition: trafficparticipantconverter.h:44
void encodeTrafficParticipant(const adore::env::traffic::Participant &object, adore_if_ros_msg::TrafficParticipant *msg)
Definition: trafficparticipantconverter.h:86
void decodeTrafficParticipantDetection(const adore_if_ros_msg::TrafficParticipantDetection *msg, adore::env::traffic::Participant *object)
Definition: trafficparticipantconverter.h:35
Definition: com_patterns.h:68
std::vector< Participant > TParticipantSet
Definition: participant.h:164
void set(T *data, T value, int size)
Definition: adoremath.h:39
Definition: areaofeffectconverter.h:20
Struct for representing a participant in traffic.
Definition: participant.h:30
EClassification
Definition: participant.h:36
Definition: quaternion.h:28
double quaternionToHeading(const geometry_msgs::Pose &p) const
convert quaternion to heading
Definition: quaternion.h:49
void setHeading(double heading, geometry_msgs::Pose &msg) const
set heading of a Pose message
Definition: quaternion.h:31