etsi_its_messages v3.5.0
Loading...
Searching...
No Matches
cdd_getters_common.h File Reference

Common getter functions for the ETSI ITS Common Data Dictionary (CDD) v1.3.1, v2.1.1 and v2.2.1. More...

#include <array>
#include <cmath>
#include <cstdint>
#include <GeographicLib/UTMUPS.hpp>

Go to the source code of this file.

Functions

uint32_t getStationID (const ItsPduHeader &header)
 Get the StationID of ItsPduHeader.
double getLatitude (const Latitude &latitude)
 Get the Latitude value.
double getLongitude (const Longitude &longitude)
 Get the Longitude value.
double getAltitude (const Altitude &altitude)
 Get the Altitude value.
double getSpeed (const Speed &speed)
 Get the vehicle speed.
double getSpeedConfidence (const Speed &speed)
 Get the Speed Confidence.
template<typename AccelerationMagnitude>
double getAccelerationMagnitude (const AccelerationMagnitude &acceleration_magnitude)
 Get the AccelerationMagnitude value.
template<typename AccelerationMagnitude>
double getAccelerationMagnitudeConfidence (const AccelerationMagnitude &acceleration_magnitude)
 Get the AccelerationMagnitude Confidence.
template<typename T>
gm::PointStamped getUTMPosition (const T &reference_position, int &zone, bool &northp)
 Get the UTM Position defined by the given ReferencePosition.
template<typename Heading>
double getHeadingCDD (const Heading &heading)
 Get the Heading value.
template<typename Heading>
double getHeadingConfidenceCDD (const Heading &heading)
 Get the Heading value.
template<typename YawRate>
double getYawRateCDD (const YawRate &yaw_rate)
 Get the Yaw Rate value.
template<typename YawRate, typename YawRateConfidence = decltype(YawRate::yaw_rate_confidence)>
double getYawRateConfidenceCDD (const YawRate &yaw_rate)
 Get the Yaw Rate Confidence.
template<typename SemiAxisLength>
double getSemiAxis (const SemiAxisLength &semi_axis_length)
 Get the Semi Axis object.
template<typename PosConfidenceEllipse>
std::tuple< double, double, double > getPosConfidenceEllipse (const PosConfidenceEllipse &position_confidence_ellipse)
 Extract major axis length, minor axis length and orientation from the given position confidence ellipse.
std::array< double, 4 > CovMatrixFromConfidenceEllipse (double semi_major, double semi_minor, double major_orientation, const double object_heading)
 Convert the confidence ellipse to a covariance matrix.
std::array< double, 4 > WGSCovMatrixFromConfidenceEllipse (double semi_major, double semi_minor, double major_orientation)
 Convert the confidence ellipse to a covariance matrix.
template<typename PosConfidenceEllipse>
std::array< double, 4 > getPosConfidenceEllipse (const PosConfidenceEllipse &position_confidence_ellipse, const double object_heading)
 Get the covariance matrix of the position confidence ellipse.
template<typename PosConfidenceEllipse>
std::array< double, 4 > getWGSPosConfidenceEllipse (const PosConfidenceEllipse &position_confidence_ellipse)
 Get the covariance matrix of the position confidence ellipse.

Detailed Description

Common getter functions for the ETSI ITS Common Data Dictionary (CDD) v1.3.1, v2.1.1 and v2.2.1.

Definition in file cdd_getters_common.h.

Function Documentation

◆ CovMatrixFromConfidenceEllipse()

std::array< double, 4 > CovMatrixFromConfidenceEllipse ( double semi_major,
double semi_minor,
double major_orientation,
const double object_heading )
inline

Convert the confidence ellipse to a covariance matrix.

Note that the major_orientation is given in degrees, while the object_heading is given in radians!

Parameters
semi_majorSemi major axis length in meters
semi_minorSemi minor axis length in meters
major_orientationOrientation of the major axis in degrees, relative to WGS84
object_headingobject heading in radians, relative to WGS84
Returns
std::array<double, 4> The covariance matrix in vehicle coordinates (x = longitudinal, y = lateral)

Definition at line 220 of file cdd_getters_common.h.

