etsi_its_messages 2.4.0
Loading...
Searching...
No Matches
cpm_ts_setters.h File Reference

Setter functions for the ETSI ITS CPM (TS) More...

Go to the source code of this file.

Functions

template<typename T1 , typename T2 >
void etsi_its_cpm_ts_msgs::access::throwIfOutOfRange (const T1 &val, const T2 &min, const T2 &max, const std::string val_desc)
 
uint16_t etsi_its_cpm_ts_msgs::access::etsi_its_msgs::getLeapSecondInsertionsSince2004 (const uint64_t unix_seconds)
 Get the leap second insertions since 2004 for given unix seconds.
 
void etsi_its_cpm_ts_msgs::access::setTimestampITS (TimestampIts &timestamp_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 etsi_its_cpm_ts_msgs::access::setLatitude (Latitude &latitude, const double deg)
 Set the Latitude object.
 
void etsi_its_cpm_ts_msgs::access::setLongitude (Longitude &longitude, const double deg)
 Set the Longitude object.
 
void etsi_its_cpm_ts_msgs::access::setAltitudeValue (AltitudeValue &altitude, const double value)
 Set the AltitudeValue object.
 
void etsi_its_cpm_ts_msgs::access::setAltitude (Altitude &altitude, const double value)
 Set the Altitude object.
 
void etsi_its_cpm_ts_msgs::access::setSpeedValue (SpeedValue &speed, const double value)
 Set the SpeedValue object.
 
void etsi_its_cpm_ts_msgs::access::setSpeed (Speed &speed, const double value)
 Set the Speed object.
 
template<typename T >
void etsi_its_cpm_ts_msgs::access::setReferencePosition (T &ref_position, const double latitude, const double longitude, const double altitude=AltitudeValue::UNAVAILABLE)
 Sets the reference position in the given ReferencePostion object.
 
template<typename T >
void etsi_its_cpm_ts_msgs::access::setFromUTMPosition (T &reference_position, const gm::PointStamped &utm_position, const int zone, const bool northp)
 Set the ReferencePosition from a given UTM-Position.
 
template<typename T >
void etsi_its_cpm_ts_msgs::access::setBitString (T &bitstring, const std::vector< bool > &bits)
 Set a Bit String by a vector of bools.
 
void etsi_its_cpm_ts_msgs::access::setStationId (StationId &station_id, const uint32_t id_value)
 Set the Station Id object.
 
void etsi_its_cpm_ts_msgs::access::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 etsi_its_cpm_ts_msgs::access::setStationType (TrafficParticipantType &station_type, const uint8_t value)
 Set the Station Type.
 
void etsi_its_cpm_ts_msgs::access::setLongitudinalAccelerationValue (AccelerationValue &accel, const double value)
 Set the LongitudinalAccelerationValue object.
 
void etsi_its_cpm_ts_msgs::access::setLongitudinalAcceleration (AccelerationComponent &accel, const double value)
 Set the LongitudinalAcceleration object.
 
void etsi_its_cpm_ts_msgs::access::setLateralAccelerationValue (AccelerationValue &accel, const double value)
 Set the LateralAccelerationValue object.
 
void etsi_its_cpm_ts_msgs::access::setLateralAcceleration (AccelerationComponent &accel, const double value)
 Set the LateralAcceleration object.
 
void etsi_its_cpm_ts_msgs::access::setItsPduHeader (CollectivePerceptionMessage &cpm, const uint32_t station_id, const uint8_t protocol_version=0)
 Sets the ITS PDU header of a CPM.
 
void etsi_its_cpm_ts_msgs::access::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 etsi_its_cpm_ts_msgs::access::setReferencePosition (CollectivePerceptionMessage &cpm, const double latitude, const double longitude, const double altitude=AltitudeValue::UNAVAILABLE)
 Set the ReferencePositionWithConfidence for a CPM TS.
 
void etsi_its_cpm_ts_msgs::access::setFromUTMPosition (CollectivePerceptionMessage &cpm, const gm::PointStamped &utm_position, const int &zone, const bool &northp)
 Set the ReferencePosition of a CPM from a given UTM-Position.
 
void etsi_its_cpm_ts_msgs::access::setIdOfPerceivedObject (PerceivedObject &object, const uint16_t id)
 Set the ID of a PerceivedObject.
 
void etsi_its_cpm_ts_msgs::access::setMeasurementDeltaTimeOfPerceivedObject (PerceivedObject &object, const int16_t delta_time=0)
 Sets the measurement delta time of a PerceivedObject.
 
void etsi_its_cpm_ts_msgs::access::setCartesianCoordinateWithConfidence (CartesianCoordinateWithConfidence &coordinate, const int32_t value, const uint16_t confidence=CoordinateConfidence::UNAVAILABLE)
 Sets the value and confidence of a CartesianCoordinateWithConfidence object.
 
void etsi_its_cpm_ts_msgs::access::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 etsi_its_cpm_ts_msgs::access::setUTMPositionOfPerceivedObject (CollectivePerceptionMessage &cpm, PerceivedObject &object, const gm::PointStamped &utm_position, 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 based on a UTM position.
 
void etsi_its_cpm_ts_msgs::access::setVelocityComponent (VelocityComponent &velocity, const int16_t value, const uint8_t confidence=SpeedConfidence::UNAVAILABLE)
 Sets the value and confidence of a VelocityComponent.
 
void etsi_its_cpm_ts_msgs::access::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 etsi_its_cpm_ts_msgs::access::setAccelerationComponent (AccelerationComponent &acceleration, const int16_t value, const uint8_t confidence=AccelerationConfidence::UNAVAILABLE)
 Sets the value and confidence of a AccelerationComponent.
 
void etsi_its_cpm_ts_msgs::access::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 etsi_its_cpm_ts_msgs::access::setYawOfPerceivedObject (PerceivedObject &object, const double yaw, const uint8_t confidence=AngleConfidence::UNAVAILABLE)
 Sets the yaw angle of a perceived object.
 
void etsi_its_cpm_ts_msgs::access::setYawRateOfPerceivedObject (PerceivedObject &object, const double yaw_rate, const uint8_t confidence=AngularSpeedConfidence::UNAVAILABLE)
 Sets the yaw rate of a perceived object.
 
void etsi_its_cpm_ts_msgs::access::setObjectDimension (ObjectDimension &dimension, const uint16_t value, const uint8_t confidence=ObjectDimensionConfidence::UNAVAILABLE)
 Sets the object dimension with the given value and confidence.
 
void etsi_its_cpm_ts_msgs::access::setXDimensionOfPerceivedObject (PerceivedObject &object, const double value, const uint8_t confidence=ObjectDimensionConfidence::UNAVAILABLE)
 Sets the x-dimension of a perceived object.
 
void etsi_its_cpm_ts_msgs::access::setYDimensionOfPerceivedObject (PerceivedObject &object, const double value, const uint8_t confidence=ObjectDimensionConfidence::UNAVAILABLE)
 Sets the y-dimension of a perceived object.
 
void etsi_its_cpm_ts_msgs::access::setZDimensionOfPerceivedObject (PerceivedObject &object, const double value, const uint8_t confidence=ObjectDimensionConfidence::UNAVAILABLE)
 Sets the z-dimension of a perceived object.
 
void etsi_its_cpm_ts_msgs::access::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 etsi_its_cpm_ts_msgs::access::initPerceivedObject (PerceivedObject &object, const gm::Point &point, const int16_t delta_time=0)
 Initializes a PerceivedObject with the given point and delta time.
 
void etsi_its_cpm_ts_msgs::access::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 etsi_its_cpm_ts_msgs::access::initPerceivedObjectContainer (WrappedCpmContainer &container, const uint8_t n_objects=0)
 Initializes a WrappedCpmContainer as a PerceivedObjectContainer with the given number of objects.
 
void etsi_its_cpm_ts_msgs::access::addPerceivedObjectToContainer (WrappedCpmContainer &container, const PerceivedObject &perceived_object)
 Adds a PerceivedObject to the PerceivedObjectContainer / WrappedCpmContainer.
 
void etsi_its_cpm_ts_msgs::access::addContainerToCPM (CollectivePerceptionMessage &cpm, const WrappedCpmContainer &container)
 Adds a container to the Collective Perception Message (CPM).
 

Detailed Description

Setter functions for the ETSI ITS CPM (TS)

Definition in file cpm_ts_setters.h.

Function Documentation

◆ addContainerToCPM()

void etsi_its_cpm_ts_msgs::access::addContainerToCPM ( CollectivePerceptionMessage & cpm,
const WrappedCpmContainer & container )
inline

Adds a container to the Collective Perception Message (CPM).

This function adds a WrappedCpmContainer to the CPM's payload. It first checks if the current number of containers is less than the maximum allowed. If so, it appends the container to the array. Otherwise, it throws an exception.

Parameters
cpmThe Collective Perception Message to which the container will be added.
containerThe WrappedCpmContainer to be added to the CPM.
Exceptions
std::invalid_argumentif the maximum number of CPM-Containers is reached.

Definition at line 715 of file cpm_ts_setters.h.

◆ addPerceivedObjectToContainer()

void etsi_its_cpm_ts_msgs::access::addPerceivedObjectToContainer ( WrappedCpmContainer & container,
const PerceivedObject & perceived_object )
inline

Adds a PerceivedObject to the PerceivedObjectContainer / WrappedCpmContainer.

This function checks if the provided container is a PerceivedObjectContainer. If it is, the function adds the given PerceivedObject to the container's perceived_objects array and updates the number_of_perceived_objects value. If the container is not a PerceivedObjectContainer, the function throws an std::invalid_argument exception.

Parameters
containerThe WrappedCpmContainer to which the PerceivedObject will be added.
perceived_objectThe PerceivedObject to add to the container.
Exceptions
std::invalid_argumentif the container is not a PerceivedObjectContainer.

Definition at line 693 of file cpm_ts_setters.h.

728 {
729
731
741inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
742 const uint8_t protocol_version = 0) {
743 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
744}
745
757inline void setReferenceTime(
758 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
759 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
760 TimestampIts t_its;
761 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
762 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
763 cpm.payload.management_container.reference_time = t_its;
764}
765
777inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
778 const double altitude = AltitudeValue::UNAVAILABLE) {
779 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
780}
781
794inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
795 const bool& northp) {
796 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
797}
798
807inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
808 object.object_id.value = id;
809 object.object_id_is_present = true;
810}
811
823inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
824 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
825 throw std::invalid_argument("MeasurementDeltaTime out of range");
826 } else {
827 object.measurement_delta_time.value = delta_time;
828 }
829}
830
844inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
845 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
846 // limit value range
847 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
848 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
849 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
850 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
851 } else {
852 coordinate.value.value = value;
853 }
854
855 // limit confidence range
856 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
857 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
858 } else {
859 coordinate.confidence.value = confidence;
860 }
861}
862
874inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
875 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
876 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
877 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
878 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
879 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
880 if (point.z != 0.0) {
881 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
882 object.position.z_coordinate_is_present = true;
883 }
884}
885
901inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
902 const gm::PointStamped& utm_position,
903 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
904 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
905 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
906 gm::PointStamped reference_position = getUTMPosition(cpm);
907 if (utm_position.header.frame_id != reference_position.header.frame_id) {
908 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
909 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
910 ")");
911 }
912 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
913 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
914 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
915 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
916 if (utm_position.point.z != 0.0) {
917 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
918 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
919 object.position.z_coordinate_is_present = true;
920 }
921}
922
934inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
935 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
936 // limit value range
937 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
938 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
939 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
940 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
941 } else {
942 velocity.value.value = value;
943 }
944
945 // limit confidence range
946 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
947 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
948 } else {
949 velocity.confidence.value = confidence;
950 }
951}
952
965inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
966 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
967 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
968 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
969 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
970 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
971 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
972 if (cartesian_velocity.z != 0.0) {
973 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
974 object.velocity.cartesian_velocity.z_velocity_is_present = true;
975 }
976 object.velocity_is_present = true;
977}
978
990inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
991 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
992 // limit value range
993 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
994 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
995 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
996 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
997 } else {
998 acceleration.value.value = value;
999 }
1000
1001 // limit confidence range
1002 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
1003 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
1004 } else {
1005 acceleration.confidence.value = confidence;
1006 }
1007}
1008
1021inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
1022 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
1023 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
1024 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
1025 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
1026 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
1027 x_confidence * 10);
1028 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
1029 y_confidence * 10);
1030 if (cartesian_acceleration.z != 0.0) {
1031 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
1032 z_confidence * 10);
1033 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
1034 }
1035 object.acceleration_is_present = true;
1036}
1037
1048inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
1049 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
1050 // wrap angle to range [0, 360]
1051 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
1052 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
1053 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
1054 object.angles.z_angle.value.value = yaw_in_degrees * 10;
1055
1056 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
1057 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
1058 } else {
1059 object.angles.z_angle.confidence.value = confidence;
1060 }
1061 object.angles_is_present = true;
1062}
1063
1075inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1076 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1077 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1078 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1079 // limit value range
1080 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1081 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1082 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1083 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1084 }
1085 }
1086 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1087 object.z_angular_velocity.confidence.value = confidence;
1088 object.z_angular_velocity_is_present = true;
1089}
1090
1105inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1106 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1107 // limit value range
1108 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1109 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1110 } else {
1111 dimension.value.value = value;
1112 }
1113
1114 // limit confidence range
1115 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1116 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1117 } else {
1118 dimension.confidence.value = confidence;
1119 }
1120}
1121
1132inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1133 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1134 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1135 object.object_dimension_x_is_present = true;
1136}
1137
1148inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1149 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1150 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1151 object.object_dimension_y_is_present = true;
1152}
1153
1164inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1165 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1166 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1167 object.object_dimension_z_is_present = true;
1168}
1169
1181inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1182 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1183 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1184 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1185 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1186 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1187 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1188}
1189
1199inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1200 setPositionOfPerceivedObject(object, point);
1201 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1202}
1203
1216inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1217 const gm::PointStamped& point, const int16_t delta_time = 0) {
1218 setUTMPositionOfPerceivedObject(cpm, object, point);
1219 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1220}
1221
1231inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1232 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1233 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1234}
1235
1249inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1250 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1251 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1252 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1253 container.container_data_perceived_object_container.perceived_objects.array.size();
1254 } else {
1255 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1256 }
1257}
1258
1271inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1272 // check for maximum number of containers
1273 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1274 cpm.payload.cpm_containers.value.array.push_back(container);
1275 } else {
1276 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1277 }
1278}
1279
1280} // namespace etsi_its_cpm_ts_msgs::access
gm::PointStamped getUTMPosition(const CAM &cam, int &zone, bool &northp)
Get the UTM Position defined within the BasicContainer of the CAM.
void setFromUTMPosition(CAM &cam, const gm::PointStamped &utm_position, const int &zone, const bool &northp)
Set the ReferencePosition of a CAM from a given UTM-Position.
void setReferencePosition(CAM &cam, const double latitude, const double longitude, const double altitude=AltitudeValue::UNAVAILABLE)
Set the ReferencePosition for a CAM.
void setTimestampITS(TimestampIts &timestamp_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.
Setter functions for the ETSI ITS Common Data Dictionary (CDD) v2.1.1.
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 setUTMPositionOfPerceivedObject(CollectivePerceptionMessage &cpm, PerceivedObject &object, const gm::PointStamped &utm_position, 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 based on a UTM position.
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 setYawRateOfPerceivedObject(PerceivedObject &object, const double yaw_rate, const uint8_t confidence=AngularSpeedConfidence::UNAVAILABLE)
Sets the yaw rate of a perceived object.
void setZDimensionOfPerceivedObject(PerceivedObject &object, const double value, const uint8_t confidence=ObjectDimensionConfidence::UNAVAILABLE)
Sets the z-dimension of a perceived object.
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 setAccelerationComponent(AccelerationComponent &acceleration, const int16_t value, const uint8_t confidence=AccelerationConfidence::UNAVAILABLE)
Sets the value and confidence of a AccelerationComponent.
void initPerceivedObject(PerceivedObject &object, const gm::Point &point, const int16_t delta_time=0)
Initializes a PerceivedObject with the given point and delta time.

◆ getLeapSecondInsertionsSince2004()

uint16_t etsi_its_cpm_ts_msgs::access::etsi_its_msgs::getLeapSecondInsertionsSince2004 ( const uint64_t unix_seconds)
inline

Get the leap second insertions since 2004 for given unix seconds.

Parameters
unix_secondsthe current unix seconds for that the leap second insertions since 2004 shall be provided
Returns
uint16_t the number of leap second insertions since 2004 for unix_seconds

Definition at line 61 of file cpm_ts_access.h.

◆ initPerceivedObject()

void etsi_its_cpm_ts_msgs::access::initPerceivedObject ( PerceivedObject & object,
const gm::Point & point,
const int16_t delta_time = 0 )
inline

Initializes a PerceivedObject with the given point and delta time.

This function sets the position and measurement delta time of the PerceivedObject.

Parameters
objectThe PerceivedObject to be initialized.
pointThe position of the PerceivedObject relative to the CPM's reference position in meters.
delta_timeThe measurement delta time of the PerceivedObject in milliseconds (default = 0).

Definition at line 643 of file cpm_ts_setters.h.

678 {
679
681
691inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
692 const uint8_t protocol_version = 0) {
693 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
694}
695
707inline void setReferenceTime(
708 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
709 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
710 TimestampIts t_its;
711 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
712 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
713 cpm.payload.management_container.reference_time = t_its;
714}
715
727inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
728 const double altitude = AltitudeValue::UNAVAILABLE) {
729 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
730}
731
744inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
745 const bool& northp) {
746 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
747}
748
757inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
758 object.object_id.value = id;
759 object.object_id_is_present = true;
760}
761
773inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
774 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
775 throw std::invalid_argument("MeasurementDeltaTime out of range");
776 } else {
777 object.measurement_delta_time.value = delta_time;
778 }
779}
780
794inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
795 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
796 // limit value range
797 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
798 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
799 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
800 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
801 } else {
802 coordinate.value.value = value;
803 }
804
805 // limit confidence range
806 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
807 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
808 } else {
809 coordinate.confidence.value = confidence;
810 }
811}
812
824inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
825 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
826 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
827 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
828 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
829 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
830 if (point.z != 0.0) {
831 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
832 object.position.z_coordinate_is_present = true;
833 }
834}
835
851inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
852 const gm::PointStamped& utm_position,
853 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
854 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
855 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
856 gm::PointStamped reference_position = getUTMPosition(cpm);
857 if (utm_position.header.frame_id != reference_position.header.frame_id) {
858 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
859 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
860 ")");
861 }
862 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
863 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
864 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
865 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
866 if (utm_position.point.z != 0.0) {
867 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
868 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
869 object.position.z_coordinate_is_present = true;
870 }
871}
872
884inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
885 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
886 // limit value range
887 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
888 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
889 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
890 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
891 } else {
892 velocity.value.value = value;
893 }
894
895 // limit confidence range
896 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
897 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
898 } else {
899 velocity.confidence.value = confidence;
900 }
901}
902
915inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
916 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
917 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
918 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
919 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
920 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
921 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
922 if (cartesian_velocity.z != 0.0) {
923 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
924 object.velocity.cartesian_velocity.z_velocity_is_present = true;
925 }
926 object.velocity_is_present = true;
927}
928
940inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
941 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
942 // limit value range
943 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
944 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
945 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
946 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
947 } else {
948 acceleration.value.value = value;
949 }
950
951 // limit confidence range
952 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
953 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
954 } else {
955 acceleration.confidence.value = confidence;
956 }
957}
958
971inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
972 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
973 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
974 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
975 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
976 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
977 x_confidence * 10);
978 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
979 y_confidence * 10);
980 if (cartesian_acceleration.z != 0.0) {
981 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
982 z_confidence * 10);
983 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
984 }
985 object.acceleration_is_present = true;
986}
987
998inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
999 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
1000 // wrap angle to range [0, 360]
1001 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
1002 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
1003 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
1004 object.angles.z_angle.value.value = yaw_in_degrees * 10;
1005
1006 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
1007 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
1008 } else {
1009 object.angles.z_angle.confidence.value = confidence;
1010 }
1011 object.angles_is_present = true;
1012}
1013
1025inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1026 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1027 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1028 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1029 // limit value range
1030 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1031 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1032 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1033 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1034 }
1035 }
1036 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1037 object.z_angular_velocity.confidence.value = confidence;
1038 object.z_angular_velocity_is_present = true;
1039}
1040
1055inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1056 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1057 // limit value range
1058 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1059 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1060 } else {
1061 dimension.value.value = value;
1062 }
1063
1064 // limit confidence range
1065 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1066 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1067 } else {
1068 dimension.confidence.value = confidence;
1069 }
1070}
1071
1082inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1083 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1084 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1085 object.object_dimension_x_is_present = true;
1086}
1087
1098inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1099 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1100 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1101 object.object_dimension_y_is_present = true;
1102}
1103
1114inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1115 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1116 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1117 object.object_dimension_z_is_present = true;
1118}
1119
1131inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1132 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1133 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1134 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1135 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1136 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1137 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1138}
1139
1149inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1150 setPositionOfPerceivedObject(object, point);
1151 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1152}
1153
1166inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1167 const gm::PointStamped& point, const int16_t delta_time = 0) {
1168 setUTMPositionOfPerceivedObject(cpm, object, point);
1169 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1170}
1171
1181inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1182 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1183 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1184}
1185
1199inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1200 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1201 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1202 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1203 container.container_data_perceived_object_container.perceived_objects.array.size();
1204 } else {
1205 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1206 }
1207}
1208
1221inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1222 // check for maximum number of containers
1223 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1224 cpm.payload.cpm_containers.value.array.push_back(container);
1225 } else {
1226 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1227 }
1228}
1229
1230} // namespace etsi_its_cpm_ts_msgs::access

