def _movement_ctrl_th_tf(self): """Target function of movement control thread. Responsive for navigation engines work (forward/backward)""" try: while self._keep_thread_alive: if self._allow_movement: if time.time() - self._start_time > self._moving_time: self._ser.write(pyvesc.encode(pyvesc.SetRPM(0))) self._last_stop_time = time.time() self._allow_movement = False continue if time.time() > self._next_alive_time: self._next_alive_time = time.time() + self._alive_freq self._ser.write(pyvesc.encode(pyvesc.SetAlive)) time.sleep(self._check_freq) except serial.SerialException as ex: print(ex)
def apply_rpm(self, rpm): if self._rpm != rpm: # TODO: bug to fix: if rpm was set by set_rpm - it won't be applied on vesc self._rpm = rpm self._ser.write(pyvesc.encode(pyvesc.SetRPM(self._rpm)))
def stop_moving(self): self._allow_movement = False self._last_stop_time = time.time() self._ser.write(pyvesc.encode(pyvesc.SetRPM(0)))
def start_moving(self): self._start_time = self._next_alive_time = time.time() self._ser.write(pyvesc.encode(pyvesc.SetRPM(self._rpm))) self._allow_movement = True
def disconnect(self): self._ser.write(pyvesc.encode(pyvesc.SetRPM(0))) self._keep_thread_alive = False self._ser.close()