220 {
221 std::array<double, 4> covariance_matrix;
222 double semi_major_squared = semi_major * semi_major / (etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR * etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR);
223 double semi_minor_squared = semi_minor * semi_minor / (etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR * etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR);
224 double major_orientation_rad = major_orientation * M_PI / 180;
225 double object_heading_rad = object_heading;
226
227 double angle_to_object = object_heading_rad - major_orientation_rad;
228
229 double cos_angle = std::cos(angle_to_object);
230 double sin_angle = std::sin(angle_to_object);
231 covariance_matrix[0] = semi_major_squared * cos_angle * cos_angle + semi_minor_squared * sin_angle * sin_angle;
232 covariance_matrix[1] = (semi_major_squared - semi_minor_squared) * cos_angle * sin_angle;
233 covariance_matrix[2] = covariance_matrix[1];
234 covariance_matrix[3] = semi_major_squared * sin_angle * sin_angle + semi_minor_squared * cos_angle * cos_angle;
235
236 return covariance_matrix;
237}

◆ getAccelerationMagnitude()

template<typename AccelerationMagnitude>
double getAccelerationMagnitude ( const AccelerationMagnitude & acceleration_magnitude)
inline

Get the AccelerationMagnitude value.

Parameters
acceleration_magnitudeto get the AccelerationMagnitude from
Returns
double acceleration magnitude in m/s^2 as decimal number

Definition at line 79 of file cdd_getters_common.h.

79 {
80 return ((double)acceleration_magnitude.acceleration_magnitude_value.value) * 1e-1;
81}

◆ getAccelerationMagnitudeConfidence()

template<typename AccelerationMagnitude>
double getAccelerationMagnitudeConfidence ( const AccelerationMagnitude & acceleration_magnitude)
inline

Get the AccelerationMagnitude Confidence.

Parameters
acceleration_magnitudeto get the AccelerationMagnitudeConfidence from
Returns
double acceleration magnitude standard deviation in m/s^2 as decimal number

Definition at line 90 of file cdd_getters_common.h.

90 {
91 return ((double)acceleration_magnitude.acceleration_confidence.value) / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR * 1e-1;
92}

◆ getAltitude()

double getAltitude ( const Altitude & altitude)
inline

Get the Altitude value.

Parameters
altitudeto get the Altitude value from
Returns
Altitude value (above the reference ellipsoid surface) in meter as decimal number (0 if unavailable)

Definition at line 47 of file cdd_getters_common.h.

47 {
48 if (altitude.altitude_value.value == AltitudeValue::UNAVAILABLE) {
49 return 0.0;
50 }
51 return ((double)altitude.altitude_value.value) * 1e-2;
52}

◆ getHeadingCDD()

template<typename Heading>
double getHeadingCDD ( const Heading & heading)
inline

Get the Heading value.

0.0° equals WGS84 North, 90.0° equals WGS84 East, 180.0° equals WGS84 South and 270.0° equals WGS84 West

Parameters
headingto get the Heading value from
Returns
Heading value in degree as decimal number

Definition at line 135 of file cdd_getters_common.h.

135{ return ((double)heading.heading_value.value) * 1e-1; }

◆ getHeadingConfidenceCDD()

template<typename Heading>
double getHeadingConfidenceCDD ( const Heading & heading)
inline

Get the Heading value.

0.0° equals WGS84 North, 90.0° equals WGS84 East, 180.0° equals WGS84 South and 270.0° equals WGS84 West

Parameters
headingto get the Heading standard deviation from
Returns
Heading standard deviation in degree as decimal number

Definition at line 146 of file cdd_getters_common.h.

146{ return ((double)heading.heading_confidence.value) * 1e-1 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; }

◆ getLatitude()

double getLatitude ( const Latitude & latitude)
inline

Get the Latitude value.

Parameters
latitudeto get the Latitude value from
Returns
Latitude value in degree as decimal number

Definition at line 31 of file cdd_getters_common.h.

31{ return ((double)latitude.value) * 1e-7; }

◆ getLongitude()

double getLongitude ( const Longitude & longitude)
inline

Get the Longitude value.

Parameters
longitudeto get the Longitude value from
Returns
Longitude value in degree as decimal number

Definition at line 39 of file cdd_getters_common.h.

39{ return ((double)longitude.value) * 1e-7; }

◆ getPosConfidenceEllipse() [1/2]

template<typename PosConfidenceEllipse>
std::tuple< double, double, double > getPosConfidenceEllipse ( const PosConfidenceEllipse & position_confidence_ellipse)
inline

