Compare commits

...

30 Commits

Author SHA1 Message Date
3408ed5760 Update diagnostics/OtherFunctions.py 2025-12-18 19:22:39 +00:00
c8b72eff51 Update diagnostics/HubDiagnostics.py 2025-12-18 19:22:25 +00:00
ae9cbac032 Update diagnostics/FullDiagnostics.py 2025-12-18 19:09:39 +00:00
5b9ab7daed Update diagnostics/ColorSensorDiagnostics.py 2025-12-18 17:14:13 +00:00
4473d794bd Update diagnostics/FullDiagnostics.py 2025-12-18 17:12:44 +00:00
6884969cc1 Update diagnostics/ColorSensorDiagnostics.py 2025-12-18 17:11:51 +00:00
9620a0d935 Upload files to "diagnostics" 2025-12-18 17:09:21 +00:00
95adf1de84 Upload files to "diagnostics" 2025-12-18 16:42:55 +00:00
8441446e44 Add diagnostics-old/OtherFunctions.py 2025-12-17 17:25:07 +00:00
3efeafc55e Update diagnostics-old/MotorDiagnostics.py 2025-12-17 17:05:29 +00:00
acbe26eb50 Update diagnostics-old/HubDiagnostics.py 2025-12-17 17:05:21 +00:00
93d17833d1 Update diagnostics-old/FullDiagnostics.py 2025-12-17 17:05:13 +00:00
35b3726f46 Update diagnostics-old/DriveBaseDiagnostics.py 2025-12-17 17:05:05 +00:00
148d7a1c43 Update diagnostics-old/ColorSensorDiagnostics.py 2025-12-17 17:04:58 +00:00
f916a02d5a Update diagnostics-oldColorSensorDiagnostics.py 2025-12-17 17:04:52 +00:00
4a6cfc9974 Update diagnostics-old/BatteryDiagnostics.py 2025-12-17 17:04:45 +00:00
f28ec4994d Update diagnostics/HubDiagnostics.py 2025-12-17 17:04:25 +00:00
c1856220b1 Update diagnostics/HubDiagnostics.py 2025-12-17 15:20:45 +00:00
e6a2c24338 Add diagnostics/HubDiagnostics.py 2025-12-17 15:18:12 +00:00
2500f3e09b Add diagnostics/DriveBaseDiagnostics.py 2025-12-17 15:17:47 +00:00
979278d437 Update diagnostics/MotorDiagnostics.py 2025-12-17 13:29:57 +00:00
e02c0a5591 Add diagnostics/ColorSensorDiagnostics.py 2025-12-15 13:35:06 +00:00
116836b86d Removed ambiguous Unicode characters 2025-12-11 14:29:13 +00:00
f58372d166 Update diagnostics/MotorDiagnostics.py 2025-12-11 14:28:52 +00:00
f688ef0cb3 Update diagnostics/MotorDiagnostics.py 2025-12-11 14:28:21 +00:00
19f735e7e2 Update diagnostics/FullDiagnostics.py 2025-12-11 14:27:56 +00:00
c2a7775d82 Update diagnostics/BatteryDiagnostics.py 2025-12-11 14:27:45 +00:00
595cfdc6eb Update README.md 2025-12-11 14:26:42 +00:00
9f94a114ae Update README.md 2025-12-09 00:22:49 +00:00
6b6cfa11b4 Update README.md 2025-12-09 00:12:26 +00:00
15 changed files with 515 additions and 7 deletions

View File

