Compare commits

...

19 Commits

Author SHA1 Message Date
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
7 changed files with 137 additions and 4 deletions

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)