def stop_all(): try: # credit for the following two lines goes to dwalton76 : https://github.com/rhempel/ev3dev-lang-python/blob/develop/utils/stop_all_motors.py for motor in list_motors(): # works for all motors, large and medium motor.stop(stop_action="coast") except ValueError: return "Not found"
def main(self): try: while True: self.remote.process() time.sleep(0.01) # Exit cleanly so that all motors are stopped except (KeyboardInterrupt, Exception) as e: log.exception(e) for motor in list_motors(): motor.stop()
def run(self): try: log.info("Started HTTP server (content) on port %d" % self.port_number) self.content_server = HTTPServer(('', self.port_number), self.handler_class) self.content_server.serve_forever() # Exit cleanly, stop both web servers and all motors except (KeyboardInterrupt, Exception) as e: log.exception(e) if self.content_server: self.content_server.socket.close() self.content_server = None for motor in list_motors(): motor.stop()
def set_motor(io_type, port, info, value): try: if io_type == 'large motor': i = ev3.LargeMotor(port) elif io_type == 'medium motor': i = ev3.MediumMotor(port) power = int(value) if info == 'run forever': i.run_forever(duty_cycle_sp=power) time.wait(1) # if info == 'run_timed': # i.run_timed(time_sp=timer, duty_cycle_sp=power) if info == 'stop': i.stop(stop_action=value) if info == 'reset': i.reset() if info == 'switch': i.duty_cycle_sp(i.duty_cycle_sp * -1) if info == 'stop all': # credit for the following two lines goes to dwalton76 : https://github.com/rhempel/ev3dev-lang-python/blob/develop/utils/stop_all_motors.py for motor in list_motors(): motor.stop(stop_action=value) except ValueError: return "Not found"
#!/usr/bin/env python3 """ Stop all motors """ from ev3dev.auto import list_motors for motor in list_motors(): motor.stop(stop_action='brake')
#!/usr/bin/env python """ Stop all motors """ from ev3dev.auto import list_motors for motor in list_motors(): motor.stop(stop_action='brake')