@@ -1,10 +1,10 @@
# Team 65266 Lego Dynamics - Pybricks Utils # Team 65266 Lego Dynamics - PYNAMICS - Pybricks Utilities
A collection of Pybricks utilities to assist in your FLL robot programming with Python. Created by FLL team 65266, Lego Dynamics. A collection of Pybricks utilities to assist in your FLL robot programming with Python. Created by FLL team 65266, Lego Dynamics.
<img src="https://codes.fll-65266.org/Arcmyx/pynamics-pybricks-utils/raw/branch/arcmyx-dev/pynamics-screenshot.png" alt="Pynamics screenshot" width="670"> <img src="https://codes.fll-65266.org/Arcmyx/pynamics-pybricks-utils/raw/branch/main/pynamics-screenshot.png" alt="Pynamics screenshot" width="670">
How to use this How to use this:
- Download the repository by clicking on the "Code" tab, clicking the "< > Code" button, then downloading as a ZIP. Additionally, you can also use ```git clone https://codes.fll-65266.org/Arcmyx/pybricks-utils.git```. Unzip the archive and open code.pybricks.com. Then choose which folder you'd like to use, and open each file in pybricks by using the import button. For example, to use the diagnostics tool, simply open each program in the ```diagnostics``` folder into Pybricks. Then, follow the instructions for each utility. - Download the repository by clicking on the "Code" tab, clicking the "< > Code" button, then downloading as a ZIP. Additionally, you can also use ```git clone https://codes.fll-65266.org/Arcmyx/pybricks-utils.git```. Unzip the archive and open code.pybricks.com. Then choose which folder you'd like to use, and open each file in pybricks by using the import button. For example, to use the diagnostics tool, simply open each program in the ```diagnostics``` folder into Pybricks. Then, follow the instructions for each utility.

View File

@@ -0,0 +1,49 @@
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
hub = PrimeHub()
class ColorSensorDiagnostics:
def __init__(self):
self.colorsensor = None
self.port_map = {
"A": Port.A,
"B": Port.B,
"C": Port.C,
"D": Port.D,
"E": Port.E,
"F": Port.F,
}
def initializeColorSensor(self):
valid_ports = {"A", "B", "C", "D", "E", "F"}
while True:
colorinput = input(
"This will test your color sensor.\n"
"Enter the port for the color sensor you would like to test (A, B, C, D, E, or F): "
).strip().upper()
if colorinput not in valid_ports:
print("Invalid port. Please enter A-F.")
continue
try:
if self.colorsensor is None:
self.colorsensor = ColorSensor(self.port_map[colorinput])
print(f"Color Sensor initialized on port {colorinput}.")
else:
print(f"Reusing existing color sensor on port {colorinput}.")
break
except OSError as e:
if e.errno == 16: # EBUSY
print(f"Port {colorinput} is already in use. Reusing existing color sensor.")
break
else:
print(f"Error initializing color sensor on port {colorinput}: {e}")
print("Make sure a color sensor is actually connected to this port.")
self.colorsensor = None
self.colorsensor.detectable_colors(Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE, Color.WHITE, Color.NONE)
def printOutput(self):
while True:
print("HSV output:", self.colorsensor.hsv)
print("Detected color:", self.colorsensor.color())

View File

@@ -0,0 +1,49 @@
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
from usys import stdin
from uselect import poll
hub = PrimeHub()
port_map = {
"A": Port.A,
"B": Port.B,
"C": Port.C,
"D": Port.D,
"E": Port.E,
"F": Port.F,
}
leftmotorport = input("Enter the left motor port: ")
left_motor = Motor(port_map[leftmotorport], Direction.COUNTERCLOCKWISE)
rightmotorport = input("Enter the right motor port: ")
right_motor = Motor(port_map[rightmotorport],Direction.CLOCKWISE) # Specify default direction
# DriveBase configuration
WHEEL_DIAMETER = 68.8 # mm (adjust for your wheels)
AXLE_TRACK = 180 # mm (distance between wheels)
drive_base = DriveBase(left_motor, right_motor, WHEEL_DIAMETER, AXLE_TRACK)
drive_base.settings(600, 500, 300, 200)
drive_base.use_gyro(True)
# Register the standard input so we can read keyboard presses.
keyboard = poll()
keyboard.register(stdin)
while True:
# Check if a key has been pressed.
if keyboard.poll(0):
# Read the key and print it.
key = stdin.read(1)
print("You pressed:", key)
if(key == "W"):
print("Insert robot go forward code here")
elif(key == "A"):
print("Insert robot go left code here")
elif(key == "S"):
print("Insert robot go backwards code here")
elif(key == "D"):
print("Insert robot go right code here")
else:
print("That key doesn't do anything.")

View File