Extract major axis length, minor axis length and orientation from the given position confidence ellipse.

Parameters
position_confidence_ellipseThe position confidence ellipse to extract the values from
Returns
std::tuple<double, double, double> major axis length in meters, minor axis length in meters, and orientation in degrees

Definition at line 201 of file cdd_getters_common.h.

201 {
202 return {
203 getSemiAxis(position_confidence_ellipse.semi_major_confidence),
204 getSemiAxis(position_confidence_ellipse.semi_minor_confidence),
205 position_confidence_ellipse.semi_major_orientation.value * 1e-1
206 };
207}
double getSemiAxis(const SemiAxisLength &semi_axis_length)
Get the Semi Axis object.

◆ getPosConfidenceEllipse() [2/2]

template<typename PosConfidenceEllipse>
std::array< double, 4 > getPosConfidenceEllipse ( const PosConfidenceEllipse & position_confidence_ellipse,
const double object_heading )
inline

Get the covariance matrix of the position confidence ellipse.

Parameters
position_confidence_ellipseThe position confidence ellipse to get the covariance matrix from
object_headingThe object heading in radians
Returns
std::array<double, 4> The covariance matrix of the position confidence ellipse in vehicle coordinates (x = longitudinal, y = lateral)

Definition at line 262 of file cdd_getters_common.h.

262 {
263 auto [semi_major, semi_minor, major_orientation] = getPosConfidenceEllipse(position_confidence_ellipse);
264 return CovMatrixFromConfidenceEllipse(semi_major, semi_minor, major_orientation, object_heading);
265}
std::tuple< double, double, double > getPosConfidenceEllipse(const PosConfidenceEllipse &position_confidence_ellipse)
Extract major axis length, minor axis length and orientation from the given position confidence ellip...
std::array< double, 4 > CovMatrixFromConfidenceEllipse(double semi_major, double semi_minor, double major_orientation, const double object_heading)
Convert the confidence ellipse to a covariance matrix.

◆ getSemiAxis()

template<typename SemiAxisLength>
double getSemiAxis ( const SemiAxisLength & semi_axis_length)
inline

Get the Semi Axis object.

Parameters
semi_axis_lengthThe SemiAxisLength object to get the semi axis from
Returns
double the semi axis length in meters

Definition at line 190 of file cdd_getters_common.h.

190 {
191 return ((double)semi_axis_length.value) * 1e-2 / etsi_its_msgs::OneCentimeterHelper<SemiAxisLength>::value;
192}

◆ getSpeed()

double getSpeed ( const Speed & speed)
inline

Get the vehicle speed.

Parameters
speedto get the speed value from
Returns
speed value in m/s as decimal number

Definition at line 60 of file cdd_getters_common.h.

60{ return ((double)speed.speed_value.value) * 1e-2; }

◆ getSpeedConfidence()

double getSpeedConfidence ( const Speed & speed)
inline

Get the Speed Confidence.

Parameters
speedto get the SpeedConfidence from
Returns
double speed standard deviation in m/s as decimal number

Definition at line 68 of file cdd_getters_common.h.

68 {
69 return ((double)speed.speed_confidence.value) / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR * 1e-2;
70}

◆ getStationID()

uint32_t getStationID ( const ItsPduHeader & header)
inline

Get the StationID of ItsPduHeader.

Parameters
headerItsPduHeader to get the StationID value from
Returns
stationID value

Definition at line 23 of file cdd_getters_common.h.

23{ return header.station_id.value; }

◆ getUTMPosition()

template<typename T>
gm::PointStamped getUTMPosition ( const T & reference_position,
int & zone,
bool & northp )
inline

Get the UTM Position defined by the given ReferencePosition.

The position is transformed into UTM by using GeographicLib::UTMUPS The altitude value is directly used as z-Coordinate

Parameters
[in]reference_positionReferencePosition or ReferencePositionWithConfidence to get the UTM Position from
[out]zonethe UTM zone (zero means UPS)
[out]northphemisphere (true means north, false means south)
Returns
gm::PointStamped geometry_msgs::PointStamped of the given position

Definition at line 106 of file cdd_getters_common.h.

