ignore target velocity if recovering from NCE

This commit is contained in:
Marco Zeisler 2021-06-02 23:09:35 +02:00
parent 4653fa5738
commit 8fb11e2cc5

View File

@ -53,6 +53,8 @@ class Vehicle:
_nce_possible = True _nce_possible = True
# stores if nce already happened, it only happens (up to) once # stores if nce already happened, it only happens (up to) once
_nce_happened = False _nce_happened = False
# stores if we are still recovering from NCE
_recovering = False
# continuous driving thread # continuous driving thread
_t: threading.Thread _t: threading.Thread
@ -93,9 +95,11 @@ class Vehicle:
def _sleep_and_recover(): def _sleep_and_recover():
recover_in = TIME_TO_RECOVER / SCALING recover_in = TIME_TO_RECOVER / SCALING
self._recovering = True
print('\nNCE !!! Recovering in {} (scaled) seconds.\n'.format(recover_in)) print('\nNCE !!! Recovering in {} (scaled) seconds.\n'.format(recover_in))
time.sleep(recover_in) time.sleep(recover_in)
print('\nRecovered.\n') print('\nRecovered.\n')
self._recovering = False
self.velocity = self._last_velocity self.velocity = self._last_velocity
self._rt = threading.Thread(target=_sleep_and_recover) self._rt = threading.Thread(target=_sleep_and_recover)
@ -218,7 +222,11 @@ class Vehicle:
response: TargetVelocity = pickle.loads(response) response: TargetVelocity = pickle.loads(response)
velocity = response.target_velocity velocity = response.target_velocity
print('Received new velocity {}'.format(velocity)) print('Received new velocity {}'.format(velocity))
if not self._recovering:
self.velocity = velocity self.velocity = velocity
else:
print('We are still recovering ... ignoring new target velocity.')
if __name__ == "__main__": if __name__ == "__main__":