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