etsi_its_messages v3.1.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 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 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 181 of file cdd_getters_common.h.

181 {
182 std::array<double, 4> covariance_matrix;
183 double semi_major_squared = semi_major * semi_major / (etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR * etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR);
184 double semi_minor_squared = semi_minor * semi_minor / (etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR * etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR);
185 double major_orientation_rad = major_orientation * M_PI / 180;
186 double object_heading_rad = object_heading;
187
188 double angle_to_object = object_heading_rad - major_orientation_rad;
189
190 double cos_angle = std::cos(angle_to_object);
191 double sin_angle = std::sin(angle_to_object);
192 covariance_matrix[0] = semi_major_squared * cos_angle * cos_angle + semi_minor_squared * sin_angle * sin_angle;
193 covariance_matrix[1] = (semi_major_squared - semi_minor_squared) * cos_angle * sin_angle;
194 covariance_matrix[2] = covariance_matrix[1];
195 covariance_matrix[3] = semi_major_squared * sin_angle * sin_angle + semi_minor_squared * cos_angle * cos_angle;
196
197 return covariance_matrix;
198}

◆ 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

Definition at line 70 of file cdd_getters_common.h.

70{ return ((double)altitude.altitude_value.value) * 1e-2; }

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

131{ 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 142 of file cdd_getters_common.h.

142{ 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 162 of file cdd_getters_common.h.

162 {
163 return {
164 getSemiAxis(position_confidence_ellipse.semi_major_confidence),
165 getSemiAxis(position_confidence_ellipse.semi_minor_confidence),
166 position_confidence_ellipse.semi_major_orientation.value * 1e-1
167 };
168}
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 223 of file cdd_getters_common.h.

223 {
224 auto [semi_major, semi_minor, major_orientation] = getPosConfidenceEllipse(position_confidence_ellipse);
225 return CovMatrixFromConfidenceEllipse(semi_major, semi_minor, major_orientation, object_heading);
226}
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 151 of file cdd_getters_common.h.

151 {
152 return ((double)semi_axis_length.value) * 1e-2 / etsi_its_msgs::OneCentimeterHelper<SemiAxisLength>::value;
153}

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

78{ 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 86 of file cdd_getters_common.h.

86 {
87 return ((double)speed.speed_confidence.value) / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR * 1e-2;
88}

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

102 {
103 gm::PointStamped utm_point;
104 double latitude = getLatitude(reference_position.latitude);
105 double longitude = getLongitude(reference_position.longitude);
106 utm_point.point.z = getAltitude(reference_position.altitude);
107 try {
108 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y);
109 std::string hemisphere;
110 if (northp) {
111 hemisphere = "N";
112 } else {
113 hemisphere = "S";
114 }
115 utm_point.header.frame_id = "utm_" + std::to_string(zone) + hemisphere;
116 } catch (GeographicLib::GeographicErr& e) {
117 throw std::invalid_argument(e.what());
118 }
119 return utm_point;
120}
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 236 of file cdd_getters_common.h.

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

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

210 {
211 // The WGS covariance matrix is the same as in vehicle coordinates, if it would have a heading of 0.0
212 return CovMatrixFromConfidenceEllipse(semi_major, semi_minor, major_orientation, 0.0);
213}