@sh.add_function(dsp, outputs=['on_engine'], weight=sh.inf(1, 0))
def predict_on_engine(
times, velocities, gears, accelerations, start_stop_model,
start_stop_activation_time, min_time_engine_on_after_start,
correct_start_stop_with_gears, has_start_stop):
"""
Predicts if the engine is on [-].
:param times:
Time vector [s].
:type times: numpy.array
:param velocities:
Velocity vector [km/h].
:type velocities: numpy.array
:param accelerations:
Acceleration vector [m/s2].
:type accelerations: numpy.array
:param gears:
Gear vector [-].
:type gears: numpy.array
:param start_stop_model:
Start/stop model.
:type start_stop_model: callable
:param start_stop_activation_time:
Start-stop activation time threshold [s].
:type start_stop_activation_time: float
:param min_time_engine_on_after_start:
Minimum time of engine on after a start [s].
:type min_time_engine_on_after_start: float
:param correct_start_stop_with_gears:
A flag to impose engine on when there is a gear > 0.
:type correct_start_stop_with_gears: bool
:param has_start_stop:
Does the vehicle have start/stop system?
:type has_start_stop: bool
:return:
If the engine is on [-].
:rtype: numpy.array
"""
if not has_start_stop:
return np.ones_like(times, bool)
on_engine = times <= start_stop_activation_time
if correct_start_stop_with_gears:
on_engine |= gears > 0
b0 = velocities > dfl.functions.StartStopModel.stop_velocity
b0 |= accelerations > dfl.functions.StartStopModel.plateau_acceleration
b1 = start_stop_model(np.column_stack((velocities, accelerations)))
ts = min_time_engine_on_after_start
# noinspection PyTypeChecker
for i, (t, on, on_b, on_m) in enumerate(zip(times, on_engine, b0, b1)):
prev = i == 0 or on_engine[i - 1]
on = on or ((prev or on_b) and on_m)
if not on and t <= ts:
on = True
if not prev and on:
ts = t + min_time_engine_on_after_start
on_engine[i] = on
return on_engine