16namespace traffic_manager {
18namespace chr = std::chrono;
20using namespace constants::PID;
22using TimeInstance = chr::time_point<chr::system_clock, chr::nanoseconds>;
30 const float previous_reference,
31 const float vehicle_speed,
32 const float target_velocity,
33 const float control_dt,
34 const bool emergency_stop) {
36 float reference{emergency_stop ? vehicle_speed : previous_reference};
44 reference = std::max(reference, std::min(vehicle_speed, target_velocity));
51 const float reference_velocity,
52 const float vehicle_speed,
53 const float target_velocity) {
55 return (reference_velocity - vehicle_speed) /
63 const float control_dt,
64 const float vehicle_speed,
67 const float speed_ratio{
69 const float steer_deadband{
STEER_DEADBAND * speed_ratio * speed_ratio};
73 actuation_signal.
throttle = std::min(
78 if (actuation_signal.
throttle > 0.0f &&
82 if (actuation_signal.
brake > 0.0f &&
86 if (std::abs(actuation_signal.
steer - previous_state.
steer) < steer_deadband) {
115 const std::vector<float> &longitudinal_parameters,
116 const std::vector<float> &lateral_parameters,
117 const float vehicle_speed,
118 const float control_dt = DT,
119 const float lateral_pursuit_steer = 0.0f,
120 const float lateral_damping_scale = 1.0f,
121 const float steer_authority_correction = 1.0f) {
124 const float inv_dt = 1.0f / dt;
130 const float gain_scale = std::min(1.0f, DT * inv_dt);
148 brake = std::min(std::abs(expr_v),
MAX_BRAKE);
159 deviation_delta = std::max(-max_deviation_delta, std::min(deviation_delta, max_deviation_delta));
160 float steer = gain_scale * (
161 lateral_pursuit_steer +
163 lateral_damping_scale * lateral_parameters[2] * deviation_delta * inv_dt);
169 steer = std::max(previous_state.
steer - max_steering_diff, std::min(steer, previous_state.
steer + max_steering_diff));
178 const float speed_sq = std::max(vehicle_speed * vehicle_speed, 1.0f);
179 const float steer_limit = std::min(
181 steer = std::max(-steer_limit, std::min(steer, steer_limit));
ActuationSignal RunStep(StateEntry present_state, StateEntry previous_state, const std::vector< float > &longitudinal_parameters, const std::vector< float > &lateral_parameters, const float vehicle_speed, const float control_dt=DT, const float lateral_pursuit_steer=0.0f, const float lateral_damping_scale=1.0f, const float steer_authority_correction=1.0f)
This function calculates the actuation signals based on the resent state change of the vehicle to min...
float RelativeVelocityDeviation(const float reference_velocity, const float vehicle_speed, const float target_velocity)
The target is exactly zero behind a stopped vehicle; the floor avoids a 0/0 NaN that the derivative t...
float ShapeReferenceVelocity(const float previous_reference, const float vehicle_speed, const float target_velocity, const float control_dt, const bool emergency_stop)
Reference speed that closes on target_velocity at COMFORT_ACCELERATION instead of stepping to it.
void SmoothActuation(const StateEntry &previous_state, const float control_dt, const float vehicle_speed, ActuationSignal &actuation_signal)
A zero pedal demand bypasses the deadband, so pedals rest exactly at zero and nothing here delays a d...
static const float EPSILON_RELATIVE_SPEED
static const float MAX_STEERING_RATE
static const float MAX_THROTTLE
static const float COMFORT_ACCELERATION
static const float STEER_LIMIT_GAIN
static constexpr float MIN_CONTROL_DT
static const float MAX_DEVIATION_RATE
static const float MAX_BRAKE
static const float REFERENCE_LEAD_FRACTION
static const float STEER_DEADBAND
static constexpr float MAX_LAUNCH_THROTTLE_RISE_RATE
static const float BRAKE_DEADBAND
static const float MAX_CONTROL_DT
static const float MAX_STEERING
static constexpr float THROTTLE_DEADBAND
static const float STEER_DEADBAND_REF_SPEED
static const float LAUNCH_RAMP_SPEED
chr::time_point< chr::system_clock, chr::nanoseconds > TimeInstance
This file contains definitions of common data structures used in traffic manager.
Structure to hold the actuation signals.
Structure to hold the controller state.