[wpilib] Fix OpModeRobot initialization (#8834)

There were 3 cases failing before.

1. An OpModeRobot with no annotation.
2. An OpModeRobot with an annotation but a parameterless constructor.
3. An OpMode with a UserControls constructor

This PR solves both of these issues. The first one is solved by adding
the null check before setting the user controls instance. That one will
never have an opmode instance.

The second one is solved by falling back to a parameterless constructor
if one with a parameter is not found.

The 3rd one is solved by using the annotation type rather than the
instance for constructor lookup.

Also fixes ExpansionHubSample's missing annotations.
This commit is contained in:
Thad House
2026-04-28 09:54:10 -10:00
committed by GitHub
parent 3bf67edc34
commit 94443c8e84
6 changed files with 28 additions and 12 deletions

View File

@@ -4,9 +4,11 @@
package org.wpilib.examples.expansionhubsample;
import org.wpilib.opmode.Autonomous;
import org.wpilib.opmode.PeriodicOpMode;
import org.wpilib.system.Timer;
@Autonomous
public class DefaultAutoMode extends PeriodicOpMode {
private final Robot robot;
private final Timer timer = new Timer();

View File

@@ -6,7 +6,9 @@ package org.wpilib.examples.expansionhubsample;
import org.wpilib.driverstation.DefaultUserControls;
import org.wpilib.opmode.PeriodicOpMode;
import org.wpilib.opmode.Teleop;
@Teleop
public class DefaultTeleMode extends PeriodicOpMode {
private final Robot robot;
private final DefaultUserControls userControls;