etsi_its_messages v3.0.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)
 Throws an exception if a given value is out of a defined range.
 
void etsi_its_cpm_ts_msgs::access::throwIfNotPresent (const bool is_present, const std::string val_desc)
 Throws an exception if the given value is not present.
 
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.
 
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 706 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 684 of file cpm_ts_setters.h.

720 {
721
723
733inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
734 const uint8_t protocol_version = 0) {
735 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
736}
737
749inline void setReferenceTime(
750 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
751 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
752 TimestampIts t_its;
753 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
754 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
755 cpm.payload.management_container.reference_time = t_its;
756}
757
769inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
770 const double altitude = AltitudeValue::UNAVAILABLE) {
771 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
772}
773
786inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
787 const bool& northp) {
788 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
789}
790
799inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
800 object.object_id.value = id;
801 object.object_id_is_present = true;
802}
803
815inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
816 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
817 throw std::invalid_argument("MeasurementDeltaTime out of range");
818 } else {
819 object.measurement_delta_time.value = delta_time;
820 }
821}
822
836inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
837 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
838 // limit value range
839 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
840 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
841 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
842 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
843 } else {
844 coordinate.value.value = value;
845 }
846
847 // limit confidence range
848 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
849 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
850 } else {
851 coordinate.confidence.value = confidence;
852 }
853}
854
866inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
867 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
868 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
869 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
870 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
871 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
872 if (point.z != 0.0) {
873 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
874 object.position.z_coordinate_is_present = true;
875 }
876}
877
893inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
894 const gm::PointStamped& utm_position,
895 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
896 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
897 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
898 gm::PointStamped reference_position = getUTMPosition(cpm);
899 if (utm_position.header.frame_id != reference_position.header.frame_id) {
900 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
901 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
902 ")");
903 }
904 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
905 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
906 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
907 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
908 if (utm_position.point.z != 0.0) {
909 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
910 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
911 object.position.z_coordinate_is_present = true;
912 }
913}
914
926inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
927 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
928 // limit value range
929 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
930 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
931 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
932 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
933 } else {
934 velocity.value.value = value;
935 }
936
937 // limit confidence range
938 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
939 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
940 } else {
941 velocity.confidence.value = confidence;
942 }
943}
944
957inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
958 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
959 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
960 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
961 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
962 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
963 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
964 if (cartesian_velocity.z != 0.0) {
965 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
966 object.velocity.cartesian_velocity.z_velocity_is_present = true;
967 }
968 object.velocity_is_present = true;
969}
970
982inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
983 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
984 // limit value range
985 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
986 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
987 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
988 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
989 } else {
990 acceleration.value.value = value;
991 }
992
993 // limit confidence range
994 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
995 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
996 } else {
997 acceleration.confidence.value = confidence;
998 }
999}
1000
1013inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
1014 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
1015 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
1016 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
1017 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
1018 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
1019 x_confidence * 10);
1020 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
1021 y_confidence * 10);
1022 if (cartesian_acceleration.z != 0.0) {
1023 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
1024 z_confidence * 10);
1025 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
1026 }
1027 object.acceleration_is_present = true;
1028}
1029
1040inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
1041 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
1042 // wrap angle to range [0, 360]
1043 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
1044 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
1045 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
1046 object.angles.z_angle.value.value = yaw_in_degrees * 10;
1047
1048 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
1049 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
1050 } else {
1051 object.angles.z_angle.confidence.value = confidence;
1052 }
1053 object.angles_is_present = true;
1054}
1055
1067inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1068 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1069 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1070 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1071 // limit value range
1072 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1073 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1074 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1075 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1076 }
1077 }
1078 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1079 object.z_angular_velocity.confidence.value = confidence;
1080 object.z_angular_velocity_is_present = true;
1081}
1082
1097inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1098 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1099 // limit value range
1100 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1101 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1102 } else {
1103 dimension.value.value = value;
1104 }
1105
1106 // limit confidence range
1107 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1108 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1109 } else {
1110 dimension.confidence.value = confidence;
1111 }
1112}
1113
1124inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1125 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1126 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1127 object.object_dimension_x_is_present = true;
1128}
1129
1140inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1141 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1142 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1143 object.object_dimension_y_is_present = true;
1144}
1145
1156inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1157 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1158 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1159 object.object_dimension_z_is_present = true;
1160}
1161
1173inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1174 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1175 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1176 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1177 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1178 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1179 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1180}
1181
1191inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1192 setPositionOfPerceivedObject(object, point);
1193 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1194}
1195
1208inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1209 const gm::PointStamped& point, const int16_t delta_time = 0) {
1210 setUTMPositionOfPerceivedObject(cpm, object, point);
1211 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1212}
1213
1223inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1224 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1225 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1226}
1227
1241inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1242 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1243 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1244 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1245 container.container_data_perceived_object_container.perceived_objects.array.size();
1246 } else {
1247 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1248 }
1249}
1250
1263inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1264 // check for maximum number of containers
1265 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1266 cpm.payload.cpm_containers.value.array.push_back(container);
1267 } else {
1268 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1269 }
1270}
1271
1272} // namespace etsi_its_cpm_ts_msgs::access
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.
Setter functions for the ETSI ITS Common Data Dictionary (CDD) v2.1.1.
void throwIfOutOfRange(const T1 &val, const T2 &min, const T2 &max, const std::string val_desc)
Throws an exception if a given value is out of a defined range.
Definition checks.h:46
const std::map< uint64_t, uint16_t > LEAP_SECOND_INSERTIONS_SINCE_2004
std::map that stores all leap second insertions since 2004 with the corresponding unix-date of the in...
Definition constants.h:45
gm::PointStamped getUTMPosition(const T &reference_position, int &zone, bool &northp)
Get the UTM Position defined by the given ReferencePosition.
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 setItsPduHeader(ItsPduHeader &header, const uint8_t message_id, const uint32_t station_id, const uint8_t protocol_version=0)
Set the Its Pdu Header object.
void setFromUTMPosition(T &reference_position, const gm::PointStamped &utm_position, const int zone, const bool northp)
Set the ReferencePosition from a given UTM-Position.
void 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 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 634 of file cpm_ts_setters.h.

