etsi_its_messages v3.4.0
Loading...
Searching...
No Matches
cdd_setters_common.h File Reference

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

#include <etsi_its_msgs_utils/impl/checks.h>
#include <etsi_its_msgs_utils/impl/constants.h>
#include <GeographicLib/UTMUPS.hpp>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <type_traits>

Go to the source code of this file.

Functions

template<typename StationId>
void setStationId (StationId &station_id, const uint32_t id_value)
 Set the Station Id object.
template<typename StationType>
void setStationType (StationType &station_type, const uint8_t value)
 Set the Station Type.
void setTimestampITS (TimestampIts &timestamp_its, const uint64_t unix_nanosecs, const uint16_t n_leap_seconds=etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.rbegin() ->second)
 Set the TimestampITS object.
void setLatitude (Latitude &latitude, const double deg)
 Set the Latitude object.
void setLongitude (Longitude &longitude, const double deg)
 Set the Longitude object.
void setAltitudeValue (AltitudeValue &altitude, const double value)
 Set the AltitudeValue object.
void setAltitude (Altitude &altitude, const double value)
 Set the Altitude object.
void setSpeedValue (SpeedValue &speed, const double value)
 Set the SpeedValue object.
void setSpeedConfidence (SpeedConfidence &speed_confidence, const double value)
 Set the Speed Confidence object.
void setSpeed (Speed &speed, const double value, const double confidence=std::numeric_limits< double >::infinity())
 Set the Speed object.
template<typename AccelerationMagnitudeValue>
void setAccelerationMagnitudeValue (AccelerationMagnitudeValue &accel_mag_value, const double value)
 Set the Acceleration Magnitude Value object.
template<typename AccelerationConfidence>
void setAccelerationMagnitudeConfidence (AccelerationConfidence &accel_mag_confidence, const double value)
 Set the AccelerationMagnitude Confidence object.
template<typename AccelerationMagnitude>
void setAccelerationMagnitude (AccelerationMagnitude &accel_mag, const double value, const double confidence=std::numeric_limits< double >::infinity())
 Set the AccelerationMagnitude object.
template<typename AccelerationConfidence>
void setAccelerationConfidence (AccelerationConfidence &accel_confidence, const double value)
 Set the Acceleration Confidence object.
template<typename T>
void setReferencePosition (T &ref_position, const double latitude, const double longitude, const double altitude=AltitudeValue::UNAVAILABLE)
 Sets the reference position in the given ReferencePostion object.
template<typename T>
void setFromUTMPosition (T &reference_position, const gm::PointStamped &utm_position, const int zone, const bool northp)
 Set the ReferencePosition from a given UTM-Position.
template<typename HeadingValue>
void setHeadingValue (HeadingValue &heading, const double value)
 Set the HeadingValue object.
template<typename HeadingConfidence>
void setHeadingConfidence (HeadingConfidence &heading_confidence, const double value)
 Set the Heading Confidence object.
template<typename Heading, typename HeadingConfidence = decltype(Heading::heading_confidence)>
void setHeadingCDD (Heading &heading, const double value, double confidence=std::numeric_limits< double >::infinity())
 Set the Heading object.
template<typename YawRate, typename YawRateValue = decltype(YawRate::yaw_rate_value), typename YawRateConfidence = decltype(YawRate::yaw_rate_confidence)>
void setYawRateCDD (YawRate &yaw_rate, const double value, double confidence=std::numeric_limits< double >::infinity())
 Set the Yaw Rate object.
template<typename SemiAxisLength>
void setSemiAxis (SemiAxisLength &semi_axis_length, const double length)
 Set the Semi Axis length.
template<typename PosConfidenceEllipse>
void setPosConfidenceEllipse (PosConfidenceEllipse &position_confidence_ellipse, const double semi_major_axis, const double semi_minor_axis, const double orientation)
 Set the Pos Confidence Ellipse object.
