36namespace etsi_its_cpm_ts_msgs::access {
56inline TimestampIts
getReferenceTime(
const CollectivePerceptionMessage &cpm) {
57 return cpm.payload.management_container.reference_time;
74inline double getLatitude(
const CollectivePerceptionMessage &cpm) {
75 return getLatitude(cpm.payload.management_container.reference_position.latitude);
84inline double getLongitude(
const CollectivePerceptionMessage &cpm) {
85 return getLongitude(cpm.payload.management_container.reference_position.longitude);
94inline double getAltitude(
const CollectivePerceptionMessage &cpm) {
95 return getAltitude(cpm.payload.management_container.reference_position.altitude);
109inline gm::PointStamped
getUTMPosition(
const CollectivePerceptionMessage &cpm,
int &zone,
bool &northp) {
110 return getUTMPosition(cpm.payload.management_container.reference_position, zone, northp);
122inline gm::PointStamped
getUTMPosition(
const CollectivePerceptionMessage &cpm) {
137inline std::vector<uint8_t>
getCpmContainerIds(
const CollectivePerceptionMessage &cpm) {
138 std::vector<uint8_t> container_ids;
139 for (
int i = 0; i < cpm.payload.cpm_containers.value.array.size(); i++) {
140 container_ids.push_back(cpm.payload.cpm_containers.value.array[i].container_id.value);
142 return container_ids;
153inline WrappedCpmContainer
getCpmContainer(
const CollectivePerceptionMessage &cpm,
const uint8_t container_id) {
154 for (
int i = 0; i < cpm.payload.cpm_containers.value.array.size(); i++) {
155 if (cpm.payload.cpm_containers.value.array[i].container_id.value == container_id) {
156 return cpm.payload.cpm_containers.value.array[i];
159 throw std::invalid_argument(
"No Container with ID " + std::to_string(container_id) +
" found in CPM");
171 return getCpmContainer(cpm, WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER);
181inline uint8_t getNumberOfPerceivedObjects(
const WrappedCpmContainer &container) {
182 if (container.container_id.value != WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
183 throw std::invalid_argument(
"Container is not a PerceivedObjectContainer");
185 uint8_t number = container.container_data_perceived_object_container.number_of_perceived_objects.value;
195inline uint8_t getNumberOfPerceivedObjects(
const CollectivePerceptionMessage &cpm) {
196 return getNumberOfPerceivedObjects(getPerceivedObjectContainer(cpm));
213 throw std::invalid_argument(
"Index out of range");
215 return container.container_data_perceived_object_container.perceived_objects.array[i];
234inline int32_t getCartesianCoordinate(
const CartesianCoordinateWithConfidence &coordinate) {
235 return coordinate.value.value;
245 return coordinate.confidence.value;
258 if (
object.position.z_coordinate_is_present) {
274 double z_confidence =
object.position.z_coordinate_is_present
276 : std::numeric_limits<double>::infinity();
277 return std::make_tuple(x_confidence, y_confidence, z_confidence);
286inline uint16_t
getCartesianAngle(
const CartesianAngle &angle) {
return angle.value.value; }
306inline gm::Quaternion getOrientationOfPerceivedObject(
const PerceivedObject &
object) {
307 if (!
object.angles_is_present)
throw std::invalid_argument(
"No angles present in PerceivedObject");
309 double roll{0}, pitch{0}, yaw{0};
311 if (
object.angles.x_angle_is_present) {
315 if (
object.angles.y_angle_is_present) {
322 q.setRPY(roll, pitch, yaw);
324 return tf2::toMsg(q);
333inline double getYawOfPerceivedObject(
const PerceivedObject &
object) {
334 gm::Quaternion orientation = getOrientationOfPerceivedObject(
object);
335 tf2::Quaternion q(orientation.x, orientation.y, orientation.z, orientation.w);
336 double roll, pitch, yaw;
337 tf2::Matrix3x3(q).getRPY(roll, pitch, yaw);
349 if(!
object.angles_is_present)
throw std::invalid_argument(
"No angles present in PerceivedObject");
350 double yaw_confidence =
object.angles.z_angle.confidence.value / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
351 yaw_confidence *= M_PI / 180.0;
352 return yaw_confidence;
376 if (!
object.z_angular_velocity_is_present)
throw std::invalid_argument(
"No yaw rate present in PerceivedObject");
377 return object.z_angular_velocity.value.value * M_PI / 180.0;
390 if (!
object.z_angular_velocity_is_present)
throw std::invalid_argument(
"No yaw rate present in PerceivedObject");
391 auto val =
object.z_angular_velocity.confidence.value;
392 static const std::map<uint8_t, double> confidence_map = {
393 {AngularSpeedConfidence::UNAVAILABLE, 0.0},
394 {AngularSpeedConfidence::DEG_SEC_01, 1.0},
395 {AngularSpeedConfidence::DEG_SEC_02, 2.0},
396 {AngularSpeedConfidence::DEG_SEC_05, 5.0},
397 {AngularSpeedConfidence::DEG_SEC_10, 10.0},
398 {AngularSpeedConfidence::DEG_SEC_20, 20.0},
399 {AngularSpeedConfidence::DEG_SEC_50, 50.0},
400 {AngularSpeedConfidence::OUT_OF_RANGE, std::numeric_limits<double>::infinity()},
402 return confidence_map.at(val) * M_PI / 180.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
411inline double getVelocityComponent(
const VelocityComponent &velocity) {
return double(velocity.value.value) / 100.0; }
419inline double getVelocityComponentConfidence(
const VelocityComponent &velocity) {
420 return double(velocity.confidence.value) / 100.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
431 if (!
object.velocity_is_present)
throw std::invalid_argument(
"No velocity present in PerceivedObject");
432 if (
object.velocity.choice != Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY) {
433 throw std::invalid_argument(
"Velocity is not Cartesian");
435 gm::Vector3 velocity;
438 if (
object.velocity.cartesian_velocity.z_velocity_is_present) {
452inline std::tuple<double, double, double> getCartesianVelocityConfidenceOfPerceivedObject(
const PerceivedObject &
object) {
453 if (!
object.velocity_is_present)
throw std::invalid_argument(
"No velocity present in PerceivedObject");
454 if (
object.velocity.choice != Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY) {
455 throw std::invalid_argument(
"Velocity is not Cartesian");
457 double x_confidence = getVelocityComponentConfidence(
object.velocity.cartesian_velocity.x_velocity);
458 double y_confidence = getVelocityComponentConfidence(
object.velocity.cartesian_velocity.y_velocity);
459 double z_confidence =
object.velocity.cartesian_velocity.z_velocity_is_present
461 : std::numeric_limits<double>::infinity();
462 return std::make_tuple(x_confidence, y_confidence, z_confidence);
472 return double(acceleration.value.value) / 10.0;
481inline double getAccelerationComponentConfidence(
const AccelerationComponent &acceleration) {
482 return double(acceleration.confidence.value) / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
493 if (!
object.acceleration_is_present)
throw std::invalid_argument(
"No acceleration present in PerceivedObject");
494 if (
object.acceleration.choice != Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION) {
495 throw std::invalid_argument(
"Acceleration is not Cartesian");
497 gm::Vector3 acceleration;
500 if (
object.acceleration.cartesian_acceleration.z_acceleration_is_present) {
514inline std::tuple<double, double, double> getCartesianAccelerationConfidenceOfPerceivedObject(
const PerceivedObject &
object) {
515 if (!
object.acceleration_is_present)
throw std::invalid_argument(
"No acceleration present in PerceivedObject");
516 if (
object.acceleration.choice != Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION) {
517 throw std::invalid_argument(
"Acceleration is not Cartesian");
519 double x_confidence = getAccelerationComponentConfidence(
object.acceleration.cartesian_acceleration.x_acceleration);
520 double y_confidence = getAccelerationComponentConfidence(
object.acceleration.cartesian_acceleration.y_acceleration);
521 double z_confidence =
object.acceleration.cartesian_acceleration.z_acceleration_is_present
522 ? getAccelerationComponentConfidence(
object.acceleration.cartesian_acceleration.z_acceleration)
523 : std::numeric_limits<double>::infinity();
524 return std::make_tuple(x_confidence, y_confidence, z_confidence);
539 if (!
object.object_dimension_x_is_present)
throw std::invalid_argument(
"No x-dimension present in PerceivedObject");
540 return object.object_dimension_x.value.value;
551 if (!
object.object_dimension_x_is_present)
throw std::invalid_argument(
"No x-dimension present in PerceivedObject");
552 return object.object_dimension_x.confidence.value;
567 if (!
object.object_dimension_y_is_present)
throw std::invalid_argument(
"No y-dimension present in PerceivedObject");
568 return object.object_dimension_y.value.value;
579 if (!
object.object_dimension_y_is_present)
throw std::invalid_argument(
"No y-dimension present in PerceivedObject");
580 return object.object_dimension_y.confidence.value;
595 if (!
object.object_dimension_z_is_present)
throw std::invalid_argument(
"No z-dimension present in PerceivedObject");
596 return object.object_dimension_z.value.value;
606inline uint8_t getZDimensionConfidenceOfPerceivedObject(
const PerceivedObject &
object) {
607 if (!
object.object_dimension_z_is_present)
throw std::invalid_argument(
"No z-dimension present in PerceivedObject");
608 return object.object_dimension_z.confidence.value;
620inline gm::Vector3 getDimensionsOfPerceivedObject(
const PerceivedObject &
object) {
621 gm::Vector3 dimensions;
634inline std::tuple<double, double, double> getDimensionsConfidenceOfPerceivedObject(
const PerceivedObject &
object) {
635 double conf_x = double(getXDimensionConfidenceOfPerceivedObject(
object)) / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
636 double conf_y = double(getYDimensionConfidenceOfPerceivedObject(
object)) / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
638 return {conf_x, conf_y, conf_z};
652 const PerceivedObject &
object) {
653 gm::PointStamped utm_position;
657 utm_position.header.frame_id = reference_position.header.frame_id;
658 utm_position.point.x = reference_position.point.x + relative_position.x;
659 utm_position.point.y = reference_position.point.y + relative_position.y;
660 utm_position.point.z = reference_position.point.z + relative_position.z;
gm::PointStamped getUTMPosition(const CAM &cam, int &zone, bool &northp)
Get the UTM Position defined within the BasicContainer of the CAM.
Getter functions for the ETSI ITS Common Data Dictionary (CDD) v2.1.1.
double getYawRateConfidenceOfPerceivedObject(const PerceivedObject &object)
Get the Yaw Rate Confidence Of Perceived Object.
double getYawConfidenceOfPerceivedObject(const PerceivedObject &object)
Get the Yaw Confidence Of Perceived Object object.
int32_t getCartesianCoordinate(const CartesianCoordinateWithConfidence &coordinate)
Retrieves the Cartesian coordinate value from a CartesianCoordinateWithConfidence object.
double getAltitude(const Altitude &altitude)
Get the Altitude value.
uint16_t getZDimensionOfPerceivedObject(const PerceivedObject &object)
Retrieves the z-dimension of a perceived object.
uint8_t getNumberOfPerceivedObjects(const WrappedCpmContainer &container)
gm::Point getPositionOfPerceivedObject(const PerceivedObject &object)
uint64_t getReferenceTimeValue(const CollectivePerceptionMessage &cpm)
Get the ReferenceTime-Value.
uint16_t getCartesianCoordinateConfidence(const CartesianCoordinateWithConfidence &coordinate)
Retrieves the confidence value from a CartesianCoordinateWithConfidence object.
uint8_t getCartesianAngleConfidence(const CartesianAngle &angle)
Get the confidence of the Cartesian angle.
uint16_t getYDimensionOfPerceivedObject(const PerceivedObject &object)
Retrieves the y-dimension of a perceived object.
double getVelocityComponent(const VelocityComponent &velocity)
Get the velocity component of the PerceivedObject.
WrappedCpmContainer getPerceivedObjectContainer(const CollectivePerceptionMessage &cpm)
Retrieves the perceived object container from a CPM.
double getYawRateOfPerceivedObject(const PerceivedObject &object)
Get the yaw rate of the PerceivedObject.
gm::Pose getPoseOfPerceivedObject(const PerceivedObject &object)
Get the pose of the PerceivedObject.
double getLongitude(const Longitude &longitude)
Get the Longitude value.
uint32_t getStationID(const ItsPduHeader &header)
Get the StationID of ItsPduHeader.
uint8_t getYDimensionConfidenceOfPerceivedObject(const PerceivedObject &object)
Gets the confidence of the y-dimension of a perceived object.
gm::PointStamped getUTMPositionOfPerceivedObject(const CollectivePerceptionMessage &cpm, const PerceivedObject &object)
Calculates the UTM position of a perceived object based on the CPMs referencep position.
double getLatitude(const Latitude &latitude)
Get the Latitude value.
uint8_t getZDimensionConfidenceOfPerceivedObject(const PerceivedObject &object)
Gets the confidence of the z-dimension of a perceived object.
uint16_t getCartesianAngle(const CartesianAngle &angle)
Get the Cartesian angle of the PerceivedObject.
double getVelocityComponentConfidence(const VelocityComponent &velocity)
Get the confidence of the velocity component.
std::array< double, 4 > getWGSPosConfidenceEllipse(const PosConfidenceEllipse &position_confidence_ellipse)
Get the covariance matrix of the position confidence ellipse.
uint8_t getXDimensionConfidenceOfPerceivedObject(const PerceivedObject &object)
Gets the confidence of the x-dimension of a perceived object.
uint16_t getIdOfPerceivedObject(const PerceivedObject &object)
Retrieves the ID of a perceived object.
gm::Vector3 getCartesianVelocityOfPerceivedObject(const PerceivedObject &object)
Get the Cartesian velocity of the PerceivedObject.
uint16_t getXDimensionOfPerceivedObject(const PerceivedObject &object)
Gets the x-dimension of a perceived object.
TimestampIts getReferenceTime(const CollectivePerceptionMessage &cpm)
Get the Reference Time object.
std::vector< uint8_t > getCpmContainerIds(const CollectivePerceptionMessage &cpm)
Retrieves the container IDs from a CPM.
const std::array< double, 4 > getWGSRefPosConfidence(const CollectivePerceptionMessage &cpm)
Get the confidence ellipse of the reference position as Covariance matrix.
WrappedCpmContainer getCpmContainer(const CollectivePerceptionMessage &cpm, const uint8_t container_id)
PerceivedObject getPerceivedObject(const WrappedCpmContainer &container, const uint8_t i)
Retrieves the PerceivedObject at the specified index from the given WrappedCpmContainer.
gm::Vector3 getCartesianAccelerationOfPerceivedObject(const PerceivedObject &object)
Get the Cartesian acceleration of the PerceivedObject.
double getAccelerationComponent(const AccelerationComponent &acceleration)
Get the acceleration component of the PerceivedObject.
std::tuple< double, double, double > getPositionConfidenceOfPerceivedObject(const PerceivedObject &object)
Get the Position Confidences Of Perceived Object.
gm::Quaternion getOrientationOfPerceivedObject(const PerceivedObject &object)
Calculates the orientation of a perceived object.
gm::PointStamped getUTMPosition(const T &reference_position, int &zone, bool &northp)
Get the UTM Position defined by the given ReferencePosition.