670 {
671
673
683inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
684 const uint8_t protocol_version = 0) {
685 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
686}
687
699inline void setReferenceTime(
700 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
701 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
702 TimestampIts t_its;
703 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
704 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
705 cpm.payload.management_container.reference_time = t_its;
706}
707
719inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
720 const double altitude = AltitudeValue::UNAVAILABLE) {
721 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
722}
723
736inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
737 const bool& northp) {
738 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
739}
740
749inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
750 object.object_id.value = id;
751 object.object_id_is_present = true;
752}
753
765inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
766 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
767 throw std::invalid_argument("MeasurementDeltaTime out of range");
768 } else {
769 object.measurement_delta_time.value = delta_time;
770 }
771}
772
786inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
787 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
788 // limit value range
789 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
790 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
791 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
792 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
793 } else {
794 coordinate.value.value = value;
795 }
796
797 // limit confidence range
798 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
799 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
800 } else {
801 coordinate.confidence.value = confidence;
802 }
803}
804
816inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
817 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
818 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
819 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
820 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
821 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
822 if (point.z != 0.0) {
823 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
824 object.position.z_coordinate_is_present = true;
825 }
826}
827
843inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
844 const gm::PointStamped& utm_position,
845 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
846 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
847 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
848 gm::PointStamped reference_position = getUTMPosition(cpm);
849 if (utm_position.header.frame_id != reference_position.header.frame_id) {
850 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
851 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
852 ")");
853 }
854 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
855 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
856 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
857 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
858 if (utm_position.point.z != 0.0) {
859 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
860 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
861 object.position.z_coordinate_is_present = true;
862 }
863}
864
876inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
877 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
878 // limit value range
879 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
880 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
881 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
882 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
883 } else {
884 velocity.value.value = value;
885 }
886
887 // limit confidence range
888 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
889 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
890 } else {
891 velocity.confidence.value = confidence;
892 }
893}
894
907inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
908 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
909 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
910 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
911 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
912 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
913 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
914 if (cartesian_velocity.z != 0.0) {
915 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
916 object.velocity.cartesian_velocity.z_velocity_is_present = true;
917 }
918 object.velocity_is_present = true;
919}
920
932inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
933 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
934 // limit value range
935 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
936 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
937 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
938 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
939 } else {
940 acceleration.value.value = value;
941 }
942
943 // limit confidence range
944 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
945 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
946 } else {
947 acceleration.confidence.value = confidence;
948 }
949}
950
963inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
964 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
965 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
966 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
967 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
968 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
969 x_confidence * 10);
970 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
971 y_confidence * 10);
972 if (cartesian_acceleration.z != 0.0) {
973 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
974 z_confidence * 10);
975 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
976 }
977 object.acceleration_is_present = true;
978}
979
990inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
991 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
992 // wrap angle to range [0, 360]
993 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
994 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
995 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
996 object.angles.z_angle.value.value = yaw_in_degrees * 10;
997
998 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
999 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
1000 } else {
1001 object.angles.z_angle.confidence.value = confidence;
1002 }
1003 object.angles_is_present = true;
1004}
1005
1017inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1018 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1019 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1020 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1021 // limit value range
1022 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1023 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1024 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1025 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1026 }
1027 }
1028 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1029 object.z_angular_velocity.confidence.value = confidence;
1030 object.z_angular_velocity_is_present = true;
1031}
1032
1047inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1048 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1049 // limit value range
1050 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1051 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1052 } else {
1053 dimension.value.value = value;
1054 }
1055
1056 // limit confidence range
1057 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1058 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1059 } else {
1060 dimension.confidence.value = confidence;
1061 }
1062}
1063
1074inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1075 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1076 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1077 object.object_dimension_x_is_present = true;
1078}
1079
1090inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1091 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1092 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1093 object.object_dimension_y_is_present = true;
1094}
1095
1106inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1107 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1108 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1109 object.object_dimension_z_is_present = true;
1110}
1111
1123inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1124 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1125 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1126 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1127 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1128 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1129 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1130}
1131
1141inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1142 setPositionOfPerceivedObject(object, point);
1143 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1144}
1145
1158inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1159 const gm::PointStamped& point, const int16_t delta_time = 0) {
1160 setUTMPositionOfPerceivedObject(cpm, object, point);
1161 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1162}
1163
1173inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1174 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1175 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1176}
1177
1191inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1192 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1193 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1194 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1195 container.container_data_perceived_object_container.perceived_objects.array.size();
1196 } else {
1197 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1198 }
1199}
1200
1213inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1214 // check for maximum number of containers
1215 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1216 cpm.payload.cpm_containers.value.array.push_back(container);
1217 } else {
1218 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1219 }
1220}
1221
1222} // 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 666 of file cpm_ts_setters.h.

