From 76b90481f6e9f915b37e770b53caad19004a6cb6 Mon Sep 17 00:00:00 2001 From: HappyZ Date: Wed, 20 Dec 2017 15:36:43 -0600 Subject: [PATCH] add keyboard interrupt stop function --- nexus.py | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/nexus.py b/nexus.py index a42ac43..b405b54 100644 --- a/nexus.py +++ b/nexus.py @@ -37,21 +37,27 @@ class NexusRobot: - -robot = NexusRobot('/dev/cu.usbserial-AL00YYCA') -robot.forward(200,10) -robot.pause() -robot.turnRight(200,90) -robot.pause() -robot.forward(200,10) -robot.pause() -robot.turnRight(200,90) -robot.pause() -robot.forward(200,10) -robot.pause() -robot.turnRight(200,90) -robot.pause() -robot.forward(200,10) -robot.pause() -robot.turnRight(200,90) -robot.pause() +if __name__ == '__main__'': + try: + robot = NexusRobot('/dev/cu.usbserial-AL00YYCA') + while 1: + robot.forward(200,20) + robot.pause() + robot.reverse(200,20) + robot.pause() +# robot.forward(200,10) +# robot.pause() +# robot.turnRight(200,90) +# robot.pause() +# robot.forward(200,10) +# robot.pause() +# robot.turnRight(200,90) +# robot.pause() +# robot.forward(200,10) +# robot.pause() +# robot.turnRight(200,90) +# robot.pause() + except KeyboardInterrupt: + robot.stop() + except BasicException: + raise