Skip to content

Commit 044114a

Browse files
committed
Resetbot.py refactor to save on processing time
1 parent be1b1c5 commit 044114a

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

XRPLib/resetbot.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
from XRPLib.encoded_motor import EncodedMotor
2-
from XRPLib.imu import IMU
3-
from XRPLib.board import Board
4-
from XRPLib.servo import Servo
5-
from XRPLib.webserver import Webserver
1+
import sys
2+
import time
63
"""
74
A simple file for shutting off all of the motors after a program gets interrupted from the REPL.
85
Run this file after interrupting a program to stop the robot by running "import XRPLib.resetbot" in the REPL.
96
"""
10-
117
print("Stopping all motors and shutting down the robot...")
128

13-
# using the EncodedMotor since the default drivetrain uses the IMU and takes 3 seconds to init
14-
for i in range(4):
15-
motor = EncodedMotor.get_default_encoded_motor(i+1)
16-
motor.set_speed(0)
17-
motor.reset_encoder_position()
9+
if "XRPLib.encoded_motor" in sys.modules:
10+
from XRPLib.encoded_motor import EncodedMotor
11+
# using the EncodedMotor since the default drivetrain uses the IMU and takes 3 seconds to init
12+
for i in range(4):
13+
motor = EncodedMotor.get_default_encoded_motor(i+1)
14+
motor.set_speed(0)
15+
motor.reset_encoder_position()
1816

19-
# Turn off the on-board LED
20-
Board.get_default_board().led_off()
17+
if "XRPLib.board" in sys.modules:
18+
from XRPLib.board import Board
19+
# Turn off the on-board LED
20+
Board.get_default_board().led_off()
2121

22-
# Turn off both Servos
23-
Servo.get_default_servo(1).free()
24-
Servo.get_default_servo(2).free()
22+
if "XRPLib.servo" in sys.modules:
23+
from XRPLib.servo import Servo
24+
# Turn off both Servos
25+
Servo.get_default_servo(1).free()
26+
Servo.get_default_servo(2).free()
2527

26-
# Shut off the webserver and close network connections
27-
Webserver.get_default_webserver().stop_server()
28+
if "XRPLib.webserver" in sys.modules:
29+
from XRPLib.webserver import Webserver
30+
# Shut off the webserver and close network connections
31+
Webserver.get_default_webserver().stop_server()

0 commit comments

Comments
 (0)