@@ -0,0 +1,33 @@
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
from pybricks import version
from OtherFunctions import vprint
import usys
print("Pybricks version information:", version)
print("MicroPython information:", usys.implementation)
print("MicroPython version:", usys.version)
class HubDiagnostics:
def __init__(self):
self.hub = PrimeHub()
self.port_map = {
"A": Port.A,
"B": Port.B,
"C": Port.C,
"D": Port.D,
"E": Port.E,
"F": Port.F,
}
def testLightSources(self, verbose):
v = verbose
hub.display.off()
for x in range(5):
for y in range(5):
vprint(f"Turning on pixel at position {x}, {y}...", v)
display.pixel(x, y, brightness=100)
wait(100)
vprint(f"Turning off pixel at position {x}, {y}...", v)
display.pixel(x, y, brightness=0)

View File

@@ -41,7 +41,7 @@ class MotorDiagnostics:
# Stability: penalize deviation relative to desired # Stability: penalize deviation relative to desired
stability = max(0, 100 - (stdev_speed / desired) * 100) stability = max(0, 100 - (stdev_speed / desired) * 100)
# Normalize load: map 1020 as baseline (0%), 200 as max (100%) # Normalize load: map 10 to 20 as baseline (around 0%), 200 as max (around 100%)
baseline = 15 # midpoint of idle range baseline = 15 # midpoint of idle range
max_observed = 200 # heavy load/stall max_observed = 200 # heavy load/stall
normalized_load = max(0, avg_load - baseline) normalized_load = max(0, avg_load - baseline)
@@ -131,11 +131,11 @@ class MotorDiagnostics:
print("\n FINAL MOTOR STATISTICS") print("\n FINAL MOTOR STATISTICS")
final = (test180 + test540 + test1000) / 3 final = (test180 + test540 + test1000) / 3
print("Final motor health score:", str(final) + "%") print("Final motor health score:", str(final) + "%")
if final < 80: if final < 65:
print("Your motor is in need of attention. Make sure to clean it regularly and charge the Prime Hub.") print("Your motor is in need of attention. Make sure to clean it regularly and charge the Prime Hub.")
elif final < 90: elif final < 85:
print("Your motor is in OK condition. Make sure to clean it regularly and charge the Prime Hub.") print("Your motor is in OK condition. Make sure to clean it regularly and charge the Prime Hub.")
elif final < 97: elif final < 95:
print("Your motor is in great condition!") print("Your motor is in great condition!")
else: else:
print("Your motor is in AMAZING condition!!!") print("Your motor is in AMAZING condition!!!")

View File

@@ -0,0 +1,2 @@
def vprint(string, verbose):
print("[LOG (verbose enabled)]", string)

View File

@@ -0,0 +1,49 @@
from pybricks.tools import wait
import umath
class BatteryDiagnostics:
def __init__(self, hub):
self.voltage = 0
self.current = 0
self.hub = hub
def printVoltage(self):
self.voltage = self.hub.battery.voltage()
if self.voltage > 7800:
print(f"Battery voltage is sufficient: {self.voltage}")
elif self.voltage < 7800 :
print(f"Charging needed: {self.voltage}")
def printCurrent(self):
self.current = self.hub.battery.current()
print("Battery current:", self.current)
def printAll(self):
timeelapsed = 0
voltageList = []
currentList = []
while True:
print("\n\n\n\n\n")
self.printVoltage()
voltageList.append(self.voltage)
self.printCurrent()
currentList.append(self.current)
wait(50)
timeelapsed += 50
if(timeelapsed >= 3000):
break
print("--------------FINAL RESULTS OF BATTERY DIAGNOSTICS---------------")
print("Voltage deviation:", self.stdev(voltageList))
print("Current deviation:", self.stdev(currentList))
def stdev(self, vals):
DATA = vals
if len(DATA) < 2:
return 0
# Calculate the mean
MEAN = sum(DATA) / len(DATA)
# Calculate the variance (sum of squared differences from the mean, divided by n-1 for sample standard deviation)
VARIANCE = sum([(x - MEAN) ** 2 for x in DATA]) / float(len(DATA) - 1)
# Calculate the standard deviation (square root of the variance)
STD_DEV_MANUAL = umath.sqrt(VARIANCE)
return (STD_DEV_MANUAL)

View File

