36namespace etsi_its_cpm_ts_msgs::access {
49inline void setItsPduHeader(CollectivePerceptionMessage& cpm,
const uint32_t station_id,
50 const uint8_t protocol_version = 0) {
51 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
66 CollectivePerceptionMessage& cpm,
const uint64_t unix_nanosecs,
67 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
70 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX,
"TimestampIts");
71 cpm.payload.management_container.reference_time = t_its;
85inline void setReferencePosition(CollectivePerceptionMessage& cpm,
const double latitude,
const double longitude,
86 const double altitude = AltitudeValue::UNAVAILABLE) {
87 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
102inline void setFromUTMPosition(CollectivePerceptionMessage& cpm,
const gm::PointStamped& utm_position,
const int& zone,
103 const bool& northp) {
104 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
116 object.object_id.value = id;
117 object.object_id_is_present =
true;
132 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
133 throw std::invalid_argument(
"MeasurementDeltaTime out of range");
135 object.measurement_delta_time.value = delta_time;
153 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
155 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
156 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
157 }
else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
158 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
160 coordinate.value.value = value;
164 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
165 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
167 coordinate.confidence.value = confidence;
183 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
184 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
185 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
188 if (point.z != 0.0) {
190 object.position.z_coordinate_is_present =
true;
209inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject&
object,
210 const gm::PointStamped& utm_position,
211 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
212 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
213 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
214 gm::PointStamped reference_position = getUTMPosition(cpm);
215 if (utm_position.header.frame_id != reference_position.header.frame_id) {
216 throw std::invalid_argument(
"UTM-Position frame_id (" + utm_position.header.frame_id +
217 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
220 setCartesianCoordinateWithConfidence(
object.position.x_coordinate,
221 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
223 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
224 if (utm_position.point.z != 0.0) {
226 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
227 object.position.z_coordinate_is_present =
true;
242inline void setVelocityComponent(VelocityComponent& velocity,
const int16_t value,
243 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
245 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
246 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
247 }
else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
248 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
250 velocity.value.value = value;
254 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
255 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
257 velocity.confidence.value = confidence;
274 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
275 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
276 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
277 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
278 setVelocityComponent(
object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
279 setVelocityComponent(
object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
280 if (cartesian_velocity.z != 0.0) {
281 setVelocityComponent(
object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
282 object.velocity.cartesian_velocity.z_velocity_is_present =
true;
284 object.velocity_is_present =
true;
299 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
301 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
302 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
303 }
else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
304 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
306 acceleration.value.value = value;
310 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
311 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
313 acceleration.confidence.value = confidence;
330 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
331 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
332 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
333 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
338 if (cartesian_acceleration.z != 0.0) {
341 object.acceleration.cartesian_acceleration.z_acceleration_is_present =
true;
343 object.acceleration_is_present =
true;
357 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
359 double yaw_in_degrees = yaw * 180 / M_PI + 180;
360 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
361 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
362 object.angles.z_angle.value.value = yaw_in_degrees * 10;
364 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
365 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
367 object.angles.z_angle.confidence.value = confidence;
369 object.angles_is_present =
true;
383inline void setYawRateOfPerceivedObject(PerceivedObject&
object,
const double yaw_rate,
384 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
385 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
386 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
388 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
389 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
390 }
else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
391 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
394 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
395 object.z_angular_velocity.confidence.value = confidence;
396 object.z_angular_velocity_is_present =
true;
414 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
416 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
417 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
419 dimension.value.value = value;
423 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
424 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
426 dimension.confidence.value = confidence;
441 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
442 setObjectDimension(
object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
443 object.object_dimension_x_is_present =
true;
457 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
458 setObjectDimension(
object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
459 object.object_dimension_y_is_present =
true;
473 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
474 setObjectDimension(
object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
475 object.object_dimension_z_is_present =
true;
490 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
491 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
492 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
507inline void initPerceivedObject(PerceivedObject&
object,
const gm::Point& point,
const int16_t delta_time = 0) {
508 setPositionOfPerceivedObject(
object, point);
509 setMeasurementDeltaTimeOfPerceivedObject(
object, delta_time);
524inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject&
object,
525 const gm::PointStamped& point,
const int16_t delta_time = 0) {
526 setUTMPositionOfPerceivedObject(cpm,
object, point);
527 setMeasurementDeltaTimeOfPerceivedObject(
object, delta_time);
540 container.container_id.value = CpmContainerId::PERCEIVED_OBJECT_CONTAINER;
541 container.container_data.choice = container.container_id;
542 container.container_data.perceived_object_container.number_of_perceived_objects.value = n_objects;
559 if (container.container_id.value == CpmContainerId::PERCEIVED_OBJECT_CONTAINER &&
560 container.container_data.choice.value == CpmContainerId::PERCEIVED_OBJECT_CONTAINER) {
561 container.container_data.perceived_object_container.perceived_objects.array.push_back(perceived_object);
562 container.container_data.perceived_object_container.number_of_perceived_objects.value =
563 container.container_data.perceived_object_container.perceived_objects.array.size();
565 throw std::invalid_argument(
"Container is not a PerceivedObjectContainer");
581inline void addContainerToCPM(CollectivePerceptionMessage& cpm,
const WrappedCpmContainer& container) {
583 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
584 cpm.payload.cpm_containers.value.array.push_back(container);
586 throw std::invalid_argument(
"Maximum number of CPM-Containers reached");
void setTimestampITS(TimestampIts ×tamp_its, const uint64_t unix_nanosecs, const uint16_t n_leap_seconds=etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end() ->second)
Set the TimestampITS 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 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 setFromUTMPosition(T &reference_position, const gm::PointStamped &utm_position, const int zone, const bool northp)
Set the ReferencePosition from a given UTM-Position.
Setter functions for the ETSI ITS Common Data Dictionary (CDD) v2.1.1.
File containing constants that are used in the context of ETIS ITS Messages.
void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence &coordinate, const int32_t value, const uint16_t confidence=CoordinateConfidence::UNAVAILABLE)
Sets the value and confidence of a CartesianCoordinateWithConfidence object.
void setDimensionsOfPerceivedObject(PerceivedObject &object, const gm::Vector3 &dimensions, const uint8_t x_confidence=ObjectDimensionConfidence::UNAVAILABLE, const uint8_t y_confidence=ObjectDimensionConfidence::UNAVAILABLE, const uint8_t z_confidence=ObjectDimensionConfidence::UNAVAILABLE)
Sets all dimensions of a perceived object.
void setVelocityComponent(VelocityComponent &velocity, const int16_t value, const uint8_t confidence=SpeedConfidence::UNAVAILABLE)
Sets the value and confidence of a VelocityComponent.
void initPerceivedObjectContainer(WrappedCpmContainer &container, const uint8_t n_objects=0)
Initializes a WrappedCpmContainer as a PerceivedObjectContainer with the given number of objects.
void setYDimensionOfPerceivedObject(PerceivedObject &object, const double value, const uint8_t confidence=ObjectDimensionConfidence::UNAVAILABLE)
Sets the y-dimension of a perceived object.
void addPerceivedObjectToContainer(WrappedCpmContainer &container, const PerceivedObject &perceived_object)
Adds a PerceivedObject to the PerceivedObjectContainer / WrappedCpmContainer.
void setObjectDimension(ObjectDimension &dimension, const uint16_t value, const uint8_t confidence=ObjectDimensionConfidence::UNAVAILABLE)
Sets the object dimension with the given value and confidence.
void addContainerToCPM(CollectivePerceptionMessage &cpm, const WrappedCpmContainer &container)
Adds a container to the Collective Perception Message (CPM).
void setIdOfPerceivedObject(PerceivedObject &object, const uint16_t id)
Set the ID of a PerceivedObject.
void setReferenceTime(CollectivePerceptionMessage &cpm, const uint64_t unix_nanosecs, const uint16_t n_leap_seconds=etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end() ->second)
Sets the reference time in a CPM.
void setYawOfPerceivedObject(PerceivedObject &object, const double yaw, const uint8_t confidence=AngleConfidence::UNAVAILABLE)
Sets the yaw angle of a perceived object.
void setXDimensionOfPerceivedObject(PerceivedObject &object, const double value, const uint8_t confidence=ObjectDimensionConfidence::UNAVAILABLE)
Sets the x-dimension of a perceived object.
void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject &object, const int16_t delta_time=0)
Sets the measurement delta time of a PerceivedObject.
void setVelocityOfPerceivedObject(PerceivedObject &object, const gm::Vector3 &cartesian_velocity, const uint8_t x_confidence=SpeedConfidence::UNAVAILABLE, const uint8_t y_confidence=SpeedConfidence::UNAVAILABLE, const uint8_t z_confidence=SpeedConfidence::UNAVAILABLE)
void setAccelerationOfPerceivedObject(PerceivedObject &object, const gm::Vector3 &cartesian_acceleration, const uint8_t x_confidence=AccelerationConfidence::UNAVAILABLE, const uint8_t y_confidence=AccelerationConfidence::UNAVAILABLE, const uint8_t z_confidence=AccelerationConfidence::UNAVAILABLE)
Sets the acceleration of a perceived object.
void setPositionOfPerceivedObject(PerceivedObject &object, const gm::Point &point, const uint16_t x_confidence=CoordinateConfidence::UNAVAILABLE, const uint16_t y_confidence=CoordinateConfidence::UNAVAILABLE, const uint16_t z_confidence=CoordinateConfidence::UNAVAILABLE)
Sets the position of a perceived object (relative to the CPM's reference position).
void setZDimensionOfPerceivedObject(PerceivedObject &object, const double value, const uint8_t confidence=ObjectDimensionConfidence::UNAVAILABLE)
Sets the z-dimension of a perceived object.
void setAccelerationComponent(AccelerationComponent &acceleration, const int16_t value, const uint8_t confidence=AccelerationConfidence::UNAVAILABLE)
Sets the value and confidence of a AccelerationComponent.