◆ initPerceivedObjectContainer()

void etsi_its_cpm_ts_msgs::access::initPerceivedObjectContainer ( WrappedCpmContainer & container,
const uint8_t n_objects = 0 )
inline

Initializes a WrappedCpmContainer as a PerceivedObjectContainer with the given number of objects.

This function sets the container ID to CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER and initializes the number of perceived objects in the container to the specified value.

Parameters
containerA reference to the WrappedCpmContainer to be initialized as a PerceivedObjectContainer.
n_objectsThe number of perceived objects to initialize in the container. Default is 0.

Definition at line 675 of file cpm_ts_setters.h.

710 {
711
713
723inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
724 const uint8_t protocol_version = 0) {
725 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
726}
727
739inline void setReferenceTime(
740 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
741 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
742 TimestampIts t_its;
743 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
744 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
745 cpm.payload.management_container.reference_time = t_its;
746}
747
759inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
760 const double altitude = AltitudeValue::UNAVAILABLE) {
761 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
762}
763
776inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
777 const bool& northp) {
778 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
779}
780
789inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
790 object.object_id.value = id;
791 object.object_id_is_present = true;
792}
793
805inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
806 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
807 throw std::invalid_argument("MeasurementDeltaTime out of range");
808 } else {
809 object.measurement_delta_time.value = delta_time;
810 }
811}
812
826inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
827 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
828 // limit value range
829 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
830 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
831 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
832 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
833 } else {
834 coordinate.value.value = value;
835 }
836
837 // limit confidence range
838 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
839 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
840 } else {
841 coordinate.confidence.value = confidence;
842 }
843}
844
856inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
857 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
858 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
859 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
860 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
861 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
862 if (point.z != 0.0) {
863 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
864 object.position.z_coordinate_is_present = true;
865 }
866}
867
883inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
884 const gm::PointStamped& utm_position,
885 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
886 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
887 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
888 gm::PointStamped reference_position = getUTMPosition(cpm);
889 if (utm_position.header.frame_id != reference_position.header.frame_id) {
890 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
891 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
892 ")");
893 }
894 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
895 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
896 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
897 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
898 if (utm_position.point.z != 0.0) {
899 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
900 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
901 object.position.z_coordinate_is_present = true;
902 }
903}
904
916inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
917 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
918 // limit value range
919 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
920 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
921 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
922 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
923 } else {
924 velocity.value.value = value;
925 }
926
927 // limit confidence range
928 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
929 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
930 } else {
931 velocity.confidence.value = confidence;
932 }
933}
934
947inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
948 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
949 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
950 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
951 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
952 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
953 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
954 if (cartesian_velocity.z != 0.0) {
955 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
956 object.velocity.cartesian_velocity.z_velocity_is_present = true;
957 }
958 object.velocity_is_present = true;
959}
960
972inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
973 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
974 // limit value range
975 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
976 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
977 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
978 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
979 } else {
980 acceleration.value.value = value;
981 }
982
983 // limit confidence range
984 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
985 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
986 } else {
987 acceleration.confidence.value = confidence;
988 }
989}
990
1003inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
1004 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
1005 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
1006 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
1007 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
1008 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
1009 x_confidence * 10);
1010 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
1011 y_confidence * 10);
1012 if (cartesian_acceleration.z != 0.0) {
1013 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
1014 z_confidence * 10);
1015 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
1016 }
1017 object.acceleration_is_present = true;
1018}
1019
1030inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
1031 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
1032 // wrap angle to range [0, 360]
1033 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
1034 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
1035 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
1036 object.angles.z_angle.value.value = yaw_in_degrees * 10;
1037
1038 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
1039 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
1040 } else {
1041 object.angles.z_angle.confidence.value = confidence;
1042 }
1043 object.angles_is_present = true;
1044}
1045
1057inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1058 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1059 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1060 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1061 // limit value range
1062 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1063 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1064 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1065 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1066 }
1067 }
1068 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1069 object.z_angular_velocity.confidence.value = confidence;
1070 object.z_angular_velocity_is_present = true;
1071}
1072
1087inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1088 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1089 // limit value range
1090 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1091 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1092 } else {
1093 dimension.value.value = value;
1094 }
1095
1096 // limit confidence range
1097 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1098 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1099 } else {
1100 dimension.confidence.value = confidence;
1101 }
1102}
1103
1114inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1115 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1116 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1117 object.object_dimension_x_is_present = true;
1118}
1119
1130inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1131 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1132 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1133 object.object_dimension_y_is_present = true;
1134}
1135
1146inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1147 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1148 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1149 object.object_dimension_z_is_present = true;
1150}
1151
1163inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1164 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1165 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1166 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1167 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1168 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1169 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1170}
1171
1181inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1182 setPositionOfPerceivedObject(object, point);
1183 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1184}
1185
1198inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1199 const gm::PointStamped& point, const int16_t delta_time = 0) {
1200 setUTMPositionOfPerceivedObject(cpm, object, point);
1201 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1202}
1203
1213inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1214 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1215 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1216}
1217
1231inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1232 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1233 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1234 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1235 container.container_data_perceived_object_container.perceived_objects.array.size();
1236 } else {
1237 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1238 }
1239}
1240
1253inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1254 // check for maximum number of containers
1255 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1256 cpm.payload.cpm_containers.value.array.push_back(container);
1257 } else {
1258 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1259 }
1260}
1261
1262} // namespace etsi_its_cpm_ts_msgs::access