std::tuple< double, double, double > confidenceEllipseFromCovMatrix (const std::array< double, 4 > &covariance_matrix, const double object_heading)
 Gets the values needed to set a confidence ellipse from a covariance matrix.
std::tuple< double, double, double > confidenceEllipseFromWGSCovMatrix (const std::array< double, 4 > &covariance_matrix)
 Gets the values needed to set a confidence ellipse from a covariance matrix.
template<typename PosConfidenceEllipse>
void setPosConfidenceEllipse (PosConfidenceEllipse &position_confidence_ellipse, const std::array< double, 4 > &covariance_matrix, const double object_heading)
 Set the Pos Confidence Ellipse object.
template<typename PosConfidenceEllipse>
void setWGSPosConfidenceEllipse (PosConfidenceEllipse &position_confidence_ellipse, const std::array< double, 4 > &covariance_matrix)
 Set the Pos Confidence Ellipse object.

Detailed Description

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

Definition in file cdd_setters_common.h.

Function Documentation

◆ confidenceEllipseFromCovMatrix()

std::tuple< double, double, double > confidenceEllipseFromCovMatrix ( const std::array< double, 4 > & covariance_matrix,
const double object_heading )
inline

Gets the values needed to set a confidence ellipse from a covariance matrix.

Parameters
covariance_matrixThe four values of the covariance matrix in the order: cov_xx, cov_xy, cov_yx, cov_yy The matrix has to be SPD, otherwise a std::invalid_argument exception is thrown. Its coordinate system is aligned with the object (x = longitudinal, y = lateral)
object_headingThe heading of the object in rad, with respect to WGS84
Returns
std::tuple<double, double, double> semi_major_axis [m], semi_minor_axis [m], orientation [deg], with respect to WGS84

Definition at line 434 of file cdd_setters_common.h.

434 {
435
436 if(std::abs(covariance_matrix[1] - covariance_matrix[2]) > 1e-6) {
437 throw std::invalid_argument("Covariance matrix is not symmetric");
438 }
439 double trace = covariance_matrix[0] + covariance_matrix[3];
440 double determinant = covariance_matrix[0] * covariance_matrix[3] - covariance_matrix[1] * covariance_matrix[1];
441 if (determinant <= 0 || covariance_matrix[0] <= 0) {
442 // https://sites.math.northwestern.edu/~clark/285/2006-07/handouts/pos-def.pdf:
443 // Therefore, a necessary and sufficient condition for the quadratic form of a symmetric 2 × 2 matrix
444 // to be positive definite is for det(A) > 0 and a > 0
445 throw std::invalid_argument("Covariance matrix is not positive definite");
446 }
447 double eigenvalue1 = trace / 2 + std::sqrt(trace * trace / 4 - determinant);
448 double eigenvalue2 = trace / 2 - std::sqrt(trace * trace / 4 - determinant);
449 double semi_major_axis = std::sqrt(eigenvalue1) * etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR;
450 double semi_minor_axis = std::sqrt(eigenvalue2) * etsi_its_msgs::TWO_D_GAUSSIAN_FACTOR;
451 // object_heading - orientation of the ellipse, as WGS84 has positive angles to the right
452 double orientation = object_heading - 0.5 * std::atan2(2 * covariance_matrix[1], covariance_matrix[0] - covariance_matrix[3]);
453 orientation = orientation * 180 / M_PI; // Convert to degrees
454 // Normalize to [0, 180)
455 // Not to 0, 360, as the ellipse is symmetric and the orientation is defined as the angle between the semi-major axis and the x-axis
456 orientation = std::fmod(orientation + 180, 180);
457 while (orientation < 0) {
458 orientation += 180;
459 }
460 while (orientation >= 180) {
461 orientation -= 180;
462 }
463 return std::make_tuple(semi_major_axis, semi_minor_axis, orientation);
464}

◆ confidenceEllipseFromWGSCovMatrix()

std::tuple< double, double, double > confidenceEllipseFromWGSCovMatrix ( const std::array< double, 4 > & covariance_matrix)
inline

