Update utils/MotorDiagnostics.py
This commit is contained in:
@@ -9,6 +9,15 @@ hub = PrimeHub()
|
||||
class MotorDiagnostics:
|
||||
def __init__(self):
|
||||
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:
|
||||
@@ -50,7 +59,7 @@ class MotorDiagnostics:
|
||||
).strip().upper()
|
||||
|
||||
if motorinput in valid_ports:
|
||||
self.testmotor = Motor(Port[motorinput])
|
||||
self.testmotor = Motor(self.port_map[motorinput])
|
||||
print(f"Motor initialized on port {motorinput}.")
|
||||
break # exit the loop once a valid port is entered
|
||||
else:
|
||||
@@ -62,40 +71,53 @@ class MotorDiagnostics:
|
||||
motorspeeds = []
|
||||
motorloads = []
|
||||
target_angle = speed * 3
|
||||
|
||||
print("\n", speed, "DEGREES PER SECOND TEST")
|
||||
self.testmotor.run_angle(speed, target_angle, Stop.HOLD, False)
|
||||
while abs(self.testmotor.speed()) > 5:
|
||||
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("Maximum motor speed (deg/s):", max_speed)
|
||||
|
||||
print("Desired motor speed (degrees per second): ", str(speed))
|
||||
|
||||
print("Desired motor speed: ", str(speed))
|
||||
if motorspeeds:
|
||||
avg = sum(motorspeeds) / len(motorspeeds)
|
||||
print("Average motor speed (degrees per second):", avg)
|
||||
print("Motor speed deviation (this measures how much your motor deviates from the average speed):", str(self.stdev(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 (mNm):", avgload)
|
||||
print("Motor load deviation (this measures how much your motor load deviates from the average load):", str(self.stdev(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:", score)
|
||||
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("FINAL MOTOR STATISTICS")
|
||||
final = (test180 + test540 + test1000) / 3
|
||||
print("Final motor health score:", final)
|
||||
# print final health scores here as a combination of the 3 speeds, include speeds individual scores and total score
|
||||
print("Final motor health score:", str(final) + "%")
|
||||
if final < 80:
|
||||
print("Your motor is in need of attention. Make sure to clean it regularly and charge the Prime Hub.")
|
||||
elif final < 90:
|
||||
print("Your motor is in OK condition. Make sure to clean it regularly and charge the Prime Hub.")
|
||||
elif final < 97:
|
||||
print("Your motor is in great condition!")
|
||||
else:
|
||||
print("Your motor is in AMAZING condition!!!")
|
||||
|
||||
Reference in New Issue
Block a user