◆ initPerceivedObjectWithUTMPosition()

void etsi_its_cpm_ts_msgs::access::initPerceivedObjectWithUTMPosition ( CollectivePerceptionMessage & cpm,
PerceivedObject & object,
const gm::PointStamped & point,
const int16_t delta_time = 0 )
inline

Initializes a PerceivedObject with the given point (utm-position) and delta time.

This function initializes a PerceivedObject within a position and measurement delta time. It sets the position of a perceived object using the provided UTM position and the CPM's reference position. It sets the measurement delta time using the provided delta_time value.

Parameters
cpmThe CPM to get the reference position from.
objectThe PerceivedObject to be initialized.
pointThe gm::PointStamped representing the UTM position of the object including the frame_id (utm_<zone><N/S>).
delta_timeThe measurement delta time in milliseconds (default: 0).

Definition at line 660 of file cpm_ts_setters.h.

695 {
696
698
708inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
709 const uint8_t protocol_version = 0) {
710 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
711}
712
724inline void setReferenceTime(
725 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
726 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
727 TimestampIts t_its;
728 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
729 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
730 cpm.payload.management_container.reference_time = t_its;
731}
732
744inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
745 const double altitude = AltitudeValue::UNAVAILABLE) {
746 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
747}
748
761inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
762 const bool& northp) {
763 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
764}
765
774inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
775 object.object_id.value = id;
776 object.object_id_is_present = true;
777}
778
790inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
791 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
792 throw std::invalid_argument("MeasurementDeltaTime out of range");
793 } else {
794 object.measurement_delta_time.value = delta_time;
795 }
796}
797
811inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
812 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
813 // limit value range
814 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
815 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
816 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
817 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
818 } else {
819 coordinate.value.value = value;
820 }
821
822 // limit confidence range
823 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
824 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
825 } else {
826 coordinate.confidence.value = confidence;
827 }
828}
829
841inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
842 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
843 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
844 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
845 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
846 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
847 if (point.z != 0.0) {
848 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
849 object.position.z_coordinate_is_present = true;
850 }
851}
852
868inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
869 const gm::PointStamped& utm_position,
870 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
871 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
872 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
873 gm::PointStamped reference_position = getUTMPosition(cpm);
874 if (utm_position.header.frame_id != reference_position.header.frame_id) {
875 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
876 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
877 ")");
878 }
879 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
880 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
881 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
882 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
883 if (utm_position.point.z != 0.0) {
884 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
885 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
886 object.position.z_coordinate_is_present = true;
887 }
888}
889
901inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
902 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
903 // limit value range
904 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
905 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
906 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
907 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
908 } else {
909 velocity.value.value = value;
910 }
911
912 // limit confidence range
913 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
914 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
915 } else {
916 velocity.confidence.value = confidence;
917 }
918}
919
932inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
933 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
934 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
935 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
936 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
937 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
938 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
939 if (cartesian_velocity.z != 0.0) {
940 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
941 object.velocity.cartesian_velocity.z_velocity_is_present = true;
942 }
943 object.velocity_is_present = true;
944}
945
957inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
958 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
959 // limit value range
960 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
961 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
962 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
963 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
964 } else {
965 acceleration.value.value = value;
966 }
967
968 // limit confidence range
969 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
970 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
971 } else {
972 acceleration.confidence.value = confidence;
973 }
974}
975
988inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
989 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
990 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
991 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
992 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
993 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
994 x_confidence * 10);
995 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
996 y_confidence * 10);
997 if (cartesian_acceleration.z != 0.0) {
998 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
999 z_confidence * 10);
1000 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
1001 }
1002 object.acceleration_is_present = true;
1003}
1004
1015inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
1016 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
1017 // wrap angle to range [0, 360]
1018 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
1019 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
1020 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
1021 object.angles.z_angle.value.value = yaw_in_degrees * 10;
1022
1023 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
1024 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
1025 } else {
1026 object.angles.z_angle.confidence.value = confidence;
1027 }
1028 object.angles_is_present = true;
1029}
1030
1042inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1043 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1044 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1045 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1046 // limit value range
1047 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1048 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1049 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1050 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1051 }
1052 }
1053 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1054 object.z_angular_velocity.confidence.value = confidence;
1055 object.z_angular_velocity_is_present = true;
1056}
1057
1072inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1073 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1074 // limit value range
1075 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1076 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1077 } else {
1078 dimension.value.value = value;
1079 }
1080
1081 // limit confidence range
1082 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1083 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1084 } else {
1085 dimension.confidence.value = confidence;
1086 }
1087}
1088
1099inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1100 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1101 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1102 object.object_dimension_x_is_present = true;
1103}
1104
1115inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1116 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1117 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1118 object.object_dimension_y_is_present = true;
1119}
1120
1131inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1132 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1133 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1134 object.object_dimension_z_is_present = true;
1135}
1136
1148inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1149 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1150 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1151 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1152 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1153 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1154 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1155}
1156
1166inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1167 setPositionOfPerceivedObject(object, point);
1168 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1169}
1170
1183inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1184 const gm::PointStamped& point, const int16_t delta_time = 0) {
1185 setUTMPositionOfPerceivedObject(cpm, object, point);
1186 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1187}
1188
1198inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1199 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1200 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1201}
1202
1216inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1217 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1218 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1219 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1220 container.container_data_perceived_object_container.perceived_objects.array.size();
1221 } else {
1222 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1223 }
1224}
1225
1238inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1239 // check for maximum number of containers
1240 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1241 cpm.payload.cpm_containers.value.array.push_back(container);
1242 } else {
1243 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1244 }
1245}
1246
1247} // namespace etsi_its_cpm_ts_msgs::access