Gets the values needed to set a confidence ellipse from a covariance matrix.

Parameters
covariance_matrixThe four values of the covariance matrix in the order: cov_xx, cov_xy, cov_yx, cov_yy The matrix has to be SPD, otherwise a std::invalid_argument exception is thrown. Its coordinate system is aligned with the WGS axes (x = North, y = East)
object_headingThe heading of the object in rad, with respect to WGS84
Returns
std::tuple<double, double, double> semi_major_axis [m], semi_minor_axis [m], orientation [deg], with respect to WGS84

Definition at line 475 of file cdd_setters_common.h.

475 {
476 // The resulting ellipse is the same as if the cov matrix was given in vehicle coordinates
477 // and the object heading was set to 0.0
478 return confidenceEllipseFromCovMatrix(covariance_matrix, 0.0);
479}
std::tuple< double, double, double > confidenceEllipseFromCovMatrix(const std::array< double, 4 > &covariance_matrix, const double object_heading)
Gets the values needed to set a confidence ellipse from a covariance matrix.

◆ setAccelerationConfidence()

template<typename AccelerationConfidence>
void setAccelerationConfidence ( AccelerationConfidence & accel_confidence,
const double value )
inline

Set the Acceleration Confidence object.

Parameters
accel_confidenceobject to set
valuestandard deviation in m/s^2 as decimal number

Definition at line 233 of file cdd_setters_common.h.

