cleanup of code, bugfixing
This commit is contained in:
parent
e87293a6e2
commit
dd341bbb67
1 changed files with 49 additions and 43 deletions
88
src/main.py
88
src/main.py
|
|
@ -21,11 +21,13 @@ from pid import PID
|
|||
|
||||
COILS = 14
|
||||
# from enum import Enum
|
||||
class SpinnyBoy(object):
|
||||
def __init__(self,state,timer1,timer2,display):
|
||||
self.state = state
|
||||
self.timer1 = timer1
|
||||
self.timer2 = timer2
|
||||
self.display = display
|
||||
|
||||
# class EditMenu(Enum):
|
||||
# DEPOSIT = 1
|
||||
# COATING = 2
|
||||
# TIME = 3
|
||||
def splash():
|
||||
# display.fill(0)
|
||||
# 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))
|
||||
|
||||
|
||||
def decode_ESC_telemetry(data, motor_poles=14):
|
||||
if len(data) > 10:
|
||||
# use latest telemetry
|
||||
data = data[-10:]
|
||||
|
||||
temperature = int(data[0]) # degrees Celsius
|
||||
voltage = int((data[1] << 8) | data[2]) * 0.01 # Volt
|
||||
current = (
|
||||
int((data[3] << 8) | data[4]) * 0.01
|
||||
) # Amps, only available if the ESC has a current meter
|
||||
consumption = int(
|
||||
(data[5] << 8) | data[6]
|
||||
) # mAh, only available if the ESC has a current meter
|
||||
erpm = int((data[7] << 8) | data[8]) * 100
|
||||
rpm = erpm / (motor_poles / 2)
|
||||
crc = data[9]
|
||||
|
||||
print(" Temp (C):", temperature)
|
||||
print(" Voltage (V):", voltage)
|
||||
print(" Current (A):", current)
|
||||
print("Consumption (mAh):", consumption)
|
||||
print(" Erpm:", erpm)
|
||||
print(" RPM:", rpm)
|
||||
print(" CRC:", crc)
|
||||
print()
|
||||
|
||||
return temperature, voltage, current, consumption, erpm, rpm
|
||||
#def decode_ESC_telemetry(data, motor_poles=14):
|
||||
# if len(data) > 10:
|
||||
# # use latest telemetry
|
||||
# data = data[-10:]
|
||||
#
|
||||
# temperature = int(data[0]) # degrees Celsius
|
||||
# voltage = int((data[1] << 8) | data[2]) * 0.01 # Volt
|
||||
# current = (
|
||||
# int((data[3] << 8) | data[4]) * 0.01
|
||||
# ) # Amps, only available if the ESC has a current meter
|
||||
# consumption = int(
|
||||
# (data[5] << 8) | data[6]
|
||||
# ) # mAh, only available if the ESC has a current meter
|
||||
# erpm = int((data[7] << 8) | data[8]) * 100
|
||||
# rpm = erpm / (motor_poles / 2)
|
||||
# crc = data[9]
|
||||
#
|
||||
# print(" Temp (C):", temperature)
|
||||
# print(" Voltage (V):", voltage)
|
||||
# print(" Current (A):", current)
|
||||
# print("Consumption (mAh):", consumption)
|
||||
# print(" Erpm:", erpm)
|
||||
# print(" RPM:", rpm)
|
||||
# print(" CRC:", crc)
|
||||
# print()
|
||||
#
|
||||
# return temperature, voltage, current, consumption, erpm, rpm
|
||||
|
||||
|
||||
async def update_display():
|
||||
|
|
@ -297,7 +299,7 @@ def update_motor_pwm():
|
|||
# time.sleep(200)
|
||||
pwm.duty_ns(1060*10**3)
|
||||
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):
|
||||
|
||||
|
|
@ -322,15 +324,19 @@ def update_motor_pwm():
|
|||
print("Killing Coater!")
|
||||
throttle = 0
|
||||
rpm_pid.reset()
|
||||
pwm.duty_ns(1055*10**3)
|
||||
return
|
||||
#pwm.duty_ns(1800*10**3)
|
||||
#time.sleep(3)
|
||||
#return
|
||||
print(throttle)
|
||||
new_duty = 1060+(int(660*throttle))
|
||||
print(new_duty)
|
||||
pwm.duty_ns(new_duty*10**3)
|
||||
if throttle !=0:
|
||||
new_duty = 1060+(int(660*throttle))
|
||||
pwm.duty_ns(new_duty*10**3)
|
||||
else:
|
||||
new_duty = 1055
|
||||
pwm.duty_ns(new_duty*10**3)
|
||||
timer2.deinit()
|
||||
break
|
||||
|
||||
pwm.duty_ns(1050*10**3)
|
||||
pwm.duty_ns(1055*10**3)
|
||||
|
||||
|
||||
def set_throttle(pwm,us):
|
||||
|
|
@ -514,12 +520,12 @@ with open("config.json", "r") as f:
|
|||
tft.fill(TFT.BLACK)
|
||||
|
||||
# splash()
|
||||
#fafo()
|
||||
fafo()
|
||||
# for ff in fonts:
|
||||
# display.set_font(ff)
|
||||
# display.print(text)
|
||||
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_motor_pwm())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue