@sh.add_function(dsp, outputs=['clutch_phases'])
def calculate_clutch_phases(
times, velocities, gears, gear_shifts, stop_velocity, clutch_window):
"""
Calculate when the clutch is active [-].
:param times:
Time vector [s].
:type times: numpy.array
:param velocities:
Velocity vector [km/h].
:type velocities: numpy.array
:param gears:
Gear vector [-].
:type gears: numpy.array
:param gear_shifts:
When there is a gear shifting [-].
:type gear_shifts: numpy.array
:param stop_velocity:
Maximum velocity to consider the vehicle stopped [km/h].
:type stop_velocity: float
:param clutch_window:
Clutching time window [s].
:type clutch_window: tuple
:return:
When the clutch is active [-].
:rtype: numpy.array
"""
dn, up = clutch_window
b = np.zeros_like(times, dtype=bool)
for t in times[gear_shifts]:
b |= ((t + dn) <= times) & (times <= (t + up))
b &= (gears > 0) & (velocities > stop_velocity)
return b