mirror of
https://github.com/brendanhaines/ECEN5458_Project.git
synced 2024-12-25 18:38:09 -07:00
add motor speed control to gui
This commit is contained in:
parent
5da1a5a8c3
commit
2045ca3013
|
@ -21,6 +21,8 @@ DEBUG = False
|
||||||
BAT_MUX_CHAN = 9
|
BAT_MUX_CHAN = 9
|
||||||
VBAT_THRESHOLD = 11.0
|
VBAT_THRESHOLD = 11.0
|
||||||
|
|
||||||
|
base_motor_speed = 0.1
|
||||||
|
|
||||||
# Configure MUX for ADC
|
# Configure MUX for ADC
|
||||||
mux_io = [None] * 4
|
mux_io = [None] * 4
|
||||||
mux_io[0] = digitalio.DigitalInOut(board.D23)
|
mux_io[0] = digitalio.DigitalInOut(board.D23)
|
||||||
|
@ -100,13 +102,14 @@ def controller():
|
||||||
global servos
|
global servos
|
||||||
global control_thread_run
|
global control_thread_run
|
||||||
global D # controller model
|
global D # controller model
|
||||||
|
global base_motor_speed
|
||||||
|
|
||||||
# TODO: make these parameters editable via network interface
|
# TODO: make these parameters editable via network interface
|
||||||
if D.dt is None:
|
if D.dt is None:
|
||||||
sample_interval = 0.01
|
sample_interval = 0.01
|
||||||
else:
|
else:
|
||||||
sample_interval = D.dt
|
sample_interval = D.dt
|
||||||
base_speed = 0.1
|
base_speed = base_motor_speed
|
||||||
iir_taps = np.append(D.den[1:], 0)
|
iir_taps = np.append(D.den[1:], 0)
|
||||||
fir_taps = np.append(D.num, 0)
|
fir_taps = np.append(D.num, 0)
|
||||||
fir_taps = np.concatenate([np.zeros((len(iir_taps) + 1) - len(fir_taps)), fir_taps])
|
fir_taps = np.concatenate([np.zeros((len(iir_taps) + 1) - len(fir_taps)), fir_taps])
|
||||||
|
@ -220,11 +223,14 @@ def stop_controller(attrname=None, old=None, new=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update_models(attrname=None, old=None, new=None):
|
def update_models(attrname=None, old=None, new=None):
|
||||||
|
global base_motor_speed
|
||||||
|
global base_motor_speed_box
|
||||||
stop_controller()
|
stop_controller()
|
||||||
try:
|
try:
|
||||||
exec("global D\n" + controller_model_text.value)
|
exec("global D\n" + controller_model_text.value)
|
||||||
print("INFO: controller model updated")
|
print("INFO: controller model updated")
|
||||||
print(D)
|
print(D)
|
||||||
|
base_motor_speed = float(base_motor_speed_box.value)
|
||||||
except:
|
except:
|
||||||
print("WARN: invalid controller model")
|
print("WARN: invalid controller model")
|
||||||
|
|
||||||
|
@ -242,6 +248,7 @@ start_button.on_click(start_controller)
|
||||||
stop_button = Button(label="Stop")
|
stop_button = Button(label="Stop")
|
||||||
stop_button.on_click(stop_controller)
|
stop_button.on_click(stop_controller)
|
||||||
|
|
||||||
|
base_motor_speed_box = TextInput(value=str(base_motor_speed))
|
||||||
# plant_model_text =
|
# plant_model_text =
|
||||||
controller_model_text = TextInput(value="D = TransferFunction([1], [1], dt=0.01)")
|
controller_model_text = TextInput(value="D = TransferFunction([1], [1], dt=0.01)")
|
||||||
update_models_button = Button(label="Update models")
|
update_models_button = Button(label="Update models")
|
||||||
|
@ -272,7 +279,7 @@ def update_battery_voltage(attrname=None, old=None, new=None):
|
||||||
# controller_iir_taps = TextInput(title="IIR taps", value=str(iir_taps))
|
# controller_iir_taps = TextInput(title="IIR taps", value=str(iir_taps))
|
||||||
|
|
||||||
controls = column(vbat_text, cal_white_button, cal_black_button, start_button, stop_button)
|
controls = column(vbat_text, cal_white_button, cal_black_button, start_button, stop_button)
|
||||||
controller_model = row(controller_model_text, update_models_button)
|
controller_model = row(controller_model_text, base_motor_speed_box, update_models_button)
|
||||||
# controller_settings = column(controller_sample_interval, controller_base_speed, controller_fir_taps, controller_iir_taps)
|
# controller_settings = column(controller_sample_interval, controller_base_speed, controller_fir_taps, controller_iir_taps)
|
||||||
curdoc().add_root(column(row(controls, brightness_plot, width=800), time_plot, controller_model))#, controller_settings))
|
curdoc().add_root(column(row(controls, brightness_plot, width=800), time_plot, controller_model))#, controller_settings))
|
||||||
curdoc().title = "TriangleBot Control Panel"
|
curdoc().title = "TriangleBot Control Panel"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user