◆ setAccelerationComponent()

void etsi_its_cpm_ts_msgs::access::setAccelerationComponent ( AccelerationComponent & acceleration,
const int16_t value,
const uint8_t confidence = AccelerationConfidence::UNAVAILABLE )
inline

Sets the value and confidence of a AccelerationComponent.

This function sets the value and confidence of a AccelerationComponent object. The value is limited to a specific range, and the confidence is limited to a specific range as well. If the provided value or confidence is out of range, it will be set to the corresponding out-of-range value.

Parameters
accelerationThe AccelerationComponent object to set the value and confidence for.
valueThe value to set for the AccelerationComponent in dm/s^2.
confidenceThe confidence to set for the AccelerationComponent in dm/s^2. Default value is AccelerationConfidence::UNAVAILABLE.

Definition at line 434 of file cpm_ts_setters.h.

441 {
442 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
443 object.object_dimension_x_is_present = true;
444}
445

◆ setAccelerationOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::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 )
inline

Sets the acceleration of a perceived object.

This function sets the acceleration of a perceived object using the provided Cartesian acceleration components. Optionally, confidence values can be specified for each acceleration component.

Parameters
objectThe perceived object for which the acceleration is being set.
cartesian_accelerationThe Cartesian acceleration components (x, y, z) of the object (in m/s^2).
x_confidenceThe confidence value in m/s^2 for the x acceleration component (default: AccelerationConfidence::UNAVAILABLE).
y_confidenceThe confidence value in m/s^2 for the y acceleration component (default: AccelerationConfidence::UNAVAILABLE).
z_confidenceThe confidence value in m/s^2 for the z acceleration component (default: AccelerationConfidence::UNAVAILABLE).

Definition at line 465 of file cpm_ts_setters.h.

473 {
474 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
475 object.object_dimension_z_is_present = true;
476}
477

◆ setAltitude()

void etsi_its_cpm_ts_msgs::access::setAltitude ( Altitude & altitude,
const double value )
inline

Set the Altitude object.

AltitudeConfidence is set to UNAVAILABLE

Parameters
altitudeobject to set
valueAltitude value (above the reference ellipsoid surface) in meter as decimal number

Definition at line 140 of file cpm_ts_setters.h.

◆ setAltitudeValue()

void etsi_its_cpm_ts_msgs::access::setAltitudeValue ( AltitudeValue & altitude,
const double value )
inline

Set the AltitudeValue object.

Parameters
altitudeobject to set
valueAltitudeValue value (above the reference ellipsoid surface) in meter as decimal number

Definition at line 121 of file cpm_ts_setters.h.

◆ setBitString()

template<typename T >
void etsi_its_cpm_ts_msgs::access::setBitString ( T & bitstring,
const std::vector< bool > & bits )
inline

Set a Bit String by a vector of bools.

Template Parameters
T
Parameters
bitstringBitString to set
bitsvector of bools

Definition at line 232 of file cpm_ts_setters.h.

