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

Utility functions for the ETSI ITS MAPEM. More...

#include <ctime>
#include <GeographicLib/UTMUPS.hpp>

Go to the source code of this file.

Functions

uint64_t etsi_its_mapem_ts_msgs::access::getUnixSecondsOfYear (const uint64_t unixSecond)
 Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.
uint64_t etsi_its_mapem_ts_msgs::access::getUnixNanosecondsFromMinuteOfTheYear (const MinuteOfTheYear &moy, const uint64_t unix_nanoseconds_estimate)
 Get the unix nanoseconds from MinuteOfTheYear object.
uint64_t etsi_its_mapem_ts_msgs::access::getUnixNanosecondsFromMapData (const MapData &map, const uint64_t unix_nanoseconds_estimate)
 Get the unix nanoseconds from MapData object.
uint64_t etsi_its_mapem_ts_msgs::access::getUnixNanoseconds (const MAPEM &mapem, const uint64_t unix_timestamp_estimate)
 Get the unix nanoseconds from MinuteOfTheYear object.
gm::PointStamped etsi_its_mapem_ts_msgs::access::getUTMPosition (const Position3D &reference_position, int &zone, bool &northp)
 Get the UTM Position defined by the given Position3D.
gm::PointStamped etsi_its_mapem_ts_msgs::access::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.
gm::PointStamped etsi_its_mapem_ts_msgs::access::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 an IntersectionGeometry object.
gm::PointStamped etsi_its_mapem_ts_msgs::access::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.

Detailed Description

Utility functions for the ETSI ITS MAPEM.

Definition in file mapem_ts_utils.h.

Function Documentation

◆ getRefPointUTMPosition()

gm::PointStamped etsi_its_mapem_ts_msgs::access::getRefPointUTMPosition ( const IntersectionGeometry & intsctn,
int & zone,
bool & northp )
inline

Get the UTM Position of ref_point defined by the Position3D along with the grid-convergence angle in an IntersectionGeometry object.

The position is transformed into UTM by using GeographicLib::UTMUPS The altitude value is directly used as z-Coordinate

Parameters
[in]intsctnIntersectionGeometry 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 144 of file mapem_ts_utils.h.

144 {
145 return getUTMPosition(intsctn.ref_point, zone, northp);
146 }
gm::PointStamped getUTMPosition(const Position3D &reference_position, int &zone, bool &northp)
Get the UTM Position defined by the given Position3D.

◆ getRefPointUTMPositionWithConvergenceAngle()

gm::PointStamped etsi_its_mapem_ts_msgs::access::getRefPointUTMPositionWithConvergenceAngle ( const IntersectionGeometry & intsctn,
int & zone,
bool & northp,
double & conv_angle )
inline

Get the UTM Position of ref_point defined by the Position3D in an IntersectionGeometry object.

The position is transformed into UTM by using GeographicLib::UTMUPS The altitude value is directly used as z-Coordinate

Parameters
[in]intsctnIntersectionGeometry to get the UTM Position from
[out]zonethe UTM zone (zero means UPS)
[out]northphemisphere (true means north, false means south)
[out]conv_anglegrid-convergence angle in degree
Returns
gm::PointStamped geometry_msgs::PointStamped of the given position

Definition at line 160 of file mapem_ts_utils.h.

160 {
161 return getUTMPositionWithConvergenceAngle(intsctn.ref_point, zone, northp, conv_angle);
162 }
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.

◆ getUnixNanoseconds()

uint64_t etsi_its_mapem_ts_msgs::access::getUnixNanoseconds ( const MAPEM & mapem,
const uint64_t unix_timestamp_estimate )
inline

Get the unix nanoseconds from MinuteOfTheYear object.

Parameters
mapemgiven MAPEM object
unix_nanoseconds_estimateunix timestamp to derive the current year from in nanoseconds
Returns
uint64_t unix timestamp according to the stored MinuteOfTheYear in nanoseconds

Definition at line 71 of file mapem_ts_utils.h.