106 {
107 gm::PointStamped utm_point;
108 double latitude = getLatitude(reference_position.latitude);
109 double longitude = getLongitude(reference_position.longitude);
110 utm_point.point.z = getAltitude(reference_position.altitude);
111 try {
112 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y);
113 std::string hemisphere;
114 if (northp) {
115 hemisphere = "N";
116 } else {
117 hemisphere = "S";
118 }
119 utm_point.header.frame_id = "utm_" + std::to_string(zone) + hemisphere;
120 } catch (GeographicLib::GeographicErr& e) {
121 throw std::invalid_argument(e.what());
122 }
123 return utm_point;
124}
double getLatitude(const Latitude &latitude)
Get the Latitude value.
double getLongitude(const Longitude &longitude)
Get the Longitude value.
double getAltitude(const Altitude &altitude)
Get the Altitude value.

◆ getWGSPosConfidenceEllipse()

template<typename PosConfidenceEllipse>
std::array< double, 4 > getWGSPosConfidenceEllipse ( const PosConfidenceEllipse & position_confidence_ellipse)
inline

Get the covariance matrix of the position confidence ellipse.

Parameters
position_confidence_ellipseThe position confidence ellipse to get the covariance matrix from
object_headingThe object heading in radians
Returns
std::array<double, 4> The covariance matrix of the position confidence ellipse in WGS coordinates (x = North, y = East)

Definition at line 275 of file cdd_getters_common.h.

275 {
276 auto [semi_major, semi_minor, major_orientation] = getPosConfidenceEllipse(position_confidence_ellipse);
277 return WGSCovMatrixFromConfidenceEllipse(semi_major, semi_minor, major_orientation);
278}
std::array< double, 4 > WGSCovMatrixFromConfidenceEllipse(double semi_major, double semi_minor, double major_orientation)
Convert the confidence ellipse to a covariance matrix.

◆ getYawRateCDD()

template<typename YawRate>
double getYawRateCDD ( const YawRate & yaw_rate)
inline

Get the Yaw Rate value.

Parameters
yaw_rateThe YawRate object to get the yaw rate from
Returns
double The yaw rate in degrees per second

Definition at line 155 of file cdd_getters_common.h.

155 {
156 return ((double)yaw_rate.yaw_rate_value.value) * 1e-2; // Yaw rate in deg/s
157}

◆ getYawRateConfidenceCDD()

template<typename YawRate, typename YawRateConfidence = decltype(YawRate::yaw_rate_confidence)>
double getYawRateConfidenceCDD ( const YawRate & yaw_rate)
inline

Get the Yaw Rate Confidence.

Parameters
yaw_rateThe YawRate object to get the yaw rate confidence from
Returns
double The yaw rate standard deviation in degrees per second

Definition at line 166 of file cdd_getters_common.h.

166 {
167 auto val = yaw_rate.yaw_rate_confidence.value;
168 static const std::map<uint8_t, double> confidence_map = {
169 {YawRateConfidence::UNAVAILABLE, std::numeric_limits<double>::infinity()},
170 {YawRateConfidence::DEG_SEC_000_01, 0.01},
171 {YawRateConfidence::DEG_SEC_000_05, 0.05},
172 {YawRateConfidence::DEG_SEC_000_10, 0.1},
173 {YawRateConfidence::DEG_SEC_001_00, 1.0},
174 {YawRateConfidence::DEG_SEC_005_00, 5.0},
175 {YawRateConfidence::DEG_SEC_010_00, 10.0},
176 {YawRateConfidence::DEG_SEC_100_00, 100.0},
177 {YawRateConfidence::OUT_OF_RANGE, std::numeric_limits<double>::infinity()},
178 };
179 return confidence_map.at(val) / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
180}

◆ WGSCovMatrixFromConfidenceEllipse()

std::array< double, 4 > WGSCovMatrixFromConfidenceEllipse ( double semi_major,
double semi_minor,
double major_orientation )
inline

Convert the confidence ellipse to a covariance matrix.

Note that the major_orientation is given in degrees, while the object_heading is given in radians!

Parameters
semi_majorSemi major axis length in meters
semi_minorSemi minor axis length in meters
major_orientationOrientation of the major axis in degrees, relative to WGS84
Returns
std::array<double, 4> The covariance matrix in WGS coordinates (x = North, y = East)

Definition at line 249 of file cdd_getters_common.h.

249 {
250 // The WGS covariance matrix is the same as in vehicle coordinates, if it would have a heading of 0.0
251 return CovMatrixFromConfidenceEllipse(semi_major, semi_minor, major_orientation, 0.0);
252}