243 {
244 // limit value range
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;
249 } else {
250 velocity.value.value = value;
251 }
252
253 // limit confidence range
254 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {

◆ setCartesianCoordinateWithConfidence()

void etsi_its_cpm_ts_msgs::access::setCartesianCoordinateWithConfidence ( CartesianCoordinateWithConfidence & coordinate,
const int32_t value,
const uint16_t confidence = CoordinateConfidence::UNAVAILABLE )
inline

Sets the value and confidence of a CartesianCoordinateWithConfidence object.

This function sets the value and confidence of a CartesianCoordinateWithConfidence object. The value is limited to the range defined by CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE and CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE. The confidence is limited to the range defined by CoordinateConfidence::MIN and CoordinateConfidence::MAX. If the provided confidence is out of range, the confidence value is set to CoordinateConfidence::OUT_OF_RANGE.

Parameters
coordinateThe CartesianCoordinateWithConfidence object to be modified.
valueThe value to be set in centimeters.
confidenceThe confidence to be set in centimeters (default: CoordinateConfidence::UNAVAILABLE).

Definition at line 288 of file cpm_ts_setters.h.

299 {
300 // limit value range
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;
305 } else {

◆ setDimensionsOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::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 )
inline

Sets all dimensions of a perceived object.

This function sets the dimensions of a perceived object using the provided dimensions and confidence values.

Parameters
objectThe perceived object to set the dimensions for.
dimensionsThe dimensions of the object as a gm::Vector3 (x, y, z) in meters.
x_confidenceThe confidence in meters for the x dimension (optional, default: ObjectDimensionConfidence::UNAVAILABLE).
y_confidenceThe confidence in meters for the y dimension (optional, default: ObjectDimensionConfidence::UNAVAILABLE).
z_confidenceThe confidence in meters for the z dimension (optional, default: ObjectDimensionConfidence::UNAVAILABLE).

Definition at line 625 of file cpm_ts_setters.h.

660 {
661
663
673inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
674 const uint8_t protocol_version = 0) {
675 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
676}
677
689inline void setReferenceTime(
690 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
691 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
692 TimestampIts t_its;
693 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
694 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
695 cpm.payload.management_container.reference_time = t_its;
696}
697
709inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
710 const double altitude = AltitudeValue::UNAVAILABLE) {
711 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
712}
713
726inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
727 const bool& northp) {
728 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
729}
730
739inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
740 object.object_id.value = id;
741 object.object_id_is_present = true;
742}
743
755inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
756 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
757 throw std::invalid_argument("MeasurementDeltaTime out of range");
758 } else {
759 object.measurement_delta_time.value = delta_time;
760 }
761}
762
776inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
777 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
778 // limit value range
779 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
780 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
781 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
782 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
783 } else {
784 coordinate.value.value = value;
785 }
786
787 // limit confidence range
788 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
789 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
790 } else {
791 coordinate.confidence.value = confidence;
792 }
793}
794
806inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
807 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
808 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
809 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
810 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
811 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
812 if (point.z != 0.0) {
813 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
814 object.position.z_coordinate_is_present = true;
815 }
816}
817
833inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
834 const gm::PointStamped& utm_position,
835 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
836 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
837 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
838 gm::PointStamped reference_position = getUTMPosition(cpm);
839 if (utm_position.header.frame_id != reference_position.header.frame_id) {
840 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
841 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
842 ")");
843 }
844 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
845 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
846 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
847 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
848 if (utm_position.point.z != 0.0) {
849 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
850 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
851 object.position.z_coordinate_is_present = true;
852 }
853}
854
866inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
867 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
868 // limit value range
869 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
870 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
871 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
872 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
873 } else {
874 velocity.value.value = value;
875 }
876
877 // limit confidence range
878 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
879 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
880 } else {
881 velocity.confidence.value = confidence;
882 }
883}
884
897inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
898 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
899 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
900 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
901 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
902 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
903 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
904 if (cartesian_velocity.z != 0.0) {
905 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
906 object.velocity.cartesian_velocity.z_velocity_is_present = true;
907 }
908 object.velocity_is_present = true;
909}
910
922inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
923 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
924 // limit value range
925 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
926 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
927 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
928 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
929 } else {
930 acceleration.value.value = value;
931 }
932
933 // limit confidence range
934 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
935 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
936 } else {
937 acceleration.confidence.value = confidence;
938 }
939}
940
953inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
954 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
955 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
956 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
957 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
958 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
959 x_confidence * 10);
960 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
961 y_confidence * 10);
962 if (cartesian_acceleration.z != 0.0) {
963 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
964 z_confidence * 10);
965 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
966 }
967 object.acceleration_is_present = true;
968}
969
980inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
981 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
982 // wrap angle to range [0, 360]
983 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
984 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
985 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
986 object.angles.z_angle.value.value = yaw_in_degrees * 10;
987
988 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
989 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
990 } else {
991 object.angles.z_angle.confidence.value = confidence;
992 }
993 object.angles_is_present = true;
994}
995
1007inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1008 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1009 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1010 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1011 // limit value range
1012 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1013 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1014 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1015 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1016 }
1017 }
1018 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1019 object.z_angular_velocity.confidence.value = confidence;
1020 object.z_angular_velocity_is_present = true;
1021}
1022
1037inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1038 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1039 // limit value range
1040 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1041 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1042 } else {
1043 dimension.value.value = value;
1044 }
1045
1046 // limit confidence range
1047 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1048 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1049 } else {
1050 dimension.confidence.value = confidence;
1051 }
1052}
1053
1064inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1065 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1066 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1067 object.object_dimension_x_is_present = true;
1068}
1069
1080inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1081 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1082 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1083 object.object_dimension_y_is_present = true;
1084}
1085
1096inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1097 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1098 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1099 object.object_dimension_z_is_present = true;
1100}
1101
1113inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1114 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1115 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1116 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1117 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1118 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1119 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1120}
1121
1131inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1132 setPositionOfPerceivedObject(object, point);
1133 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1134}
1135
1148inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1149 const gm::PointStamped& point, const int16_t delta_time = 0) {
1150 setUTMPositionOfPerceivedObject(cpm, object, point);
1151 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1152}
1153
1163inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1164 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1165 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1166}
1167
1181inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1182 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1183 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1184 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1185 container.container_data_perceived_object_container.perceived_objects.array.size();
1186 } else {
1187 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1188 }
1189}
1190
1203inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1204 // check for maximum number of containers
1205 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1206 cpm.payload.cpm_containers.value.array.push_back(container);
1207 } else {
1208 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1209 }
1210}
1211
1212} // namespace etsi_its_cpm_ts_msgs::access

◆ setFromUTMPosition() [1/2]

void etsi_its_cpm_ts_msgs::access::setFromUTMPosition ( CollectivePerceptionMessage & cpm,
const gm::PointStamped & utm_position,
const int & zone,
const bool & northp )
inline

Set the ReferencePosition of a CPM from a given UTM-Position.

The position is transformed to latitude and longitude by using GeographicLib::UTMUPS The z-Coordinate is directly used as altitude value The frame_id of the given utm_position must be set to 'utm_<zone><N/S>'

Parameters
[out]cpmCPM for which to set the ReferencePosition
[in]utm_positiongeometry_msgs::PointStamped describing the given utm position in meters
[in]zonethe UTM zone (zero means UPS) of the given position
[in]northphemisphere (true means north, false means south)

Definition at line 238 of file cpm_ts_setters.h.

◆ setFromUTMPosition() [2/2]

template<typename T >
void etsi_its_cpm_ts_msgs::access::setFromUTMPosition ( T & reference_position,
const gm::PointStamped & utm_position,
const int zone,
const bool northp )
inline

Set the ReferencePosition from a given UTM-Position.

The position is transformed to latitude and longitude by using GeographicLib::UTMUPS The z-Coordinate is directly used as altitude value The frame_id of the given utm_position must be set to 'utm_<zone><N/S>'

Parameters
[out]reference_positionReferencePostion or ReferencePositionWithConfidence to set
[in]utm_positiongeometry_msgs::PointStamped describing the given utm position
[in]zonethe UTM zone (zero means UPS) of the given position
[in]northphemisphere (true means north, false means south)

Definition at line 208 of file cpm_ts_setters.h.