702 {
703
705
715inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
716 const uint8_t protocol_version = 0) {
717 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
718}
719
731inline void setReferenceTime(
732 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
733 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
734 TimestampIts t_its;
735 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
736 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
737 cpm.payload.management_container.reference_time = t_its;
738}
739
751inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
752 const double altitude = AltitudeValue::UNAVAILABLE) {
753 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
754}
755
768inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
769 const bool& northp) {
770 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
771}
772
781inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
782 object.object_id.value = id;
783 object.object_id_is_present = true;
784}
785
797inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
798 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
799 throw std::invalid_argument("MeasurementDeltaTime out of range");
800 } else {
801 object.measurement_delta_time.value = delta_time;
802 }
803}
804
818inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
819 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
820 // limit value range
821 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
822 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
823 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
824 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
825 } else {
826 coordinate.value.value = value;
827 }
828
829 // limit confidence range
830 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
831 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
832 } else {
833 coordinate.confidence.value = confidence;
834 }
835}
836
848inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
849 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
850 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
851 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
852 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
853 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
854 if (point.z != 0.0) {
855 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
856 object.position.z_coordinate_is_present = true;
857 }
858}
859
875inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
876 const gm::PointStamped& utm_position,
877 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
878 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
879 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
880 gm::PointStamped reference_position = getUTMPosition(cpm);
881 if (utm_position.header.frame_id != reference_position.header.frame_id) {
882 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
883 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
884 ")");
885 }
886 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
887 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
888 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
889 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
890 if (utm_position.point.z != 0.0) {
891 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
892 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
893 object.position.z_coordinate_is_present = true;
894 }
895}
896
908inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
909 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
910 // limit value range
911 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
912 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
913 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
914 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
915 } else {
916 velocity.value.value = value;
917 }
918
919 // limit confidence range
920 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
921 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
922 } else {
923 velocity.confidence.value = confidence;
924 }
925}
926
939inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
940 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
941 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
942 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
943 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
944 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
945 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
946 if (cartesian_velocity.z != 0.0) {
947 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
948 object.velocity.cartesian_velocity.z_velocity_is_present = true;
949 }
950 object.velocity_is_present = true;
951}
952
964inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
965 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
966 // limit value range
967 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
968 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
969 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
970 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
971 } else {
972 acceleration.value.value = value;
973 }
974
975 // limit confidence range
976 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
977 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
978 } else {
979 acceleration.confidence.value = confidence;
980 }
981}
982
995inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
996 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
997 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
998 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
999 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
1000 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
1001 x_confidence * 10);
1002 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
1003 y_confidence * 10);
1004 if (cartesian_acceleration.z != 0.0) {
1005 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
1006 z_confidence * 10);
1007 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
1008 }
1009 object.acceleration_is_present = true;
1010}
1011
1022inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
1023 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
1024 // wrap angle to range [0, 360]
1025 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
1026 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
1027 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
1028 object.angles.z_angle.value.value = yaw_in_degrees * 10;
1029
1030 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
1031 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
1032 } else {
1033 object.angles.z_angle.confidence.value = confidence;
1034 }
1035 object.angles_is_present = true;
1036}
1037
1049inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1050 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1051 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1052 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1053 // limit value range
1054 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1055 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1056 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1057 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1058 }
1059 }
1060 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1061 object.z_angular_velocity.confidence.value = confidence;
1062 object.z_angular_velocity_is_present = true;
1063}
1064
1079inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1080 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1081 // limit value range
1082 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1083 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1084 } else {
1085 dimension.value.value = value;
1086 }
1087
1088 // limit confidence range
1089 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1090 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1091 } else {
1092 dimension.confidence.value = confidence;
1093 }
1094}
1095
1106inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1107 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1108 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1109 object.object_dimension_x_is_present = true;
1110}
1111
1122inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1123 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1124 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1125 object.object_dimension_y_is_present = true;
1126}
1127
1138inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1139 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1140 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1141 object.object_dimension_z_is_present = true;
1142}
1143
1155inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1156 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1157 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1158 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1159 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1160 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1161 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1162}
1163
1173inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1174 setPositionOfPerceivedObject(object, point);
1175 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1176}
1177
1190inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1191 const gm::PointStamped& point, const int16_t delta_time = 0) {
1192 setUTMPositionOfPerceivedObject(cpm, object, point);
1193 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1194}
1195
1205inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1206 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1207 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1208}
1209
1223inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1224 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1225 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1226 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1227 container.container_data_perceived_object_container.perceived_objects.array.size();
1228 } else {
1229 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1230 }
1231}
1232
1245inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1246 // check for maximum number of containers
1247 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1248 cpm.payload.cpm_containers.value.array.push_back(container);
1249 } else {
1250 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1251 }
1252}
1253
1254} // 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 651 of file cpm_ts_setters.h.

