etsi_its_messages
v3.5.0
Toggle main menu visibility
Loading...
Searching...
No Matches
mapem_ts_utils.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
3
8
9
#include <ctime>
10
#include <GeographicLib/UTMUPS.hpp>
11
12
#pragma once
13
14
namespace
etsi_its_mapem_ts_msgs {
15
16
namespace
access {
17
24
inline
uint64_t
getUnixSecondsOfYear
(
const
uint64_t unixSecond) {
25
26
// Get current time as a time_point
27
time_t ts =
static_cast<
time_t
>
(unixSecond);
// Convert uint64_t to time_t
28
29
struct
tm* timeinfo;
30
timeinfo = gmtime(&ts);
31
32
// Set the timeinfo to the beginning of the year
33
timeinfo->tm_sec = 0;
34
timeinfo->tm_min = 0;
35
timeinfo->tm_hour = 0;
36
timeinfo->tm_mday = 1;
37
timeinfo->tm_mon = 0;
38
39
return
timegm(timeinfo);
// Convert struct tm back to Unix timestamp
40
}
41
49
inline
uint64_t
getUnixNanosecondsFromMinuteOfTheYear
(
const
MinuteOfTheYear& moy,
const
uint64_t unix_nanoseconds_estimate) {
50
return
((uint64_t)(moy.value*60) +
getUnixSecondsOfYear
(unix_nanoseconds_estimate*1e-9))*1e9;
51
}
52
60
inline
uint64_t
getUnixNanosecondsFromMapData
(
const
MapData& map,
const
uint64_t unix_nanoseconds_estimate) {
61
return
getUnixNanosecondsFromMinuteOfTheYear
(
getMinuteOfTheYear
(map), unix_nanoseconds_estimate);
62
}
63
71
inline
uint64_t
getUnixNanoseconds
(
const
MAPEM& mapem,
const
uint64_t unix_timestamp_estimate) {
72
return
getUnixNanosecondsFromMapData
(mapem.map, unix_timestamp_estimate);
73
}
74
86
inline
gm::PointStamped
getUTMPosition
(
const
Position3D& reference_position,
int
& zone,
bool
& northp) {
87
gm::PointStamped utm_point;
88
double
latitude =
getLatitude
(reference_position.lat);
89
double
longitude =
getLongitude
(reference_position.lon);
90
if
(reference_position.elevation_is_present) utm_point.point.z =
getElevation
(reference_position.elevation);
91
try
{
92
GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y);
93
std::string hemisphere;
94
if
(northp) hemisphere=
"N"
;
95
else
hemisphere=
"S"
;
96
utm_point.header.frame_id=
"utm_"
+std::to_string(zone)+hemisphere;
97
}
catch
(GeographicLib::GeographicErr& e) {
98
throw
std::invalid_argument(e.what());
99
}
100
return
utm_point;
101
}
102
115
inline
gm::PointStamped
getUTMPositionWithConvergenceAngle
(
const
Position3D& reference_position,
int
& zone,
bool
& northp,
double
& conv_angle) {
116
gm::PointStamped utm_point;
117
double
latitude =
getLatitude
(reference_position.lat);
118
double
longitude =
getLongitude
(reference_position.lon);
119
if
(reference_position.elevation_is_present) utm_point.point.z =
getElevation
(reference_position.elevation);
120
try
{
121
double
scale;
122
GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y, conv_angle, scale);
123
std::string hemisphere;
124
if
(northp) hemisphere=
"N"
;
125
else
hemisphere=
"S"
;
126
utm_point.header.frame_id=
"utm_"
+std::to_string(zone)+hemisphere;
127
}
catch
(GeographicLib::GeographicErr& e) {
128
throw
std::invalid_argument(e.what());
129
}
130
return
utm_point;
131
}
132
144
inline
gm::PointStamped
getRefPointUTMPosition
(
const
IntersectionGeometry& intsctn,
int
& zone,
bool
& northp) {
145
return
getUTMPosition
(intsctn.ref_point, zone, northp);
146
}
147
160
inline
gm::PointStamped
getRefPointUTMPositionWithConvergenceAngle
(
const
IntersectionGeometry& intsctn,
int
& zone,
bool
& northp,
double
& conv_angle) {
161
return
getUTMPositionWithConvergenceAngle
(intsctn.ref_point, zone, northp, conv_angle);
162
}
163
164
}
// namespace etsi_its_mapem_ts_msgs
165
}
// namespace access
etsi_its_mapem_ts_msgs::access::getLongitude
double getLongitude(const Longitude &longitude)
Get the Longitude value.
Definition
mapem_ts_getters.h:96
etsi_its_mapem_ts_msgs::access::getMinuteOfTheYear
MinuteOfTheYear getMinuteOfTheYear(const MapData &map)
Get the value of MinuteOfTheYear object MapData object.
Definition
mapem_ts_getters.h:24
etsi_its_mapem_ts_msgs::access::getLatitude
double getLatitude(const Latitude &latitude)
Get the Latitude value.
Definition
mapem_ts_getters.h:86
etsi_its_mapem_ts_msgs::access::getElevation
double getElevation(const Elevation &elevation)
Get the Elevation value.
Definition
mapem_ts_getters.h:106
etsi_its_mapem_ts_msgs::access::getRefPointUTMPosition
gm::PointStamped getRefPointUTMPosition(const IntersectionGeometry &intsctn, int &zone, bool &northp)
Get the UTM Position of ref_point defined by the Position3D along with the grid-convergence angle in ...
Definition
mapem_ts_utils.h:144
etsi_its_mapem_ts_msgs::access::getRefPointUTMPositionWithConvergenceAngle
gm::PointStamped getRefPointUTMPositionWithConvergenceAngle(const IntersectionGeometry &intsctn, int &zone, bool &northp, double &conv_angle)
Get the UTM Position of ref_point defined by the Position3D in an IntersectionGeometry object.
Definition
mapem_ts_utils.h:160
etsi_its_mapem_ts_msgs::access::getUTMPosition
gm::PointStamped getUTMPosition(const Position3D &reference_position, int &zone, bool &northp)
Get the UTM Position defined by the given Position3D.
Definition
mapem_ts_utils.h:86
etsi_its_mapem_ts_msgs::access::getUnixSecondsOfYear
uint64_t getUnixSecondsOfYear(const uint64_t unixSecond)
Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.
Definition
mapem_ts_utils.h:24
etsi_its_mapem_ts_msgs::access::getUnixNanosecondsFromMinuteOfTheYear
uint64_t getUnixNanosecondsFromMinuteOfTheYear(const MinuteOfTheYear &moy, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from MinuteOfTheYear object.
Definition
mapem_ts_utils.h:49
etsi_its_mapem_ts_msgs::access::getUTMPositionWithConvergenceAngle
gm::PointStamped getUTMPositionWithConvergenceAngle(const Position3D &reference_position, int &zone, bool &northp, double &conv_angle)
Get the UTM Position defined by the given Position3D along with the grid-convergence angle.
Definition
mapem_ts_utils.h:115
etsi_its_mapem_ts_msgs::access::getUnixNanoseconds
uint64_t getUnixNanoseconds(const MAPEM &mapem, const uint64_t unix_timestamp_estimate)
Get the unix nanoseconds from MinuteOfTheYear object.
Definition
mapem_ts_utils.h:71
etsi_its_mapem_ts_msgs::access::getUnixNanosecondsFromMapData
uint64_t getUnixNanosecondsFromMapData(const MapData &map, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from MapData object.
Definition
mapem_ts_utils.h:60
etsi_its_msgs_utils
include
etsi_its_msgs_utils
impl
mapem
mapem_ts_utils.h
Generated by
1.18.0