51 float mass = vehicle_physics.
mass;
52 float max_steer_angle_deg = 0.f;
53 float sum_max_brake_torque = 0.f;
55 for (
auto const &wheel : vehicle_physics.
wheels) {
56 sum_max_brake_torque += wheel.max_brake_torque;
57 radius = wheel.radius;
58 max_steer_angle_deg = std::max(max_steer_angle_deg, wheel.max_steer_angle);
63 _logger->debug(
"Lon {}, L {}, R {}; LatSpeed {}, Accel {}, Avg {}, Hdg {}, AllowedHeadingRanges {}",
64 proper_response.accelerationRestrictions.longitudinalRange,
65 proper_response.accelerationRestrictions.lateralLeftRange,
66 proper_response.accelerationRestrictions.lateralRightRange, ego_dynamics_on_route.
route_speed_lat,
68 ego_dynamics_on_route.
ego_heading, proper_response.headingRanges);
69 if (proper_response.accelerationRestrictions.lateralLeftRange.maximum <= ::ad::physics::Acceleration(0.0)) {
70 if (ego_dynamics_on_route.
route_speed_lat < ::ad::physics::Speed(0.0)) {
72 if (ego_dynamics_on_route.
route_speed_lon != ::ad::physics::Speed(0.0)) {
74 float desired_steer_ratio = -180.f *
static_cast<float>(angle_rad / M_PI) / max_steer_angle_deg;
76 desired_steer_ratio += 0.1f;
78 float orig_steer = restricted_vehicle_control.
steer;
79 restricted_vehicle_control.
steer = std::max(restricted_vehicle_control.
steer, desired_steer_ratio);
80 restricted_vehicle_control.
steer = std::min(restricted_vehicle_control.
steer, 1.0f);
81 _logger->debug(
"EgoVelocity: {}", ego_dynamics_on_route);
82 _logger->debug(
"Countersteer left to right: {} -> {}", orig_steer, restricted_vehicle_control.
steer);
87 if (proper_response.accelerationRestrictions.lateralRightRange.maximum <= ::ad::physics::Acceleration(0.0)) {
88 if (ego_dynamics_on_route.
route_speed_lat > ::ad::physics::Speed(0.0)) {
90 if (ego_dynamics_on_route.
route_speed_lon != ::ad::physics::Speed(0.0)) {
92 float desired_steer_ratio = -180.f *
static_cast<float>(angle_rad / M_PI) / max_steer_angle_deg;
94 desired_steer_ratio -= 0.1f;
96 float orig_steer = restricted_vehicle_control.
steer;
97 restricted_vehicle_control.
steer = std::min(restricted_vehicle_control.
steer, desired_steer_ratio);
98 restricted_vehicle_control.
steer = std::max(restricted_vehicle_control.
steer, -1.0f);
99 _logger->debug(
"EgoVelocity: {}", ego_dynamics_on_route);
100 _logger->debug(
"Countersteer right to left: {} -> {}", orig_steer, restricted_vehicle_control.
steer);
106 auto accel_lon = proper_response.accelerationRestrictions.longitudinalRange.maximum;
107 if (proper_response.unstructuredSceneResponse == ad::rss::state::UnstructuredSceneResponse::DriveAway) {
109 auto heading_allowed =
false;
110 if (!proper_response.headingRanges.empty()) {
111 auto max_steer_angle = max_steer_angle_deg * (ad::physics::cPI / ad::physics::Angle(180.0));
112 auto current_steering_angle =
static_cast<double>(ego_dynamics_on_route.
ego_heading) - vehicle_control.
steer * max_steer_angle;
113 for (
auto it = proper_response.headingRanges.cbegin(); (it != proper_response.headingRanges.cend() && !heading_allowed); ++it) {
114 heading_allowed = ad::rss::unstructured::isInsideHeadingRange(current_steering_angle, *it);
118 if (!heading_allowed) {
119 accel_lon = proper_response.accelerationRestrictions.longitudinalRange.minimum;
123 if (accel_lon > ::ad::physics::Acceleration(0.0)) {
128 if (accel_lon < ::ad::physics::Acceleration(0.0)) {
129 restricted_vehicle_control.
throttle = 0.0f;
131 double brake_acceleration =
132 std::fabs(
static_cast<double>(proper_response.accelerationRestrictions.longitudinalRange.minimum));
133 double sum_brake_torque = mass * brake_acceleration * radius / 100.0;
134 restricted_vehicle_control.
brake = std::min(
static_cast<float>(sum_brake_torque / sum_max_brake_torque), 1.0f);
137 if (restricted_vehicle_control != vehicle_control) {
139 "Restrictor active: throttle({} -> {}), brake ({} -> {}). steer ({} -> "
142 restricted_vehicle_control.
brake, vehicle_control.
steer, restricted_vehicle_control.
steer);
144 return restricted_vehicle_control;