Handle Restriction Alerts
Handle restriction alerts
This tutorial shows how to handle restriction alerts.
Get started
Restriction alerts are all zone alerts indicating vehicle may not pass the zone or should pass with caution.
Following types are restriction alerts:
* tn::drive::models::v1::AlertType::AccessRestriction
* tn::drive::models::v1::AlertType::PhysicalRestriction
* tn::drive::models::v1::AlertType::TimedRestriction
Restriction alerts work for recreational vehicle (RV) only at present.
Vehicle category is set via tn::foundation::VehicleInfoProvider
implementation.
Access restrictions
Access restriction alerts are raised if vehicle category is restricted to access a road on the most possible path (MPP)
in free mode or on the route in navigation mode.
| void AlertObserver::onAlertInfoUpdated(const tn::drive::models::v1::AlertInfo& alertInfo)
{
const auto& aheadAlerts = alertInfo.alerts_ahead;
for (const auto& alert : aheadAlerts.restriction_alerts)
{
// each alert item has a unique identifier, can be used to match alert updates
const auto id = alert.basic.id;
const auto type = alert.basic.type;
const auto severity = alert.severity;
const auto affectedVehicleCategory = alert.vehicle_category_restriction;
if ((type == tn::drive::models::v1::AlertType::AccessRestriction) &&
(severity == tn::drive::models::v1::Severity::Critical) &&
(affectedVehicleCategory == tn::foundation::VehicleCategory::RV))
{
// vehicle cannot access the road
showAlertIconOnMap(id, type, alert.zone.begin, alert.zone.end);
const auto divergeLocation = alert.diverge_location;
if (divergeLocation.has_value())
{
// along road distance from current vehicle location to diverge location
const auto distanceToDivergeLocation =
alert.basic.distance_to_vehicle - divergeLocation->distance_from_alert_point;
showHintIconOnMap(id, type, divergeLocation->location);
}
}
}
}
|
Physical restrictions
Physical restriction alerts are raised if vehicle dimensions are over or near the maximum allowed ones
on the most possible path (MPP) in free mode or on the route in navigation mode.
Vehicle dimensions can be changed via tn::foundation::VehicleInfoProvider::setDimensions()
.
| void AlertObserver::onAlertInfoUpdated(const tn::drive::models::v1::AlertInfo& alertInfo)
{
const auto& aheadAlerts = alertInfo.alerts_ahead;
for (const auto& alert : aheadAlerts.restriction_alerts)
{
// each alert item has a unique identifier, can be used to match alert updates
const auto id = alert.basic.id;
const auto type = alert.basic.type;
const auto severity = alert.severity;
const auto affectedVehicleCategory = alert.vehicle_category_restriction;
if ((type == tn::drive::models::v1::AlertType::PhysicalRestriction) &&
(affectedVehicleCategory == tn::foundation::VehicleCategory::RV))
{
if (severity == tn::drive::models::v1::Severity::Critical)
{
// vehicle cannot pass the road
showAlertIconOnMap(id, type, alert.zone.begin, alert.zone.end);
const auto provider = system->vehicleInfoProvider();
const auto dimensions = provider->getDimensions();
if (alert.length_restriction.has_value() &&
(dimensions.length > alert.length_restriction.value()))
{
// throw a message indicating vehicle length exceeds the limitation
}
if (alert.width_restriction.has_value() &&
(dimensions.width > alert.width_restriction.value()))
{
// throw a message indicating vehicle width exceeds the limitation
}
if (alert.height_restriction.has_value() &&
(dimensions.height > alert.height_restriction.value()))
{
// throw a message indicating vehicle height exceeds the limitation
}
if (alert.weight_restriction.has_value() &&
(dimensions.weight > alert.weight_restriction.value()))
{
// throw a message indicating vehicle weight exceeds the limitation
}
if (alert.gross_mass_restriction.has_value() &&
(dimensions.gross_vehicle_mass > alert.gross_mass_restriction.value()))
{
// throw a message indicating vehicle gross mass exceeds the limitation
}
const auto divergeLocation = alert.diverge_location;
if (divergeLocation.has_value())
{
// along road distance from current vehicle location to diverge location
const auto distanceToDivergeLocation =
alert.basic.distance_to_vehicle - divergeLocation->distance_from_alert_point;
showHintIconOnMap(id, type, divergeLocation->location);
}
}
else if (severity == tn::drive::models::v1::Severity::Medium)
{
// throw a message indicating vehicle should pass with caution
}
}
}
}
|
Timed restrictions
Timed restrictions are raised when vehicle is estimated to be in a zone that has timed restriction take effect.
| void AlertObserver::onAlertInfoUpdated(const tn::drive::models::v1::AlertInfo& alertInfo)
{
const auto& aheadAlerts = alertInfo.alerts_ahead;
for (const auto& alert : aheadAlerts.restriction_alerts)
{
// each alert item has a unique identifier, can be used to match alert updates
const auto id = alert.basic.id;
const auto type = alert.basic.type;
const auto severity = alert.severity;
const auto affectedVehicleCategory = alert.vehicle_category_restriction;
if ((type == tn::drive::models::v1::AlertType::PhysicalRestriction) &&
(affectedVehicleCategory == tn::foundation::VehicleCategory::RV))
{
if (severity == tn::drive::models::v1::Severity::Critical)
{
// vehicle cannot pass the road, it's already in the restricted period
showAlertIconOnMap(id, type, alert.zone.begin, alert.zone.end);
}
else if (severity == tn::drive::models::v1::Severity::Medium)
{
// throw a message indicating vehicle may encounter a timed restriction rules applied road in less than half an hour
const auto divergeLocation = alert.diverge_location;
if (divergeLocation.has_value())
{
// along road distance from current vehicle location to diverge location
const auto distanceToDivergeLocation =
alert.basic.distance_to_vehicle - divergeLocation->distance_from_alert_point;
showHintIconOnMap(id, type, divergeLocation->location);
}
}
}
}
}
|
Hazardous material restrictions
Hazardous material restriction alerts are triggered if there are restrictions on goods carried ahead
on the most possible path (MPP) in free mode or on the route in navigation mode.
Vehicle hazardous material can be changed via tn::foundation::VehicleInfoProvider::setHazardousMaterialTypes()
.
Vehicle tunnel restriction code can be changed via tn::foundation::VehicleInfoProvider::setTunnelRestrictionCode()
.
| void AlertObserver::onAlertInfoUpdated(const tn::drive::models::v1::AlertInfo& alertInfo)
{
const auto& aheadAlerts = alertInfo.alerts_ahead;
for (const auto& alert : aheadAlerts.restriction_alerts)
{
// each alert item has a unique identifier, can be used to match alert updates
const auto id = alert.basic.id;
const auto type = alert.basic.type;
const auto severity = alert.severity;
const auto affectedVehicleCategory = alert.vehicle_category_restriction;
if ((type == tn::drive::models::v1::AlertType::HazardousMaterialRestriction) &&
(affectedVehicleCategory == tn::foundation::VehicleCategory::RV))
{
if (severity == tn::drive::models::v1::Severity::Critical)
{
// vehicle cannot pass the road
showAlertIconOnMap(id, type, alert.zone.begin, alert.zone.end);
const auto divergeLocation = alert.diverge_location;
if (divergeLocation.has_value())
{
// along road distance from current vehicle location to diverge location
const auto distanceToDivergeLocation =
alert.basic.distance_to_vehicle - divergeLocation->distance_from_alert_point;
showHintIconOnMap(id, type, divergeLocation->location);
}
for (const auto& item : alert.hazardous_material_types)
{
// Show the hazardous material type this alert apply to.
}
const auto tunnelCategory = alert.tunnel_category;
if (tunnelCategory.has_value())
{
// Show the tunnel category this alert apply to.
}
}
else
{
// Ignore.
}
}
}
}
|