etsi_its_messages v3.0.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 167 of file mapem_ts_utils.h.

167 {
168 return getUTMPosition(intsctn.ref_point, zone, northp);
169 }
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 183 of file mapem_ts_utils.h.

183 {
184 return getUTMPositionWithConvergenceAngle(intsctn.ref_point, zone, northp, conv_angle);
185 }
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 94 of file mapem_ts_utils.h.

94 {
95 return getUnixNanosecondsFromMapData(mapem.map, unix_timestamp_estimate);
96 }
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 83 of file mapem_ts_utils.h.

83 {
84 return getUnixNanosecondsFromMinuteOfTheYear(getMinuteOfTheYear(map), unix_nanoseconds_estimate);
85 }
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 72 of file mapem_ts_utils.h.

72 {
73 return ((uint64_t)(moy.value*60) + getUnixSecondsOfYear(unix_nanoseconds_estimate*1e-9))*1e9;
74 }
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 47 of file mapem_ts_utils.h.

47 {
48
49 // Get current time as a time_point
50 time_t ts = static_cast<time_t>(unixSecond); // Convert uint64_t to time_t
51
52 struct tm* timeinfo;
53 timeinfo = gmtime(&ts);
54
55 // Set the timeinfo to the beginning of the year
56 timeinfo->tm_sec = 0;
57 timeinfo->tm_min = 0;
58 timeinfo->tm_hour = 0;
59 timeinfo->tm_mday = 1;
60 timeinfo->tm_mon = 0;
61
62 return timegm(timeinfo); // Convert struct tm back to Unix timestamp
63 }

◆ 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 109 of file mapem_ts_utils.h.

109 {
110 gm::PointStamped utm_point;
111 double latitude = getLatitude(reference_position.lat);
112 double longitude = getLongitude(reference_position.lon);
113 if(reference_position.elevation_is_present) utm_point.point.z = getElevation(reference_position.elevation);
114 try {
115 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y);
116 std::string hemisphere;
117 if(northp) hemisphere="N";
118 else hemisphere="S";
119 utm_point.header.frame_id="utm_"+std::to_string(zone)+hemisphere;
120 } catch (GeographicLib::GeographicErr& e) {
121 throw std::invalid_argument(e.what());
122 }
123 return utm_point;
124 }
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 138 of file mapem_ts_utils.h.

138 {
139 gm::PointStamped utm_point;
140 double latitude = getLatitude(reference_position.lat);
141 double longitude = getLongitude(reference_position.lon);
142 if(reference_position.elevation_is_present) utm_point.point.z = getElevation(reference_position.elevation);
143 try {
144 double scale;
145 GeographicLib::UTMUPS::Forward(latitude, longitude, zone, northp, utm_point.point.x, utm_point.point.y, conv_angle, scale);
146 std::string hemisphere;
147 if(northp) hemisphere="N";
148 else hemisphere="S";
149 utm_point.header.frame_id="utm_"+std::to_string(zone)+hemisphere;
150 } catch (GeographicLib::GeographicErr& e) {
151 throw std::invalid_argument(e.what());
152 }
153 return utm_point;
154 }