687 {
688
690
700inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
701 const uint8_t protocol_version = 0) {
702 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
703}
704
716inline void setReferenceTime(
717 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
718 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
719 TimestampIts t_its;
720 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
721 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
722 cpm.payload.management_container.reference_time = t_its;
723}
724
736inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
737 const double altitude = AltitudeValue::UNAVAILABLE) {
738 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
739}
740
753inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
754 const bool& northp) {
755 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
756}
757
766inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
767 object.object_id.value = id;
768 object.object_id_is_present = true;
769}
770
782inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
783 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
784 throw std::invalid_argument("MeasurementDeltaTime out of range");
785 } else {
786 object.measurement_delta_time.value = delta_time;
787 }
788}
789
803inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
804 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
805 // limit value range
806 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
807 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
808 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
809 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
810 } else {
811 coordinate.value.value = value;
812 }
813
814 // limit confidence range
815 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
816 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
817 } else {
818 coordinate.confidence.value = confidence;
819 }
820}
821
833inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
834 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
835 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
836 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
837 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
838 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
839 if (point.z != 0.0) {
840 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
841 object.position.z_coordinate_is_present = true;
842 }
843}
844
860inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
861 const gm::PointStamped& utm_position,
862 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
863 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
864 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
865 gm::PointStamped reference_position = getUTMPosition(cpm);
866 if (utm_position.header.frame_id != reference_position.header.frame_id) {
867 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
868 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
869 ")");
870 }
871 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
872 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
873 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
874 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
875 if (utm_position.point.z != 0.0) {
876 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
877 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
878 object.position.z_coordinate_is_present = true;
879 }
880}
881
893inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
894 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
895 // limit value range
896 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
897 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
898 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
899 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
900 } else {
901 velocity.value.value = value;
902 }
903
904 // limit confidence range
905 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
906 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
907 } else {
908 velocity.confidence.value = confidence;
909 }
910}
911
924inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
925 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
926 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
927 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
928 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
929 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
930 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
931 if (cartesian_velocity.z != 0.0) {
932 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
933 object.velocity.cartesian_velocity.z_velocity_is_present = true;
934 }
935 object.velocity_is_present = true;
936}
937
949inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
950 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
951 // limit value range
952 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
953 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
954 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
955 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
956 } else {
957 acceleration.value.value = value;
958 }
959
960 // limit confidence range
961 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
962 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
963 } else {
964 acceleration.confidence.value = confidence;
965 }
966}
967
980inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
981 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
982 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
983 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
984 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
985 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
986 x_confidence * 10);
987 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
988 y_confidence * 10);
989 if (cartesian_acceleration.z != 0.0) {
990 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
991 z_confidence * 10);
992 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
993 }
994 object.acceleration_is_present = true;
995}
996
1007inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
1008 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
1009 // wrap angle to range [0, 360]
1010 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
1011 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
1012 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
1013 object.angles.z_angle.value.value = yaw_in_degrees * 10;
1014
1015 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
1016 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
1017 } else {
1018 object.angles.z_angle.confidence.value = confidence;
1019 }
1020 object.angles_is_present = true;
1021}
1022
1034inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1035 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1036 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1037 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1038 // limit value range
1039 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1040 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1041 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1042 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1043 }
1044 }
1045 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1046 object.z_angular_velocity.confidence.value = confidence;
1047 object.z_angular_velocity_is_present = true;
1048}
1049
1064inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1065 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1066 // limit value range
1067 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1068 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1069 } else {
1070 dimension.value.value = value;
1071 }
1072
1073 // limit confidence range
1074 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1075 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1076 } else {
1077 dimension.confidence.value = confidence;
1078 }
1079}
1080
1091inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1092 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1093 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1094 object.object_dimension_x_is_present = true;
1095}
1096
1107inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1108 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1109 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1110 object.object_dimension_y_is_present = true;
1111}
1112
1123inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1124 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1125 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1126 object.object_dimension_z_is_present = true;
1127}
1128
1140inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1141 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1142 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1143 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1144 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1145 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1146 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1147}
1148
1158inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1159 setPositionOfPerceivedObject(object, point);
1160 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1161}
1162
1175inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1176 const gm::PointStamped& point, const int16_t delta_time = 0) {
1177 setUTMPositionOfPerceivedObject(cpm, object, point);
1178 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1179}
1180
1190inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1191 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1192 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1193}
1194
1208inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1209 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1210 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1211 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1212 container.container_data_perceived_object_container.perceived_objects.array.size();
1213 } else {
1214 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1215 }
1216}
1217
1230inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1231 // check for maximum number of containers
1232 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1233 cpm.payload.cpm_containers.value.array.push_back(container);
1234 } else {
1235 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1236 }
1237}
1238
1239} // 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 425 of file cpm_ts_setters.h.

