13namespace etsi_its_cpm_ts_msgs::access {
34 return cpm.payload.management_container.reference_time;
51inline double getLatitude(
const CollectivePerceptionMessage &cpm) {
52 return getLatitude(cpm.payload.management_container.reference_position.latitude);
61inline double getLongitude(
const CollectivePerceptionMessage &cpm) {
62 return getLongitude(cpm.payload.management_container.reference_position.longitude);
71inline double getAltitude(
const CollectivePerceptionMessage &cpm) {
72 return getAltitude(cpm.payload.management_container.reference_position.altitude);
86inline gm::PointStamped
getUTMPosition(
const CollectivePerceptionMessage &cpm,
int &zone,
bool &northp) {
87 return getUTMPosition(cpm.payload.management_container.reference_position, zone, northp);
99inline gm::PointStamped
getUTMPosition(
const CollectivePerceptionMessage &cpm) {
115 std::vector<uint8_t> container_ids;
116 for (
int i = 0; i < cpm.payload.cpm_containers.value.array.size(); i++) {
117 container_ids.push_back(cpm.payload.cpm_containers.value.array[i].container_id.value);
119 return container_ids;
130inline WrappedCpmContainer
getCpmContainer(
const CollectivePerceptionMessage &cpm,
const uint8_t container_id) {
131 for (
int i = 0; i < cpm.payload.cpm_containers.value.array.size(); i++) {
132 if (cpm.payload.cpm_containers.value.array[i].container_id.value == container_id) {
133 return cpm.payload.cpm_containers.value.array[i];
136 throw std::invalid_argument(
"No Container with ID " + std::to_string(container_id) +
" found in CPM");
148 return getCpmContainer(cpm, WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER);
159 if (container.container_id.value != WrappedCpmContainer::CHOICE_CONTAINER_DATA_PERCEIVED_OBJECT_CONTAINER) {
160 throw std::invalid_argument(
"Container is not a PerceivedObjectContainer");
162 uint8_t number = container.container_data_perceived_object_container.number_of_perceived_objects.value;
190 throw std::invalid_argument(
"Index out of range");
192 return container.container_data_perceived_object_container.perceived_objects.array[i];
204 if (!
object.object_id_is_present) {
205 throw std::invalid_argument(
"No object_id present in PerceivedObject");
207 return object.object_id.value;
217 return coordinate.value.value;
227 return coordinate.confidence.value;
240 if (
object.position.z_coordinate_is_present) {
256 double z_confidence =
object.position.z_coordinate_is_present
258 : std::numeric_limits<double>::infinity();
259 return std::make_tuple(x_confidence, y_confidence, z_confidence);
289 if (!
object.angles_is_present)
throw std::invalid_argument(
"No angles present in PerceivedObject");
291 double roll{0}, pitch{0}, yaw{0};
293 if (
object.angles.x_angle_is_present) {
297 if (
object.angles.y_angle_is_present) {
304 q.setRPY(roll, pitch, yaw);
306 return tf2::toMsg(q);
317 tf2::Quaternion q(orientation.x, orientation.y, orientation.z, orientation.w);
318 double roll, pitch, yaw;
319 tf2::Matrix3x3(q).getRPY(roll, pitch, yaw);
331 if(!
object.angles_is_present)
throw std::invalid_argument(
"No angles present in PerceivedObject");
332 double yaw_confidence =
object.angles.z_angle.confidence.value / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
333 yaw_confidence *= M_PI / 180.0;
334 return yaw_confidence;
358 if (!
object.z_angular_velocity_is_present)
throw std::invalid_argument(
"No yaw rate present in PerceivedObject");
359 return object.z_angular_velocity.value.value * M_PI / 180.0;
372 if (!
object.z_angular_velocity_is_present)
throw std::invalid_argument(
"No yaw rate present in PerceivedObject");
373 auto val =
object.z_angular_velocity.confidence.value;
374 static const std::map<uint8_t, double> confidence_map = {
375 {AngularSpeedConfidence::UNAVAILABLE, 0.0},
376 {AngularSpeedConfidence::DEG_SEC_01, 1.0},
377 {AngularSpeedConfidence::DEG_SEC_02, 2.0},
378 {AngularSpeedConfidence::DEG_SEC_05, 5.0},
379 {AngularSpeedConfidence::DEG_SEC_10, 10.0},
380 {AngularSpeedConfidence::DEG_SEC_20, 20.0},
381 {AngularSpeedConfidence::DEG_SEC_50, 50.0},
382 {AngularSpeedConfidence::OUT_OF_RANGE, std::numeric_limits<double>::infinity()},
384 return confidence_map.at(val) * M_PI / 180.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
393inline double getVelocityComponent(
const VelocityComponent &velocity) {
return double(velocity.value.value) / 100.0; }
402 return double(velocity.confidence.value) / 100.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
413 if (!
object.velocity_is_present) {
414 throw std::invalid_argument(
"No velocity present in PerceivedObject");
416 gm::Vector3 velocity;
417 if (
object.velocity.choice == Velocity3dWithConfidence::CHOICE_POLAR_VELOCITY) {
418 double speed =
getSpeed(
object.velocity.polar_velocity.velocity_magnitude);
419 double angle =
getCartesianAngle(
object.velocity.polar_velocity.velocity_direction) * M_PI / 180.0 / 10.0;
420 velocity.x = speed * cos(angle);
421 velocity.y = speed * sin(angle);
422 if (
object.velocity.polar_velocity.z_velocity_is_present) {
425 }
else if (
object.velocity.choice == Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY) {
428 if (
object.velocity.cartesian_velocity.z_velocity_is_present) {
432 throw std::invalid_argument(
"Velocity is neither Polar nor Cartesian");
446 if (!
object.velocity_is_present) {
447 throw std::invalid_argument(
"No velocity present in PerceivedObject");
449 if (
object.velocity.choice == Velocity3dWithConfidence::CHOICE_POLAR_VELOCITY) {
450 double speed_confidence =
getSpeedConfidence(
object.velocity.polar_velocity.velocity_magnitude);
451 double angle_confidence =
getCartesianAngleConfidence(
object.velocity.polar_velocity.velocity_direction) * M_PI / 180.0 / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
452 double speed =
getSpeed(
object.velocity.polar_velocity.velocity_magnitude);
453 double angle =
getCartesianAngle(
object.velocity.polar_velocity.velocity_direction) * M_PI / 180.0 / 10.0;
454 double lateral_confidence = speed * angle_confidence;
455 double x_confidence = speed_confidence * cos(angle) * cos(angle)
456 + lateral_confidence * sin(angle) * sin(angle);
457 double y_confidence = speed_confidence * sin(angle) * sin(angle)
458 + lateral_confidence * cos(angle) * cos(angle);
460 double z_confidence =
object.velocity.polar_velocity.z_velocity_is_present
462 : std::numeric_limits<double>::infinity();
463 return std::make_tuple(x_confidence, y_confidence, z_confidence);
464 }
else if (
object.velocity.choice == Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY) {
467 double z_confidence =
object.velocity.cartesian_velocity.z_velocity_is_present
469 : std::numeric_limits<double>::infinity();
470 return std::make_tuple(x_confidence, y_confidence, z_confidence);
472 throw std::invalid_argument(
"Velocity is neither Polar nor Cartesian");
484 return double(acceleration.value.value) / 10.0;
494 return double(acceleration.confidence.value) / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
505 if (!
object.acceleration_is_present) {
506 throw std::invalid_argument(
"No acceleration present in PerceivedObject");
508 gm::Vector3 acceleration;
510 if (
object.acceleration.choice == Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION) {
513 if (
object.acceleration.cartesian_acceleration.z_acceleration_is_present) {
516 }
else if (
object.acceleration.choice == Acceleration3dWithConfidence::CHOICE_POLAR_ACCELERATION) {
518 double angle =
getCartesianAngle(
object.acceleration.polar_acceleration.acceleration_direction) * M_PI / 180.0 / 10.0;
519 acceleration.x = magnitude * cos(angle);
520 acceleration.y = magnitude * sin(angle);
521 if (
object.acceleration.polar_acceleration.z_acceleration_is_present) {
525 throw std::invalid_argument(
"Acceleration is neither Cartesian nor Polar");
540 if (!
object.acceleration_is_present)
throw std::invalid_argument(
"No acceleration present in PerceivedObject");
542 if (
object.acceleration.choice == Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION) {
545 double z_confidence =
object.acceleration.cartesian_acceleration.z_acceleration_is_present
547 : std::numeric_limits<double>::infinity();
548 return std::make_tuple(x_confidence, y_confidence, z_confidence);
549 }
else if (
object.acceleration.choice == Acceleration3dWithConfidence::CHOICE_POLAR_ACCELERATION) {
551 double angle_confidence =
getCartesianAngleConfidence(
object.acceleration.polar_acceleration.acceleration_direction) * M_PI / 180.0 / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
553 double angle =
getCartesianAngle(
object.acceleration.polar_acceleration.acceleration_direction) * M_PI / 180.0 / 10.0;
554 double lateral_confidence = magnitude * angle_confidence;
555 double x_confidence = magnitude_confidence * cos(angle) * cos(angle)
556 + lateral_confidence * sin(angle) * sin(angle);
557 double y_confidence = magnitude_confidence * sin(angle) * sin(angle)
558 + lateral_confidence * cos(angle) * cos(angle);
560 double z_confidence =
object.acceleration.polar_acceleration.z_acceleration_is_present
562 : std::numeric_limits<double>::infinity();
563 return std::make_tuple(x_confidence, y_confidence, z_confidence);
565 throw std::invalid_argument(
"Acceleration is neither Cartesian nor Polar");
581 if (!
object.object_dimension_x_is_present)
throw std::invalid_argument(
"No x-dimension present in PerceivedObject");
582 return object.object_dimension_x.value.value;
593 if (!
object.object_dimension_x_is_present)
throw std::invalid_argument(
"No x-dimension present in PerceivedObject");
594 return object.object_dimension_x.confidence.value;
609 if (!
object.object_dimension_y_is_present)
throw std::invalid_argument(
"No y-dimension present in PerceivedObject");
610 return object.object_dimension_y.value.value;
621 if (!
object.object_dimension_y_is_present)
throw std::invalid_argument(
"No y-dimension present in PerceivedObject");
622 return object.object_dimension_y.confidence.value;
637 if (!
object.object_dimension_z_is_present)
throw std::invalid_argument(
"No z-dimension present in PerceivedObject");
638 return object.object_dimension_z.value.value;
649 if (!
object.object_dimension_z_is_present)
throw std::invalid_argument(
"No z-dimension present in PerceivedObject");
650 return object.object_dimension_z.confidence.value;
663 gm::Vector3 dimensions;
680 return {conf_x, conf_y, conf_z};
694 const PerceivedObject &
object) {
695 gm::PointStamped utm_position;
699 utm_position.header.frame_id = reference_position.header.frame_id;
700 utm_position.point.x = reference_position.point.x + relative_position.x;
701 utm_position.point.y = reference_position.point.y + relative_position.y;
702 utm_position.point.z = reference_position.point.z + relative_position.z;
726inline uint8_t
getSensorID(
const SensorInformation &sensor_information) {
727 return sensor_information.sensor_id.value;
737 return sensor_information.sensor_type.value;
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 getSpeed(const Speed &speed)
Get the vehicle speed.
double getAccelerationMagnitude(const AccelerationMagnitude &acceleration_magnitude)
Get the AccelerationMagnitude value.
std::tuple< double, double, double > getDimensionsConfidenceOfPerceivedObject(const PerceivedObject &object)
Get the Dimensions Confidence Of Perceived Object.
std::tuple< double, double, double > getCartesianAccelerationConfidenceOfPerceivedObject(const PerceivedObject &object)
Get the Cartesian Acceleration 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.
uint8_t getSensorType(const SensorInformation &sensor_information)
Get the sensorType of a SensorInformation object.
double getYawRateOfPerceivedObject(const PerceivedObject &object)
Get the yaw rate of the PerceivedObject.
gm::Vector3 getDimensionsOfPerceivedObject(const PerceivedObject &object)
Retrieves the dimensions of a perceived object.
gm::Pose getPoseOfPerceivedObject(const PerceivedObject &object)
Get the pose of the PerceivedObject.
double getSpeedConfidence(const Speed &speed)
Get the Speed Confidence.
double getYawOfPerceivedObject(const PerceivedObject &object)
Get the yaw 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.
std::tuple< double, double, double > getCartesianVelocityConfidenceOfPerceivedObject(const PerceivedObject &object)
Get the Cartesian Velocity Confidence Of Perceived Object object.
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.
double getAccelerationMagnitudeConfidence(const AccelerationMagnitude &acceleration_magnitude)
Get the AccelerationMagnitude Confidence.
uint8_t getSensorID(const SensorInformation &sensor_information)
Get the sensorId of a SensorInformation 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.
double getAccelerationComponentConfidence(const AccelerationComponent &acceleration)
Get the confidence of the acceleration component.
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.