Skip to content

Commit 1782de0

Browse files
committed
Update installation_verification.py
Add print statements to help guide user Remove other examples as dependencies to make IVP more standalone Add comments to explain the code more clearly Format sensor values to limit decimal places
1 parent 7d97472 commit 1782de0

File tree

1 file changed

+69
-12
lines changed

1 file changed

+69
-12
lines changed

Examples/installation_verification.py

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,84 @@
11
from XRPLib.defaults import *
2-
from .drive_examples import *
3-
from .misc_examples import *
42
import time
53

64
# Installation Verification Program
75
def ivp():
6+
# Print welcome message
7+
print("------------------------------------------")
8+
print("Running Installation Verification Program!")
9+
print("------------------------------------------")
10+
print()
11+
print("Welcome to the XRP! This example code will help")
12+
print("you verify that everything is working on your robot.")
13+
print("After each test, press the user button to continue.")
14+
print()
15+
16+
# Flash LED at 5Hz
17+
print("Flashing LED")
18+
board.led_blink(5)
19+
20+
# Wait for user to press button
21+
print("Press user button to test reflectance sensor")
22+
board.wait_for_button()
23+
24+
# Stop blinking LED
25+
board.led_off()
26+
27+
# Print reflectance values until button is pressed
828
while not board.is_button_pressed():
9-
print(f"Left Reflectance: {reflectance.get_left()}, Right Reflectance: {reflectance.get_right()}")
29+
print(f"Reflectance Left: {reflectance.get_left():.3f} Right: {reflectance.get_right():.3f} Press user button to test range sensor")
1030
time.sleep(0.1)
31+
32+
# Wait until button is released
1133
while board.is_button_pressed():
12-
time.sleep(.01)
34+
time.sleep(0.1)
35+
36+
# Print range values until button is pressed
1337
while not board.is_button_pressed():
14-
print(f"Ultrasonic Distance: {rangefinder.distance()}")
38+
print(f"Range Distance: {rangefinder.distance():.1f} Press user button to test servo")
1539
time.sleep(0.1)
40+
41+
# Wait until button is released
1642
while board.is_button_pressed():
17-
time.sleep(.01)
18-
print("Testing Servo")
19-
test_servo()
20-
print("Testing LEDs")
43+
time.sleep(0.1)
44+
45+
# Print warning and wait for button press
46+
print()
47+
print("The next test will move the servo, so keep your hands clear!")
48+
print("Also please make sure the power switch is turned on!")
49+
print("Press user button to test servo")
2150
board.wait_for_button()
22-
test_leds()
23-
print("Testing Drivetrain:")
51+
52+
# Test servo
53+
print("Testing servo")
54+
time.sleep(1)
55+
servo_one.set_angle(90)
56+
time.sleep(1)
57+
servo_one.set_angle(0)
58+
time.sleep(1)
59+
servo_one.set_angle(180)
60+
61+
# Print warning and wait for button press
62+
print()
63+
print("The next test will drive the motors, so place the robot on a flat surface!")
64+
print("Also please make sure the power switch is turned on!")
65+
print("Press user button to test drivetrain")
2466
board.wait_for_button()
25-
test_drive()
67+
68+
# Test drivetrain
69+
print("Testing drivetrain")
70+
time.sleep(1)
71+
drivetrain.straight(25, 0.8)
72+
time.sleep(1)
73+
drivetrain.turn(90,0.8)
74+
time.sleep(1)
75+
drivetrain.turn(90, -0.8)
76+
time.sleep(1)
77+
drivetrain.straight(-25,0.8)
78+
79+
print()
80+
print("-----------------------------------")
81+
print("All tests complete! Happy roboting!")
82+
print("-----------------------------------")
2683

2784
ivp()

0 commit comments

Comments
 (0)