426 {
427 dimension.confidence.value = confidence;
428 }
429}
430
441inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
442 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {

◆ 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 456 of file cpm_ts_setters.h.

458 {
459 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
460 object.object_dimension_y_is_present = true;
461}
462

◆ 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.

◆ 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 279 of file cpm_ts_setters.h.

◆ 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 616 of file cpm_ts_setters.h.

665inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
666 const uint8_t protocol_version = 0) {
667 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
668}
669
681inline void setReferenceTime(
682 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
683 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
684 TimestampIts t_its;
685 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
686 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
687 cpm.payload.management_container.reference_time = t_its;
688}
689
701inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
702 const double altitude = AltitudeValue::UNAVAILABLE) {
703 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
704}
705
718inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
719 const bool& northp) {
720 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
721}
722
731inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
732 object.object_id.value = id;
733 object.object_id_is_present = true;
734}
735
747inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
748 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
749 throw std::invalid_argument("MeasurementDeltaTime out of range");
750 } else {
751 object.measurement_delta_time.value = delta_time;
752 }
753}
754
768inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
769 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
770 // limit value range
771 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
772 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
773 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
774 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
775 } else {
776 coordinate.value.value = value;
777 }
778
779 // limit confidence range
780 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
781 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
782 } else {
783 coordinate.confidence.value = confidence;
784 }
785}
786
798inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
799 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
800 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
801 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
802 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
803 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
804 if (point.z != 0.0) {
805 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
806 object.position.z_coordinate_is_present = true;
807 }
808}
809
825inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
826 const gm::PointStamped& utm_position,
827 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
828 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
829 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
830 gm::PointStamped reference_position = getUTMPosition(cpm);
831 if (utm_position.header.frame_id != reference_position.header.frame_id) {
832 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
833 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
834 ")");
835 }
836 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
837 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
838 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
839 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
840 if (utm_position.point.z != 0.0) {
841 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
842 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
843 object.position.z_coordinate_is_present = true;
844 }
845}
846
858inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
859 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
860 // limit value range
861 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
862 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
863 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
864 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
865 } else {
866 velocity.value.value = value;
867 }
868
869 // limit confidence range
870 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
871 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
872 } else {
873 velocity.confidence.value = confidence;
874 }
875}
876
889inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
890 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
891 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
892 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
893 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
894 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
895 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
896 if (cartesian_velocity.z != 0.0) {
897 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
898 object.velocity.cartesian_velocity.z_velocity_is_present = true;
899 }
900 object.velocity_is_present = true;
901}
902
914inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
915 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
916 // limit value range
917 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
918 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
919 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
920 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
921 } else {
922 acceleration.value.value = value;
923 }
924
925 // limit confidence range
926 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
927 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
928 } else {
929 acceleration.confidence.value = confidence;
930 }
931}
932
945inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
946 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
947 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
948 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
949 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
950 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
951 x_confidence * 10);
952 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
953 y_confidence * 10);
954 if (cartesian_acceleration.z != 0.0) {
955 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
956 z_confidence * 10);
957 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
958 }
959 object.acceleration_is_present = true;
960}
961
972inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
973 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
974 // wrap angle to range [0, 360]
975 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
976 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
977 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
978 object.angles.z_angle.value.value = yaw_in_degrees * 10;
979
980 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
981 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
982 } else {
983 object.angles.z_angle.confidence.value = confidence;
984 }
985 object.angles_is_present = true;
986}
987
999inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
1000 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
1001 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
1002 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
1003 // limit value range
1004 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
1005 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
1006 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
1007 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
1008 }
1009 }
1010 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
1011 object.z_angular_velocity.confidence.value = confidence;
1012 object.z_angular_velocity_is_present = true;
1013}
1014
1029inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1030 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1031 // limit value range
1032 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1033 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1034 } else {
1035 dimension.value.value = value;
1036 }
1037
1038 // limit confidence range
1039 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1040 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1041 } else {
1042 dimension.confidence.value = confidence;
1043 }
1044}
1045
1056inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1057 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1058 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1059 object.object_dimension_x_is_present = true;
1060}
1061
1072inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1073 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1074 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1075 object.object_dimension_y_is_present = true;
1076}
1077
1088inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1089 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1090 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1091 object.object_dimension_z_is_present = true;
1092}
1093
1105inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1106 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1107 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1108 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1109 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1110 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1111 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1112}
1113
1123inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1124 setPositionOfPerceivedObject(object, point);
1125 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1126}
1127
1140inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1141 const gm::PointStamped& point, const int16_t delta_time = 0) {
1142 setUTMPositionOfPerceivedObject(cpm, object, point);
1143 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1144}
1145
1155inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1156 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1157 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1158}
1159
1173inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1174 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1175 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1176 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1177 container.container_data_perceived_object_container.perceived_objects.array.size();
1178 } else {
1179 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1180 }
1181}
1182
1195inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1196 // check for maximum number of containers
1197 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1198 cpm.payload.cpm_containers.value.array.push_back(container);
1199 } else {
1200 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1201 }
1202}
1203
1204} // 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 229 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.

214 {
215 gm::PointStamped reference_position = getUTMPosition(cpm);
216 if (utm_position.header.frame_id != reference_position.header.frame_id) {
217 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
218 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
219 ")");
220 }
221 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
222 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);

◆ 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 242 of file cpm_ts_setters.h.

244 {
245 // limit value range

◆ 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 176 of file cpm_ts_setters.h.

179 : CoordinateConfidence::UNAVAILABLE).

◆ 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 85 of file cpm_ts_setters.h.

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

◆ 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 160 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 141 of file cpm_ts_setters.h.

◆ 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 130 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 111 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 258 of file cpm_ts_setters.h.

◆ 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 540 of file cpm_ts_setters.h.

◆ 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 309 of file cpm_ts_setters.h.

◆ 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 212 of file cpm_ts_setters.h.

◆ 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.

◆ 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 192 of file cpm_ts_setters.h.

◆ 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.

◆ 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.

