etsi_its_messages v3.1.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
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
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}
90
91
93
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
109 * @brief Set the ID of a PerceivedObject
110 *
111 * Sets the object_id of the PerceivedObject to the given ID.
112 *
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
121
123 *
124 * This function sets the measurement delta time of a PerceivedObject.
125 * The measurement delta time represents the time difference
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
140
141 * @brief Sets the value and confidence of a CartesianCoordinateWithConfidence object.
142 *
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
174/**
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
198
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 ")");
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}
233
238 * and the confidence is limited to a specific range as well. If the provided value or confidence is out of range,
239 * it will be set to the corresponding out-of-range value.
240 *
241 * @param velocity The VelocityComponent object to set the value and confidence for.
242 * @param value The value to set for the VelocityComponent in cm/s.
243 * @param confidence The confidence to set for the VelocityComponent in cm/s. Default value is infinity, mapping to SpeedConfidence::UNAVAILABLE.
244 */
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 }
255
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
269 * This function sets the velocity of a perceived object using the provided Cartesian velocity components.
270 * Optionally, confidence values can be specified for each velocity component.
271 *
272 * @param object The perceived object for which the velocity is being set.
273 * @param cartesian_velocity The Cartesian velocity components (x, y, z) of the object (in m/s).
274 * @param x_std The standard deviation in m/s for the x velocity component (default: infinity).
275 * @param y_std The standard deviation in m/s for the y velocity component (default: infinity).
276 * @param z_std The standard deviation in m/s for the z velocity component (default: infinity).
277 */
278inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
279 const double x_std = std::numeric_limits<double>::infinity(),
280 const double y_std = std::numeric_limits<double>::infinity(),
281 const double z_std = std::numeric_limits<double>::infinity()) {
282 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
283 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
284 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
285 if (cartesian_velocity.z != 0.0) {
286 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_std * 100 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
287 object.velocity.cartesian_velocity.z_velocity_is_present = true;
289 object.velocity_is_present = true;
290}
291
292
293 * @brief Sets the value and confidence of a AccelerationComponent.
294 *
295 * This function sets the value and confidence of a AccelerationComponent object. The value is limited to a specific range,
296 * and the confidence is limited to a specific range as well. If the provided value or confidence is out of range,
297 * it will be set to the corresponding out-of-range value.
298 *
299 * @param acceleration The AccelerationComponent object to set the value and confidence for.
300 * @param value The value to set for the AccelerationComponent in dm/s^2.
301 * @param confidence The confidence to set for the AccelerationComponent in dm/s^2. Default value is infinity, mapping to AccelerationConfidence::UNAVAILABLE.
302 */
303inline void setAccelerationComponent(AccelerationComponent& acceleration, const double value,
304 const double confidence = std::numeric_limits<double>::infinity()) {
305 // limit value range
306 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
307 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
308 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
309 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
310 } else {
311 acceleration.value.value = static_cast<int16_t>(value);
312 }
313
314 // limit confidence range
315 if(confidence == std::numeric_limits<double>::infinity()) {
316 acceleration.confidence.value = AccelerationConfidence::UNAVAILABLE;
317 } else if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
318 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
319 } else {
320 acceleration.confidence.value = static_cast<uint8_t>(confidence);
321 }
322}
323
325 * @brief Sets the acceleration of a perceived object.
326 *
327 * This function sets the acceleration of a perceived object using the provided Cartesian acceleration components.
328 * Optionally, confidence values can be specified for each acceleration component.
329 *
330 * @param object The perceived object for which the acceleration is being set.
331 * @param cartesian_acceleration The Cartesian acceleration components (x, y, z) of the object (in m/s^2).
332 * @param x_std The standard deviation in m/s^2 for the x acceleration component (default: infinity).
333 * @param y_std The standard deviation in m/s^2 for the y acceleration component (default: infinity).
334 * @param z_std The standard deviation in m/s^2 for the z acceleration component (default: infinity).
335 */
336inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
337 const double x_std = std::numeric_limits<double>::infinity(),
338 const double y_std = std::numeric_limits<double>::infinity(),
339 const double z_std = std::numeric_limits<double>::infinity()) {
340 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
341 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
342 x_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
343 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
344 y_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
345 if (cartesian_acceleration.z != 0.0) {
346 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
347 z_std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
348 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
349 }
350 object.acceleration_is_present = true;
351}
352
357 * The function also allows specifying the confidence level of the yaw angle.
358 *
359 * @param object The PerceivedObject to set the yaw angle for.
360 * @param yaw The yaw angle in radians.
361 * @param yaw_std The standard deviation of the yaw angle in radians (optional, default is Infinity).
362 */
363inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
364 double yaw_std = std::numeric_limits<double>::infinity()) {
365 // wrap angle to range [0, 360)
366 double yaw_in_degrees = yaw * 180 / M_PI;
367 while (yaw_in_degrees >= 360.0) yaw_in_degrees -= 360.0;
368 while (yaw_in_degrees < 0.0) yaw_in_degrees += 360.0;
369 object.angles.z_angle.value.value = yaw_in_degrees * 10;
370
371 if(yaw_std == std::numeric_limits<double>::infinity()) {
372 object.angles.z_angle.confidence.value = AngleConfidence::UNAVAILABLE;
373 } else {
374 yaw_std *= 180.0 / M_PI;
375 yaw_std *= 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; // convert to 0.1 degrees
377 if (yaw_std > AngleConfidence::MAX || yaw_std < AngleConfidence::MIN) {
378 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
379 } else {
380 object.angles.z_angle.confidence.value = static_cast<uint8_t>(yaw_std);
381 }
382 }
383 object.angles_is_present = true;
385
397inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
398 double yaw_rate_std = std::numeric_limits<double>::infinity()) {
399 double yaw_rate_in_degrees = yaw_rate * 180.0 / M_PI;
400 // limit value range
401 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
402 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
403 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
404 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
405 }
406
407 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
408
409 if(yaw_rate_std == std::numeric_limits<double>::infinity()) {
410 object.z_angular_velocity.confidence.value = AngularSpeedConfidence::UNAVAILABLE;
411 } else {
412 yaw_rate_std *= 180.0 / M_PI;
413 yaw_rate_std *= etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; // convert to degrees/s
414 // How stupid is this?!
415 static const std::map<double, uint8_t> confidence_map = {
416 {1.0, AngularSpeedConfidence::DEG_SEC_01},
417 {2.0, AngularSpeedConfidence::DEG_SEC_02},
418 {5.0, AngularSpeedConfidence::DEG_SEC_05},
419 {10.0, AngularSpeedConfidence::DEG_SEC_10},
420 {20.0, AngularSpeedConfidence::DEG_SEC_20},
421 {50.0, AngularSpeedConfidence::DEG_SEC_50},
422 {std::numeric_limits<double>::infinity(), AngularSpeedConfidence::OUT_OF_RANGE},
423 };
424 for(const auto& [thresh, conf_val] : confidence_map) {
425 if (yaw_rate_std <= thresh) {
426 object.z_angular_velocity.confidence.value = conf_val;
427 break;
428 }
429 }
430 }
431
432 object.z_angular_velocity_is_present = true;
434
437
448 */
449inline void setObjectDimension(ObjectDimension& dimension, const double value,
450 const double confidence = std::numeric_limits<double>::infinity()) {
451 // limit value range
452 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
453 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
454 } else {
455 dimension.value.value = static_cast<uint16_t>(value);
456 }
457
458 // limit confidence range
459 if (confidence == std::numeric_limits<double>::infinity()) {
460 dimension.confidence.value = ObjectDimensionConfidence::UNAVAILABLE;
461 } else if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
462 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
463 } else {
464 dimension.confidence.value = static_cast<uint8_t>(confidence);
465 }
466
467}
468
475 * @param object The `PerceivedObject` to modify.
476 * @param value The value to set as the x-dimension in meters.
477 * @param std The standard deviation of the x-dimension value in meters (optional, default is infinity).
478 */
479inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
480 const double std = std::numeric_limits<double>::infinity()) {
481 setObjectDimension(object.object_dimension_x, value * 10, std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
482 object.object_dimension_x_is_present = true;
483}
484
495inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
496 const double std = std::numeric_limits<double>::infinity()) {
497 setObjectDimension(object.object_dimension_y, value * 10, std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
498 object.object_dimension_y_is_present = true;
499}
500
508 * @param value The value to set as the z-dimension in meters.
509 * @param std The standard deviation of the z-dimension value in meters (optional, default is infinity).
510 */
511inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
512 const double std = std::numeric_limits<double>::infinity()) {
513 setObjectDimension(object.object_dimension_z, value * 10, std * 10 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
514 object.object_dimension_z_is_present = true;
515}
516
524
528inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
529 const double x_std = std::numeric_limits<double>::infinity(),
530 const double y_std = std::numeric_limits<double>::infinity(),
531 const double z_std = std::numeric_limits<double>::infinity()) {
532 setXDimensionOfPerceivedObject(object, dimensions.x, x_std);
533 setYDimensionOfPerceivedObject(object, dimensions.y, y_std);
534 setZDimensionOfPerceivedObject(object, dimensions.z, z_std);
536
546inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
547 setPositionOfPerceivedObject(object, point);
548 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
549}
550
557
563inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
564 const gm::PointStamped& point, const int16_t delta_time = 0) {
565 setUTMPositionOfPerceivedObject(cpm, object, point);
566 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
567}
568
569/**
570 * @brief Initializes a WrappedCpmContainer as a PerceivedObjectContainer with the given number of objects.
571 *
572 * This function sets the container ID to CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER and initializes
573 * the number of perceived objects in the container to the specified value.
574 *
575 * @param container A reference to the WrappedCpmContainer to be initialized as a PerceivedObjectContainer.
576 * @param n_objects The number of perceived objects to initialize in the container. Default is 0.
577 */
578inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
579 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
580 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
581}
582
596inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
597 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
598 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
599 container.container_data_perceived_object_container.number_of_perceived_objects.value =
600 container.container_data_perceived_object_container.perceived_objects.array.size();
601 } else {
602 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
603 }
604}
605
606
618inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
619 // check for maximum number of containers
620 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
621 cpm.payload.cpm_containers.value.array.push_back(container);
622 } else {
623 throw std::invalid_argument("Maximum number of CPM-Containers reached");
624 }
625}
626
635inline void setWGSRefPosConfidence(CollectivePerceptionMessage& cpm, const std::array<double, 4>& covariance_matrix) {
636 setWGSPosConfidenceEllipse(cpm.payload.management_container.reference_position.position_confidence_ellipse,
637 covariance_matrix);
638}
639
640} // 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 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 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 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 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 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 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.
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 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 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.