etsi_its_messages v3.4.0
Loading...
Searching...
No Matches
cpm_ts_setters.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
3
8
9#pragma once
10
13
14namespace etsi_its_cpm_ts_msgs::access {
15
17
23 * @param cpm The CPM to set the ITS PDU header for.
24 * @param station_id The station ID to set in the ITS PDU header.
25 * @param protocol_version The protocol version to set in the ITS PDU header. Default is 0.
26 */
27inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
28 const uint8_t protocol_version = 0) {
29 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
30}
31
32
35 * This function sets the reference time in a CPM object. The reference time is represented
36 * by a Unix timestamp in nanoseconds including the number of leap seconds.
37 * The reference time is stored in the payload management container of the CPM.
38 *
39 * @param cpm The CPM object to set the reference time in.
40 * @param unix_nanosecs The Unix timestamp in nanoseconds representing the reference time.
41 * @param n_leap_seconds The number of leap seconds to be considered. Defaults to the todays number of leap seconds since 2004.
42 */
43inline void setReferenceTime(
44 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
45 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.rbegin()->second) {
46 TimestampIts t_its;
47 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
48 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
49 cpm.payload.management_container.reference_time = t_its;
50}
51
53 * @brief Set the ReferencePositionWithConfidence for a CPM TS
54 *
55 * This function sets the latitude, longitude, and altitude of the CPMs reference position.
56 * If the altitude is not provided, it is set to AltitudeValue::UNAVAILABLE.
57 *
58 * @param cpm CPM to set the ReferencePosition
59 * @param latitude The latitude value position in degree as decimal number.
60 * @param longitude The longitude value in degree as decimal number.
61 * @param altitude The altitude value (above the reference ellipsoid surface) in meter as decimal number (optional).
62 */
63inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
64 const double altitude = AltitudeValue::UNAVAILABLE) {
65 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
66}
70 *
71 * The position is transformed to latitude and longitude by using GeographicLib::UTMUPS
72 * The z-Coordinate is directly used as altitude value
73 * The frame_id of the given utm_position must be set to 'utm_<zone><N/S>'
74 *
75 * @param[out] cpm CPM for which to set the ReferencePosition
76 * @param[in] utm_position geometry_msgs::PointStamped describing the given utm position in meters
77 * @param[in] zone the UTM zone (zero means UPS) of the given position
78 * @param[in] northp hemisphere (true means north, false means south)
79 */
80inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
81 const bool& northp) {
82 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
83}
84
89 *
90 * @param object PerceivedObject to set the ID for
91 * @param id ID to set
92 */
93inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
94 object.object_id.value = id;
95 object.object_id_is_present = true;
96}
97
101
103 * between the reference time of the CPM and the measurement of the object.
104 *
105 * @param object The PerceivedObject to set the measurement delta time for.
106 * @param delta_time The measurement delta time to set in milliseconds. Default value is 0.
107 * @throws std::invalid_argument if the delta_time is out of range.
108 */
109inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
110 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
111 throw std::invalid_argument("MeasurementDeltaTime out of range");
112 } else {
113 object.measurement_delta_time.value = delta_time;
114 }
115}
116
120 * This function sets the value and confidence of a CartesianCoordinateWithConfidence object.
121 * The value is limited to the range defined by CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE
122 * and CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE. The confidence is limited to the range
123 * defined by CoordinateConfidence::MIN and CoordinateConfidence::MAX. If the provided confidence
124 * is out of range, the confidence value is set to CoordinateConfidence::OUT_OF_RANGE.
125 *
126 * @param coordinate The CartesianCoordinateWithConfidence object to be modified.
127 * @param value The value to be set in centimeters.
128 * @param confidence The confidence to be set in centimeters (default: infinity, which will map to CoordinateConfidence::UNAVAILABLE).
129 */
130inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const double value,
131 const double confidence = std::numeric_limits<double>::infinity()) {
132 // limit value range
133 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
134 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
135 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
136 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
137 } else {
138 coordinate.value.value = static_cast<int32_t>(value);
139 }
140
141 // limit confidence range
142 if (confidence == std::numeric_limits<double>::infinity()) {
143 coordinate.confidence.value = CoordinateConfidence::UNAVAILABLE;
144 } else if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
145 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
146 } else {
147 coordinate.confidence.value = static_cast<uint16_t>(confidence);
148 }
149}
150
152 * @brief Sets the position of a perceived object (relative to the CPM's reference position).
153 *
154 * This function sets the position of a perceived object using the provided coordinates and confidence values.
155 *
156 * @param object The PerceivedObject to set the position for.
157 * @param point The gm::Point representing the coordinates of the object in meters.
158 * @param x_std The standard deviation in meters for the x-coordinate (default: infinity).
159 * @param y_std The standard deviation in meters for the y-coordinate (default: infinity).
160 * @param z_std The standard deviation in meters for the z-coordinate (default: infinity).
161 */
162inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
163 const double x_std = std::numeric_limits<double>::infinity(),
164 const double y_std = std::numeric_limits<double>::infinity(),
165 const double z_std = std::numeric_limits<double>::infinity()) {
166 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
167 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
168 if (point.z != 0.0) {
169 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
170 object.position.z_coordinate_is_present = true;
171 }
172}
173
177 * This function sets the position of a perceived object using the provided UTM position and the CPM's reference position.
178 * It also allows specifying confidence values for the x, y, and z coordinates.
179 *
180 * @param cpm The CPM to get the reference position from.
181 * @param object The PerceivedObject to set the position for.
182 * @param utm_position gm::PointStamped representing the UTM position of the object including the frame_id (utm_<zone><N/S>).
183 * @param x_confidence The standard deviation in meters for the x coordinate (default: CoordinateConfidence::UNAVAILABLE).
184 * @param y_confidence The standard deviation in meters for the y coordinate (default: CoordinateConfidence::UNAVAILABLE).
185 * @param z_confidence The standard deviation in meters for the z coordinate (default: CoordinateConfidence::UNAVAILABLE).
186 *
187 * @throws std::invalid_argument if the UTM-Position frame_id does not match the reference position frame_id.
188 */
189inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
190 const gm::PointStamped& utm_position,
191 const double x_std = std::numeric_limits<double>::infinity(),
192 const double y_std = std::numeric_limits<double>::infinity(),
193 const double z_std = std::numeric_limits<double>::infinity()) {
194 gm::PointStamped reference_position = getUTMPosition(cpm);
195 if (utm_position.header.frame_id != reference_position.header.frame_id) {
196 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
197 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
198 ")");
199 }
200 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
201 (utm_position.point.x - reference_position.point.x) * 100, x_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
202 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
203 (utm_position.point.y - reference_position.point.y) * 100, y_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
204 if (utm_position.point.z != 0.0) {
205 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
206 (utm_position.point.z - reference_position.point.z) * 100, z_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
207 object.position.z_coordinate_is_present = true;
208 }
209}
219
222inline void setVelocityComponent(VelocityComponent& velocity, const double value,
223 const double confidence = std::numeric_limits<double>::infinity()) {
224 // limit value range
225 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
226 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
227 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
228 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
229 } else {
230 velocity.value.value = static_cast<int16_t>(value);
231 }
233 // limit confidence range
234 if(confidence == std::numeric_limits<double>::infinity()) {
235 velocity.confidence.value = SpeedConfidence::UNAVAILABLE;
236 } else if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
237 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
238 } else {
239 velocity.confidence.value = static_cast<uint8_t>(confidence);
240 }
241}
242
244
250inline void setCartesianAngle(CartesianAngle& angle, const double value,
251 double confidence = std::numeric_limits<double>::infinity()) {
252 // wrap angle to 0..2pi
253 double wrapped_value = fmod(value, 2*M_PI);
254 if (wrapped_value < 0.0) {
255 wrapped_value += 2 * M_PI;
256 }
257 angle.value.value = static_cast<uint16_t>(wrapped_value * 180 / M_PI * 10); // convert to 0.1 degrees
259 confidence *= 180.0 / M_PI * 10.0 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; // convert to 0.1 degrees
260 // limit confidence range
261 if(confidence == std::numeric_limits<double>::infinity() || confidence <= 0.0) {
262 angle.confidence.value = AngleConfidence::UNAVAILABLE;
263 } else if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
264 angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
265 } else {
266 angle.confidence.value = static_cast<uint8_t>(confidence);
267 }
268}
269
273
282inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
283 const double x_std = std::numeric_limits<double>::infinity(),
284 const double y_std = std::numeric_limits<double>::infinity(),
285 const double z_std = std::numeric_limits<double>::infinity()) {
286 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
287 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
288 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
289 if (cartesian_velocity.z != 0.0) {
290 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
291 object.velocity.cartesian_velocity.z_velocity_is_present = true;
292 } else {
293 object.velocity.cartesian_velocity.z_velocity_is_present = false;
294 }
295 object.velocity_is_present = true;
297
312inline void setPolarVelocityOfPerceivedObject(PerceivedObject& object,
313 const double magnitude,
314 const double angle,
315 const double z = 0.0,
316 const double magnitude_std = std::numeric_limits<double>::infinity(),
317 const double angle_std = std::numeric_limits<double>::infinity(),
318 const double z_std = std::numeric_limits<double>::infinity()) {
319 object.velocity.choice = Velocity3dWithConfidence::CHOICE_POLAR_VELOCITY;
320 setSpeed(object.velocity.polar_velocity.velocity_magnitude, magnitude, magnitude_std);
321 setCartesianAngle(object.velocity.polar_velocity.velocity_direction, angle, angle_std);
322 if (z != 0.0) {
323 setVelocityComponent(object.velocity.polar_velocity.z_velocity, z * 100, z_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
324 object.velocity.polar_velocity.z_velocity_is_present = true;
325 } else {
326 object.velocity.polar_velocity.z_velocity_is_present = false;
327 }
328}
329
330/**
331 * @brief Sets the value and confidence of a AccelerationComponent.
332 *
333 * This function sets the value and confidence of a AccelerationComponent object. The value is limited to a specific range,
334 * and the confidence is limited to a specific range as well. If the provided value or confidence is out of range,
335 * it will be set to the corresponding out-of-range value.
336 *
337 * @param acceleration The AccelerationComponent object to set the value and confidence for.
338 * @param value The value to set for the AccelerationComponent in dm/s^2.
339 * @param confidence The confidence to set for the AccelerationComponent in dm/s^2. Default value is infinity, mapping to AccelerationConfidence::UNAVAILABLE.
340 */
341inline void setAccelerationComponent(AccelerationComponent& acceleration, const double value,
342 const double confidence = std::numeric_limits<double>::infinity()) {
343 // limit value range
344 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
345 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
346 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
347 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
348 } else {
349 acceleration.value.value = static_cast<int16_t>(value);
350 }
351
352 // limit confidence range
353 if(confidence == std::numeric_limits<double>::infinity()) {
354 acceleration.confidence.value = AccelerationConfidence::UNAVAILABLE;
355 } else if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
356 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
357 } else {
358 acceleration.confidence.value = static_cast<uint8_t>(confidence);
359 }
360}
361
366
374inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
375 const double x_std = std::numeric_limits<double>::infinity(),
376 const double y_std = std::numeric_limits<double>::infinity(),
377 const double z_std = std::numeric_limits<double>::infinity()) {
378 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
379 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
380 x_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
381 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
382 y_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
383 if (cartesian_acceleration.z != 0.0) {
384 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
385 z_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
386 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
387 }
388 object.acceleration_is_present = true;
389}
390
395 * @param magnitude The magnitude of the acceleration in m/s^2 in the xy plane.
396 * @param angle The angle of the acceleration in radians in the xy plane.
397 * @param z The z component of the acceleration in m/s^2 (default: 0.0).
398 * @param magnitude_std The standard deviation in m/s^2 for the acceleration magnitude (default: infinity).
399 * @param angle_std The standard deviation in radians for the angle (default: infinity).
400 * @param z_std The standard deviation in m/s^2 for the z acceleration component (default: infinity).
401 */
402inline void setPolarAccelerationOfPerceivedObject(PerceivedObject& object,
403 const double magnitude,
404 const double angle,
405 const double z = 0.0,
406 const double magnitude_std = std::numeric_limits<double>::infinity(),
407 const double angle_std = std::numeric_limits<double>::infinity(),
408 const double z_std = std::numeric_limits<double>::infinity()) {
409 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_POLAR_ACCELERATION;
410 setAccelerationMagnitude(object.acceleration.polar_acceleration.acceleration_magnitude, magnitude, magnitude_std);
411 setCartesianAngle(object.acceleration.polar_acceleration.acceleration_direction, angle, angle_std);
412 if (z != 0.0) {
413 setAccelerationComponent(object.acceleration.polar_acceleration.z_acceleration, z * 10,
414 z_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
415 object.acceleration.polar_acceleration.z_acceleration_is_present = true;
416 } else {
417 object.acceleration.polar_acceleration.z_acceleration_is_present = false;
418 }
419 object.acceleration_is_present = true;
420}
421
432inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
433 double yaw_std = std::numeric_limits<double>::infinity()) {
434 // wrap angle to range [0, 360)
435 double yaw_in_degrees = yaw * 180 / M_PI;
436 while (yaw_in_degrees >= 360.0) yaw_in_degrees -= 360.0;
437 while (yaw_in_degrees < 0.0) yaw_in_degrees += 360.0;
438 object.angles.z_angle.value.value = yaw_in_degrees * 10;
439
440 if(yaw_std == std::numeric_limits<double>::infinity()) {
441 object.angles.z_angle.confidence.value = AngleConfidence::UNAVAILABLE;
442 } else {
443 yaw_std *= 180.0 / M_PI;
444 yaw_std *= 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; // convert to 0.1 degrees
445
446 if (yaw_std > AngleConfidence::MAX || yaw_std < AngleConfidence::MIN) {
447 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
448 } else {
449 object.angles.z_angle.confidence.value = static_cast<uint8_t>(yaw_std);
450 }
451 }
452 object.angles_is_present = true;
453}
454
457
466inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
467 double yaw_rate_std = std::numeric_limits<double>::infinity()) {
468 double yaw_rate_in_degrees = yaw_rate * 180.0 / M_PI;
469 // limit value range
470 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
471 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
472 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
473 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
474 }
475
476 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
477
478 if(yaw_rate_std == std::numeric_limits<double>::infinity()) {
479 object.z_angular_velocity.confidence.value = AngularSpeedConfidence::UNAVAILABLE;
480 } else {
481 yaw_rate_std *= 180.0 / M_PI;
482 yaw_rate_std *= etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; // convert to degrees/s
483 // How stupid is this?!
484 static const std::map<double, uint8_t> confidence_map = {
485 {1.0, AngularSpeedConfidence::DEG_SEC_01},
486 {2.0, AngularSpeedConfidence::DEG_SEC_02},
487 {5.0, AngularSpeedConfidence::DEG_SEC_05},
488 {10.0, AngularSpeedConfidence::DEG_SEC_10},
489 {20.0, AngularSpeedConfidence::DEG_SEC_20},
490 {50.0, AngularSpeedConfidence::DEG_SEC_50},
491 {std::numeric_limits<double>::infinity(), AngularSpeedConfidence::OUT_OF_RANGE},
492 };
493 for(const auto& [thresh, conf_val] : confidence_map) {
494 if (yaw_rate_std <= thresh) {
495 object.z_angular_velocity.confidence.value = conf_val;
496 break;
497 }
498 }
499 }
500
501 object.z_angular_velocity_is_present = true;
502}
503
518inline void setObjectDimension(ObjectDimension& dimension, const double value,
519 const double confidence = std::numeric_limits<double>::infinity()) {
520 // limit value range
521 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
522 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
523 } else {
524 dimension.value.value = static_cast<uint16_t>(value);
525 }
526
527 // limit confidence range
528 if (confidence == std::numeric_limits<double>::infinity()) {
529 dimension.confidence.value = ObjectDimensionConfidence::UNAVAILABLE;
530 } else if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
531 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
532 } else {
533 dimension.confidence.value = static_cast<uint8_t>(confidence);
534 }
535
536}
537
548inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
549 const double std = std::numeric_limits<double>::infinity()) {
550 setObjectDimension(object.object_dimension_x, value * 10, std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
551 object.object_dimension_x_is_present = true;
552}
553
564inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
565 const double std = std::numeric_limits<double>::infinity()) {
566 setObjectDimension(object.object_dimension_y, value * 10, std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
567 object.object_dimension_y_is_present = true;
568}
569
580inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
581 const double std = std::numeric_limits<double>::infinity()) {
582 setObjectDimension(object.object_dimension_z, value * 10, std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
583 object.object_dimension_z_is_present = true;
584}
585
597inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
598 const double x_std = std::numeric_limits<double>::infinity(),
599 const double y_std = std::numeric_limits<double>::infinity(),
600 const double z_std = std::numeric_limits<double>::infinity()) {
601 setXDimensionOfPerceivedObject(object, dimensions.x, x_std);
602 setYDimensionOfPerceivedObject(object, dimensions.y, y_std);
603 setZDimensionOfPerceivedObject(object, dimensions.z, z_std);
604}
605
615inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
616 setPositionOfPerceivedObject(object, point);
618}
619
632inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
633 const gm::PointStamped& point, const int16_t delta_time = 0) {
634 setUTMPositionOfPerceivedObject(cpm, object, point);
636}
637
647inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
648 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
649 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
650}
651
665inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
666 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
667 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
668 container.container_data_perceived_object_container.number_of_perceived_objects.value =
669 container.container_data_perceived_object_container.perceived_objects.array.size();
670 } else {
671 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
672 }
673}
674
687inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
688 // check for maximum number of containers
689 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
690 cpm.payload.cpm_containers.value.array.push_back(container);
691 } else {
692 throw std::invalid_argument("Maximum number of CPM-Containers reached");
693 }
694}
695
704inline void setWGSRefPosConfidence(CollectivePerceptionMessage& cpm, const std::array<double, 4>& covariance_matrix) {
705 setWGSPosConfidenceEllipse(cpm.payload.management_container.reference_position.position_confidence_ellipse,
706 covariance_matrix);
707}
708
717inline void initSensorInformationContainer(WrappedCpmContainer& container) {
718 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_SENSOR_INFORMATION_CONTAINER;
719 container.container_data_sensor_information_container.array = std::vector<SensorInformation>();
720}
721
732inline void setSensorID(SensorInformation& sensor_information, const uint8_t sensor_id = 0) {
733 throwIfOutOfRange(sensor_id, Identifier1B::MIN, Identifier1B::MAX, "SensorID");
734 sensor_information.sensor_id.value = sensor_id;
735}
736
747inline void setSensorType(SensorInformation& sensor_information, const uint8_t sensor_type = SensorType::UNDEFINED) {
748 throwIfOutOfRange(sensor_type, SensorType::MIN, SensorType::MAX, "SensorType");
749 sensor_information.sensor_type.value = sensor_type;
750}
751
770inline void addSensorInformationToContainer(WrappedCpmContainer& container, const SensorInformation& sensor_information) {
771 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_SENSOR_INFORMATION_CONTAINER) {
772 // check for maximum number of SensorInformation entries
773 if (container.container_data_sensor_information_container.array.size() < SensorInformationContainer::MAX_SIZE ) {
774 throwIfOutOfRange(sensor_information.sensor_id.value, Identifier1B::MIN, Identifier1B::MAX, "SensorID");
775 throwIfOutOfRange(sensor_information.sensor_type.value, SensorType::MIN, SensorType::MAX, "SensorType");
776 container.container_data_sensor_information_container.array.push_back(sensor_information);
777 } else {
778 throw std::invalid_argument("Maximum number of entries SensorInformationContainers reached");
779 }
780 } else {
781 throw std::invalid_argument("Container is not a SensorInformationContainer");
782 }
783}
784
799inline void addSensorInformationContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
800 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_SENSOR_INFORMATION_CONTAINER) {
801 throwIfOutOfRange(container.container_data_sensor_information_container.array.size(),
802 SensorInformationContainer::MIN_SIZE, SensorInformationContainer::MAX_SIZE, "SensorInformationContainer array size"
803 );
804 addContainerToCPM(cpm, container);
805 } else {
806 throw std::invalid_argument("Container is not a SensorInformationContainer");
807 }
808}
809
810} // 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.