cleanup of code, bugfixing

This commit is contained in:
Robert Schauklies 2025-11-23 03:25:03 +01:00
parent e87293a6e2
commit dd341bbb67

View file

@ -21,11 +21,13 @@ from pid import PID
COILS = 14 COILS = 14
# from enum import Enum # from enum import Enum
class SpinnyBoy(object):
# class EditMenu(Enum): def __init__(self,state,timer1,timer2,display):
# DEPOSIT = 1 self.state = state
# COATING = 2 self.timer1 = timer1
# TIME = 3 self.timer2 = timer2
self.display = display
def splash(): def splash():
# display.fill(0) # display.fill(0)
# display.fill_rect(0, 0, 32, 32, 1) # display.fill_rect(0, 0, 32, 32, 1)
@ -172,33 +174,33 @@ def coating_view(state, rotary):
display.print("{: >{w}} sec".format(state["timer"], w=4)) display.print("{: >{w}} sec".format(state["timer"], w=4))
def decode_ESC_telemetry(data, motor_poles=14): #def decode_ESC_telemetry(data, motor_poles=14):
if len(data) > 10: # if len(data) > 10:
# use latest telemetry # # use latest telemetry
data = data[-10:] # data = data[-10:]
#
temperature = int(data[0]) # degrees Celsius # temperature = int(data[0]) # degrees Celsius
voltage = int((data[1] << 8) | data[2]) * 0.01 # Volt # voltage = int((data[1] << 8) | data[2]) * 0.01 # Volt
current = ( # current = (
int((data[3] << 8) | data[4]) * 0.01 # int((data[3] << 8) | data[4]) * 0.01
) # Amps, only available if the ESC has a current meter # ) # Amps, only available if the ESC has a current meter
consumption = int( # consumption = int(
(data[5] << 8) | data[6] # (data[5] << 8) | data[6]
) # mAh, only available if the ESC has a current meter # ) # mAh, only available if the ESC has a current meter
erpm = int((data[7] << 8) | data[8]) * 100 # erpm = int((data[7] << 8) | data[8]) * 100
rpm = erpm / (motor_poles / 2) # rpm = erpm / (motor_poles / 2)
crc = data[9] # crc = data[9]
#
print(" Temp (C):", temperature) # print(" Temp (C):", temperature)
print(" Voltage (V):", voltage) # print(" Voltage (V):", voltage)
print(" Current (A):", current) # print(" Current (A):", current)
print("Consumption (mAh):", consumption) # print("Consumption (mAh):", consumption)
print(" Erpm:", erpm) # print(" Erpm:", erpm)
print(" RPM:", rpm) # print(" RPM:", rpm)
print(" CRC:", crc) # print(" CRC:", crc)
print() # print()
#
return temperature, voltage, current, consumption, erpm, rpm # return temperature, voltage, current, consumption, erpm, rpm
async def update_display(): async def update_display():
@ -297,7 +299,7 @@ def update_motor_pwm():
# time.sleep(200) # time.sleep(200)
pwm.duty_ns(1060*10**3) pwm.duty_ns(1060*10**3)
state["target_rpm"] = 5000 state["target_rpm"] = 5000
timer2.init(mode=Timer.PERIODIC, period=30000, callback=kill_me) timer2.init(mode=Timer.PERIODIC, period=10000, callback=kill_me)
while(True): while(True):
@ -322,15 +324,19 @@ def update_motor_pwm():
print("Killing Coater!") print("Killing Coater!")
throttle = 0 throttle = 0
rpm_pid.reset() rpm_pid.reset()
pwm.duty_ns(1055*10**3) #pwm.duty_ns(1800*10**3)
return #time.sleep(3)
#return
print(throttle) print(throttle)
new_duty = 1060+(int(660*throttle)) if throttle !=0:
print(new_duty) new_duty = 1060+(int(660*throttle))
pwm.duty_ns(new_duty*10**3) pwm.duty_ns(new_duty*10**3)
else:
pwm.duty_ns(1050*10**3) new_duty = 1055
pwm.duty_ns(1055*10**3) pwm.duty_ns(new_duty*10**3)
timer2.deinit()
break
def set_throttle(pwm,us): def set_throttle(pwm,us):
@ -514,12 +520,12 @@ with open("config.json", "r") as f:
tft.fill(TFT.BLACK) tft.fill(TFT.BLACK)
# splash() # splash()
#fafo() fafo()
# for ff in fonts: # for ff in fonts:
# display.set_font(ff) # display.set_font(ff)
# display.print(text) # display.print(text)
update_motor_pwm() update_motor_pwm()
# event_loop = uasyncio.get_event_loop() event_loop = uasyncio.get_event_loop()
# event_loop.create_task(update_display()) # event_loop.create_task(update_display())
# #event_loop.create_task(update_motor_pwm()) # #event_loop.create_task(update_motor_pwm())