etsi_its_messages v3.3.0
 
Loading...
Searching...
No Matches
mcm_getters.h
Go to the documentation of this file.
1/*
2=============================================================================
3MIT License
4
5Copyright (c) 2023-2025 Institute for Automotive Engineering (ika), RWTH Aachen University
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24=============================================================================
25*/
26
31
32#pragma once
33
34namespace etsi_its_mcm_uulm_msgs::access {
35
42inline double getLatitude(const Latitude& latitude) { return ((double)latitude.value) * 1e-7; }
43
50inline double getLongitude(const Longitude& longitude) { return ((double)longitude.value) * 1e-7; }
51
58inline double getAltitude(const Altitude& altitude) {
59 if (altitude.altitude_value.value == AltitudeValue::UNAVAILABLE) {
60 return 0.0;
61 }
62
63 return ((double)altitude.altitude_value.value) * 1e-2;
64}
65
78template <typename T>
79inline gm::PointStamped getUTMPosition(const T& reference_position, int& zone, bool& northp, double& conv_angle) {
80 gm::PointStamped utm_point;
81 double latitude = getLatitude(reference_position.latitude);
82 double longitude = getLongitude(reference_position.longitude);
83 utm_point.point.z = getAltitude(reference_position.altitude);
84 try {
85 double scale;
86 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y, conv_angle,
87 scale);
88 std::string hemisphere;
89 if (northp) {
90 hemisphere = "N";
91 } else {
92 hemisphere = "S";
93 }
94 utm_point.header.frame_id = "utm_" + std::to_string(zone) + hemisphere;
95 } catch (GeographicLib::GeographicErr& e) {
96 throw std::invalid_argument(e.what());
97 }
98 return utm_point;
99}
100
113inline gm::PointStamped getUTMPosition(const MCM& mcm, int& zone, bool& northp, double& conv_angle) {
114 return getUTMPosition(mcm.mcm.mcm_parameters.basic_container.reference_position, zone, northp, conv_angle);
115}
116
128inline gm::PointStamped getUTMPosition(const MCM& mcm, int& zone, bool& northp) {
129 double conv_angle; // unused, but required by the function signature
130 return getUTMPosition(mcm.mcm.mcm_parameters.basic_container.reference_position, zone, northp, conv_angle);
131}
132
142inline gm::PointStamped getUTMPosition(const MCM& mcm) {
143 int zone; // unused, but required by the function signature
144 bool northp; // unused, but required by the function signature
145 double conv_angle; // unused, but required by the function signature
146 return getUTMPosition(mcm.mcm.mcm_parameters.basic_container.reference_position, zone, northp, conv_angle);
147}
148
149// ---------- suggested maneuver container getters ----------
150
158inline SuggestedManeuverContainer getSuggestedManeuverContainer(const MCM& mcm) {
159 if (mcm.mcm.mcm_parameters.maneuver_container.choice != ManeuverContainer::CHOICE_SUGGESTED_MANEUVER_CONTAINER) {
160 throw std::invalid_argument("No suggested maneuver container present in MCM");
161 }
162 return mcm.mcm.mcm_parameters.maneuver_container.suggested_maneuver_container;
163}
164
171inline uint32_t getTargetStationId(const SuggestedManeuverContainer& suggested_maneuver_container) {
172 return suggested_maneuver_container.target_station_id.value;
173}
174
182inline SuggestedManeuver getSuggestedManeuver(const SuggestedManeuverContainer& suggested_maneuver_container) {
183 if (!suggested_maneuver_container.suggested_maneuver_is_present) {
184 throw std::invalid_argument("No suggested maneuver present in SuggestedManeuverContainer");
185 }
186 return suggested_maneuver_container.suggested_maneuver;
187}
188
195inline SuggestedManeuver getSuggestedManeuver(const MCM& mcm) {
197}
198
205inline uint16_t getManeuverId(const SuggestedManeuver& suggested_maneuver) {
206 return suggested_maneuver.maneuver_id.value;
207}
208
215inline uint16_t getAdviceUpdateId(const SuggestedManeuver& suggested_maneuver) {
216 return suggested_maneuver.advice_update_id.value;
217}
218
225inline bool getConfirmationRequiredFlag(const SuggestedManeuver& suggested_maneuver) {
226 return suggested_maneuver.confirmation_required_flag.value;
227}
228
236inline ManeuverConstraints getManeuverConstraints(const SuggestedManeuver& suggested_maneuver) {
237 if (suggested_maneuver.maneuver_parameters.choice != ManeuverParameters::CHOICE_MANEUVER_CONSTRAINTS) {
238 throw std::invalid_argument("No maneuver constraints present in SuggestedManeuver");
239 }
240 return suggested_maneuver.maneuver_parameters.maneuver_constraints;
241}
242
249inline ManeuverConstraints getManeuverConstraints(const MCM& mcm) {
251}
252
259inline std::vector<LongitudinalWaypoint> getLongitudinalWaypoints(const ManeuverConstraints& maneuver_constraints) {
260 return maneuver_constraints.longitudinal_maneuver_waypoint_container.array;
261}
262
269inline std::vector<LongitudinalWaypoint> getLongitudinalWaypoints(const MCM& mcm) {
271}
272
279inline gm::Point getWaypointDelta(const LongitudinalWaypoint& longitudinal_waypoint) {
280 gm::Point point;
281 point.x = static_cast<double>(longitudinal_waypoint.waypoint.x_distance.value * 1e-2); // convert cm to m
282 point.y = static_cast<double>(longitudinal_waypoint.waypoint.y_distance.value * 1e-2); // convert cm to m
283 point.z = 0.0; // z-coordinate is not used in longitudinal waypoints
284 return point;
285}
286
293inline double getMinArrivalTimeDelta(const LongitudinalWaypoint& longitudinal_waypoint) {
294 return static_cast<double>(longitudinal_waypoint.min_arrival_time.value * 1e-3); // convert ms to s
295}
296
303inline double getMaxArrivalTimeDelta(const LongitudinalWaypoint& longitudinal_waypoint) {
304 return static_cast<double>(longitudinal_waypoint.max_arrival_time.value * 1e-3); // convert ms to s
305}
306
314inline double getMinVelocity(const LongitudinalWaypoint& longitudinal_waypoint) {
315 if (!longitudinal_waypoint.min_velocity_is_present) {
316 throw std::invalid_argument("No min velocity present in LongitudinalWaypoint");
317 } else if (longitudinal_waypoint.min_velocity.value == SpeedValue::UNAVAILABLE) {
318 return std::numeric_limits<double>::quiet_NaN();
319 }
320 return static_cast<double>(longitudinal_waypoint.min_velocity.value * 1e-2); // convert cm/s to m/s
321}
322
330inline double getMaxVelocity(const LongitudinalWaypoint& longitudinal_waypoint) {
331 if (!longitudinal_waypoint.max_velocity_is_present) {
332 throw std::invalid_argument("No max velocity present in LongitudinalWaypoint");
333 } else if (longitudinal_waypoint.max_velocity.value == SpeedValue::UNAVAILABLE) {
334 return std::numeric_limits<double>::quiet_NaN();
335 }
336 return static_cast<double>(longitudinal_waypoint.max_velocity.value * 1e-2); // convert cm/s to m/s
337}
338
339// ---------- road user container getters ----------
340
348inline RoadUserContainer getRoadUserContainer(const MCM& mcm) {
349 if (mcm.mcm.mcm_parameters.maneuver_container.choice != ManeuverContainer::CHOICE_ROAD_USER_CONTAINER) {
350 throw std::invalid_argument("No road user container present in MCM");
351 }
352 return mcm.mcm.mcm_parameters.maneuver_container.road_user_container;
353}
354
355} // namespace etsi_its_mcm_uulm_msgs::access
std::vector< LongitudinalWaypoint > getLongitudinalWaypoints(const ManeuverConstraints &maneuver_constraints)
Retrieves the list of longitudinal waypoints from the given maneuver constraints.
double getMinVelocity(const LongitudinalWaypoint &longitudinal_waypoint)
Retrieves the minimum velocity from a LongitudinalWaypoint.
gm::Point getWaypointDelta(const LongitudinalWaypoint &longitudinal_waypoint)
Converts a LongitudinalWaypoint to a gm::Point.
double getLatitude(const Latitude &latitude)
Get the Latitude value.
Definition mcm_getters.h:42
uint16_t getAdviceUpdateId(const SuggestedManeuver &suggested_maneuver)
Retrieves the advice update identifier from a SuggestedManeuver object.
bool getConfirmationRequiredFlag(const SuggestedManeuver &suggested_maneuver)
Retrieves the confirmation required flag from a SuggestedManeuver.
double getMaxArrivalTimeDelta(const LongitudinalWaypoint &longitudinal_waypoint)
Returns the maximum allowed arrival time delta for a given longitudinal waypoint.
uint16_t getManeuverId(const SuggestedManeuver &suggested_maneuver)
Retrieves the maneuver ID from a SuggestedManeuver object.
double getMaxVelocity(const LongitudinalWaypoint &longitudinal_waypoint)
Retrieves the maximum velocity from a LongitudinalWaypoint object.
double getMinArrivalTimeDelta(const LongitudinalWaypoint &longitudinal_waypoint)
Returns the minimum arrival time delta for a given longitudinal waypoint.
SuggestedManeuver getSuggestedManeuver(const SuggestedManeuverContainer &suggested_maneuver_container)
Retrieves the suggested maneuver from a SuggestedManeuverContainer.
ManeuverConstraints getManeuverConstraints(const SuggestedManeuver &suggested_maneuver)
Retrieves the ManeuverConstraints from a SuggestedManeuver.
uint32_t getTargetStationId(const SuggestedManeuverContainer &suggested_maneuver_container)
Retrieves the target station ID from a SuggestedManeuverContainer.
double getAltitude(const Altitude &altitude)
Get the Altitude value.
Definition mcm_getters.h:58
SuggestedManeuverContainer getSuggestedManeuverContainer(const MCM &mcm)
Retrieves the SuggestedManeuverContainer from the given MCM object.
RoadUserContainer getRoadUserContainer(const MCM &mcm)
Retrieves the RoadUserContainer from the given MCM object.
double getLongitude(const Longitude &longitude)
Get the Longitude value.
Definition mcm_getters.h:50
gm::PointStamped getUTMPosition(const T &reference_position, int &zone, bool &northp, double &conv_angle)
Get the UTM Position defined by the given ReferencePosition along with the grid-convergence angle.
Definition mcm_getters.h:79