@@ -0,0 +1,47 @@
from pybricks.parameters import Color, Port, Stop
from pybricks.tools import wait, StopWatch
class ColorSensorDiagnostics:
def __init__(self, hub, colorsensorclass):
self.colorsensor = None
self.PORT_MAP = {
"A": Port.A,
"B": Port.B,
"C": Port.C,
"D": Port.D,
"E": Port.E,
"F": Port.F,
}
def initializeColorSensor(self):
VALID_PORTS = {"A", "B", "C", "D", "E", "F"}
while True:
colorinput = input(
"This will test your color sensor.\n"
"Enter the port for the color sensor you would like to test (A, B, C, D, E, or F): "
).strip().upper()
if colorinput not in VALID_PORTS:
print("Invalid port. Please enter A-F.")
continue
try:
if self.colorsensor is None:
self.colorsensor = self.colorsensorclass(self.PORT_MAP[colorinput])
print(f"Color Sensor initialized on port {colorinput}.")
else:
print(f"Reusing existing color sensor on port {colorinput}.")
break
except OSError as e:
if e.errno == 16: # EBUSY
print(f"Port {colorinput} is already in use. Reusing existing color sensor.")
break
else:
print(f"Error initializing color sensor on port {colorinput}: {e}")
print("Make sure a color sensor is actually connected to this port.")
self.colorsensor = None
self.colorsensor.detectable_colors(Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE, Color.WHITE, Color.NONE)
def printAll(self):
self.initializeColorSensor()
stopwatch = StopWatch()
while stopwatch.time < 5000:
print("HSV output:", self.colorsensor.hsv)
print("Detected color:", self.colorsensor.color())

View File

@@ -0,0 +1,51 @@
from pybricks.parameters import Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
from usys import stdin
from uselect import poll
class DriveBaseDiagnostics:
def __init__(self, hub, motorclass, dbclass):
self.PORT_MAP = {
"A": Port.A,
"B": Port.B,
"C": Port.C,
"D": Port.D,
"E": Port.E,
"F": Port.F,
}
def initializeDriveBase():
leftmotorport = input("Enter the left motor port: ")
left_motor = self.motorclass(port_map[leftmotorport], Direction.COUNTERCLOCKWISE)
rightmotorport = input("Enter the right motor port: ")
right_motor = self.motorclass(port_map[rightmotorport],Direction.CLOCKWISE)
# DriveBase configuration
WHEEL_DIAMETER = 68.8 # mm
AXLE_TRACK = 180 # mm
drive_base = self.dbclass(left_motor, right_motor, WHEEL_DIAMETER, AXLE_TRACK)
drive_base.settings(600, 500, 300, 200)
drive_base.use_gyro(True)
def driveRobot():
# Register the standard input so we can read keyboard presses.
keyboard = poll()
keyboard.register(stdin)
while True:
# Check if a key has been pressed.
if keyboard.poll(0):
# Read the key and print it.
key = stdin.read(1)
print("You pressed:", key)
if(key == "W"):
print("Insert robot go forward code here")
elif(key == "A"):
print("Insert robot go left code here")
elif(key == "S"):
print("Insert robot go backwards code here")
elif(key == "D"):
print("Insert robot go right code here")
elif(key == "X")
break
else:
print("That key doesn't do anything.")

View File