71 {
72 return getUnixNanosecondsFromMapData(mapem.map, unix_timestamp_estimate);
73 }
uint64_t getUnixNanosecondsFromMapData(const MapData &map, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from MapData object.

◆ getUnixNanosecondsFromMapData()

uint64_t etsi_its_mapem_ts_msgs::access::getUnixNanosecondsFromMapData ( const MapData & map,
const uint64_t unix_nanoseconds_estimate )
inline

Get the unix nanoseconds from MapData object.

Parameters
mapgiven MapData object
unix_nanoseconds_estimateunix timestamp to derive the current year from in nanoseconds
Returns
uint64_t unix timestamp according to the given MinuteOfTheYear in nanoseconds

Definition at line 60 of file mapem_ts_utils.h.

60 {
61 return getUnixNanosecondsFromMinuteOfTheYear(getMinuteOfTheYear(map), unix_nanoseconds_estimate);
62 }
MinuteOfTheYear getMinuteOfTheYear(const MapData &map)
Get the value of MinuteOfTheYear object MapData object.
uint64_t getUnixNanosecondsFromMinuteOfTheYear(const MinuteOfTheYear &moy, const uint64_t unix_nanoseconds_estimate)
Get the unix nanoseconds from MinuteOfTheYear object.

◆ getUnixNanosecondsFromMinuteOfTheYear()

uint64_t etsi_its_mapem_ts_msgs::access::getUnixNanosecondsFromMinuteOfTheYear ( const MinuteOfTheYear & moy,
const uint64_t unix_nanoseconds_estimate )
inline

Get the unix nanoseconds from MinuteOfTheYear object.

Parameters
moygiven MinuteOfTheYear object
unix_nanoseconds_estimateunix timestamp to derive the current year from in nanoseconds
Returns
uint64_t unix timestamp according to the given MinuteOfTheYear in nanoseconds

Definition at line 49 of file mapem_ts_utils.h.

49 {
50 return ((uint64_t)(moy.value*60) + getUnixSecondsOfYear(unix_nanoseconds_estimate*1e-9))*1e9;
51 }
uint64_t getUnixSecondsOfYear(const uint64_t unixSecond)
Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.

◆ getUnixSecondsOfYear()

uint64_t etsi_its_mapem_ts_msgs::access::getUnixSecondsOfYear ( const uint64_t unixSecond)
inline

Get the unix seconds of the beginning of a year that corresponds to a given unix timestamp.

Parameters
unixSecondtimestamp that defines the year for that the unix seconds for the beginning of the year should be derived
Returns
uint64_t unix seconds of the beginning of the year

Definition at line 24 of file mapem_ts_utils.h.

24 {
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 }

◆ getUTMPosition()

gm::PointStamped etsi_its_mapem_ts_msgs::access::getUTMPosition ( const Position3D & reference_position,
int & zone,
bool & northp )
inline

Get the UTM Position defined by the given Position3D.

The position is transformed into UTM by using GeographicLib::UTMUPS The altitude value is directly used as z-Coordinate

Parameters
[in]reference_positionPosition3D 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 86 of file mapem_ts_utils.h.

86 {
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 }
double getLongitude(const Longitude &longitude)
Get the Longitude value.
double getLatitude(const Latitude &latitude)
Get the Latitude value.
double getElevation(const Elevation &elevation)
Get the Elevation value.

◆ getUTMPositionWithConvergenceAngle()

gm::PointStamped etsi_its_mapem_ts_msgs::access::getUTMPositionWithConvergenceAngle ( const Position3D & reference_position,
int & zone,
bool & northp,
double & conv_angle )
inline

Get the UTM Position defined by the given Position3D along with the grid-convergence angle.

The position is transformed into UTM by using GeographicLib::UTMUPS The altitude value is directly used as z-Coordinate

Parameters
[in]reference_positionPosition3D to get the UTM Position from
[out]zonethe UTM zone (zero means UPS)
[out]northphemisphere (true means north, false means south)
[out]conv_anglegrid-convergence angle in degree
Returns
gm::PointStamped geometry_msgs::PointStamped of the given position

Definition at line 115 of file mapem_ts_utils.h.

115 {
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 }