![]() |
IterativeRobot Race Condition
We were testing our autonomous lockin procedure tonight and noticed a pretty bad race condition within the IterativeRobot class.
Traditionally, our lockin procedure consists of switches at the driver station to select the program to run and a lockin switch to confirm the selection. If the switch is set to "unlock" we will run our "sleeper" program in which nothing moves. If the switch is "locked" we will run whatever program is desired. The lockin function is called within DisabledPeriodic and has the following flow Code:
if switch == unlockedCode:
if program == 0After investigation, we found that the lockin switch state was being transitioned from locked to unlocked within the DisabledPeriodic function. This caused our lockin procedure to set the program number to 0. We believe that the issue is due to the fact that new driver station data is being read while we are in DisabledPeriodic and the driver station is in Autonomous/Enable, thus zeroing out the inputs. We worked around this by limiting the chance that we'll hit the race condition by checking IsDisabled before calling the lockin function and reading the switch states immediately upon entering the function (we were doing this from the start). If this can be fixed within WPILib we would really appreciate it. Until then, teams should be aware of this situation and guard against it. |
Re: IterativeRobot Race Condition
Dave,
Thanks for this post. Hopefully it will save somebody a headache! To novice programmers: read about race conditions here. |
| All times are GMT -5. The time now is 02:38. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi