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

Setter functions for the UULM MCM (TR). More...

Go to the source code of this file.

Functions

void etsi_its_mcm_uulm_msgs::access::setItsPduHeader (MCM &mcm, const uint32_t station_id, const uint8_t protocol_version=2)
 Sets the ITS PDU header for the given MCM message.
void etsi_its_mcm_uulm_msgs::access::setGenerationDeltaTime (MCM &mcm, const uint64_t unix_nanosecs, const uint16_t n_leap_seconds=etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.rbegin() ->second)
 Set the Generation Delta Time object.
void etsi_its_mcm_uulm_msgs::access::setStationType (MCM &mcm, const int value)
 Set the StationType for a MCM.
void etsi_its_mcm_uulm_msgs::access::setLatitude (Latitude &latitude, const double deg)
 Set the Latitude object.
void etsi_its_mcm_uulm_msgs::access::setLongitude (Longitude &longitude, const double deg)
 Set the Longitude object.
void etsi_its_mcm_uulm_msgs::access::setAltitudeValue (AltitudeValue &altitude, const double value)
 Set the AltitudeValue object.
void etsi_its_mcm_uulm_msgs::access::setAltitude (Altitude &altitude, const double value)
 Set the Altitude object.
void etsi_its_mcm_uulm_msgs::access::setReferencePosition (MCM &mcm, const double latitude, const double longitude, const double altitude=AltitudeValue::UNAVAILABLE)
 Set the ReferencePosition for an MCM.
void etsi_its_mcm_uulm_msgs::access::setFromUTMPosition (MCM &mcm, const gm::PointStamped &utm_position, const int zone, const bool northp)
 Set the ReferencePosition of a MCM from a given UTM-Position.
void etsi_its_mcm_uulm_msgs::access::setSpeedValue (SpeedValue &speed, const double value)
 Set the SpeedValue object.
void etsi_its_mcm_uulm_msgs::access::setHeadingValue (HeadingValue &heading, const double value)
 Set the HeadingValue object.
template<typename T>
void etsi_its_mcm_uulm_msgs::access::setRoadUserDimension (T &dim, const double value)
 Sets the dimension value for a road user (width or length).
void etsi_its_mcm_uulm_msgs::access::setRoadUserState (RoadUserContainer &road_user_container, const uint8_t type, const double speed, const double heading, const double length, const double width)
 Sets the state of a road user in the given container.
void etsi_its_mcm_uulm_msgs::access::setCartesianCoordinateLarge (CartesianCoordinateLarge &coordinate, const double value)
 Sets the value of a CartesianCoordinateLarge object.
void etsi_its_mcm_uulm_msgs::access::setWaypoint (Waypoint &waypoint, const double x, const double y)
 Sets the coordinates of a Waypoint object.

Detailed Description

Setter functions for the UULM MCM (TR).

Definition in file mcm_setters.h.

Function Documentation

◆ setAltitude()

void etsi_its_mcm_uulm_msgs::access::setAltitude ( Altitude & altitude,
const double value )
inline

Set the Altitude object.

Parameters
altitudeobject to set
valueAltitude value (above the reference ellipsoid surface) in meter as decimal number

Definition at line 109 of file mcm_setters.h.

109 {
110 altitude.altitude_confidence.value = AltitudeConfidence::UNAVAILABLE;
111 setAltitudeValue(altitude.altitude_value, value);
112}
void setAltitudeValue(AltitudeValue &altitude, const double value)
Set the AltitudeValue object.
Definition mcm_setters.h:92

◆ setAltitudeValue()

void etsi_its_mcm_uulm_msgs::access::setAltitudeValue ( AltitudeValue & altitude,
const double value )
inline

Set the AltitudeValue object.

Parameters
altitudeobject to set
valueAltitudeValue value (above the reference ellipsoid surface) in meter as decimal number

Definition at line 92 of file mcm_setters.h.

92 {
93 int64_t alt_in_cm = (int64_t)std::round(value * 1e2);
94 if (alt_in_cm >= AltitudeValue::MIN && alt_in_cm <= AltitudeValue::MAX) {
95 altitude.value = alt_in_cm;
96 } else if (alt_in_cm < AltitudeValue::MIN) {
97 altitude.value = AltitudeValue::MIN;
98 } else if (alt_in_cm > AltitudeValue::MAX) {
99 altitude.value = AltitudeValue::MAX;
100 }
101}

◆ setCartesianCoordinateLarge()

void etsi_its_mcm_uulm_msgs::access::setCartesianCoordinateLarge ( CartesianCoordinateLarge & coordinate,
const double value )
inline

Sets the value of a CartesianCoordinateLarge object.

If the converted value is outside the valid range, sets the value to NEGATIVE_OUT_OF_RANGE or POSITIVE_OUT_OF_RANGE accordingly.

Parameters
coordinateReference to the CartesianCoordinateLarge object to set.
valueThe coordinate value in meters.

Definition at line 249 of file mcm_setters.h.

249 {
250 auto coord_value = std::round(value * 1e2); // convert m to cm
251 if (coord_value < CartesianCoordinateLarge::MIN) {
252 coord_value = CartesianCoordinateLarge::NEGATIVE_OUT_OF_RANGE;
253 } else if (coord_value > CartesianCoordinateLarge::MAX) {
254 coord_value = CartesianCoordinateLarge::POSITIVE_OUT_OF_RANGE;
255 }
256 coordinate.value = static_cast<decltype(coordinate.value)>(coord_value);
257}

◆ setFromUTMPosition()

void etsi_its_mcm_uulm_msgs::access::setFromUTMPosition ( MCM & mcm,
const gm::PointStamped & utm_position,
const int zone,
const bool northp )
inline

Set the ReferencePosition of a MCM from a given UTM-Position.

The position is transformed to latitude and longitude by using GeographicLib::UTMUPS The z-Coordinate is directly used as altitude value The frame_id of the given utm_position must be set to 'utm_<zone><N/S>'

Parameters
[out]mcmMCM to set the ReferencePosition
[in]utm_positiongeometry_msgs::PointStamped describing the given utm position
[in]zonethe UTM zone (zero means UPS) of the given position
[in]northphemisphere (true means north, false means south)

Definition at line 159 of file mcm_setters.h.

159 {
160 std::string required_frame_prefix = "utm_";
161 if (utm_position.header.frame_id.rfind(required_frame_prefix, 0) != 0) {
162 throw std::invalid_argument("Frame-ID of UTM Position '" + utm_position.header.frame_id +
163 "' does not start with required prefix '" + required_frame_prefix + "'!");
164 }
165 double latitude, longitude;
166 try {
167 GeographicLib::UTMUPS::Reverse(zone, northp, utm_position.point.x, utm_position.point.y, latitude, longitude);
168 } catch (GeographicLib::GeographicErr& e) {
169 throw std::invalid_argument(e.what());
170 }
171 setReferencePosition(mcm, latitude, longitude, utm_position.point.z);
172}
void setReferencePosition(MCM &mcm, const double latitude, const double longitude, const double altitude=AltitudeValue::UNAVAILABLE)
Set the ReferencePosition for an MCM.

◆ setGenerationDeltaTime()

void etsi_its_mcm_uulm_msgs::access::setGenerationDeltaTime ( MCM & mcm,
const uint64_t unix_nanosecs,
const uint16_t n_leap_seconds = etsi_its_msgs::LEAP_SECOND_INSERTIONS_SINCE_2004.rbegin()->second )
inline

Set the Generation Delta Time object.

Parameters
mcmMCM to set the GenerationDeltaTime-Value for
unix_nanosecsTimestamp in unix-nanoseconds to set the GenerationDeltaTime-Value from
n_leap_secondsNumber of leap seconds since 2004 for the given timestamp (Defaults to the todays number of leap seconds since 2004.)

Definition at line 40 of file mcm_setters.h.

42 {
43 uint64_t t_its = unix_nanosecs * 1e-6 + (uint64_t)(n_leap_seconds * 1e3) - etsi_its_msgs::UNIX_SECONDS_2004 * 1e3;
44 uint16_t gdt_value = t_its % 65536;
45 throwIfOutOfRange(gdt_value, GenerationDeltaTime::MIN, GenerationDeltaTime::MAX, "GenerationDeltaTime");
46 mcm.mcm.generation_delta_time.value = gdt_value;
47}
void throwIfOutOfRange(const T1 &val, const T2 &min, const T2 &max, const std::string val_desc)
Throws an exception if a given value is out of a defined range.
Definition mcm_access.h:24

◆ setHeadingValue()

void etsi_its_mcm_uulm_msgs::access::setHeadingValue ( HeadingValue & heading,
const double value )
inline

Set the HeadingValue object.

0.0° equals WGS84 North, 90.0° equals WGS84 East, 180.0° equals WGS84 South and 270.0° equals WGS84 West

Parameters
headingobject to set
valueHeading value in degree as decimal number

Definition at line 196 of file mcm_setters.h.

196 {
197 int64_t deg = (int64_t)std::round(value * 1e1);
198 throwIfOutOfRange(deg, HeadingValue::MIN, HeadingValue::MAX, "HeadingValue");
199 heading.value = deg;
200}

◆ setItsPduHeader()

void etsi_its_mcm_uulm_msgs::access::setItsPduHeader ( MCM & mcm,
const uint32_t station_id,
const uint8_t protocol_version = 2 )
inline

Sets the ITS PDU header for the given MCM message.

Parameters
mcmReference to the MCM message whose header will be set.
station_idThe unique identifier of the ITS station.
protocol_versionThe protocol version to use (default is 2).
Exceptions
std::out_of_rangeif the protocol_version is outside the valid range defined by OrdinalNumber1B::MIN and OrdinalNumber1B::MAX.

Definition at line 26 of file mcm_setters.h.

26 {
27 mcm.header.message_id.value = MessageId::MCM;
28 mcm.header.station_id.value = station_id;
29 throwIfOutOfRange(protocol_version, OrdinalNumber1B::MIN, OrdinalNumber1B::MAX, "ProtocolVersion");
30 mcm.header.protocol_version.value = protocol_version;
31}

◆ setLatitude()

void etsi_its_mcm_uulm_msgs::access::setLatitude ( Latitude & latitude,
const double deg )
inline

Set the Latitude object.

Parameters
latitudeobject to set
degLatitude value in degree as decimal number

Definition at line 68 of file mcm_setters.h.

68 {
69 int64_t angle_in_10_micro_degree = (int64_t)std::round(deg * 1e7);
70 throwIfOutOfRange(angle_in_10_micro_degree, Latitude::MIN, Latitude::MAX, "Latitude");
71 latitude.value = angle_in_10_micro_degree;
72}

◆ setLongitude()

void etsi_its_mcm_uulm_msgs::access::setLongitude ( Longitude & longitude,
const double deg )
inline

Set the Longitude object.

Parameters
longitudeobject to set
degLongitude value in degree as decimal number

Definition at line 80 of file mcm_setters.h.

80 {
81 int64_t angle_in_10_micro_degree = (int64_t)std::round(deg * 1e7);
82 throwIfOutOfRange(angle_in_10_micro_degree, Longitude::MIN, Longitude::MAX, "Longitude");
83 longitude.value = angle_in_10_micro_degree;
84}

◆ setReferencePosition()

void etsi_its_mcm_uulm_msgs::access::setReferencePosition ( MCM & mcm,
const double latitude,
const double longitude,
const double altitude = AltitudeValue::UNAVAILABLE )
inline

Set the ReferencePosition for an MCM.

If the altitude is not provided, it is set to AltitudeValue::UNAVAILABLE. Resets all Confidence values to UNAVAILABLE.

Parameters
mcmMCM object to set the reference position in.
latitudeThe latitude value position in degree as decimal number.
longitudeThe longitude value in degree as decimal number.
altitudeThe altitude value (above the reference ellipsoid surface) in meter as decimal number (optional).

Definition at line 125 of file mcm_setters.h.

126 {
127 setLatitude(mcm.mcm.mcm_parameters.basic_container.reference_position.latitude, latitude);
128 setLongitude(mcm.mcm.mcm_parameters.basic_container.reference_position.longitude, longitude);
129 if (altitude != AltitudeValue::UNAVAILABLE) {
130 setAltitude(mcm.mcm.mcm_parameters.basic_container.reference_position.altitude, altitude);
131 } else {
132 mcm.mcm.mcm_parameters.basic_container.reference_position.altitude.altitude_value.value =
133 AltitudeValue::UNAVAILABLE;
134 mcm.mcm.mcm_parameters.basic_container.reference_position.altitude.altitude_confidence.value =
135 AltitudeConfidence::UNAVAILABLE;
136 }
137
138 // reset PositionConfidenceEllipse to unavailable
139 mcm.mcm.mcm_parameters.basic_container.reference_position.position_confidence_ellipse.semi_major_axis_length.value =
140 SemiAxisLength::UNAVAILABLE;
141 mcm.mcm.mcm_parameters.basic_container.reference_position.position_confidence_ellipse.semi_minor_axis_length.value =
142 SemiAxisLength::UNAVAILABLE;
143 mcm.mcm.mcm_parameters.basic_container.reference_position.position_confidence_ellipse.semi_major_axis_orientation
144 .value = Wgs84AngleValue::UNAVAILABLE;
145}
void setAltitude(Altitude &altitude, const double value)
Set the Altitude object.
void setLatitude(Latitude &latitude, const double deg)
Set the Latitude object.
Definition mcm_setters.h:68
void setLongitude(Longitude &longitude, const double deg)
Set the Longitude object.
Definition mcm_setters.h:80

◆ setRoadUserDimension()

template<typename T>
void etsi_its_mcm_uulm_msgs::access::setRoadUserDimension ( T & dim,
const double value )
inline

Sets the dimension value for a road user (width or length).

Template Parameters
TType representing the road user dimension, which must have static MIN and MAX members and a value member.
Parameters
dimReference to the dimension object to be set.
valueThe dimension value (in meters) to be set.
Exceptions
std::exceptionif the scaled value is out of the allowed range.

Definition at line 212 of file mcm_setters.h.

212 {
213 int64_t dim_value = (int64_t)std::round(value * 1e1);
214 throwIfOutOfRange(dim_value, T::MIN, T::MAX, "RoadUserDimension (Width/Length)");
215 dim.value = dim_value;
216}

◆ setRoadUserState()

void etsi_its_mcm_uulm_msgs::access::setRoadUserState ( RoadUserContainer & road_user_container,
const uint8_t type,
const double speed,
const double heading,
const double length,
const double width )
inline

Sets the state of a road user in the given container.

This function updates the road user type, speed, heading, length, and width of the specified RoadUserContainer object.

Parameters
road_user_containerReference to the RoadUserContainer to update.
typeThe type of the road user (as a uint8_t value).
speedThe speed of the road user (in m/s).
headingThe heading of the road user (in degrees).
lengthThe length of the road user (in meters).
widthThe width of the road user (in meters).

Definition at line 231 of file mcm_setters.h.

232 {
233 road_user_container.road_user_state.road_user_type.value = type;
234 setSpeedValue(road_user_container.road_user_state.speed, speed);
235 setHeadingValue(road_user_container.road_user_state.heading, heading);
236 setRoadUserDimension(road_user_container.road_user_state.length, length);
237 setRoadUserDimension(road_user_container.road_user_state.width, width);
238}
void setHeadingValue(HeadingValue &heading, const double value)
Set the HeadingValue object.
void setSpeedValue(SpeedValue &speed, const double value)
Set the SpeedValue object.
void setRoadUserDimension(T &dim, const double value)
Sets the dimension value for a road user (width or length).

◆ setSpeedValue()

void etsi_its_mcm_uulm_msgs::access::setSpeedValue ( SpeedValue & speed,
const double value )
inline

Set the SpeedValue object.

Parameters
speedobject to set
valueSpeedValue in m/s as decimal number

Definition at line 182 of file mcm_setters.h.

182 {
183 auto speed_val = std::round(value * 1e2);
184 throwIfOutOfRange(speed_val, SpeedValue::MIN, SpeedValue::MAX, "SpeedValue");
185 speed.value = static_cast<decltype(speed.value)>(speed_val);
186}

◆ setStationType()

void etsi_its_mcm_uulm_msgs::access::setStationType ( MCM & mcm,
const int value )
inline

Set the StationType for a MCM.

Parameters
mcmMCM-Message to set the station_type value
valuestation_type value to set

Definition at line 57 of file mcm_setters.h.

57 {
58 throwIfOutOfRange(value, TrafficParticipantType::MIN, TrafficParticipantType::MAX, "StationType");
59 mcm.mcm.mcm_parameters.basic_container.station_type.value = value;
60}

◆ setWaypoint()

void etsi_its_mcm_uulm_msgs::access::setWaypoint ( Waypoint & waypoint,
const double x,
const double y )
inline

Sets the coordinates of a Waypoint object.

Parameters
waypointReference to the Waypoint object to be modified.
xThe x-coordinate value to set (in meters as decimal number).
yThe y-coordinate value to set (in meters as decimal number).

Definition at line 266 of file mcm_setters.h.

266 {
267 setCartesianCoordinateLarge(waypoint.x_distance, x);
268 setCartesianCoordinateLarge(waypoint.y_distance, y);
269}
void setCartesianCoordinateLarge(CartesianCoordinateLarge &coordinate, const double value)
Sets the value of a CartesianCoordinateLarge object.