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
6
3
"""
7
4
A simple file for shutting off all of the motors after a program gets interrupted from the REPL.
8
5
Run this file after interrupting a program to stop the robot by running "import XRPLib.resetbot" in the REPL.
9
6
"""
10
-
11
7
print ("Stopping all motors and shutting down the robot..." )
12
8
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 ()
18
16
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 ()
21
21
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 ()
25
27
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