|
Re: If you could write the default code...
It would be nice if was organized with hooks for discrete events since the programs all follow a similar lifecycle. This is rough, but something like:
masterSystemInit() - runs once at startup to configure the device
masterUserInit() - runs once at startup to configure user information
runDisabled() - runs while robot is disabled
initAutonomous() - runs once when state changes to autonomous
runAutonomous() - runs each cycle during autonomous
initTeleoperation() - runs once when state changes to teleoperation mode
runTeleoperation() - runs each cycle during teleoperation
readInputs() - runs at the start of each cycle to collect any inputs
writeOutputs() - runs at the end of each cycle to update relays and motors
This framework would allow you to focus on these relatively simple stubs. The flow of the framework code would be something like:
masterSystemInit()
masterUserInit()
while 1=1
wait for master uP
readInputs()
if runState != previous runState then
if runState = AUTO then
initAutonomous()
elseif runState = TELEOP then
initTeleoperation()
end if
if runState = DISABLED then
runDisabled()
else if runState = AUTO then
runAutonomous()
else
runTeleoperation()
end if
writeOutputs()
wend
|