@@ -0,0 +1,61 @@
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
HUB = PrimeHub()
from BatteryDiagnostics import BatteryDiagnostics
from MotorDiagnostics import MotorDiagnostics
from ColorSensorDiagnostics import ColorSensorDiagnostics
battery = BatteryDiagnostics(HUB)
motor = MotorDiagnostics(HUB, Motor)
colorsensor = ColorSensorDiagnostics(HUB, ColorSensor)
CLEARCONFIRM = input("Clear the console before proceeding? Y/N (default: yes): ")
if(CLEARCONFIRM == "Y" or CLEARCONFIRM == "y" or CLEARCONFIRM == "yes" or CLEARCONFIRM == ""):
print("Clearing console... \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
print("""
███████████ █████ █████ ██████ █████ █████████ ██████ ██████ █████ █████████ █████████
▒▒███▒▒▒▒▒███▒▒███ ▒▒███ ▒▒██████ ▒▒███ ███▒▒▒▒▒███ ▒▒██████ ██████ ▒▒███ ███▒▒▒▒▒███ ███▒▒▒▒▒███
▒███ ▒███ ▒▒███ ███ ▒███▒███ ▒███ ▒███ ▒███ ▒███▒█████▒███ ▒███ ███ ▒▒▒ ▒███ ▒▒▒
▒██████████ ▒▒█████ ▒███▒▒███▒███ ▒███████████ ▒███▒▒███ ▒███ ▒███ ▒███ ▒▒█████████
▒███▒▒▒▒▒▒ ▒▒███ ▒███ ▒▒██████ ▒███▒▒▒▒▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒▒▒▒▒▒▒▒███
▒███ ▒███ ▒███ ▒▒█████ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒███ ███ ███ ▒███
█████ █████ █████ ▒▒█████ █████ █████ █████ █████ █████ ▒▒█████████ ▒▒█████████
▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒
The free and open source diagnostics tool for LEGO® Education SPIKE™ Prime robots, designed for FIRST Lego League.
Developed by Team 65266, Lego Dynamics.
"""
)
while True:
print("\nWhich diagnostic do you want to perform?")
print("Enter 'b' for battery diagnostics")
print("Enter 'm' for motor diagnostics")
print("Enter 'cs' for color sensor diagnostics")
print("Enter 'q' to quit")
choice = input("Your choice: ").strip().lower()
if choice == "b":
print("-----------------------BATTERY DIAGNOSTICS-----------------------")
print("This test will check the battery voltage and current. It will measure these over a period of 3 seconds and provide average and deviation values. Your voltage should be above 7800 mV for optimal performance.")
input("Press Enter to begin the battery diagnostics.")
battery.printAll()
print("Battery diagnostics completed.")
elif choice == "m":
print("------------------------MOTOR DIAGNOSTICS------------------------")
motor.fullTest()
print("Motor diagnostics completed.")
elif choice == "q":
print("Diagnostics completed successfully. Exiting with code 0. Good luck in the robot game!")
break
elif choice == "cs":
print("---------------------COLOR SENSOR DIAGNOSTICS---------------------")
colorsensor.printAll()
print("Color sensor diagnostics completed.")
break
else:
print("Invalid choice. Please enter 'b', 'm', or 'q'.")

View File

@@ -0,0 +1,28 @@
from pybricks.tools import wait, StopWatch
from pybricks import version
import OtherFunctions as debug
import usys
print("Pybricks version information:", version)
print("MicroPython information:", usys.implementation)
print("MicroPython version:", usys.version)
class HubDiagnostics:
def __init__(self, hub):
self.port_map = {
"A": Port.A,
"B": Port.B,
"C": Port.C,
"D": Port.D,
"E": Port.E,
"F": Port.F,
}
def testLightSources(self, verbose):
v = verbose
self.hub.display.off()
for x in range(5):
for y in range(5):
debug.log(f"Turning on pixel at position {x}, {y}...", v)
display.pixel(x, y, brightness=100)
wait(100)
debug.log(f"Turning off pixel at position {x}, {y}...", v)
display.pixel(x, y, brightness=0)

View File

@@ -0,0 +1,135 @@
from pybricks.parameters import Direction, Port, Stop
from pybricks.tools import wait, StopWatch
import umath
class MotorDiagnostics:
def __init__(self, hub, motorclass):
self.testmotor = None
self.port_map = {
"A": Port.A,
"B": Port.B,
"C": Port.C,
"D": Port.D,
"E": Port.E,
"F": Port.F,
}
def stdev(self, vals):
DATA = vals
if len(DATA) < 2:
return 0
# Calculate the mean
MEAN = sum(DATA) / len(DATA)
# Calculate the variance (sum of squared differences from the mean, divided by n-1 for sample standard deviation)
VARIANCE = sum([(x - MEAN) ** 2 for x in DATA]) / float(len(DATA) - 1)
# Calculate the standard deviation (square root of the variance)
STD_DEV_MANUAL = umath.sqrt(VARIANCE)
return (STD_DEV_MANUAL)
def health_score(self, desired, avg_speed, stdev_speed, avg_load):
# Speed accuracy: penalize % error
ACCURACY = max(0, 100 - abs(avg_speed - desired) / desired * 100)
# Stability: penalize deviation relative to desired
STABILITY = max(0, 100 - (stdev_speed / desired) * 100)
# Normalize load: map 10 to 20 as baseline (around 0%), 200 as max (around 100%)
BASELINE = 15 # midpoint of idle range
MAX_OBSERVED = 200 # heavy load/stall
NORMALIZED_LOAD = max(0, avg_load - BASELINE)
LOAD_PCT = min(100, (NORMALIZED_LOAD / (MAX_OBSERVED - BASELINE)) * 100)
LOAD_SCORE = max(0, 100 - LOAD_PCT)
# Final score: average of the three
return (ACCURACY + STABILITY + LOAD_SCORE) / 3
def initializeMotor(self):
VALID_PORTS = {"A", "B", "C", "D", "E", "F"}
while True:
motorinput = input(
"This test will run your motor at 3 speeds: 180, 540, and 1000 degrees per second.\n"
"Please make sure your motor is not under any load (for example, your hand) during the test.\n"
"If you want to test the wheel's load, note that this will affect the load measurements.\n"
"Enter the port for the motor you would like to test (A, B, C, D, E, or F): "
).strip().upper()
if motorinput not in VALID_PORTS:
print("That is not a valid port. Please enter A-F.")
continue
try:
# Only create a new Motor if we don't already have one
if self.testmotor is None:
self.testmotor = self.motorclass(self.port_map[motorinput])
print(f"Motor initialized on port {motorinput}.")
else:
print(f"Reusing existing motor on port {motorinput}.")
break
except OSError as e:
if e.errno == 16: # EBUSY
print(f"Port {motorinput} is already in use. Reusing existing motor.")
# Do not overwrite self.testmotor here — keep the existing reference
break
else:
print(f"Error initializing motor on port {motorinput}: {e}")
print("Make sure a motor is actually connected to this port.")
self.testmotor = None
def testSpeed(self, speed):
self.testmotor.reset_angle(0)
motorspeeds = []
motorloads = []
TARGET_ANGLE = speed * 3
print("\n", speed, "DEGREES PER SECOND TEST")
self.testmotor.run_angle(speed, TARGET_ANGLE, Stop.HOLD, False)
stopwatchmotor = StopWatch()
while stopwatchmotor.time() < 3000:
wait(20)
motorspeeds.append(self.testmotor.speed())
motorloads.append(self.testmotor.load())
MAX_SPEED, MAX_ACCEL, MAX_TORQUE = self.testmotor.control.limits()
print("Desired motor speed: ", str(speed))
if motorspeeds:
avg = sum(motorspeeds) / len(motorspeeds)
print("Average motor speed:", avg)
print("Motor speed deviation:", str(self.stdev(motorspeeds)))
else:
print("No speed samples collected.")
avg = 0
if motorloads:
avgload = sum(motorloads) / len(motorloads)
print("Average motor load:", avgload)
print("Motor load deviation:", str(self.stdev(motorloads)))
else:
print("No load samples collected.")
avgload = 0
SCORE = self.health_score(speed, avg, self.stdev(motorspeeds), avgload)
print("Health score for this test:", str(SCORE) + "%")
return SCORE
def fullTest(self):
self.initializeMotor()
print("Load measurements are in mNm. Speed measurements are in degrees per second.")
MAX_SPEED, MAX_ACCEL, MAX_TORQUE = self.testmotor.control.limits()
print("Maximum motor speed:", MAX_SPEED)
test180 = self.testSpeed(180)
test540 = self.testSpeed(540)
test1000 = self.testSpeed(1000)
print("\n FINAL MOTOR STATISTICS")
final = (test180 + test540 + test1000) / 3
print("Final motor health score:", str(final) + "%")
if final < 65:
print("Your motor is in need of attention. Make sure to clean it regularly and charge the Prime Hub.")
elif final < 85:
print("Your motor is in OK condition. Make sure to clean it regularly and charge the Prime Hub.")
elif final < 95:
print("Your motor is in great condition!")
else:
print("Your motor is in AMAZING condition!!!")
self.testmotor.stop()

View File

@@ -0,0 +1,4 @@
verbose = True
def log(string):
if(verbose):
print("[LOG (verbose)]", string)