etsi_its_messages v3.4.0
Loading...
Searching...
No Matches
cpm_ts_setters.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
36
37namespace etsi_its_cpm_ts_msgs::access {
38
40
46 * @param cpm The CPM to set the ITS PDU header for.
47 * @param station_id The station ID to set in the ITS PDU header.
48 * @param protocol_version The protocol version to set in the ITS PDU header. Default is 0.
49 */
50inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
51 const uint8_t protocol_version = 0) {
52 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
53}
54
55
58 * This function sets the reference time in a CPM object. The reference time is represented
59 * by a Unix timestamp in nanoseconds including the number of leap seconds.
60 * The reference time is stored in the payload management container of the CPM.
61 *
62 * @param cpm The CPM object to set the reference time in.
63 * @param unix_nanosecs The Unix timestamp in nanoseconds representing the reference time.
64 * @param n_leap_seconds The number of leap seconds to be considered. Defaults to the todays number of leap seconds since 2004.
65 */
66inline void setReferenceTime(
67 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
68 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.rbegin()->second) {
69 TimestampIts t_its;
70 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
71 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
72 cpm.payload.management_container.reference_time = t_its;
73}
74
76 * @brief Set the ReferencePositionWithConfidence for a CPM TS
77 *
78 * This function sets the latitude, longitude, and altitude of the CPMs reference position.
79 * If the altitude is not provided, it is set to AltitudeValue::UNAVAILABLE.
80 *
81 * @param cpm CPM to set the ReferencePosition
82 * @param latitude The latitude value position in degree as decimal number.
83 * @param longitude The longitude value in degree as decimal number.
84 * @param altitude The altitude value (above the reference ellipsoid surface) in meter as decimal number (optional).
85 */
86inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
87 const double altitude = AltitudeValue::UNAVAILABLE) {
88 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
89}
93 *
94 * The position is transformed to latitude and longitude by using GeographicLib::UTMUPS
95 * The z-Coordinate is directly used as altitude value
96 * The frame_id of the given utm_position must be set to 'utm_<zone><N/S>'
97 *
98 * @param[out] cpm CPM for which to set the ReferencePosition
99 * @param[in] utm_position geometry_msgs::PointStamped describing the given utm position in meters
100 * @param[in] zone the UTM zone (zero means UPS) of the given position
101 * @param[in] northp hemisphere (true means north, false means south)
102 */
103inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
104 const bool& northp) {
105 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
106}
107
113 * @param object PerceivedObject to set the ID for
114 * @param id ID to set
115 */
116inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
117 object.object_id.value = id;
118 object.object_id_is_present = true;
119}
120
124
126 * between the reference time of the CPM and the measurement of the object.
127 *
128 * @param object The PerceivedObject to set the measurement delta time for.
129 * @param delta_time The measurement delta time to set in milliseconds. Default value is 0.
130 * @throws std::invalid_argument if the delta_time is out of range.
131 */
132inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
133 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
134 throw std::invalid_argument("MeasurementDeltaTime out of range");
135 } else {
136 object.measurement_delta_time.value = delta_time;
137 }
138}
139
143 * This function sets the value and confidence of a CartesianCoordinateWithConfidence object.
144 * The value is limited to the range defined by CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE
145 * and CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE. The confidence is limited to the range
146 * defined by CoordinateConfidence::MIN and CoordinateConfidence::MAX. If the provided confidence
147 * is out of range, the confidence value is set to CoordinateConfidence::OUT_OF_RANGE.
148 *
149 * @param coordinate The CartesianCoordinateWithConfidence object to be modified.
150 * @param value The value to be set in centimeters.
151 * @param confidence The confidence to be set in centimeters (default: infinity, which will map to CoordinateConfidence::UNAVAILABLE).
152 */
153inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const double value,
154 const double confidence = std::numeric_limits<double>::infinity()) {
155 // limit value range
156 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
157 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
158 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
159 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
160 } else {
161 coordinate.value.value = static_cast<int32_t>(value);
162 }
163
164 // limit confidence range
165 if (confidence == std::numeric_limits<double>::infinity()) {
166 coordinate.confidence.value = CoordinateConfidence::UNAVAILABLE;
167 } else if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
168 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
169 } else {
170 coordinate.confidence.value = static_cast<uint16_t>(confidence);
171 }
172}
173
175 * @brief Sets the position of a perceived object (relative to the CPM's reference position).
176 *
177 * This function sets the position of a perceived object using the provided coordinates and confidence values.
178 *
179 * @param object The PerceivedObject to set the position for.
180 * @param point The gm::Point representing the coordinates of the object in meters.
181 * @param x_std The standard deviation in meters for the x-coordinate (default: infinity).
182 * @param y_std The standard deviation in meters for the y-coordinate (default: infinity).
183 * @param z_std The standard deviation in meters for the z-coordinate (default: infinity).
184 */
185inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
186 const double x_std = std::numeric_limits<double>::infinity(),
187 const double y_std = std::numeric_limits<double>::infinity(),
188 const double z_std = std::numeric_limits<double>::infinity()) {
189 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
190 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
191 if (point.z != 0.0) {
192 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
193 object.position.z_coordinate_is_present = true;
194 }
195}
196
200 * This function sets the position of a perceived object using the provided UTM position and the CPM's reference position.
201 * It also allows specifying confidence values for the x, y, and z coordinates.
202 *
203 * @param cpm The CPM to get the reference position from.
204 * @param object The PerceivedObject to set the position for.
205 * @param utm_position gm::PointStamped representing the UTM position of the object including the frame_id (utm_<zone><N/S>).
206 * @param x_confidence The standard deviation in meters for the x coordinate (default: CoordinateConfidence::UNAVAILABLE).
207 * @param y_confidence The standard deviation in meters for the y coordinate (default: CoordinateConfidence::UNAVAILABLE).
208 * @param z_confidence The standard deviation in meters for the z coordinate (default: CoordinateConfidence::UNAVAILABLE).
209 *
210 * @throws std::invalid_argument if the UTM-Position frame_id does not match the reference position frame_id.
211 */
212inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
213 const gm::PointStamped& utm_position,
214 const double x_std = std::numeric_limits<double>::infinity(),
215 const double y_std = std::numeric_limits<double>::infinity(),
216 const double z_std = std::numeric_limits<double>::infinity()) {
217 gm::PointStamped reference_position = getUTMPosition(cpm);
218 if (utm_position.header.frame_id != reference_position.header.frame_id) {
219 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
220 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
221 ")");
222 }
223 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
224 (utm_position.point.x - reference_position.point.x) * 100, x_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
225 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
226 (utm_position.point.y - reference_position.point.y) * 100, y_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
227 if (utm_position.point.z != 0.0) {
228 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
229 (utm_position.point.z - reference_position.point.z) * 100, z_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
230 object.position.z_coordinate_is_present = true;
231 }
232}
242
245inline void setVelocityComponent(VelocityComponent& velocity, const double value,
246 const double confidence = std::numeric_limits<double>::infinity()) {
247 // limit value range
248 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
249 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
250 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
251 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
252 } else {
253 velocity.value.value = static_cast<int16_t>(value);
254 }
256 // limit confidence range
257 if(confidence == std::numeric_limits<double>::infinity()) {
258 velocity.confidence.value = SpeedConfidence::UNAVAILABLE;
259 } else if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
260 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
261 } else {
262 velocity.confidence.value = static_cast<uint8_t>(confidence);
263 }
264}
265
267
273inline void setCartesianAngle(CartesianAngle& angle, const double value,
274 double confidence = std::numeric_limits<double>::infinity()) {
275 // wrap angle to 0..2pi
276 double wrapped_value = fmod(value, 2*M_PI);
277 if (wrapped_value < 0.0) {
278 wrapped_value += 2 * M_PI;
279 }
280 angle.value.value = static_cast<uint16_t>(wrapped_value * 180 / M_PI * 10); // convert to 0.1 degrees
282 confidence *= 180.0 / M_PI * 10.0 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; // convert to 0.1 degrees
283 // limit confidence range
284 if(confidence == std::numeric_limits<double>::infinity() || confidence <= 0.0) {
285 angle.confidence.value = AngleConfidence::UNAVAILABLE;
286 } else if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
287 angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
288 } else {
289 angle.confidence.value = static_cast<uint8_t>(confidence);
290 }
291}
292
296
305inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
306 const double x_std = std::numeric_limits<double>::infinity(),
307 const double y_std = std::numeric_limits<double>::infinity(),
308 const double z_std = std::numeric_limits<double>::infinity()) {
309 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
310 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
311 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
312 if (cartesian_velocity.z != 0.0) {
313 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
314 object.velocity.cartesian_velocity.z_velocity_is_present = true;
315 } else {
316 object.velocity.cartesian_velocity.z_velocity_is_present = false;
317 }
318 object.velocity_is_present = true;
320
335inline void setPolarVelocityOfPerceivedObject(PerceivedObject& object,
336 const double magnitude,
337 const double angle,
338 const double z = 0.0,
339 const double magnitude_std = std::numeric_limits<double>::infinity(),
340 const double angle_std = std::numeric_limits<double>::infinity(),
341 const double z_std = std::numeric_limits<double>::infinity()) {
342 object.velocity.choice = Velocity3dWithConfidence::CHOICE_POLAR_VELOCITY;
343 setSpeed(object.velocity.polar_velocity.velocity_magnitude, magnitude, magnitude_std);
344 setCartesianAngle(object.velocity.polar_velocity.velocity_direction, angle, angle_std);
345 if (z != 0.0) {
346 setVelocityComponent(object.velocity.polar_velocity.z_velocity, z * 100, z_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
347 object.velocity.polar_velocity.z_velocity_is_present = true;
348 } else {
349 object.velocity.polar_velocity.z_velocity_is_present = false;
350 }
351}
352
353/**
354 * @brief Sets the value and confidence of a AccelerationComponent.
355 *
356 * This function sets the value and confidence of a AccelerationComponent object. The value is limited to a specific range,
357 * and the confidence is limited to a specific range as well. If the provided value or confidence is out of range,
358 * it will be set to the corresponding out-of-range value.
359 *
360 * @param acceleration The AccelerationComponent object to set the value and confidence for.
361 * @param value The value to set for the AccelerationComponent in dm/s^2.
362 * @param confidence The confidence to set for the AccelerationComponent in dm/s^2. Default value is infinity, mapping to AccelerationConfidence::UNAVAILABLE.
363 */
364inline void setAccelerationComponent(AccelerationComponent& acceleration, const double value,
365 const double confidence = std::numeric_limits<double>::infinity()) {
366 // limit value range
367 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
368 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
369 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
370 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
371 } else {
372 acceleration.value.value = static_cast<int16_t>(value);
373 }
374
375 // limit confidence range
376 if(confidence == std::numeric_limits<double>::infinity()) {
377 acceleration.confidence.value = AccelerationConfidence::UNAVAILABLE;
378 } else if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
379 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
380 } else {
381 acceleration.confidence.value = static_cast<uint8_t>(confidence);
382 }
383}
384
389
397inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
398 const double x_std = std::numeric_limits<double>::infinity(),
399 const double y_std = std::numeric_limits<double>::infinity(),
400 const double z_std = std::numeric_limits<double>::infinity()) {
401 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
402 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
403 x_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
404 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
405 y_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
406 if (cartesian_acceleration.z != 0.0) {
407 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
408 z_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
409 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
410 }
411 object.acceleration_is_present = true;
412}
413
418 * @param magnitude The magnitude of the acceleration in m/s^2 in the xy plane.
419 * @param angle The angle of the acceleration in radians in the xy plane.
420 * @param z The z component of the acceleration in m/s^2 (default: 0.0).
421 * @param magnitude_std The standard deviation in m/s^2 for the acceleration magnitude (default: infinity).
422 * @param angle_std The standard deviation in radians for the angle (default: infinity).
423 * @param z_std The standard deviation in m/s^2 for the z acceleration component (default: infinity).
424 */
425inline void setPolarAccelerationOfPerceivedObject(PerceivedObject& object,
426 const double magnitude,
427 const double angle,
428 const double z = 0.0,
429 const double magnitude_std = std::numeric_limits<double>::infinity(),
430 const double angle_std = std::numeric_limits<double>::infinity(),
431 const double z_std = std::numeric_limits<double>::infinity()) {
432 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_POLAR_ACCELERATION;
433 setAccelerationMagnitude(object.acceleration.polar_acceleration.acceleration_magnitude, magnitude, magnitude_std);
434 setCartesianAngle(object.acceleration.polar_acceleration.acceleration_direction, angle, angle_std);
435 if (z != 0.0) {
436 setAccelerationComponent(object.acceleration.polar_acceleration.z_acceleration, z * 10,
437 z_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
438 object.acceleration.polar_acceleration.z_acceleration_is_present = true;
439 } else {
440 object.acceleration.polar_acceleration.z_acceleration_is_present = false;
441 }
442 object.acceleration_is_present = true;
443}
444
455inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
456 double yaw_std = std::numeric_limits<double>::infinity()) {
457 // wrap angle to range [0, 360)
458 double yaw_in_degrees = yaw * 180 / M_PI;
459 while (yaw_in_degrees >= 360.0) yaw_in_degrees -= 360.0;
460 while (yaw_in_degrees < 0.0) yaw_in_degrees += 360.0;
461 object.angles.z_angle.value.value = yaw_in_degrees * 10;
462
463 if(yaw_std == std::numeric_limits<double>::infinity()) {
464 object.angles.z_angle.confidence.value = AngleConfidence::UNAVAILABLE;
465 } else {
466 yaw_std *= 180.0 / M_PI;
467 yaw_std *= 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; // convert to 0.1 degrees
468
469 if (yaw_std > AngleConfidence::MAX || yaw_std < AngleConfidence::MIN) {
470 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
471 } else {
472 object.angles.z_angle.confidence.value = static_cast<uint8_t>(yaw_std);
473 }
474 }
475 object.angles_is_present = true;
476}
477
480
489inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
490 double yaw_rate_std = std::numeric_limits<double>::infinity()) {
491 double yaw_rate_in_degrees = yaw_rate * 180.0 / M_PI;
492 // limit value range
493 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
494 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
495 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
496 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
497 }
498
499 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
500
501 if(yaw_rate_std == std::numeric_limits<double>::infinity()) {
502 object.z_angular_velocity.confidence.value = AngularSpeedConfidence::UNAVAILABLE;
503 } else {
504 yaw_rate_std *= 180.0 / M_PI;
505 yaw_rate_std *= etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; // convert to degrees/s
506 // How stupid is this?!
507 static const std::map<double, uint8_t> confidence_map = {
508 {1.0, AngularSpeedConfidence::DEG_SEC_01},
509 {2.0, AngularSpeedConfidence::DEG_SEC_02},
510 {5.0, AngularSpeedConfidence::DEG_SEC_05},
511 {10.0, AngularSpeedConfidence::DEG_SEC_10},
512 {20.0, AngularSpeedConfidence::DEG_SEC_20},
513 {50.0, AngularSpeedConfidence::DEG_SEC_50},
514 {std::numeric_limits<double>::infinity(), AngularSpeedConfidence::OUT_OF_RANGE},
515 };
516 for(const auto& [thresh, conf_val] : confidence_map) {
517 if (yaw_rate_std <= thresh) {
518 object.z_angular_velocity.confidence.value = conf_val;
519 break;
520 }
521 }
522 }
523
524 object.z_angular_velocity_is_present = true;
525}
526
541inline void setObjectDimension(ObjectDimension& dimension, const double value,
542 const double confidence = std::numeric_limits<double>::infinity()) {
543 // limit value range
544 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
545 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
546 } else {
547 dimension.value.value = static_cast<uint16_t>(value);
548 }
549
550 // limit confidence range
551 if (confidence == std::numeric_limits<double>::infinity()) {
552 dimension.confidence.value = ObjectDimensionConfidence::UNAVAILABLE;
553 } else if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
554 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
555 } else {
556 dimension.confidence.value = static_cast<uint8_t>(confidence);
557 }
558
559}
560
571inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
572 const double std = std::numeric_limits<double>::infinity()) {
573 setObjectDimension(object.object_dimension_x, value * 10, std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
574 object.object_dimension_x_is_present = true;
575}
576
587inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
588 const double std = std::numeric_limits<double>::infinity()) {
589 setObjectDimension(object.object_dimension_y, value * 10, std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
590 object.object_dimension_y_is_present = true;
591}
592
603inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
604 const double std = std::numeric_limits<double>::infinity()) {
605 setObjectDimension(object.object_dimension_z, value * 10, std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
606 object.object_dimension_z_is_present = true;
607}
608
620inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
621 const double x_std = std::numeric_limits<double>::infinity(),
622 const double y_std = std::numeric_limits<double>::infinity(),
623 const double z_std = std::numeric_limits<double>::infinity()) {
624 setXDimensionOfPerceivedObject(object, dimensions.x, x_std);
625 setYDimensionOfPerceivedObject(object, dimensions.y, y_std);
626 setZDimensionOfPerceivedObject(object, dimensions.z, z_std);
627}
628
638inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
639 setPositionOfPerceivedObject(object, point);
641}
642
655inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
656 const gm::PointStamped& point, const int16_t delta_time = 0) {
657 setUTMPositionOfPerceivedObject(cpm, object, point);
659}
660
670inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
671 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
672 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
673}
674
688inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
689 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
690 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
691 container.container_data_perceived_object_container.number_of_perceived_objects.value =
692 container.container_data_perceived_object_container.perceived_objects.array.size();
693 } else {
694 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
695 }
696}
697
710inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
711 // check for maximum number of containers
712 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
713 cpm.payload.cpm_containers.value.array.push_back(container);
714 } else {
715 throw std::invalid_argument("Maximum number of CPM-Containers reached");
716 }
717}
718
727inline void setWGSRefPosConfidence(CollectivePerceptionMessage& cpm, const std::array<double, 4>& covariance_matrix) {
728 setWGSPosConfidenceEllipse(cpm.payload.management_container.reference_position.position_confidence_ellipse,
729 covariance_matrix);
730}
731
740inline void initSensorInformationContainer(WrappedCpmContainer& container) {
741 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_SENSOR_INFORMATION_CONTAINER;
742 container.container_data_sensor_information_container.array = std::vector<SensorInformation>();
743}
744
755inline void setSensorID(SensorInformation& sensor_information, const uint8_t sensor_id = 0) {
756 throwIfOutOfRange(sensor_id, Identifier1B::MIN, Identifier1B::MAX, "SensorID");
757 sensor_information.sensor_id.value = sensor_id;
758}
759
770inline void setSensorType(SensorInformation& sensor_information, const uint8_t sensor_type = SensorType::UNDEFINED) {
771 throwIfOutOfRange(sensor_type, SensorType::MIN, SensorType::MAX, "SensorType");
772 sensor_information.sensor_type.value = sensor_type;
773}
774
793inline void addSensorInformationToContainer(WrappedCpmContainer& container, const SensorInformation& sensor_information) {
794 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_SENSOR_INFORMATION_CONTAINER) {
795 // check for maximum number of SensorInformation entries
796 if (container.container_data_sensor_information_container.array.size() < SensorInformationContainer::MAX_SIZE ) {
797 throwIfOutOfRange(sensor_information.sensor_id.value, Identifier1B::MIN, Identifier1B::MAX, "SensorID");
798 throwIfOutOfRange(sensor_information.sensor_type.value, SensorType::MIN, SensorType::MAX, "SensorType");
799 container.container_data_sensor_information_container.array.push_back(sensor_information);
800 } else {
801 throw std::invalid_argument("Maximum number of entries SensorInformationContainers reached");
802 }
803 } else {
804 throw std::invalid_argument("Container is not a SensorInformationContainer");
805 }
806}
807
822inline void addSensorInformationContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
823 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_SENSOR_INFORMATION_CONTAINER) {
824 throwIfOutOfRange(container.container_data_sensor_information_container.array.size(),
825 SensorInformationContainer::MIN_SIZE, SensorInformationContainer::MAX_SIZE, "SensorInformationContainer array size"
826 );
827 addContainerToCPM(cpm, container);
828 } else {
829 throw std::invalid_argument("Container is not a SensorInformationContainer");
830 }
831}
832
833} // namespace etsi_its_cpm_ts_msgs::access
Setter functions for the ETSI ITS Common Data Dictionary (CDD) v2.1.1.
Sanity-check functions etc.
File containing constants that are used in the context of ETIS ITS Messages.
gm::PointStamped getUTMPosition(const T &reference_position, int &zone, bool &northp)
Get the UTM Position defined by the given ReferencePosition.
void setReferencePosition(T &ref_position, const double latitude, const double longitude, const double altitude=AltitudeValue::UNAVAILABLE)
Sets the reference position in the given ReferencePostion object.
void setCartesianAngle(CartesianAngle &angle, const double value, double confidence=std::numeric_limits< double >::infinity())
Set a Cartesian Angle.
void addSensorInformationToContainer(WrappedCpmContainer &container, const SensorInformation &sensor_information)
Adds a SensorInformation to the SensorInformationContainer / WrappedCpmContainer.
void setVelocityOfPerceivedObject(PerceivedObject &object, const gm::Vector3 &cartesian_velocity, const double x_std=std::numeric_limits< double >::infinity(), const double y_std=std::numeric_limits< double >::infinity(), const double z_std=std::numeric_limits< double >::infinity())
void setWGSPosConfidenceEllipse(PosConfidenceEllipse &position_confidence_ellipse, const std::array< double, 4 > &covariance_matrix)
Set the Pos Confidence Ellipse object.
void setAccelerationComponent(AccelerationComponent &acceleration, const double value, const double confidence=std::numeric_limits< double >::infinity())
Sets the value and confidence of a AccelerationComponent.
void setAccelerationOfPerceivedObject(PerceivedObject &object, const gm::Vector3 &cartesian_acceleration, const double x_std=std::numeric_limits< double >::infinity(), const double y_std=std::numeric_limits< double >::infinity(), const double z_std=std::numeric_limits< double >::infinity())
Sets the acceleration of a perceived object.
void initPerceivedObjectContainer(WrappedCpmContainer &container, const uint8_t n_objects=0)
Initializes a WrappedCpmContainer as a PerceivedObjectContainer with the given number of objects.
void setDimensionsOfPerceivedObject(PerceivedObject &object, const gm::Vector3 &dimensions, const double x_std=std::numeric_limits< double >::infinity(), const double y_std=std::numeric_limits< double >::infinity(), const double z_std=std::numeric_limits< double >::infinity())
Sets all dimensions of a perceived object.
void setYDimensionOfPerceivedObject(PerceivedObject &object, const double value, const double std=std::numeric_limits< double >::infinity())
Sets the y-dimension of a perceived object.
void addSensorInformationContainerToCPM(CollectivePerceptionMessage &cpm, const WrappedCpmContainer &container)
Adds a container to the Collective Perception Message (CPM).
void setWGSRefPosConfidence(CollectivePerceptionMessage &cpm, const std::array< double, 4 > &covariance_matrix)
Set the confidence of the reference position.
void setVelocityComponent(VelocityComponent &velocity, const double value, const double confidence=std::numeric_limits< double >::infinity())
Sets the value and confidence of a VelocityComponent.
void setYawRateOfPerceivedObject(PerceivedObject &object, const double yaw_rate, double yaw_rate_std=std::numeric_limits< double >::infinity())
Sets the yaw rate of a perceived object.
void setItsPduHeader(ItsPduHeader &header, const uint8_t message_id, const uint32_t station_id, const uint8_t protocol_version=0)
Set the Its Pdu Header object.
void setFromUTMPosition(T &reference_position, const gm::PointStamped &utm_position, const int zone, const bool northp)
Set the ReferencePosition from a given UTM-Position.
void setYawOfPerceivedObject(PerceivedObject &object, const double yaw, double yaw_std=std::numeric_limits< double >::infinity())
Sets the yaw angle of a perceived object.
void addPerceivedObjectToContainer(WrappedCpmContainer &container, const PerceivedObject &perceived_object)
Adds a PerceivedObject to the PerceivedObjectContainer / WrappedCpmContainer.
void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage &cpm, PerceivedObject &object, const gm::PointStamped &utm_position, const double x_std=std::numeric_limits< double >::infinity(), const double y_std=std::numeric_limits< double >::infinity(), const double z_std=std::numeric_limits< double >::infinity())
Sets the position of a perceived object based on a UTM position.
void setPolarVelocityOfPerceivedObject(PerceivedObject &object, const double magnitude, const double angle, const double z=0.0, const double magnitude_std=std::numeric_limits< double >::infinity(), const double angle_std=std::numeric_limits< double >::infinity(), const double z_std=std::numeric_limits< double >::infinity())
void addContainerToCPM(CollectivePerceptionMessage &cpm, const WrappedCpmContainer &container)
Adds a container to the Collective Perception Message (CPM).
void throwIfOutOfRange(const T1 &val, const T2 &min, const T2 &max, const std::string val_desc)
Throws an exception if a given value is out of a defined range.
void setIdOfPerceivedObject(PerceivedObject &object, const uint16_t id)
Set the ID of a PerceivedObject.
void setAccelerationMagnitude(AccelerationMagnitude &accel_mag, const double value, const double confidence=std::numeric_limits< double >::infinity())
Set the AccelerationMagnitude object.
void setPolarAccelerationOfPerceivedObject(PerceivedObject &object, const double magnitude, const double angle, const double z=0.0, const double magnitude_std=std::numeric_limits< double >::infinity(), const double angle_std=std::numeric_limits< double >::infinity(), const double z_std=std::numeric_limits< double >::infinity())
Set the Polar Acceleration Of Perceived Object object.
void setObjectDimension(ObjectDimension &dimension, const double value, const double confidence=std::numeric_limits< double >::infinity())
Sets the object dimension with the given value and confidence.
void setXDimensionOfPerceivedObject(PerceivedObject &object, const double value, const double std=std::numeric_limits< double >::infinity())
Sets the x-dimension of a perceived object.
void setZDimensionOfPerceivedObject(PerceivedObject &object, const double value, const double std=std::numeric_limits< double >::infinity())
Sets the z-dimension of a perceived object.
void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence &coordinate, const double value, const double confidence=std::numeric_limits< double >::infinity())
Sets the value and confidence of a CartesianCoordinateWithConfidence object.
void setPositionOfPerceivedObject(PerceivedObject &object, const gm::Point &point, const double x_std=std::numeric_limits< double >::infinity(), const double y_std=std::numeric_limits< double >::infinity(), const double z_std=std::numeric_limits< double >::infinity())
Sets the position of a perceived object (relative to the CPM's reference position).
void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject &object, const int16_t delta_time=0)
Sets the measurement delta time of a PerceivedObject.
void setSensorType(SensorInformation &sensor_information, const uint8_t sensor_type=SensorType::UNDEFINED)
Sets the sensorType of a SensorInformation object.
const std::map< uint64_t, uint16_t > LEAP_SECOND_INSERTIONS_SINCE_2004
std::map that stores all leap second insertions since 2004 with the corresponding unix-date of the in...
void setSpeed(Speed &speed, const double value, const double confidence=std::numeric_limits< double >::infinity())
Set the Speed object.
void setReferenceTime(CollectivePerceptionMessage &cpm, const uint64_t unix_nanosecs, const uint16_t n_leap_seconds=etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.rbegin() ->second)
Sets the reference time in a CPM.
void initSensorInformationContainer(WrappedCpmContainer &container)
Initializes a WrappedCpmContainer as a SensorInformationContainer.
void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage &cpm, PerceivedObject &object, const gm::PointStamped &point, const int16_t delta_time=0)
Initializes a PerceivedObject with the given point (utm-position) and delta time.
void setSensorID(SensorInformation &sensor_information, const uint8_t sensor_id=0)
Sets the sensorId of a SensorInformation object.
void setTimestampITS(TimestampIts &timestamp_its, const uint64_t unix_nanosecs, const uint16_t n_leap_seconds=etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.rbegin() ->second)
Set the TimestampITS object.
void initPerceivedObject(PerceivedObject &object, const gm::Point &point, const int16_t delta_time=0)
Initializes a PerceivedObject with the given point and delta time.