Homepage GitHub

Scripting from the interactive console

I am trying to run a periodic stress test by cycling an ESC on and off every 20 min. I also need throttle (ideally current control) and I wrote a script. I am not great at coding and I can’t figure out why the entire gui tool crashes. Also I don’t know how to run a certain number of times without using a blocking call.

# length of test and time between tests in minutes
length = 20
wait = 20
no_runs = 10
throttle = 64

def run_once():
	print('Starting run')
        # warning beep
	broadcast(uavcan.equipment.indication.BeepCommand(frequency=500, duration=0.1), interval=0.5, duration=1)
	node.defer(5, spin)

def spin():

def run_test():
	print('Starting test')
	message = uavcan.equipment.esc.RawCommand(cmd=[int(82*throttle), 0, 0, 0])
	periodic((length+wait)*60, run_once)

It crashes when it tries to run node.spin. Any help is appreciated.

node.spin is run by the GUI tool itself, you must not call it from your script. You can implement your functions in a non-blocking way as in any IoC framework; you can find a useful example here: https://uavcan.org/GUI_Tool/User_guide/#programming-tips