233 {
234 auto accel_conf = std::round(value * 1e1 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
235 if (accel_conf < AccelerationConfidence::MIN && accel_conf > 0.0){
236 accel_conf = AccelerationConfidence::MIN;
237 } else if (accel_conf >= AccelerationConfidence::OUT_OF_RANGE || accel_conf <= 0.0) {
238 accel_conf = AccelerationConfidence::UNAVAILABLE;
239 }
240 accel_confidence.value = static_cast<decltype(accel_confidence.value)>(accel_conf);
241}

◆ setAccelerationMagnitude()

template<typename AccelerationMagnitude>
void setAccelerationMagnitude ( AccelerationMagnitude & accel_mag,
const double value,
const double confidence = std::numeric_limits<double>::infinity() )
inline

Set the AccelerationMagnitude object.

AccelerationConfidence is set to UNAVAILABLE

Parameters
accel_magobject to set
valueAccelerationMagnitudeValue in m/s^2 as decimal number
confidencestandard deviation in m/s^2 as decimal number (default: infinity, mapping to AccelerationConfidence::UNAVAILABLE)

Definition at line 220 of file cdd_setters_common.h.

221 {
222 setAccelerationMagnitudeConfidence(accel_mag.acceleration_confidence, confidence);
223 setAccelerationMagnitudeValue(accel_mag.acceleration_magnitude_value, value);
224}
void setAccelerationMagnitudeValue(AccelerationMagnitudeValue &accel_mag_value, const double value)
Set the Acceleration Magnitude Value object.
void setAccelerationMagnitudeConfidence(AccelerationConfidence &accel_mag_confidence, const double value)
Set the AccelerationMagnitude Confidence object.

◆ setAccelerationMagnitudeConfidence()

template<typename AccelerationConfidence>
void setAccelerationMagnitudeConfidence ( AccelerationConfidence & accel_mag_confidence,
const double value )
inline

Set the AccelerationMagnitude Confidence object.

Parameters
accel_mag_confidenceobject to set
valuestandard deviation in m/s^2 as decimal number

Definition at line 200 of file cdd_setters_common.h.

200 {
201 auto accel_mag_conf = std::round(value * 1e1 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
202 if (accel_mag_conf < AccelerationConfidence::MIN && accel_mag_conf > 0.0){
203 accel_mag_conf = AccelerationConfidence::MIN;
204 } else if (accel_mag_conf >= AccelerationConfidence::OUT_OF_RANGE || accel_mag_conf <= 0.0) {
205 accel_mag_conf = AccelerationConfidence::UNAVAILABLE;
206 }
207 accel_mag_confidence.value = static_cast<decltype(accel_mag_confidence.value)>(accel_mag_conf);
208}

◆ setAccelerationMagnitudeValue()

template<typename AccelerationMagnitudeValue>
void setAccelerationMagnitudeValue ( AccelerationMagnitudeValue & accel_mag_value,
const double value )
inline

Set the Acceleration Magnitude Value object.

Parameters
accel_mag_valueobject to set
valueAccelerationMagnitudeValue in m/s^2 as decimal number

Definition at line 187 of file cdd_setters_common.h.

187 {
188 auto accel_mag = std::round(value * 1e1);
189 throwIfOutOfRange(accel_mag, AccelerationMagnitudeValue::MIN, AccelerationMagnitudeValue::MAX, "AccelerationMagnitudeValue");
190 accel_mag_value.value = static_cast<decltype(accel_mag_value.value)>(accel_mag);
191}
void throwIfOutOfRange(const T1 &val, const T2 &min, const T2 &max, const std::string val_desc)
Throws an exception if a given value is out of a defined range.
Definition checks.h:46

◆ setAltitude()

void setAltitude ( Altitude & altitude,
const double value )
inline

Set the Altitude object.

AltitudeConfidence is set to UNAVAILABLE

Parameters
altitudeobject to set
valueAltitude value (above the reference ellipsoid surface) in meter as decimal number

Definition at line 133 of file cdd_setters_common.h.

133 {
134 altitude.altitude_confidence.value = AltitudeConfidence::UNAVAILABLE;
135 setAltitudeValue(altitude.altitude_value, value);
136}
void setAltitudeValue(AltitudeValue &altitude, const double value)
Set the AltitudeValue object.

◆ setAltitudeValue()

void setAltitudeValue ( AltitudeValue & altitude,
const double value )
inline

Set the AltitudeValue object.

Parameters
altitudeobject to set
valueAltitudeValue value (above the reference ellipsoid surface) in meter as decimal number

Definition at line 114 of file cdd_setters_common.h.

114 {
115 int64_t alt_in_cm = (int64_t)std::round(value * 1e2);
116 if (alt_in_cm >= AltitudeValue::MIN && alt_in_cm <= AltitudeValue::MAX) {
117 altitude.value = alt_in_cm;
118 } else if (alt_in_cm < AltitudeValue::MIN) {
119 altitude.value = AltitudeValue::MIN;
120 } else if (alt_in_cm > AltitudeValue::MAX) {
121 altitude.value = AltitudeValue::MAX;
122 }
123}

◆ setFromUTMPosition()

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

Set the ReferencePosition from a given UTM-Position.

The position is transformed to latitude and longitude by using GeographicLib::UTMUPS The z-Coordinate is directly used as altitude value The frame_id of the given utm_position must be set to 'utm_<zone><N/S>'

Parameters
[out]reference_positionReferencePostion or ReferencePositionWithConfidence to set
[in]utm_positiongeometry_msgs::PointStamped describing the given utm position
[in]zonethe UTM zone (zero means UPS) of the given position
[in]northphemisphere (true means north, false means south)

Definition at line 281 of file cdd_setters_common.h.

282 {
283 std::string required_frame_prefix = "utm_";
284 if (utm_position.header.frame_id.rfind(required_frame_prefix, 0) != 0) {
285 throw std::invalid_argument("Frame-ID of UTM Position '" + utm_position.header.frame_id +
286 "' does not start with required prefix '" + required_frame_prefix + "'!");
287 }
288 double latitude, longitude;
289 try {
290 GeographicLib::UTMUPS::Reverse(zone, northp, utm_position.point.x, utm_position.point.y, latitude, longitude);
291 } catch (GeographicLib::GeographicErr& e) {
292 throw std::invalid_argument(e.what());
293 }
294 setReferencePosition(reference_position, latitude, longitude, utm_position.point.z);
295}
void setReferencePosition(T &ref_position, const double latitude, const double longitude, const double altitude=AltitudeValue::UNAVAILABLE)
Sets the reference position in the given ReferencePostion object.

◆ setHeadingCDD()

template<typename Heading, typename HeadingConfidence = decltype(Heading::heading_confidence)>
void setHeadingCDD ( Heading & heading,
const double value,
double confidence = std::numeric_limits<double>::infinity() )

Set the Heading object.

0.0° equals WGS84 North, 90.0° equals WGS84 East, 180.0° equals WGS84 South and 270.0° equals WGS84 West HeadingConfidence is set to UNAVAILABLE

Parameters
headingobject to set
valueHeading value in degree as decimal number
confidencestandard deviation of heading in degree as decimal number (default: infinity, mapping to HeadingConfidence::UNAVAILABLE)

Definition at line 340 of file cdd_setters_common.h.

340 {
341 setHeadingConfidence(heading.heading_confidence, confidence);
342 setHeadingValue(heading.heading_value, value);
343}
void setHeadingConfidence(HeadingConfidence &heading_confidence, const double value)
Set the Heading Confidence object.
void setHeadingValue(HeadingValue &heading, const double value)
Set the HeadingValue object.

◆ setHeadingConfidence()

template<typename HeadingConfidence>
void setHeadingConfidence ( HeadingConfidence & heading_confidence,
const double value )
inline

Set the Heading Confidence object.

Parameters
heading_confidenceobject to set
valuestandard deviation of heading in degree as decimal number

Definition at line 319 of file cdd_setters_common.h.

319 {
320 auto heading_conf = std::round(value * 1e1 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
321 if (heading_conf < HeadingConfidence::MIN && heading_conf > 0.0){
322 heading_conf = HeadingConfidence::MIN;
323 } else if (heading_conf >= HeadingConfidence::OUT_OF_RANGE || heading_conf <= 0.0) {
324 heading_conf = HeadingConfidence::UNAVAILABLE;
325 }
326 heading_confidence.value = static_cast<decltype(heading_confidence.value)>(heading_conf);
327}

◆ setHeadingValue()

template<typename HeadingValue>
void setHeadingValue ( HeadingValue & heading,
const double value )
inline

Set the HeadingValue object.

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

Parameters
headingobject to set
valueHeading value in degree as decimal number

Definition at line 306 of file cdd_setters_common.h.

306 {
307 int64_t deg = (int64_t)std::round(value * 1e1);
308 throwIfOutOfRange(deg, HeadingValue::MIN, HeadingValue::MAX, "HeadingValue");
309 heading.value = deg;
310}

◆ setLatitude()

void setLatitude ( Latitude & latitude,
const double deg )
inline

Set the Latitude object.

Parameters
latitudeobject to set
degLatitude value in degree as decimal number

Definition at line 90 of file cdd_setters_common.h.

90 {
91 int64_t angle_in_10_micro_degree = (int64_t)std::round(deg * 1e7);
92 throwIfOutOfRange(angle_in_10_micro_degree, Latitude::MIN, Latitude::MAX, "Latitude");
93 latitude.value = angle_in_10_micro_degree;
94}

◆ setLongitude()

void setLongitude ( Longitude & longitude,
const double deg )
inline

Set the Longitude object.

Parameters
longitudeobject to set
degLongitude value in degree as decimal number

Definition at line 102 of file cdd_setters_common.h.

102 {
103 int64_t angle_in_10_micro_degree = (int64_t)std::round(deg * 1e7);
104 throwIfOutOfRange(angle_in_10_micro_degree, Longitude::MIN, Longitude::MAX, "Longitude");
105 longitude.value = angle_in_10_micro_degree;
106}

◆ setPosConfidenceEllipse() [1/2]

template<typename PosConfidenceEllipse>
void setPosConfidenceEllipse ( PosConfidenceEllipse & position_confidence_ellipse,
const double semi_major_axis,
const double semi_minor_axis,
const double orientation )
inline

Set the Pos Confidence Ellipse object.

Parameters
[out]position_confidence_ellipseThe PosConfidenceEllipse to set
[in]semi_major_axislength of the semi-major axis in meters
[in]semi_minor_axislength of the semi-minor axis in meters
[in]orientationof the semi-major axis in degrees, with respect to WGS84

Definition at line 418 of file cdd_setters_common.h.

419 {
420 setSemiAxis(position_confidence_ellipse.semi_major_confidence, semi_major_axis);
421 setSemiAxis(position_confidence_ellipse.semi_minor_confidence, semi_minor_axis);
422 setHeadingValue(position_confidence_ellipse.semi_major_orientation, orientation);
423}
void setSemiAxis(SemiAxisLength &semi_axis_length, const double length)
Set the Semi Axis length.

◆ setPosConfidenceEllipse() [2/2]

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

Set the Pos Confidence Ellipse object.

Parameters
position_confidence_ellipse
covariance_matrixThe four values of the covariance matrix in the order: cov_xx, cov_xy, cov_yx, cov_yy The matrix has to be SPD, otherwise a std::invalid_argument exception is thrown. Its coordinate system is aligned with the object (x = longitudinal, y = lateral)
object_headingThe heading of the object in rad, with respect to WGS84

Definition at line 491 of file cdd_setters_common.h.

491 {
492 auto [semi_major_axis, semi_minor_axis, orientation] = confidenceEllipseFromCovMatrix(covariance_matrix, object_heading);
493 setPosConfidenceEllipse(position_confidence_ellipse, semi_major_axis, semi_minor_axis, orientation);
494}
void setPosConfidenceEllipse(PosConfidenceEllipse &position_confidence_ellipse, const double semi_major_axis, const double semi_minor_axis, const double orientation)
Set the Pos Confidence Ellipse object.

◆ setReferencePosition()

template<typename T>
void setReferencePosition ( T & ref_position,
const double latitude,
const double longitude,
const double altitude = AltitudeValue::UNAVAILABLE )
inline

Sets the reference position in the given ReferencePostion object.

This function sets the latitude, longitude, and altitude of the reference position. If the altitude is not provided, it is set to AltitudeValue::UNAVAILABLE.

Parameters
ref_positionReferencePostion or ReferencePositionWithConfidence object to set the reference position in.
latitudeThe latitude value position in degree as decimal number.
longitudeThe longitude value in degree as decimal number.
altitudeThe altitude value (above the reference ellipsoid surface) in meter as decimal number (optional).

Definition at line 255 of file cdd_setters_common.h.

256 {
257 setLatitude(ref_position.latitude, latitude);
258 setLongitude(ref_position.longitude, longitude);
259 if (altitude != AltitudeValue::UNAVAILABLE) {
260 setAltitude(ref_position.altitude, altitude);
261 } else {
262 ref_position.altitude.altitude_value.value = AltitudeValue::UNAVAILABLE;
263 ref_position.altitude.altitude_confidence.value = AltitudeConfidence::UNAVAILABLE;
264 }
265 // TODO: set confidence values
266}
void setLongitude(Longitude &longitude, const double deg)
Set the Longitude object.
void setAltitude(Altitude &altitude, const double value)
Set the Altitude object.
void setLatitude(Latitude &latitude, const double deg)
Set the Latitude object.

◆ setSemiAxis()

template<typename SemiAxisLength>
void setSemiAxis ( SemiAxisLength & semi_axis_length,
const double length )
inline

Set the Semi Axis length.

// See https://godbolt.org/z/Eceavfo99 on how the OneCentimeterHelper works with this template

Parameters
semi_axis_lengthThe SemiAxisLength to set
lengththe desired length in meters

Definition at line 399 of file cdd_setters_common.h.

399 {
400 double semi_axis_length_val = std::round(length * etsi_its_msgs::OneCentimeterHelper<SemiAxisLength>::value * 1e2);
401 if(semi_axis_length_val < SemiAxisLength::MIN) {
402 semi_axis_length_val = SemiAxisLength::MIN;
403 } else if(semi_axis_length_val >= SemiAxisLength::OUT_OF_RANGE) {
404 semi_axis_length_val = SemiAxisLength::OUT_OF_RANGE;
405 }
406 semi_axis_length.value = static_cast<uint16_t>(semi_axis_length_val);
407}

◆ setSpeed()

void setSpeed ( Speed & speed,
const double value,
const double confidence = std::numeric_limits<double>::infinity() )
inline

Set the Speed object.

SpeedConfidence is set to UNAVAILABLE

Parameters
speedobject to set
valueSpeed in in m/s as decimal number
confidencestandard deviation in m/s as decimal number (Optional. Default is std::numeric_limits<double>::infinity(), mapping to SpeedConfidence::UNAVAILABLE)

Definition at line 175 of file cdd_setters_common.h.

175 {
176 setSpeedConfidence(speed.speed_confidence, confidence);
177 setSpeedValue(speed.speed_value, value);
178}
void setSpeedValue(SpeedValue &speed, const double value)
Set the SpeedValue object.
void setSpeedConfidence(SpeedConfidence &speed_confidence, const double value)
Set the Speed Confidence object.

◆ setSpeedConfidence()

void setSpeedConfidence ( SpeedConfidence & speed_confidence,
const double value )
inline

Set the Speed Confidence object.

Parameters
speed_confidenceobject to set
valuestandard deviation in m/s as decimal number

Definition at line 156 of file cdd_setters_common.h.

156 {
157 auto speed_conf = std::round(value * 1e2 * etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR);
158 if (speed_conf < SpeedConfidence::MIN && speed_conf > 0.0){
159 speed_conf = SpeedConfidence::MIN;
160 } else if (speed_conf >= SpeedConfidence::OUT_OF_RANGE || speed_conf <= 0.0) {
161 speed_conf = SpeedConfidence::UNAVAILABLE;
162 }
163 speed_confidence.value = static_cast<decltype(speed_confidence.value)>(speed_conf);
164}

◆ setSpeedValue()

void setSpeedValue ( SpeedValue & speed,
const double value )
inline

Set the SpeedValue object.

Parameters
speedobject to set
valueSpeedValue in m/s as decimal number

Definition at line 144 of file cdd_setters_common.h.

144 {
145 auto speed_val = std::round(value * 1e2);
146 throwIfOutOfRange(speed_val, SpeedValue::MIN, SpeedValue::MAX, "SpeedValue");
147 speed.value = static_cast<decltype(speed.value)>(speed_val);
148}

◆ setStationId()

template<typename StationId>
void setStationId ( StationId & station_id,
const uint32_t id_value )
inline

Set the Station Id object.

Parameters
station_id
id_value

Definition at line 51 of file cdd_setters_common.h.

51 {
52 throwIfOutOfRange(id_value, StationId::MIN, StationId::MAX, "StationId");
53 station_id.value = id_value;
54}

◆ setStationType()

template<typename StationType>
void setStationType ( StationType & station_type,
const uint8_t value )
inline

Set the Station Type.

Parameters
station_type
value

Definition at line 63 of file cdd_setters_common.h.

63 {
64 throwIfOutOfRange(value, StationType::MIN, StationType::MAX, "StationType");
65 station_type.value = value;
66}

◆ setTimestampITS()

void setTimestampITS ( TimestampIts & timestamp_its,
const uint64_t unix_nanosecs,
const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.rbegin()->second )
inline

Set the TimestampITS object.

Parameters
[in]timestamp_itsTimestampITS object to set the timestamp
[in]unix_nanosecsUnix-Nanoseconds to set the timestamp for
[in]n_leap_secondsNumber of leap-seconds since 2004. (Defaults to the todays number of leap seconds since 2004.)
[in]epoch_offsetUnix-Timestamp in seconds for the 01.01.2004 at 00:00:00

Definition at line 76 of file cdd_setters_common.h.

78 {
79 uint64_t t_its = unix_nanosecs * 1e-6 + (uint64_t)(n_leap_seconds * 1e3) - etsi_its_msgs::UNIX_SECONDS_2004 * 1e3;
80 throwIfOutOfRange(t_its, TimestampIts::MIN, TimestampIts::MAX, "TimestampIts");
81 timestamp_its.value = t_its;
82}

◆ setWGSPosConfidenceEllipse()

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

Set the Pos Confidence Ellipse object.

Parameters
position_confidence_ellipse
covariance_matrixThe four values of the covariance matrix in the order: cov_xx, cov_xy, cov_yx, cov_yy The matrix has to be SPD, otherwise a std::invalid_argument exception is thrown. Its coordinate system is aligned with the WGS axes (x = North, y = East)
object_headingThe heading of the object in rad, with respect to WGS84

Definition at line 506 of file cdd_setters_common.h.

506 {
507 auto [semi_major_axis, semi_minor_axis, orientation] = confidenceEllipseFromWGSCovMatrix(covariance_matrix);
508 setPosConfidenceEllipse(position_confidence_ellipse, semi_major_axis, semi_minor_axis, orientation);
509}
std::tuple< double, double, double > confidenceEllipseFromWGSCovMatrix(const std::array< double, 4 > &covariance_matrix)
Gets the values needed to set a confidence ellipse from a covariance matrix.

◆ setYawRateCDD()

template<typename YawRate, typename YawRateValue = decltype(YawRate::yaw_rate_value), typename YawRateConfidence = decltype(YawRate::yaw_rate_confidence)>
void setYawRateCDD ( YawRate & yaw_rate,
const double value,
double confidence = std::numeric_limits<double>::infinity() )
inline

Set the Yaw Rate object.

Parameters
yaw_rateobject to set
valueYaw rate in degrees per second as decimal number
confidencestandard deviation of yaw rate in degrees per second as decimal number (default: infinity, mapping to YawRateConfidence::UNAVAILABLE)

Definition at line 353 of file cdd_setters_common.h.

354 {
355 double yaw_rate_in_001_degrees = value * 100.0;
356 // limit value range
357 if (yaw_rate_in_001_degrees < YawRateValue::MIN) {
358 yaw_rate_in_001_degrees = YawRateValue::MIN; // MIN should be NEGATIVE_OUT_OF_RANGE, but CAM only has MIN
359 } else if (yaw_rate_in_001_degrees > YawRateValue::MAX - 1) {
360 yaw_rate_in_001_degrees = YawRateValue::MAX - 1; // MAX - 1 should be POSITIVE_OUT_OF_RANGE, but CAM only has MAX
361 }
362
363 yaw_rate.yaw_rate_value.value = static_cast<decltype(yaw_rate.yaw_rate_value.value)>(yaw_rate_in_001_degrees);
364
365 double yaw_rate_std = confidence;
366 if(yaw_rate_std == std::numeric_limits<double>::infinity()) {
367 yaw_rate.yaw_rate_confidence.value = YawRateConfidence::UNAVAILABLE;
368 } else {
369 yaw_rate_std *= etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR;
370 // How stupid is this?!
371 static const std::map<double, uint8_t> confidence_map = {
372 {0.01, YawRateConfidence::DEG_SEC_000_01},
373 {0.05, YawRateConfidence::DEG_SEC_000_05},
374 {0.1, YawRateConfidence::DEG_SEC_000_10},
375 {1.0, YawRateConfidence::DEG_SEC_001_00},
376 {5.0, YawRateConfidence::DEG_SEC_005_00},
377 {10.0, YawRateConfidence::DEG_SEC_010_00},
378 {100.0, YawRateConfidence::DEG_SEC_100_00},
379 {std::numeric_limits<double>::infinity(), YawRateConfidence::OUT_OF_RANGE},
380 };
381 for(const auto& [thresh, conf_val] : confidence_map) {
382 if (yaw_rate_std <= thresh) {
383 yaw_rate.yaw_rate_confidence.value = conf_val;
384 break;
385 }
386 }
387 }
388}