mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib] OpModeRobot: set up notifier before calling observe starting (#8547)
This avoids a simulation race.
This commit is contained in:
@@ -566,7 +566,6 @@ public abstract class OpModeRobot extends RobotBase {
|
||||
@Override
|
||||
public final void startCompetition() {
|
||||
System.out.println("********** Robot program startup complete **********");
|
||||
DriverStationJNI.observeUserProgramStarting();
|
||||
|
||||
int event = WPIUtilJNI.createEvent(false, false);
|
||||
DriverStationJNI.provideNewDataEventHandle(event);
|
||||
@@ -577,11 +576,22 @@ public abstract class OpModeRobot extends RobotBase {
|
||||
try {
|
||||
// Implement the opmode lifecycle
|
||||
long lastModeId = -1;
|
||||
boolean calledObserveUserProgramStarting = false;
|
||||
boolean calledDriverStationConnected = false;
|
||||
int[] events = {event, m_notifier};
|
||||
while (true) {
|
||||
// Wait for new data from the driver station, with 50 ms timeout
|
||||
NotifierJNI.setNotifierAlarm(m_notifier, 50000, 0, false, true);
|
||||
|
||||
// Call observeUserProgramStarting() here as a one-shot to ensure it is called after the
|
||||
// notifier alarm is set. The notifier alarm is set using relative time, so tests that
|
||||
// wait on the user program to start and then step time won't work correctly if we call
|
||||
// this before setting the alarm.
|
||||
if (!calledObserveUserProgramStarting) {
|
||||
calledObserveUserProgramStarting = true;
|
||||
DriverStationJNI.observeUserProgramStarting();
|
||||
}
|
||||
|
||||
try {
|
||||
int[] signaled = WPIUtilJNI.waitForObjects(events);
|
||||
for (int val : signaled) {
|
||||
|
||||
Reference in New Issue
Block a user