etsi_its_messages v3.3.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 and v2.1.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 and v2.1.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 243 of file cdd_getters_common.h.

243 {
244 std::array<double, 4> covariance_matrix;
245 double semi_major_squared = semi_major * semi_major / (etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR * etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR);
246 double semi_minor_squared = semi_minor * semi_minor / (etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR * etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR);
247 double major_orientation_rad = major_orientation * M_PI / 180;
248 double object_heading_rad = object_heading;
249
250 double angle_to_object = object_heading_rad - major_orientation_rad;
251
252 double cos_angle = std::cos(angle_to_object);
253 double sin_angle = std::sin(angle_to_object);
254 covariance_matrix[0] = semi_major_squared * cos_angle * cos_angle + semi_minor_squared * sin_angle * sin_angle;
255 covariance_matrix[1] = (semi_major_squared - semi_minor_squared) * cos_angle * sin_angle;
256 covariance_matrix[2] = covariance_matrix[1];
257 covariance_matrix[3] = semi_major_squared * sin_angle * sin_angle + semi_minor_squared * cos_angle * cos_angle;
258
259 return covariance_matrix;
260}

◆ 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 102 of file cdd_getters_common.h.

102 {
103 return ((double)acceleration_magnitude.acceleration_magnitude_value.value) * 1e-1;
104}

◆ 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 113 of file cdd_getters_common.h.

113 {
114 return ((double)acceleration_magnitude.acceleration_confidence.value) / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR * 1e-1;
115}

◆ 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 70 of file cdd_getters_common.h.

70 {
71 if (altitude.altitude_value.value == AltitudeValue::UNAVAILABLE) {
72 return 0.0;
73 }
74 return ((double)altitude.altitude_value.value) * 1e-2;
75}

◆ 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 158 of file cdd_getters_common.h.

158{ 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 169 of file cdd_getters_common.h.

169{ 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 54 of file cdd_getters_common.h.

54{ 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 62 of file cdd_getters_common.h.

62{ 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 224 of file cdd_getters_common.h.

224 {
225 return {
226 getSemiAxis(position_confidence_ellipse.semi_major_confidence),
227 getSemiAxis(position_confidence_ellipse.semi_minor_confidence),
228 position_confidence_ellipse.semi_major_orientation.value * 1e-1
229 };
230}
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 285 of file cdd_getters_common.h.

285 {
286 auto [semi_major, semi_minor, major_orientation] = getPosConfidenceEllipse(position_confidence_ellipse);
287 return CovMatrixFromConfidenceEllipse(semi_major, semi_minor, major_orientation, object_heading);
288}
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 213 of file cdd_getters_common.h.

213 {
214 return ((double)semi_axis_length.value) * 1e-2 / etsi_its_msgs::OneCentimeterHelper<SemiAxisLength>::value;
215}

◆ 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 83 of file cdd_getters_common.h.

83{ 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 91 of file cdd_getters_common.h.

91 {
92 return ((double)speed.speed_confidence.value) / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR * 1e-2;
93}

◆ 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 46 of file cdd_getters_common.h.

46{ 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 129 of file cdd_getters_common.h.

129 {
130 gm::PointStamped utm_point;
131 double latitude = getLatitude(reference_position.latitude);
132 double longitude = getLongitude(reference_position.longitude);
133 utm_point.point.z = getAltitude(reference_position.altitude);
134 try {
135 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y);
136 std::string hemisphere;
137 if (northp) {
138 hemisphere = "N";
139 } else {
140 hemisphere = "S";
141 }
142 utm_point.header.frame_id = "utm_" + std::to_string(zone) + hemisphere;
143 } catch (GeographicLib::GeographicErr& e) {
144 throw std::invalid_argument(e.what());
145 }
146 return utm_point;
147}
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 298 of file cdd_getters_common.h.

298 {
299 auto [semi_major, semi_minor, major_orientation] = getPosConfidenceEllipse(position_confidence_ellipse);
300 return WGSCovMatrixFromConfidenceEllipse(semi_major, semi_minor, major_orientation);
301}
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 178 of file cdd_getters_common.h.

178 {
179 return ((double)yaw_rate.yaw_rate_value.value) * 1e-2; // Yaw rate in deg/s
180}

◆ 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 189 of file cdd_getters_common.h.

189 {
190 auto val = yaw_rate.yaw_rate_confidence.value;
191 static const std::map<uint8_t, double> confidence_map = {
192 {YawRateConfidence::UNAVAILABLE, 0.0},
193 {YawRateConfidence::DEG_SEC_000_01, 0.01},
194 {YawRateConfidence::DEG_SEC_000_05, 0.05},
195 {YawRateConfidence::DEG_SEC_000_10, 0.1},
196 {YawRateConfidence::DEG_SEC_001_00, 1.0},
197 {YawRateConfidence::DEG_SEC_005_00, 5.0},
198 {YawRateConfidence::DEG_SEC_010_00, 10.0},
199 {YawRateConfidence::DEG_SEC_100_00, 100.0},
200 {YawRateConfidence::OUT_OF_RANGE, std::numeric_limits<double>::infinity()},
201 };
202 return confidence_map.at(val) / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
203}

◆ 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 272 of file cdd_getters_common.h.

272 {
273 // The WGS covariance matrix is the same as in vehicle coordinates, if it would have a heading of 0.0
274 return CovMatrixFromConfidenceEllipse(semi_major, semi_minor, major_orientation, 0.0);
275}