ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
lanegeometryconverter.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  * Thomas Lobig - initial API and implementation
13  ********************************************************************************/
14 
15 #pragma once
16 
17 #include <adore/env/afactory.h>
21 #include <adore_if_ros_msg/LinearPiecewiseFunction3d.h>
22 #include <adore_if_ros_msg/LaneGeometry.h>
23 #include <adore_if_ros_msg/LaneFollowingGeometry.h>
24 #include <adore_if_ros_msg/LaneChangeGeometry.h>
25 #include <std_msgs/Float64.h>
26 
27 namespace adore
28 {
29  namespace if_ROS
30  {
32  {
33  public:
37  void operator()(adore_if_ros_msg::LaneGeometryConstPtr msg,
39  {
40  if (msg->centerlane.isValid)
41  {
42  copyLanefromMsg(combined.center, msg->centerlane);
43  }
44  if (msg->leftlane.isValid)
45  {
46  copyLanefromMsg(combined.left, msg->lefttargetlane);
47  copyLaneChangefromMsg(combined.leftChange, msg->leftlane);
48  }
49  if (msg->rightlane.isValid)
50  {
51  copyLanefromMsg(combined.right, msg->righttargetlane);
52  copyLaneChangefromMsg(combined.rightChange, msg->rightlane);
53  }
54  }
55 
56  void copyLanefromMsg(std::shared_ptr<adore::env::BorderBased::LaneGeometryDataProxy> lane,
57  adore_if_ros_msg::LaneFollowingGeometry const& msg)
58  {
59  copyto(lane->centerSmoothed_fct, msg.centerline);
60  copyto(lane->leftDistance_fct, msg.leftDistance);
61  copyto(lane->rightDistance_fct, msg.rightDistance);
62  copyto(lane->centerNormal_fct, msg.centerNormal);
63  copyto(lane->centerSmoothedCurvature_fct, msg.centerCurvature);
64  copyto(lane->centerSmoothedCurvatureDerivative_fct, msg.centerCurvatureDerivative);
65  copyto(lane->navigationCost_fct, msg.navigationCost);
66  copyto(lane->speedLimit_fct, msg.speedLimit);
67  copyto(lane->left_indicator_hint_fct, msg.leftIndicatorHint);
68  copyto(lane->right_indicator_hint_fct, msg.rightIndicatorHint);
69  lane->isValid = msg.isValid;
70  }
71 
72  void copyLaneChangefromMsg(std::shared_ptr<adore::env::BorderBased::LaneChangeDataProxy> lane,
73  adore_if_ros_msg::LaneChangeGeometry const& msg)
74  {
75  lane->gate_s0 = msg.gate_s0;
76  lane->gate_s1 = msg.gate_s1;
77  switch(msg.direction)
78  {
79  case adore_if_ros_msg::LaneChangeGeometry::LEFT:
80  lane->direction = adore::view::ALaneChangeView::LEFT;
81  break;
82  case adore_if_ros_msg::LaneChangeGeometry::RIGHT:
83  lane->direction = adore::view::ALaneChangeView::RIGHT;
84  break;
85  default:
86  throw std::logic_error("Undefine value for direction in LaneChangeGeometry msg");
87  }
88  lane->isValid = msg.isValid;
89  copyto(lane->targetOuterBorderDistance_fct, msg.targetOuterBorderDistance);
90  copyto(lane->separatingBorderDistance_fct, msg.separatingBorderDistance);
91  copyto(lane->sourceOuterBorderDistance_fct, msg.sourceOuterBorderDistance);
92 
93  }
94 
98  adore_if_ros_msg::LaneGeometry operator()(const adore::env::BorderBased::CombinedLaneGeometry& combined)
99  {
100  adore_if_ros_msg::LaneGeometry msg;
101  if (combined.center->isValid)
102  {
103  copyMsgfromLane(msg.centerlane, combined.center);
104  }
105  if (combined.leftChange->isValid)
106  {
107  copyMsgfromLaneChange(msg.leftlane,combined.leftChange);
108  copyMsgfromLane(msg.lefttargetlane, combined.left);
109  }
110  if (combined.rightChange->isValid)
111  {
112  copyMsgfromLaneChange(msg.rightlane,combined.rightChange);
113  copyMsgfromLane(msg.righttargetlane, combined.right);
114  }
115  return msg;
116  }
117 
118  void copyMsgfromLane(adore_if_ros_msg::LaneFollowingGeometry& msg,
119  std::shared_ptr<adore::env::BorderBased::LaneGeometryDataProxy> lane)
120  {
121  msg.isValid = lane->isValid;
122  copyto(msg.centerline, lane->centerSmoothed_fct);
123  copyto(msg.leftDistance, lane->leftDistance_fct);
124  copyto(msg.rightDistance, lane->rightDistance_fct);
125  copyto(msg.centerNormal, lane->centerNormal_fct);
126  copyto(msg.centerCurvature, lane->centerSmoothedCurvature_fct);
127  copyto(msg.centerCurvatureDerivative, lane->centerSmoothedCurvatureDerivative_fct);
128  copyto(msg.navigationCost, lane->navigationCost_fct);
129  copyto(msg.speedLimit, lane->speedLimit_fct);
130  copyto(msg.leftIndicatorHint, lane->left_indicator_hint_fct);
131  copyto(msg.rightIndicatorHint, lane->right_indicator_hint_fct);
132  }
133 
134  void copyMsgfromLaneChange(adore_if_ros_msg::LaneChangeGeometry& msg,
135  std::shared_ptr<adore::env::BorderBased::LaneChangeDataProxy> lane)
136  {
137  msg.isValid = lane->isValid;
138  msg.gate_s0 = lane->gate_s0;
139  msg.gate_s1 = lane->gate_s1;
140  msg.direction = static_cast<int>(lane->direction);
141  switch(lane->direction)
142  {
144  msg.direction = adore_if_ros_msg::LaneChangeGeometry::LEFT;
145  break;
147  msg.direction = adore_if_ros_msg::LaneChangeGeometry::RIGHT;
148  break;
149  default:
150  throw std::logic_error("Undefine value for direction in LaneChangeGeometry msg");
151  }
152  copyto(msg.targetOuterBorderDistance,lane->targetOuterBorderDistance_fct);
153  copyto(msg.separatingBorderDistance,lane->separatingBorderDistance_fct);
154  copyto(msg.sourceOuterBorderDistance,lane->sourceOuterBorderDistance_fct);
155  }
156 
160  void operator()(adore_if_ros_msg::LinearPiecewiseFunction3dConstPtr msg, adore::mad::function_type_xyz& lpf)
161  {
162  lpf.getData().set_size(4, msg->s.size());
163  for (std::size_t counter = 0; counter < msg->s.size(); counter++)
164  {
165  lpf.getData()(0, counter) = msg->s[counter];
166  lpf.getData()(1, counter) = msg->x[counter];
167  lpf.getData()(2, counter) = msg->y[counter];
168  lpf.getData()(3, counter) = msg->z[counter];
169  }
170  }
171 
175  adore_if_ros_msg::LinearPiecewiseFunction3d operator()(const adore::mad::function_type_xyz& lpf)
176  {
177  adore_if_ros_msg::LinearPiecewiseFunction3d msg;
178  for (std::size_t counter = 0; counter < lpf.getData().nc(); counter++)
179  {
180  msg.s.push_back(lpf.getData()(0, counter));
181  msg.x.push_back(lpf.getData()(1, counter));
182  msg.y.push_back(lpf.getData()(2, counter));
183  msg.z.push_back(lpf.getData()(3, counter));
184  }
185  return msg;
186  }
187 
194  void copyto(adore::mad::function_type_xyz& lpf, adore_if_ros_msg::LinearPiecewiseFunction3d const& msg)
195  {
196  lpf.getData().set_size(4, msg.s.size());
197  for (std::size_t counter = 0; counter < msg.s.size(); counter++)
198  {
199  lpf.getData()(0, counter) = msg.s[counter];
200  lpf.getData()(1, counter) = msg.x[counter];
201  lpf.getData()(2, counter) = msg.y[counter];
202  lpf.getData()(3, counter) = msg.z[counter];
203  }
204  }
205 
212  void copyto(adore_if_ros_msg::LinearPiecewiseFunction3d& msg, adore::mad::function_type_xyz const& lpf)
213  {
214  msg.s.clear();
215  msg.x.clear();
216  msg.y.clear();
217  msg.z.clear();
218  for (std::size_t counter = 0; counter < lpf.getData().nc(); counter++)
219  {
220  msg.s.push_back(lpf.getData()(0, counter));
221  msg.x.push_back(lpf.getData()(1, counter));
222  msg.y.push_back(lpf.getData()(2, counter));
223  msg.z.push_back(lpf.getData()(3, counter));
224  }
225  }
226 
233  void copyto(adore::mad::function_type_scalar& lpf, adore_if_ros_msg::LinearPiecewiseFunction1d const& msg)
234  {
235  lpf.getData().set_size(2, msg.s.size());
236  for (std::size_t counter = 0; counter < msg.s.size(); counter++)
237  {
238  lpf.getData()(0, counter) = msg.s[counter];
239  lpf.getData()(1, counter) = msg.x[counter];
240  }
241  }
242 
249  void copyto(adore_if_ros_msg::LinearPiecewiseFunction1d& msg, adore::mad::function_type_scalar const& lpf)
250  {
251  msg.s.clear();
252  msg.x.clear();
253  for (std::size_t counter = 0; counter < lpf.getData().nc(); counter++)
254  {
255  msg.s.push_back(lpf.getData()(0, counter));
256  msg.x.push_back(lpf.getData()(1, counter));
257  }
258  }
259 
266  void copyto(adore::mad::function_type2d& lpf, adore_if_ros_msg::LinearPiecewiseFunction2d const& msg)
267  {
268  lpf.getData().set_size(3, msg.s.size());
269  for (std::size_t counter = 0; counter < msg.s.size(); counter++)
270  {
271  lpf.getData()(0, counter) = msg.s[counter];
272  lpf.getData()(1, counter) = msg.x[counter];
273  lpf.getData()(2, counter) = msg.y[counter];
274  }
275  }
276 
283  void copyto(adore_if_ros_msg::LinearPiecewiseFunction2d& msg, adore::mad::function_type2d const& lpf)
284  {
285  msg.s.clear();
286  msg.x.clear();
287  msg.y.clear();
288  for (std::size_t counter = 0; counter < lpf.getData().nc(); counter++)
289  {
290  msg.s.push_back(lpf.getData()(0, counter));
291  msg.x.push_back(lpf.getData()(1, counter));
292  msg.y.push_back(lpf.getData()(2, counter));
293  }
294  }
295  };
296  } // namespace if_ROS
297 } // namespace adore
adoreMatrix< T, n+1, 0 > & getData()
Definition: llinearpiecewisefunction.h:147
@ LEFT
Definition: alanechangeview.h:43
@ RIGHT
Definition: alanechangeview.h:43
Definition: areaofeffectconverter.h:20
Definition: lanecombinedgeometry.h:27
std::shared_ptr< LaneGeometryDataProxy > center
Definition: lanecombinedgeometry.h:29
std::shared_ptr< LaneChangeDataProxy > rightChange
Definition: lanecombinedgeometry.h:35
std::shared_ptr< LaneChangeDataProxy > leftChange
Definition: lanecombinedgeometry.h:33
std::shared_ptr< LaneGeometryDataProxy > right
Definition: lanecombinedgeometry.h:34
std::shared_ptr< LaneGeometryDataProxy > left
Definition: lanecombinedgeometry.h:30
Definition: lanegeometryconverter.h:32
adore_if_ros_msg::LaneGeometry operator()(const adore::env::BorderBased::CombinedLaneGeometry &combined)
Definition: lanegeometryconverter.h:98
adore_if_ros_msg::LinearPiecewiseFunction3d operator()(const adore::mad::function_type_xyz &lpf)
Definition: lanegeometryconverter.h:175
void copyto(adore_if_ros_msg::LinearPiecewiseFunction2d &msg, adore::mad::function_type2d const &lpf)
copy of lpf function type scalar to adore_if_ros_msg::LinearPieceWiseFunction1d
Definition: lanegeometryconverter.h:283
void copyto(adore::mad::function_type2d &lpf, adore_if_ros_msg::LinearPiecewiseFunction2d const &msg)
copy of adore_if_ros_msg::LinearPieceWiseFunction1d to lpf function type scalar
Definition: lanegeometryconverter.h:266
void copyLaneChangefromMsg(std::shared_ptr< adore::env::BorderBased::LaneChangeDataProxy > lane, adore_if_ros_msg::LaneChangeGeometry const &msg)
Definition: lanegeometryconverter.h:72
void copyto(adore_if_ros_msg::LinearPiecewiseFunction3d &msg, adore::mad::function_type_xyz const &lpf)
copy of lpf function type xyz to adore_if_ros_msg::LinearPieceWiseFunction3d
Definition: lanegeometryconverter.h:212
void operator()(adore_if_ros_msg::LaneGeometryConstPtr msg, adore::env::BorderBased::CombinedLaneGeometry &combined)
Definition: lanegeometryconverter.h:37
void copyto(adore::mad::function_type_xyz &lpf, adore_if_ros_msg::LinearPiecewiseFunction3d const &msg)
copy of adore_if_ros_msg::LinearPieceWiseFunction3d to lpf function type xyz
Definition: lanegeometryconverter.h:194
void copyMsgfromLaneChange(adore_if_ros_msg::LaneChangeGeometry &msg, std::shared_ptr< adore::env::BorderBased::LaneChangeDataProxy > lane)
Definition: lanegeometryconverter.h:134
void copyto(adore::mad::function_type_scalar &lpf, adore_if_ros_msg::LinearPiecewiseFunction1d const &msg)
copy of adore_if_ros_msg::LinearPieceWiseFunction1d to lpf function type scalar
Definition: lanegeometryconverter.h:233
void copyto(adore_if_ros_msg::LinearPiecewiseFunction1d &msg, adore::mad::function_type_scalar const &lpf)
copy of lpf function type scalar to adore_if_ros_msg::LinearPieceWiseFunction1d
Definition: lanegeometryconverter.h:249
void copyMsgfromLane(adore_if_ros_msg::LaneFollowingGeometry &msg, std::shared_ptr< adore::env::BorderBased::LaneGeometryDataProxy > lane)
Definition: lanegeometryconverter.h:118
void copyLanefromMsg(std::shared_ptr< adore::env::BorderBased::LaneGeometryDataProxy > lane, adore_if_ros_msg::LaneFollowingGeometry const &msg)
Definition: lanegeometryconverter.h:56
void operator()(adore_if_ros_msg::LinearPiecewiseFunction3dConstPtr msg, adore::mad::function_type_xyz &lpf)
Definition: lanegeometryconverter.h:160