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>
54 inline double getLatitude(
const Latitude& latitude) {
return ((
double)latitude.value) * 1e-7; }
62 inline double getLongitude(
const Longitude& longitude) {
return ((
double)longitude.value) * 1e-7; }
70 inline double getAltitude(
const Altitude& altitude) {
return ((
double)altitude.altitude_value.value) * 1e-2; }
78 inline double getSpeed(
const Speed& speed) {
return ((
double)speed.speed_value.value) * 1e-2; }
101 template <
typename T>
102 inline 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());
130 template <
typename Heading>
131 inline double getHeadingCDD(
const Heading& heading) {
return ((
double)heading.heading_value.value) * 1e-1; }
141 template <
typename Heading>
150 template <
typename SemiAxisLength>
151 inline double getSemiAxis(
const SemiAxisLength& semi_axis_length) {
161 template <
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;
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;
222 template <
typename PosConf
idenceEllipse>
223 inline std::array<double, 4>
getPosConfidenceEllipse(
const PosConfidenceEllipse& position_confidence_ellipse,
const double object_heading){
235 template <
typename PosConf
idenceEllipse>
241 #endif // ETSI_ITS_MSGS_UTILS_IMPL_CDD_CDD_GETTERS_COMMON_H