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);
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;
211inline PerceivedObject getPerceivedObject(
const WrappedCpmContainer &container,
const uint8_t i) {
212 if (i >= getNumberOfPerceivedObjects(container)) {
213 throw std::invalid_argument(
"Index out of range");
215 return container.container_data_perceived_object_container.perceived_objects.array[i];
227 if (!
object.object_id_is_present) {
228 throw std::invalid_argument(
"No object_id present in PerceivedObject");
230 return object.object_id.value;
239inline int32_t getCartesianCoordinate(
const CartesianCoordinateWithConfidence &coordinate) {
240 return coordinate.value.value;
250 return coordinate.confidence.value;
259inline gm::Point getPositionOfPerceivedObject(
const PerceivedObject &
object) {
261 point.x = double(getCartesianCoordinate(
object.position.x_coordinate)) / 100.0;
262 point.y = double(getCartesianCoordinate(
object.position.y_coordinate)) / 100.0;
263 if (
object.position.z_coordinate_is_present) {
264 point.z = double(getCartesianCoordinate(
object.position.z_coordinate)) / 100.0;
279 double z_confidence =
object.position.z_coordinate_is_present
281 : std::numeric_limits<double>::infinity();
282 return std::make_tuple(x_confidence, y_confidence, z_confidence);
291inline uint16_t
getCartesianAngle(
const CartesianAngle &angle) {
return angle.value.value; }
311inline gm::Quaternion getOrientationOfPerceivedObject(
const PerceivedObject &
object) {
312 if (!
object.angles_is_present)
throw std::invalid_argument(
"No angles present in PerceivedObject");
314 double roll{0}, pitch{0}, yaw{0};
316 if (
object.angles.x_angle_is_present) {
320 if (
object.angles.y_angle_is_present) {
324 yaw = (((double(getCartesianAngle(
object.angles.z_angle)) / 10.0)) / 180.0) *
327 q.setRPY(roll, pitch, yaw);
329 return tf2::toMsg(q);
340 tf2::Quaternion q(orientation.x, orientation.y, orientation.z, orientation.w);
341 double roll, pitch, yaw;
342 tf2::Matrix3x3(q).getRPY(roll, pitch, yaw);
353inline double getYawConfidenceOfPerceivedObject(
const PerceivedObject &
object) {
354 if(!
object.angles_is_present)
throw std::invalid_argument(
"No angles present in PerceivedObject");
355 double yaw_confidence =
object.angles.z_angle.confidence.value / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
356 yaw_confidence *= M_PI / 180.0;
357 return yaw_confidence;
366inline gm::Pose getPoseOfPerceivedObject(
const PerceivedObject &
object) {
368 pose.position = getPositionOfPerceivedObject(
object);
369 pose.orientation = getOrientationOfPerceivedObject(
object);
380inline double getYawRateOfPerceivedObject(
const PerceivedObject &
object) {
381 if (!
object.z_angular_velocity_is_present)
throw std::invalid_argument(
"No yaw rate present in PerceivedObject");
382 return object.z_angular_velocity.value.value * M_PI / 180.0;
394inline double getYawRateConfidenceOfPerceivedObject(
const PerceivedObject &
object) {
395 if (!
object.z_angular_velocity_is_present)
throw std::invalid_argument(
"No yaw rate present in PerceivedObject");
396 auto val =
object.z_angular_velocity.confidence.value;
397 static const std::map<uint8_t, double> confidence_map = {
398 {AngularSpeedConfidence::UNAVAILABLE, 0.0},
399 {AngularSpeedConfidence::DEG_SEC_01, 1.0},
400 {AngularSpeedConfidence::DEG_SEC_02, 2.0},
401 {AngularSpeedConfidence::DEG_SEC_05, 5.0},
402 {AngularSpeedConfidence::DEG_SEC_10, 10.0},
403 {AngularSpeedConfidence::DEG_SEC_20, 20.0},
404 {AngularSpeedConfidence::DEG_SEC_50, 50.0},
405 {AngularSpeedConfidence::OUT_OF_RANGE, std::numeric_limits<double>::infinity()},
407 return confidence_map.at(val) * M_PI / 180.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
416inline double getVelocityComponent(
const VelocityComponent &velocity) {
return double(velocity.value.value) / 100.0; }
425 return double(velocity.confidence.value) / 100.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
436 if (!
object.velocity_is_present) {
437 throw std::invalid_argument(
"No velocity present in PerceivedObject");
439 gm::Vector3 velocity;
440 if (
object.velocity.choice == Velocity3dWithConfidence::CHOICE_POLAR_VELOCITY) {
441 double speed =
getSpeed(
object.velocity.polar_velocity.velocity_magnitude);
442 double angle =
getCartesianAngle(
object.velocity.polar_velocity.velocity_direction) * M_PI / 180.0 / 10.0;
443 velocity.x = speed * cos(angle);
444 velocity.y = speed * sin(angle);
445 if (
object.velocity.polar_velocity.z_velocity_is_present) {
448 }
else if (
object.velocity.choice == Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY) {
449 velocity.x = getVelocityComponent(
object.velocity.cartesian_velocity.x_velocity);
450 velocity.y = getVelocityComponent(
object.velocity.cartesian_velocity.y_velocity);
451 if (
object.velocity.cartesian_velocity.z_velocity_is_present) {
452 velocity.z = getVelocityComponent(
object.velocity.cartesian_velocity.z_velocity);
455 throw std::invalid_argument(
"Velocity is neither Polar nor Cartesian");
469 if (!
object.velocity_is_present) {
470 throw std::invalid_argument(
"No velocity present in PerceivedObject");
472 if (
object.velocity.choice == Velocity3dWithConfidence::CHOICE_POLAR_VELOCITY) {
473 double speed_confidence =
getSpeedConfidence(
object.velocity.polar_velocity.velocity_magnitude) / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
474 double angle_confidence =
getCartesianAngleConfidence(
object.velocity.polar_velocity.velocity_direction) * M_PI / 180.0 / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
475 double speed =
getSpeed(
object.velocity.polar_velocity.velocity_magnitude);
476 double angle =
getCartesianAngle(
object.velocity.polar_velocity.velocity_direction) * M_PI / 180.0 / 10.0;
477 double lateral_confidence = speed * angle_confidence;
478 double x_confidence = speed_confidence * cos(angle) * cos(angle)
479 + lateral_confidence * sin(angle) * sin(angle);
480 double y_confidence = speed_confidence * sin(angle) * sin(angle)
481 + lateral_confidence * cos(angle) * cos(angle);
483 double z_confidence =
object.velocity.polar_velocity.z_velocity_is_present
485 : std::numeric_limits<double>::infinity();
486 return std::make_tuple(x_confidence, y_confidence, z_confidence);
487 }
else if (
object.velocity.choice == Velocity3dWithConfidence::CHOICE_CARTESIAN_VELOCITY) {
490 double z_confidence =
object.velocity.cartesian_velocity.z_velocity_is_present
492 : std::numeric_limits<double>::infinity();
493 return std::make_tuple(x_confidence, y_confidence, z_confidence);
495 throw std::invalid_argument(
"Velocity is neither Polar nor Cartesian");
507 return double(acceleration.value.value) / 10.0;
516inline double getAccelerationComponentConfidence(
const AccelerationComponent &acceleration) {
517 return double(acceleration.confidence.value) / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
528 if (!
object.acceleration_is_present) {
529 throw std::invalid_argument(
"No acceleration present in PerceivedObject");
531 gm::Vector3 acceleration;
533 if (
object.acceleration.choice == Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION) {
536 if (
object.acceleration.cartesian_acceleration.z_acceleration_is_present) {
539 }
else if (
object.acceleration.choice == Acceleration3dWithConfidence::CHOICE_POLAR_ACCELERATION) {
541 double angle = getCartesianAngle(
object.acceleration.polar_acceleration.acceleration_direction) * M_PI / 180.0 / 10.0;
542 acceleration.x = magnitude * cos(angle);
543 acceleration.y = magnitude * sin(angle);
544 if (
object.acceleration.polar_acceleration.z_acceleration_is_present) {
545 acceleration.z = getAccelerationComponent(
object.acceleration.polar_acceleration.z_acceleration);
548 throw std::invalid_argument(
"Acceleration is neither Cartesian nor Polar");
563 if (!
object.acceleration_is_present)
throw std::invalid_argument(
"No acceleration present in PerceivedObject");
565 if (
object.acceleration.choice == Acceleration3dWithConfidence::CHOICE_CARTESIAN_ACCELERATION) {
568 double z_confidence =
object.acceleration.cartesian_acceleration.z_acceleration_is_present
570 : std::numeric_limits<double>::infinity();
571 return std::make_tuple(x_confidence, y_confidence, z_confidence);
572 }
else if (
object.acceleration.choice == Acceleration3dWithConfidence::CHOICE_POLAR_ACCELERATION) {
574 double angle_confidence =
getCartesianAngleConfidence(
object.acceleration.polar_acceleration.acceleration_direction) * M_PI / 180.0 / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
576 double angle =
getCartesianAngle(
object.acceleration.polar_acceleration.acceleration_direction) * M_PI / 180.0 / 10.0;
577 double lateral_confidence = magnitude * angle_confidence;
578 double x_confidence = magnitude_confidence * cos(angle) * cos(angle)
579 + lateral_confidence * sin(angle) * sin(angle);
580 double y_confidence = magnitude_confidence * sin(angle) * sin(angle)
581 + lateral_confidence * cos(angle) * cos(angle);
583 double z_confidence =
object.acceleration.polar_acceleration.z_acceleration_is_present
585 : std::numeric_limits<double>::infinity();
586 return std::make_tuple(x_confidence, y_confidence, z_confidence);
588 throw std::invalid_argument(
"Acceleration is neither Cartesian nor Polar");
604 if (!
object.object_dimension_x_is_present)
throw std::invalid_argument(
"No x-dimension present in PerceivedObject");
605 return object.object_dimension_x.value.value;
616 if (!
object.object_dimension_x_is_present)
throw std::invalid_argument(
"No x-dimension present in PerceivedObject");
617 return object.object_dimension_x.confidence.value;
632 if (!
object.object_dimension_y_is_present)
throw std::invalid_argument(
"No y-dimension present in PerceivedObject");
633 return object.object_dimension_y.value.value;
644 if (!
object.object_dimension_y_is_present)
throw std::invalid_argument(
"No y-dimension present in PerceivedObject");
645 return object.object_dimension_y.confidence.value;
660 if (!
object.object_dimension_z_is_present)
throw std::invalid_argument(
"No z-dimension present in PerceivedObject");
661 return object.object_dimension_z.value.value;
671inline uint8_t getZDimensionConfidenceOfPerceivedObject(
const PerceivedObject &
object) {
672 if (!
object.object_dimension_z_is_present)
throw std::invalid_argument(
"No z-dimension present in PerceivedObject");
673 return object.object_dimension_z.confidence.value;
685inline gm::Vector3 getDimensionsOfPerceivedObject(
const PerceivedObject &
object) {
686 gm::Vector3 dimensions;
687 dimensions.x = double(getXDimensionOfPerceivedObject(
object)) / 10.0;
688 dimensions.y = double(getYDimensionOfPerceivedObject(
object)) / 10.0;
699inline std::tuple<double, double, double> getDimensionsConfidenceOfPerceivedObject(
const PerceivedObject &
object) {
700 double conf_x = double(getXDimensionConfidenceOfPerceivedObject(
object)) / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
701 double conf_y = double(getYDimensionConfidenceOfPerceivedObject(
object)) / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
702 double conf_z = double(getZDimensionConfidenceOfPerceivedObject(
object)) / 10.0 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
703 return {conf_x, conf_y, conf_z};
716inline gm::PointStamped getUTMPositionOfPerceivedObject(
const CollectivePerceptionMessage &cpm,
717 const PerceivedObject &
object) {
718 gm::PointStamped utm_position;
722 utm_position.header.frame_id = reference_position.header.frame_id;
723 utm_position.point.x = reference_position.point.x + relative_position.x;
724 utm_position.point.y = reference_position.point.y + relative_position.y;
725 utm_position.point.z = reference_position.point.z + relative_position.z;
749inline uint8_t
getSensorID(
const SensorInformation &sensor_information) {
750 return sensor_information.sensor_id.value;
759inline uint8_t getSensorType(
const SensorInformation &sensor_information) {
760 return sensor_information.sensor_type.value;
double getAccelerationMagnitude(const AccelerationMagnitude &acceleration_magnitude)
Get the AccelerationMagnitude value.
Getter functions for the ETSI ITS Common Data Dictionary (CDD) v2.1.1.
double getSpeed(const Speed &speed)
Get the vehicle speed.
double getAccelerationMagnitude(const AccelerationMagnitude &acceleration_magnitude)
Get the AccelerationMagnitude value.
std::tuple< double, double, double > getCartesianAccelerationConfidenceOfPerceivedObject(const PerceivedObject &object)
Get the Cartesian Acceleration Confidence Of Perceived 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 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.
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.
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)
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.