213 {
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 +
218 ")");
219 }
220 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
221 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
222 setCartesianCoordinateWithConfidence(object.position.y_coordinate,

◆ setIdOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::setIdOfPerceivedObject ( PerceivedObject & object,
const uint16_t id )
inline

Set the ID of a PerceivedObject.

Sets the object_id of the PerceivedObject to the given ID.

Parameters
objectPerceivedObject to set the ID for
idID to set

Definition at line 251 of file cpm_ts_setters.h.

254 {

◆ setItsPduHeader() [1/2]

void etsi_its_cpm_ts_msgs::access::setItsPduHeader ( CollectivePerceptionMessage & cpm,
const uint32_t station_id,
const uint8_t protocol_version = 0 )
inline

Sets the ITS PDU header of a CPM.

This function sets the ITS PDU header of a CPM with the provided station ID and protocol version.

Parameters
cpmThe CPM to set the ITS PDU header for.
station_idThe station ID to set in the ITS PDU header.
protocol_versionThe protocol version to set in the ITS PDU header. Default is 0.

Definition at line 185 of file cpm_ts_setters.h.

185 {
186 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
187 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
188 if (point.z != 0.0) {

◆ setItsPduHeader() [2/2]

void etsi_its_cpm_ts_msgs::access::setItsPduHeader ( ItsPduHeader & header,
const uint8_t message_id,
const uint32_t station_id,
const uint8_t protocol_version = 0 )
inline

Set the Its Pdu Header object.

Parameters
headerItsPduHeader to be set
message_idID of the message
station_id
protocol_version

Definition at line 94 of file cpm_ts_setters.h.

◆ setLateralAcceleration()

void etsi_its_cpm_ts_msgs::access::setLateralAcceleration ( AccelerationComponent & accel,
const double value )
inline

Set the LateralAcceleration object.

AccelerationConfidence is set to UNAVAILABLE

Parameters
accelobject to set
valueLaterallAccelerationValue in m/s^2 as decimal number (left is positive)

Definition at line 169 of file cpm_ts_setters.h.

◆ setLateralAccelerationValue()

void etsi_its_cpm_ts_msgs::access::setLateralAccelerationValue ( AccelerationValue & accel,
const double value )
inline

Set the LateralAccelerationValue object.

Parameters
accelobject to set
valueLateralAccelerationValue in m/s^2 as decimal number (left is positive)

Definition at line 150 of file cpm_ts_setters.h.

150 : CoordinateConfidence::UNAVAILABLE).
151 */
152inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
153 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
154 // limit value range
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;
159 } else {

◆ setLatitude()

void etsi_its_cpm_ts_msgs::access::setLatitude ( Latitude & latitude,
const double deg )
inline

Set the Latitude object.

Parameters
latitudeobject to set
degLatitude value in degree as decimal number

Definition at line 97 of file cpm_ts_setters.h.

◆ setLongitude()

void etsi_its_cpm_ts_msgs::access::setLongitude ( Longitude & longitude,
const double deg )
inline

Set the Longitude object.

Parameters
longitudeobject to set
degLongitude value in degree as decimal number

Definition at line 109 of file cpm_ts_setters.h.

◆ setLongitudinalAcceleration()

void etsi_its_cpm_ts_msgs::access::setLongitudinalAcceleration ( AccelerationComponent & accel,
const double value )
inline

Set the LongitudinalAcceleration object.

AccelerationConfidence is set to UNAVAILABLE

Parameters
accelobject to set
valueLongitudinalAccelerationValue in m/s^2 as decimal number (braking is negative)

Definition at line 139 of file cpm_ts_setters.h.

◆ setLongitudinalAccelerationValue()

void etsi_its_cpm_ts_msgs::access::setLongitudinalAccelerationValue ( AccelerationValue & accel,
const double value )
inline

Set the LongitudinalAccelerationValue object.

Parameters
accelobject to set
valueLongitudinalAccelerationValue in m/s^2 as decimal number (braking is negative)

Definition at line 120 of file cpm_ts_setters.h.

◆ setMeasurementDeltaTimeOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::setMeasurementDeltaTimeOfPerceivedObject ( PerceivedObject & object,
const int16_t delta_time = 0 )
inline

Sets the measurement delta time of a PerceivedObject.

This function sets the measurement delta time of a PerceivedObject. The measurement delta time represents the time difference between the reference time of the CPM and the measurement of the object.

Parameters
objectThe PerceivedObject to set the measurement delta time for.
delta_timeThe measurement delta time to set in milliseconds. Default value is 0.
Exceptions
std::invalid_argumentif the delta_time is out of range.

Definition at line 267 of file cpm_ts_setters.h.

269 : SpeedConfidence::UNAVAILABLE).
270 * @param y_confidence The confidence value in m/s for the y velocity component (default: SpeedConfidence::UNAVAILABLE).
271 * @param z_confidence The confidence value in m/s for the z velocity component (default: SpeedConfidence::UNAVAILABLE).
272 */
273inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,

◆ setObjectDimension()

void etsi_its_cpm_ts_msgs::access::setObjectDimension ( ObjectDimension & dimension,
const uint16_t value,
const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE )
inline

Sets the object dimension with the given value and confidence.

This function sets the value and confidence of the object dimension based on the provided parameters. The value is limited to the range defined by ObjectDimensionValue::MIN and ObjectDimensionValue::MAX. If the provided value is outside this range, the dimension value is set to ObjectDimensionValue::OUT_OF_RANGE.

The confidence is limited to the range defined by ObjectDimensionConfidence::MIN and ObjectDimensionConfidence::MAX. If the provided confidence is outside this range, the confidence value is set to ObjectDimensionConfidence::OUT_OF_RANGE.

Parameters
dimensionThe object dimension to be set.
valueThe value of the object dimension in decimeters.
confidenceThe confidence of the object dimension in decimeters (optional, default is ObjectDimensionConfidence::UNAVAILABLE).

Definition at line 549 of file cpm_ts_setters.h.

557 {
558 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
559 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
560 container.container_data_perceived_object_container.number_of_perceived_objects.value =
561 container.container_data_perceived_object_container.perceived_objects.array.size();
562 } else {
563 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
564 }

◆ setPositionOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::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 )
inline

Sets the position of a perceived object (relative to the CPM's reference position).

This function sets the position of a perceived object using the provided coordinates and confidence values.

Parameters
objectThe PerceivedObject to set the position for.
pointThe gm::Point representing the coordinates of the object in meters.
x_confidenceThe confidence value in meters for the x-coordinate (default: CoordinateConfidence::UNAVAILABLE).
y_confidenceThe confidence value in meters for the y-coordinate (default: CoordinateConfidence::UNAVAILABLE).
z_confidenceThe confidence value in meters for the z-coordinate (default: CoordinateConfidence::UNAVAILABLE).

Definition at line 318 of file cpm_ts_setters.h.

325 : AccelerationConfidence::UNAVAILABLE).
326 * @param y_confidence The confidence value in m/s^2 for the y acceleration component (default: AccelerationConfidence::UNAVAILABLE).
327 * @param z_confidence The confidence value in m/s^2 for the z acceleration component (default: AccelerationConfidence::UNAVAILABLE).
328 */

◆ setReferencePosition() [1/2]

void etsi_its_cpm_ts_msgs::access::setReferencePosition ( CollectivePerceptionMessage & cpm,
const double latitude,
const double longitude,
const double altitude = AltitudeValue::UNAVAILABLE )
inline

Set the ReferencePositionWithConfidence for a CPM TS.

This function sets the latitude, longitude, and altitude of the CPMs reference position. If the altitude is not provided, it is set to AltitudeValue::UNAVAILABLE.

Parameters
cpmCPM to set the ReferencePosition
latitudeThe latitude value position in degree as decimal number.
longitudeThe longitude value in degree as decimal number.
altitudeThe altitude value (above the reference ellipsoid surface) in meter as decimal number (optional).

Definition at line 221 of file cpm_ts_setters.h.

224 {

◆ setReferencePosition() [2/2]

template<typename T >
void etsi_its_cpm_ts_msgs::access::setReferencePosition ( T & ref_position,
const double latitude,
const double longitude,
const double altitude = AltitudeValue::UNAVAILABLE )
inline

Sets the reference position in the given ReferencePostion object.

This function sets the latitude, longitude, and altitude of the reference position. If the altitude is not provided, it is set to AltitudeValue::UNAVAILABLE.

Parameters
ref_positionReferencePostion or ReferencePositionWithConfidence object to set the reference position in.
latitudeThe latitude value position in degree as decimal number.
longitudeThe longitude value in degree as decimal number.
altitudeThe altitude value (above the reference ellipsoid surface) in meter as decimal number (optional).

Definition at line 182 of file cpm_ts_setters.h.

185 {
186 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
187 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
188 if (point.z != 0.0) {
189 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
190 object.position.z_coordinate_is_present = true;
191 }
192}
193

◆ setReferenceTime()

void etsi_its_cpm_ts_msgs::access::setReferenceTime ( CollectivePerceptionMessage & cpm,
const uint64_t unix_nanosecs,
const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second )
inline

Sets the reference time in a CPM.

This function sets the reference time in a CPM object. The reference time is represented by a Unix timestamp in nanoseconds including the number of leap seconds. The reference time is stored in the payload management container of the CPM.

Parameters
cpmThe CPM object to set the reference time in.
unix_nanosecsThe Unix timestamp in nanoseconds representing the reference time.
n_leap_secondsThe number of leap seconds to be considered. Defaults to the todays number of leap seconds since 2004.

Definition at line 201 of file cpm_ts_setters.h.

203 : CoordinateConfidence::UNAVAILABLE).
204 * @param y_confidence The confidence value in meters for the y coordinate (default: CoordinateConfidence::UNAVAILABLE).
205 * @param z_confidence The confidence value in meters for the z coordinate (default: CoordinateConfidence::UNAVAILABLE).
206 *
207 * @throws std::invalid_argument if the UTM-Position frame_id does not match the reference position frame_id.
208 */

◆ setSpeed()

void etsi_its_cpm_ts_msgs::access::setSpeed ( Speed & speed,
const double value )
inline

Set the Speed object.

SpeedConfidence is set to UNAVAILABLE

Parameters
speedobject to set
valueSpeed in in m/s as decimal number

Definition at line 165 of file cpm_ts_setters.h.

166 {
167 coordinate.confidence.value = confidence;
168 }

◆ setSpeedValue()

void etsi_its_cpm_ts_msgs::access::setSpeedValue ( SpeedValue & speed,
const double value )
inline

Set the SpeedValue object.

Parameters
speedobject to set
valueSpeedValue in m/s as decimal number

Definition at line 151 of file cpm_ts_setters.h.

153 {
154 // limit value range
155 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {

◆ setStationId()

void etsi_its_cpm_ts_msgs::access::setStationId ( StationId & station_id,
const uint32_t id_value )
inline

Set the Station Id object.

Parameters
station_id
id_value

Definition at line 81 of file cpm_ts_setters.h.

◆ setStationType()

void etsi_its_cpm_ts_msgs::access::setStationType ( TrafficParticipantType & station_type,
const uint8_t value )
inline

Set the Station Type.

Parameters
station_type
value

Definition at line 109 of file cpm_ts_setters.h.

◆ setTimestampITS()

void etsi_its_cpm_ts_msgs::access::setTimestampITS ( TimestampIts & timestamp_its,
const uint64_t unix_nanosecs,
const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second )
inline

Set the TimestampITS object.

Parameters
[in]timestamp_itsTimestampITS object to set the timestamp
[in]unix_nanosecsUnix-Nanoseconds to set the timestamp for
[in]n_leap_secondsNumber of leap-seconds since 2004. (Default: etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second)
[in]epoch_offsetUnix-Timestamp in seconds for the 01.01.2004 at 00:00:00

Definition at line 83 of file cpm_ts_setters.h.

86 {
87 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
88}
89

◆ setUTMPositionOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::setUTMPositionOfPerceivedObject ( CollectivePerceptionMessage & cpm,
PerceivedObject & object,
const gm::PointStamped & utm_position,
const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE )
inline

Sets the position of a perceived object based on a UTM position.

This function sets the position of a perceived object using the provided UTM position and the CPM's reference position. It also allows specifying confidence values for the x, y, and z coordinates.

Parameters
cpmThe CPM to get the reference position from.
objectThe PerceivedObject to set the position for.
utm_positiongm::PointStamped representing the UTM position of the object including the frame_id (utm_<zone><N/S>).
x_confidenceThe confidence value in meters for the x coordinate (default: CoordinateConfidence::UNAVAILABLE).
y_confidenceThe confidence value in meters for the y coordinate (default: CoordinateConfidence::UNAVAILABLE).
z_confidenceThe confidence value in meters for the z coordinate (default: CoordinateConfidence::UNAVAILABLE).
Exceptions
std::invalid_argumentif the UTM-Position frame_id does not match the reference position frame_id.

Definition at line 345 of file cpm_ts_setters.h.

357 {
358 // wrap angle to range [0, 360]
359 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
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;
363
364 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
365 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;

◆ setVelocityComponent()

void etsi_its_cpm_ts_msgs::access::setVelocityComponent ( VelocityComponent & velocity,
const int16_t value,
const uint8_t confidence = SpeedConfidence::UNAVAILABLE )
inline

Sets the value and confidence of a VelocityComponent.

This function sets the value and confidence of a VelocityComponent object. The value is limited to a specific range, and the confidence is limited to a specific range as well. If the provided value or confidence is out of range, it will be set to the corresponding out-of-range value.

Parameters
velocityThe VelocityComponent object to set the value and confidence for.
valueThe value to set for the VelocityComponent in cm/s.
confidenceThe confidence to set for the VelocityComponent in cm/s. Default value is SpeedConfidence::UNAVAILABLE.

Definition at line 378 of file cpm_ts_setters.h.

384 {
385 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
386 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
387 // limit value range
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;
392 }
393 }
394 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
395 object.z_angular_velocity.confidence.value = confidence;

◆ setVelocityOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::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 )
inline

Sets the velocity of a perceived object.

This function sets the velocity of a perceived object using the provided Cartesian velocity components. Optionally, confidence values can be specified for each velocity component.

Parameters
objectThe perceived object for which the velocity is being set.
cartesian_velocityThe Cartesian velocity components (x, y, z) of the object (in m/s).
x_confidenceThe confidence value in m/s for the x velocity component (default: SpeedConfidence::UNAVAILABLE).
y_confidenceThe confidence value in m/s for the y velocity component (default: SpeedConfidence::UNAVAILABLE).
z_confidenceThe confidence value in m/s for the z velocity component (default: SpeedConfidence::UNAVAILABLE).

Definition at line 409 of file cpm_ts_setters.h.

414 {
415 // limit value range
416 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
417 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
418 } else {
419 dimension.value.value = value;
420 }
421

◆ setXDimensionOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::setXDimensionOfPerceivedObject ( PerceivedObject & object,
const double value,
const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE )
inline

Sets the x-dimension of a perceived object.

This function sets the x-dimension of the given PerceivedObject to the specified value. The x-dimension usually represents the length of the object.

Parameters
objectThe PerceivedObject to modify.
valueThe value to set as the x-dimension in meters.
confidenceThe confidence of the x-dimension value in meters (optional, default is ObjectDimensionConfidence::UNAVAILABLE).

Definition at line 576 of file cpm_ts_setters.h.

579 {
580 // check for maximum number of containers

◆ setYawOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::setYawOfPerceivedObject ( PerceivedObject & object,
const double yaw,
const uint8_t confidence = AngleConfidence::UNAVAILABLE )
inline

Sets the yaw angle of a perceived object.

This function sets the yaw angle of a PerceivedObject. The yaw angle is wrapped to the range [0, 360] degrees. The function also allows specifying the confidence level of the yaw angle.

Parameters
objectThe PerceivedObject to set the yaw angle for.
yawThe yaw angle in radians.
confidenceThe confidence level of the yaw angle in 0,1 degrees (optional, default is AngleConfidence::UNAVAILABLE).

Definition at line 492 of file cpm_ts_setters.h.

492 {
493 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
494 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
495 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
496}
497

◆ setYawRateOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::setYawRateOfPerceivedObject ( PerceivedObject & object,
const double yaw_rate,
const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE )
inline

Sets the yaw rate of a perceived object.

This function sets the yaw rate of a PerceivedObject. The yaw rate is limited to the range defined by CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE and CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE. The function also allows specifying the confidence level of the yaw rate.

Parameters
objectThe PerceivedObject to set the yaw rate for.
yaw_rateThe yaw rate in rad/s.
confidenceConfidence of the yaw rate defined in AngularSpeedConfidence (optional, default is AngularSpeedConfidence::UNAVAILABLE).

Definition at line 519 of file cpm_ts_setters.h.

522 : 0).
523 */
524inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
525 const gm::PointStamped& point, const int16_t delta_time = 0) {
526 setUTMPositionOfPerceivedObject(cpm, object, point);
528}
529

◆ setYDimensionOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::setYDimensionOfPerceivedObject ( PerceivedObject & object,
const double value,
const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE )
inline

Sets the y-dimension of a perceived object.

This function sets the y-dimension of the given PerceivedObject to the specified value. The y-dimension usually represents the width of the object.

Parameters
objectThe PerceivedObject to modify.
valueThe value to set as the y-dimension in meters.
confidenceThe confidence of the y-dimension value in meters (optional, default is ObjectDimensionConfidence::UNAVAILABLE).

Definition at line 592 of file cpm_ts_setters.h.

627 {
628
630
640inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
641 const uint8_t protocol_version = 0) {
642 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
643}
644
656inline void setReferenceTime(
657 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
658 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
659 TimestampIts t_its;
660 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
661 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
662 cpm.payload.management_container.reference_time = t_its;
663}
664
676inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
677 const double altitude = AltitudeValue::UNAVAILABLE) {
678 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
679}
680
693inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
694 const bool& northp) {
695 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
696}
697
706inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
707 object.object_id.value = id;
708 object.object_id_is_present = true;
709}
710
722inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
723 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
724 throw std::invalid_argument("MeasurementDeltaTime out of range");
725 } else {
726 object.measurement_delta_time.value = delta_time;
727 }
728}
729
743inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
744 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
745 // limit value range
746 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
747 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
748 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
749 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
750 } else {
751 coordinate.value.value = value;
752 }
753
754 // limit confidence range
755 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
756 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
757 } else {
758 coordinate.confidence.value = confidence;
759 }
760}
761
773inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
774 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
775 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
776 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
777 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
778 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
779 if (point.z != 0.0) {
780 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
781 object.position.z_coordinate_is_present = true;
782 }
783}
784
800inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
801 const gm::PointStamped& utm_position,
802 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
803 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
804 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
805 gm::PointStamped reference_position = getUTMPosition(cpm);
806 if (utm_position.header.frame_id != reference_position.header.frame_id) {
807 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
808 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
809 ")");
810 }
811 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
812 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
813 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
814 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
815 if (utm_position.point.z != 0.0) {
816 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
817 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
818 object.position.z_coordinate_is_present = true;
819 }
820}
821
833inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
834 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
835 // limit value range
836 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
837 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
838 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
839 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
840 } else {
841 velocity.value.value = value;
842 }
843
844 // limit confidence range
845 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
846 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
847 } else {
848 velocity.confidence.value = confidence;
849 }
850}
851
864inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
865 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
866 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
867 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
868 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
869 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
870 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
871 if (cartesian_velocity.z != 0.0) {
872 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
873 object.velocity.cartesian_velocity.z_velocity_is_present = true;
874 }
875 object.velocity_is_present = true;
876}
877
889inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
890 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
891 // limit value range
892 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
893 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
894 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
895 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
896 } else {
897 acceleration.value.value = value;
898 }
899
900 // limit confidence range
901 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
902 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
903 } else {
904 acceleration.confidence.value = confidence;
905 }
906}
907
920inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
921 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
922 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
923 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
924 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
925 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
926 x_confidence * 10);
927 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
928 y_confidence * 10);
929 if (cartesian_acceleration.z != 0.0) {
930 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
931 z_confidence * 10);
932 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
933 }
934 object.acceleration_is_present = true;
935}
936
947inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
948 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
949 // wrap angle to range [0, 360]
950 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
951 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
952 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
953 object.angles.z_angle.value.value = yaw_in_degrees * 10;
954
955 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
956 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
957 } else {
958 object.angles.z_angle.confidence.value = confidence;
959 }
960 object.angles_is_present = true;
961}
962
974inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
975 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
976 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
977 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
978 // limit value range
979 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
980 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
981 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
982 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
983 }
984 }
985 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
986 object.z_angular_velocity.confidence.value = confidence;
987 object.z_angular_velocity_is_present = true;
988}
989
1004inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1005 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1006 // limit value range
1007 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1008 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1009 } else {
1010 dimension.value.value = value;
1011 }
1012
1013 // limit confidence range
1014 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1015 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1016 } else {
1017 dimension.confidence.value = confidence;
1018 }
1019}
1020
1031inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1032 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1033 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1034 object.object_dimension_x_is_present = true;
1035}
1036
1047inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1048 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1049 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1050 object.object_dimension_y_is_present = true;
1051}
1052
1063inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1064 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1065 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1066 object.object_dimension_z_is_present = true;
1067}
1068
1080inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1081 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1082 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1083 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1084 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1085 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1086 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1087}
1088
1098inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1099 setPositionOfPerceivedObject(object, point);
1100 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1101}
1102
1115inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1116 const gm::PointStamped& point, const int16_t delta_time = 0) {
1117 setUTMPositionOfPerceivedObject(cpm, object, point);
1118 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1119}
1120
1130inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1131 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1132 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1133}
1134
1148inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1149 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1150 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1151 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1152 container.container_data_perceived_object_container.perceived_objects.array.size();
1153 } else {
1154 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1155 }
1156}
1157
1170inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1171 // check for maximum number of containers
1172 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1173 cpm.payload.cpm_containers.value.array.push_back(container);
1174 } else {
1175 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1176 }
1177}
1178
1179} // namespace etsi_its_cpm_ts_msgs::access