◆ 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 72 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 100 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.

◆ 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 336 of file cpm_ts_setters.h.

◆ 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 369 of file cpm_ts_setters.h.

385 {
386 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;

◆ 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 400 of file cpm_ts_setters.h.

◆ 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 567 of file cpm_ts_setters.h.

◆ 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 483 of file cpm_ts_setters.h.

486 : ObjectDimensionConfidence::UNAVAILABLE).
487 * @param y_confidence The confidence in meters for the y dimension (optional, default: ObjectDimensionConfidence::UNAVAILABLE).
488 * @param z_confidence The confidence in meters for the z dimension (optional, default: ObjectDimensionConfidence::UNAVAILABLE).
489 */
490inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
491 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
492 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
493 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
494 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
495 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
496 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
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 510 of file cpm_ts_setters.h.

◆ 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 583 of file cpm_ts_setters.h.

584 {
585 throw std::invalid_argument("Maximum number of CPM-Containers reached");
586 }
587}

◆ 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 599 of file cpm_ts_setters.h.

635 {
636
638
648inline void setItsPduHeader(CollectivePerceptionMessage& cpm, const uint32_t station_id,
649 const uint8_t protocol_version = 0) {
650 setItsPduHeader(cpm.header, MessageId::CPM, station_id, protocol_version);
651}
652
664inline void setReferenceTime(
665 CollectivePerceptionMessage& cpm, const uint64_t unix_nanosecs,
666 const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.end()->second) {
667 TimestampIts t_its;
668 setTimestampITS(t_its, unix_nanosecs, n_leap_seconds);
669 throwIfOutOfRange(t_its.value, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
670 cpm.payload.management_container.reference_time = t_its;
671}
672
684inline void setReferencePosition(CollectivePerceptionMessage& cpm, const double latitude, const double longitude,
685 const double altitude = AltitudeValue::UNAVAILABLE) {
686 setReferencePosition(cpm.payload.management_container.reference_position, latitude, longitude, altitude);
687}
688
701inline void setFromUTMPosition(CollectivePerceptionMessage& cpm, const gm::PointStamped& utm_position, const int& zone,
702 const bool& northp) {
703 setFromUTMPosition(cpm.payload.management_container.reference_position, utm_position, zone, northp);
704}
705
714inline void setIdOfPerceivedObject(PerceivedObject& object, const uint16_t id) {
715 object.object_id.value = id;
716 object.object_id_is_present = true;
717}
718
730inline void setMeasurementDeltaTimeOfPerceivedObject(PerceivedObject& object, const int16_t delta_time = 0) {
731 if (delta_time < DeltaTimeMilliSecondSigned::MIN || delta_time > DeltaTimeMilliSecondSigned::MAX) {
732 throw std::invalid_argument("MeasurementDeltaTime out of range");
733 } else {
734 object.measurement_delta_time.value = delta_time;
735 }
736}
737
751inline void setCartesianCoordinateWithConfidence(CartesianCoordinateWithConfidence& coordinate, const int32_t value,
752 const uint16_t confidence = CoordinateConfidence::UNAVAILABLE) {
753 // limit value range
754 if (value < CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE) {
755 coordinate.value.value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
756 } else if (value > CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE) {
757 coordinate.value.value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
758 } else {
759 coordinate.value.value = value;
760 }
761
762 // limit confidence range
763 if (confidence > CoordinateConfidence::MAX || confidence < CoordinateConfidence::MIN) {
764 coordinate.confidence.value = CoordinateConfidence::OUT_OF_RANGE;
765 } else {
766 coordinate.confidence.value = confidence;
767 }
768}
769
781inline void setPositionOfPerceivedObject(PerceivedObject& object, const gm::Point& point,
782 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
783 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
784 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
785 setCartesianCoordinateWithConfidence(object.position.x_coordinate, point.x * 100, x_confidence * 100);
786 setCartesianCoordinateWithConfidence(object.position.y_coordinate, point.y * 100, y_confidence * 100);
787 if (point.z != 0.0) {
788 setCartesianCoordinateWithConfidence(object.position.z_coordinate, point.z * 100, z_confidence * 100);
789 object.position.z_coordinate_is_present = true;
790 }
791}
792
808inline void setUTMPositionOfPerceivedObject(CollectivePerceptionMessage& cpm, PerceivedObject& object,
809 const gm::PointStamped& utm_position,
810 const uint16_t x_confidence = CoordinateConfidence::UNAVAILABLE,
811 const uint16_t y_confidence = CoordinateConfidence::UNAVAILABLE,
812 const uint16_t z_confidence = CoordinateConfidence::UNAVAILABLE) {
813 gm::PointStamped reference_position = getUTMPosition(cpm);
814 if (utm_position.header.frame_id != reference_position.header.frame_id) {
815 throw std::invalid_argument("UTM-Position frame_id (" + utm_position.header.frame_id +
816 ") does not match the reference position frame_id (" + reference_position.header.frame_id +
817 ")");
818 }
819 setCartesianCoordinateWithConfidence(object.position.x_coordinate,
820 (utm_position.point.x - reference_position.point.x) * 100, x_confidence);
821 setCartesianCoordinateWithConfidence(object.position.y_coordinate,
822 (utm_position.point.y - reference_position.point.y) * 100, y_confidence);
823 if (utm_position.point.z != 0.0) {
824 setCartesianCoordinateWithConfidence(object.position.z_coordinate,
825 (utm_position.point.z - reference_position.point.z) * 100, z_confidence);
826 object.position.z_coordinate_is_present = true;
827 }
828}
829
841inline void setVelocityComponent(VelocityComponent& velocity, const int16_t value,
842 const uint8_t confidence = SpeedConfidence::UNAVAILABLE) {
843 // limit value range
844 if (value < VelocityComponentValue::NEGATIVE_OUT_OF_RANGE) {
845 velocity.value.value = VelocityComponentValue::NEGATIVE_OUT_OF_RANGE;
846 } else if (value > VelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
847 velocity.value.value = VelocityComponentValue::POSITIVE_OUT_OF_RANGE;
848 } else {
849 velocity.value.value = value;
850 }
851
852 // limit confidence range
853 if (confidence > SpeedConfidence::MAX || confidence < SpeedConfidence::MIN) {
854 velocity.confidence.value = SpeedConfidence::OUT_OF_RANGE;
855 } else {
856 velocity.confidence.value = confidence;
857 }
858}
859
872inline void setVelocityOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_velocity,
873 const uint8_t x_confidence = SpeedConfidence::UNAVAILABLE,
874 const uint8_t y_confidence = SpeedConfidence::UNAVAILABLE,
875 const uint8_t z_confidence = SpeedConfidence::UNAVAILABLE) {
876 object.velocity.choice = Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY;
877 setVelocityComponent(object.velocity.cartesian_velocity.x_velocity, cartesian_velocity.x * 100, x_confidence * 100);
878 setVelocityComponent(object.velocity.cartesian_velocity.y_velocity, cartesian_velocity.y * 100, y_confidence * 100);
879 if (cartesian_velocity.z != 0.0) {
880 setVelocityComponent(object.velocity.cartesian_velocity.z_velocity, cartesian_velocity.z * 100, z_confidence * 100);
881 object.velocity.cartesian_velocity.z_velocity_is_present = true;
882 }
883 object.velocity_is_present = true;
884}
885
897inline void setAccelerationComponent(AccelerationComponent& acceleration, const int16_t value,
898 const uint8_t confidence = AccelerationConfidence::UNAVAILABLE) {
899 // limit value range
900 if (value < AccelerationValue::NEGATIVE_OUT_OF_RANGE) {
901 acceleration.value.value = AccelerationValue::NEGATIVE_OUT_OF_RANGE;
902 } else if (value > AccelerationValue::POSITIVE_OUT_OF_RANGE) {
903 acceleration.value.value = AccelerationValue::POSITIVE_OUT_OF_RANGE;
904 } else {
905 acceleration.value.value = value;
906 }
907
908 // limit confidence range
909 if (confidence > AccelerationConfidence::MAX || confidence < AccelerationConfidence::MIN) {
910 acceleration.confidence.value = AccelerationConfidence::OUT_OF_RANGE;
911 } else {
912 acceleration.confidence.value = confidence;
913 }
914}
915
928inline void setAccelerationOfPerceivedObject(PerceivedObject& object, const gm::Vector3& cartesian_acceleration,
929 const uint8_t x_confidence = AccelerationConfidence::UNAVAILABLE,
930 const uint8_t y_confidence = AccelerationConfidence::UNAVAILABLE,
931 const uint8_t z_confidence = AccelerationConfidence::UNAVAILABLE) {
932 object.acceleration.choice = Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION;
933 setAccelerationComponent(object.acceleration.cartesian_acceleration.x_acceleration, cartesian_acceleration.x * 10,
934 x_confidence * 10);
935 setAccelerationComponent(object.acceleration.cartesian_acceleration.y_acceleration, cartesian_acceleration.y * 10,
936 y_confidence * 10);
937 if (cartesian_acceleration.z != 0.0) {
938 setAccelerationComponent(object.acceleration.cartesian_acceleration.z_acceleration, cartesian_acceleration.z * 10,
939 z_confidence * 10);
940 object.acceleration.cartesian_acceleration.z_acceleration_is_present = true;
941 }
942 object.acceleration_is_present = true;
943}
944
955inline void setYawOfPerceivedObject(PerceivedObject& object, const double yaw,
956 const uint8_t confidence = AngleConfidence::UNAVAILABLE) {
957 // wrap angle to range [0, 360]
958 double yaw_in_degrees = yaw * 180 / M_PI + 180; // TODO: check if this is correct
959 while (yaw_in_degrees > 360.0) yaw_in_degrees -= 360.0;
960 while (yaw_in_degrees < 0) yaw_in_degrees += 360.0;
961 object.angles.z_angle.value.value = yaw_in_degrees * 10;
962
963 if (confidence > AngleConfidence::MAX || confidence < AngleConfidence::MIN) {
964 object.angles.z_angle.confidence.value = AngleConfidence::OUT_OF_RANGE;
965 } else {
966 object.angles.z_angle.confidence.value = confidence;
967 }
968 object.angles_is_present = true;
969}
970
982inline void setYawRateOfPerceivedObject(PerceivedObject& object, const double yaw_rate,
983 const uint8_t confidence = AngularSpeedConfidence::UNAVAILABLE) {
984 int16_t yaw_rate_in_degrees = yaw_rate * 180 / M_PI;
985 if (yaw_rate_in_degrees != CartesianAngularVelocityComponentValue::UNAVAILABLE) {
986 // limit value range
987 if (yaw_rate_in_degrees < CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE) {
988 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::NEGATIVE_OUTOF_RANGE;
989 } else if (yaw_rate_in_degrees > CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE) {
990 yaw_rate_in_degrees = CartesianAngularVelocityComponentValue::POSITIVE_OUT_OF_RANGE;
991 }
992 }
993 object.z_angular_velocity.value.value = yaw_rate_in_degrees;
994 object.z_angular_velocity.confidence.value = confidence;
995 object.z_angular_velocity_is_present = true;
996}
997
1012inline void setObjectDimension(ObjectDimension& dimension, const uint16_t value,
1013 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1014 // limit value range
1015 if (value < ObjectDimensionValue::MIN || value > ObjectDimensionValue::MAX) {
1016 dimension.value.value = ObjectDimensionValue::OUT_OF_RANGE;
1017 } else {
1018 dimension.value.value = value;
1019 }
1020
1021 // limit confidence range
1022 if (confidence > ObjectDimensionConfidence::MAX || confidence < ObjectDimensionConfidence::MIN) {
1023 dimension.confidence.value = ObjectDimensionConfidence::OUT_OF_RANGE;
1024 } else {
1025 dimension.confidence.value = confidence;
1026 }
1027}
1028
1039inline void setXDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1040 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1041 setObjectDimension(object.object_dimension_x, (uint16_t)(value * 10), confidence * 10);
1042 object.object_dimension_x_is_present = true;
1043}
1044
1055inline void setYDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1056 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1057 setObjectDimension(object.object_dimension_y, (uint16_t)(value * 10), confidence * 10);
1058 object.object_dimension_y_is_present = true;
1059}
1060
1071inline void setZDimensionOfPerceivedObject(PerceivedObject& object, const double value,
1072 const uint8_t confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1073 setObjectDimension(object.object_dimension_z, (uint16_t)(value * 10), confidence * 10);
1074 object.object_dimension_z_is_present = true;
1075}
1076
1088inline void setDimensionsOfPerceivedObject(PerceivedObject& object, const gm::Vector3& dimensions,
1089 const uint8_t x_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1090 const uint8_t y_confidence = ObjectDimensionConfidence::UNAVAILABLE,
1091 const uint8_t z_confidence = ObjectDimensionConfidence::UNAVAILABLE) {
1092 setXDimensionOfPerceivedObject(object, dimensions.x, x_confidence);
1093 setYDimensionOfPerceivedObject(object, dimensions.y, y_confidence);
1094 setZDimensionOfPerceivedObject(object, dimensions.z, z_confidence);
1095}
1096
1106inline void initPerceivedObject(PerceivedObject& object, const gm::Point& point, const int16_t delta_time = 0) {
1107 setPositionOfPerceivedObject(object, point);
1108 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1109}
1110
1123inline void initPerceivedObjectWithUTMPosition(CollectivePerceptionMessage& cpm, PerceivedObject& object,
1124 const gm::PointStamped& point, const int16_t delta_time = 0) {
1125 setUTMPositionOfPerceivedObject(cpm, object, point);
1126 setMeasurementDeltaTimeOfPerceivedObject(object, delta_time);
1127}
1128
1138inline void initPerceivedObjectContainer(WrappedCpmContainer& container, const uint8_t n_objects = 0) {
1139 container.container_id.value = WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER;
1140 container.container_data_perceived_object_container.number_of_perceived_objects.value = n_objects;
1141}
1142
1156inline void addPerceivedObjectToContainer(WrappedCpmContainer& container, const PerceivedObject& perceived_object) {
1157 if (container.container_id.value == WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
1158 container.container_data_perceived_object_container.perceived_objects.array.push_back(perceived_object);
1159 container.container_data_perceived_object_container.number_of_perceived_objects.value =
1160 container.container_data_perceived_object_container.perceived_objects.array.size();
1161 } else {
1162 throw std::invalid_argument("Container is not a PerceivedObjectContainer");
1163 }
1164}
1165
1178inline void addContainerToCPM(CollectivePerceptionMessage& cpm, const WrappedCpmContainer& container) {
1179 // check for maximum number of containers
1180 if (cpm.payload.cpm_containers.value.array.size() < WrappedCpmContainers::MAX_SIZE) {
1181 cpm.payload.cpm_containers.value.array.push_back(container);
1182 } else {
1183 throw std::invalid_argument("Maximum number of CPM-Containers reached");
1184 }
1185}
1186
1187} // namespace etsi_its_cpm_ts_msgs::access

◆ throwIfNotPresent()

void etsi_its_cpm_ts_msgs::access::throwIfNotPresent ( const bool is_present,
const std::string val_desc )
inline

Throws an exception if the given value is not present.

Parameters
is_presentWhether the value is present.
val_descDescription of the value for the exception message.

Definition at line 58 of file cpm_ts_setters.h.

◆ 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 )

Throws an exception if a given value is out of a defined range.

Template Parameters
T1
T2
Parameters
valThe value to check if it is in the range.
minThe minimum value of the range.
maxThe maximum value of the range.
val_descDescription of the value for the exception message.

Definition at line 47 of file cpm_ts_setters.h.

51 {