32#ifndef ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_GETTERS_COMMON_H
33#define ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_GETTERS_COMMON_H
38#include <GeographicLib/UTMUPS.hpp>
46inline uint32_t
getStationID(
const ItsPduHeader& header) {
return header.station_id.value; }
54inline double getLatitude(
const Latitude& latitude) {
return ((
double)latitude.value) * 1e-7; }
62inline double getLongitude(
const Longitude& longitude) {
return ((
double)longitude.value) * 1e-7; }
70inline double getAltitude(
const Altitude& altitude) {
return ((
double)altitude.altitude_value.value) * 1e-2; }
78inline double getSpeed(
const Speed& speed) {
return ((
double)speed.speed_value.value) * 1e-2; }
87 return ((
double)speed.speed_confidence.value) / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR * 1e-2;
102inline gm::PointStamped
getUTMPosition(
const T& reference_position,
int& zone,
bool& northp) {
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);
108 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y);
109 std::string hemisphere;
115 utm_point.header.frame_id =
"utm_" + std::to_string(zone) + hemisphere;
116 }
catch (GeographicLib::GeographicErr& e) {
117 throw std::invalid_argument(e.what());
130template <
typename Heading>
131inline double getHeadingCDD(
const Heading& heading) {
return ((
double)heading.heading_value.value) * 1e-1; }
141template <
typename Heading>
142inline double getHeadingConfidenceCDD(
const Heading& heading) {
return ((
double)heading.heading_confidence.value) * 1e-1 / etsi_its_msgs::ONE_D_GAUSSIAN_FACTOR; }
150template <
typename SemiAxisLength>
151inline double getSemiAxis(
const SemiAxisLength& semi_axis_length) {
152 return ((
double)semi_axis_length.value) * 1e-2 / etsi_its_msgs::OneCentimeterHelper<SemiAxisLength>::value;
161template <
typename PosConf
idenceEllipse>
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
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;
188 double angle_to_object = object_heading_rad - major_orientation_rad;
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;
197 return covariance_matrix;
222template <
typename PosConf
idenceEllipse>
223inline std::array<double, 4>
getPosConfidenceEllipse(
const PosConfidenceEllipse& position_confidence_ellipse,
const double object_heading){
235template <
typename PosConf
idenceEllipse>
double getHeadingCDD(const Heading &heading)
Get the Heading value.
double getSpeedConfidence(const Speed &speed)
Get the Speed Confidence.
gm::PointStamped getUTMPosition(const T &reference_position, int &zone, bool &northp)
Get the UTM Position defined by the given ReferencePosition.
double getSemiAxis(const SemiAxisLength &semi_axis_length)
Get the Semi Axis object.
std::array< double, 4 > getWGSPosConfidenceEllipse(const PosConfidenceEllipse &position_confidence_ellipse)
Get the covariance matrix of the position confidence ellipse.
double getLatitude(const Latitude &latitude)
Get the Latitude value.
double getHeadingConfidenceCDD(const Heading &heading)
Get the Heading value.
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...
double getLongitude(const Longitude &longitude)
Get the Longitude value.
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.
uint32_t getStationID(const ItsPduHeader &header)
Get the StationID of ItsPduHeader.
std::array< double, 4 > WGSCovMatrixFromConfidenceEllipse(double semi_major, double semi_minor, double major_orientation)
Convert the confidence ellipse to a covariance matrix.
double getAltitude(const Altitude &altitude)
Get the Altitude value.
double getSpeed(const Speed &speed)
Get the vehicle speed.