◆ setZDimensionOfPerceivedObject()

void etsi_its_cpm_ts_msgs::access::setZDimensionOfPerceivedObject ( PerceivedObject & object,
const double value,
const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE )
inline

Sets the z-dimension of a perceived object.

This function sets the z-dimension of the given PerceivedObject to the specified value. The z-dimension usually represents the height of the object.

Parameters
objectThe PerceivedObject to modify.
valueThe value to set as the z-dimension in meters.
confidenceThe confidence of the z-dimension value in meters (optional, default is ObjectDimensionConfidence::UNAVAILABLE).

Definition at line 608 of file cpm_ts_setters.h.

643 {
644
646
656inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
657 const uint8_t protocol_version = 0) {
658 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
659}
660
672inline void setReferenceTime(
673 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
674 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
675 TimestampIts t_its;
676 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
677 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
678 cpm.payload.management_container.reference_time = t_its;
679}
680
692inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
693 const double altitude = AltitudeValue::UNAVAILABLE) {
694 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
695}
696
709inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
710 const bool& northp) {
711 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
712}
713
722inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
723 object.object_id.value = id;
724 object.object_id_is_present = true;
725}
726
738inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
739 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
740 throw std::invalid_argument("MeasurementDeltaTime out of range");
741 } else {
742 object.measurement_delta_time.value = delta_time;
743 }
744}
745
759inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
760 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
761 // limit value range
762 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
763 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
764 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
765 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
766 } else {
767 coordinate.value.value = value;
768 }
769
770 // limit confidence range
771 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
772 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
773 } else {
774 coordinate.confidence.value = confidence;
775 }
776}
777
789inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
790 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
791 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
792 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
793 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
794 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
795 if (point.z != 0.0) {
796 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
797 object.position.z_coordinate_is_present = true;
798 }
799}
800
816inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
817 const gm::PointStamped& utm_position,
818 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
819 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
820 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
821 gm::PointStamped reference_position = getUTMPosition(cpm);
822 if (utm_position.header.frame_id != reference_position.header.frame_id) {
823 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
824 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
825 ")");
826 }
827 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
828 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
829 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
830 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
831 if (utm_position.point.z != 0.0) {
832 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
833 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
834 object.position.z_coordinate_is_present = true;
835 }
836}
837
849inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
850 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
851 // limit value range
852 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
853 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
854 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
855 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
856 } else {
857 velocity.value.value = value;
858 }
859
860 // limit confidence range
861 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
862 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
863 } else {
864 velocity.confidence.value = confidence;
865 }
866}
867
880inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
881 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
882 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
883 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
884 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
885 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
886 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
887 if (cartesian_velocity.z != 0.0) {
888 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
889 object.velocity.cartesian_velocity.z_velocity_is_present = true;
890 }
891 object.velocity_is_present = true;
892}
893
905inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
906 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
907 // limit value range
908 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
909 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
910 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
911 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
912 } else {
913 acceleration.value.value = value;
914 }
915
916 // limit confidence range
917 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
918 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
919 } else {
920 acceleration.confidence.value = confidence;
921 }
922}
923
936inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
937 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
938 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
939 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
940 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
941 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
942 x_confidence * 10);
943 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
944 y_confidence * 10);
945 if (cartesian_acceleration.z != 0.0) {
946 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
947 z_confidence * 10);
948 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
949 }
950 object.acceleration_is_present = true;
951}
952
963inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
964 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
965 // wrap angle to range [0, 360]
966 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
967 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
968 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
969 object.angles.z_angle.value.value = yaw_in_degrees * 10;
970
971 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
972 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
973 } else {
974 object.angles.z_angle.confidence.value = confidence;
975 }
976 object.angles_is_present = true;
977}
978
990inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
991 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
992 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
993 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
994 // limit value range
995 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
996 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
997 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
998 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
999 }
1000 }
1001 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1002 object.z_angular_velocity.confidence.value = confidence;
1003 object.z_angular_velocity_is_present = true;
1004}
1005
1020inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1021 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1022 // limit value range
1023 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1024 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1025 } else {
1026 dimension.value.value = value;
1027 }
1028
1029 // limit confidence range
1030 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1031 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1032 } else {
1033 dimension.confidence.value = confidence;
1034 }
1035}
1036
1047inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1048 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1049 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1050 object.object_dimension_x_is_present = true;
1051}
1052
1063inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1064 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1065 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1066 object.object_dimension_y_is_present = true;
1067}
1068
1079inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1080 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1081 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1082 object.object_dimension_z_is_present = true;
1083}
1084
1096inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1097 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1098 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1099 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1100 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1101 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1102 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1103}
1104
1114inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1115 setPositionOfPerceivedObject(object, point);
1116 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1117}
1118
1131inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1132 const gm::PointStamped& point, const int16_t delta_time = 0) {
1133 setUTMPositionOfPerceivedObject(cpm, object, point);
1134 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1135}
1136
1146inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1147 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1148 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1149}
1150
1164inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1165 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1166 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1167 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1168 container.container_data_perceived_object_container.perceived_objects.array.size();
1169 } else {
1170 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1171 }
1172}
1173
1186inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1187 // check for maximum number of containers
1188 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1189 cpm.payload.cpm_containers.value.array.push_back(container);
1190 } else {
1191 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1192 }
1193}
1194
1195} // namespace etsi_its_cpm_ts_msgs::access

◆ throwIfOutOfRange()

template<typename T1 , typename T2 >
void etsi_its_cpm_ts_msgs::access::throwIfOutOfRange ( const T1 & val,
const T2 & min,
const T2 & max,
const std::string val_desc )

Definition at line 37 of file cpm_ts_access.h.