Installation Verification¶
Ensure your device works with this simple test.
1from XRPLib.defaults import *
2import time
3
4# Installation Verification Program
5def 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
28 while not board.is_button_pressed():
29 print(f"Reflectance Left: {reflectance.get_left():.3f} Right: {reflectance.get_right():.3f} Press user button to test range sensor")
30 time.sleep(0.1)
31
32 # Wait until button is released
33 while board.is_button_pressed():
34 time.sleep(0.1)
35
36 # Print range values until button is pressed
37 while not board.is_button_pressed():
38 print(f"Range Distance: {rangefinder.distance():.1f} Press user button to test servo")
39 time.sleep(0.1)
40
41 # Wait until button is released
42 while board.is_button_pressed():
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")
50 board.wait_for_button()
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")
66 board.wait_for_button()
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("-----------------------------------")
83
84ivp()