mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[wpilib] Split DriverStation into smaller classes (#8628)
This commit is contained in:
@@ -23,7 +23,8 @@ import java.util.WeakHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import org.wpilib.command2.Command.InterruptionBehavior;
|
||||
import org.wpilib.driverstation.DriverStation;
|
||||
import org.wpilib.driverstation.DriverStationErrors;
|
||||
import org.wpilib.driverstation.RobotState;
|
||||
import org.wpilib.event.EventLoop;
|
||||
import org.wpilib.framework.RobotBase;
|
||||
import org.wpilib.framework.TimedRobot;
|
||||
@@ -175,7 +176,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
*/
|
||||
private void schedule(Command command) {
|
||||
if (command == null) {
|
||||
DriverStation.reportWarning("Tried to schedule a null command", true);
|
||||
DriverStationErrors.reportWarning("Tried to schedule a null command", true);
|
||||
return;
|
||||
}
|
||||
if (m_inRunLoop) {
|
||||
@@ -189,7 +190,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
// run when disabled, or the command is already scheduled.
|
||||
if (m_disabled
|
||||
|| isScheduled(command)
|
||||
|| DriverStation.isDisabled() && !command.runsWhenDisabled()) {
|
||||
|| RobotState.isDisabled() && !command.runsWhenDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -269,7 +270,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
m_watchdog.addEpoch("buttons.run()");
|
||||
|
||||
m_inRunLoop = true;
|
||||
boolean isDisabled = DriverStation.isDisabled();
|
||||
boolean isDisabled = RobotState.isDisabled();
|
||||
// Run scheduled commands, remove finished commands.
|
||||
for (Iterator<Command> iterator = m_scheduledCommands.iterator(); iterator.hasNext(); ) {
|
||||
Command command = iterator.next();
|
||||
@@ -337,11 +338,12 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
public void registerSubsystem(Subsystem... subsystems) {
|
||||
for (Subsystem subsystem : subsystems) {
|
||||
if (subsystem == null) {
|
||||
DriverStation.reportWarning("Tried to register a null subsystem", true);
|
||||
DriverStationErrors.reportWarning("Tried to register a null subsystem", true);
|
||||
continue;
|
||||
}
|
||||
if (m_subsystems.containsKey(subsystem)) {
|
||||
DriverStation.reportWarning("Tried to register an already-registered subsystem", true);
|
||||
DriverStationErrors.reportWarning(
|
||||
"Tried to register an already-registered subsystem", true);
|
||||
continue;
|
||||
}
|
||||
m_subsystems.put(subsystem, null);
|
||||
@@ -379,11 +381,12 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
*/
|
||||
public void setDefaultCommand(Subsystem subsystem, Command defaultCommand) {
|
||||
if (subsystem == null) {
|
||||
DriverStation.reportWarning("Tried to set a default command for a null subsystem", true);
|
||||
DriverStationErrors.reportWarning(
|
||||
"Tried to set a default command for a null subsystem", true);
|
||||
return;
|
||||
}
|
||||
if (defaultCommand == null) {
|
||||
DriverStation.reportWarning("Tried to set a null default command", true);
|
||||
DriverStationErrors.reportWarning("Tried to set a null default command", true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -394,7 +397,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
}
|
||||
|
||||
if (defaultCommand.getInterruptionBehavior() == InterruptionBehavior.kCancelIncoming) {
|
||||
DriverStation.reportWarning(
|
||||
DriverStationErrors.reportWarning(
|
||||
"Registering a non-interruptible default command!\n"
|
||||
+ "This will likely prevent any other commands from requiring this subsystem.",
|
||||
true);
|
||||
@@ -413,7 +416,8 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
*/
|
||||
public void removeDefaultCommand(Subsystem subsystem) {
|
||||
if (subsystem == null) {
|
||||
DriverStation.reportWarning("Tried to remove a default command for a null subsystem", true);
|
||||
DriverStationErrors.reportWarning(
|
||||
"Tried to remove a default command for a null subsystem", true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -458,7 +462,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
*/
|
||||
private void cancel(Command command, Optional<Command> interruptor) {
|
||||
if (command == null) {
|
||||
DriverStation.reportWarning("Tried to cancel a null command", true);
|
||||
DriverStationErrors.reportWarning("Tried to cancel a null command", true);
|
||||
return;
|
||||
}
|
||||
if (m_endingCommands.contains(command)) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class WaitUntilCommand extends Command {
|
||||
* wait.
|
||||
*
|
||||
* @param time the match time after which to end, in seconds
|
||||
* @see org.wpilib.driverstation.DriverStation#getMatchTime()
|
||||
* @see org.wpilib.driverstation.MatchState#getMatchTime()
|
||||
*/
|
||||
public WaitUntilCommand(double time) {
|
||||
this(() -> Timer.getMatchTime() < time);
|
||||
|
||||
@@ -7,8 +7,8 @@ package org.wpilib.command2.button;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.wpilib.command2.CommandScheduler;
|
||||
import org.wpilib.driverstation.DriverStation.POVDirection;
|
||||
import org.wpilib.driverstation.GenericHID;
|
||||
import org.wpilib.driverstation.POVDirection;
|
||||
import org.wpilib.event.EventLoop;
|
||||
import org.wpilib.math.util.Pair;
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ package org.wpilib.command2.button;
|
||||
|
||||
import static org.wpilib.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import org.wpilib.driverstation.DriverStation.POVDirection;
|
||||
import org.wpilib.driverstation.GenericHID;
|
||||
import org.wpilib.driverstation.POVDirection;
|
||||
|
||||
/**
|
||||
* A {@link Trigger} that gets its state from a POV on a {@link GenericHID}.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
package org.wpilib.command2.button;
|
||||
|
||||
import org.wpilib.driverstation.DriverStation;
|
||||
import org.wpilib.driverstation.RobotState;
|
||||
|
||||
/**
|
||||
* A class containing static {@link Trigger} factories for running callbacks when the robot mode
|
||||
@@ -20,7 +20,7 @@ public final class RobotModeTriggers {
|
||||
* @return A trigger that is true when the robot is enabled in autonomous mode.
|
||||
*/
|
||||
public static Trigger autonomous() {
|
||||
return new Trigger(DriverStation::isAutonomousEnabled);
|
||||
return new Trigger(RobotState::isAutonomousEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ public final class RobotModeTriggers {
|
||||
* @return A trigger that is true when the robot is enabled in teleop mode.
|
||||
*/
|
||||
public static Trigger teleop() {
|
||||
return new Trigger(DriverStation::isTeleopEnabled);
|
||||
return new Trigger(RobotState::isTeleopEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ public final class RobotModeTriggers {
|
||||
* @return A trigger that is true when the robot is disabled.
|
||||
*/
|
||||
public static Trigger disabled() {
|
||||
return new Trigger(DriverStation::isDisabled);
|
||||
return new Trigger(RobotState::isDisabled);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,6 +47,6 @@ public final class RobotModeTriggers {
|
||||
* @return A trigger that is true when the robot is enabled in test mode.
|
||||
*/
|
||||
public static Trigger test() {
|
||||
return new Trigger(DriverStation::isTestEnabled);
|
||||
return new Trigger(RobotState::isTestEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#include "wpi/commands2/CommandPtr.hpp"
|
||||
#include "wpi/commands2/Subsystem.hpp"
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/driverstation/RobotState.hpp"
|
||||
#include "wpi/framework/RobotBase.hpp"
|
||||
#include "wpi/framework/TimedRobot.hpp"
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
@@ -99,7 +99,7 @@ void CommandScheduler::Schedule(Command* command) {
|
||||
RequireUngrouped(command);
|
||||
|
||||
if (m_impl->disabled || m_impl->scheduledCommands.contains(command) ||
|
||||
(wpi::DriverStation::IsDisabled() && !command->RunsWhenDisabled())) {
|
||||
(wpi::RobotState::IsDisabled() && !command->RunsWhenDisabled())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ void CommandScheduler::Run() {
|
||||
loopCache->Poll();
|
||||
m_watchdog.AddEpoch("buttons.Run()");
|
||||
|
||||
bool isDisabled = wpi::DriverStation::IsDisabled();
|
||||
bool isDisabled = wpi::RobotState::IsDisabled();
|
||||
// create a new set to avoid iterator invalidation.
|
||||
for (Command* command : wpi::util::SmallSet(m_impl->scheduledCommands)) {
|
||||
if (!IsScheduled(command)) {
|
||||
|
||||
@@ -16,51 +16,51 @@ Trigger CommandGenericHID::Button(int button, wpi::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, button] { return m_hid.GetRawButton(button); });
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POV(wpi::DriverStation::POVDirection angle,
|
||||
Trigger CommandGenericHID::POV(wpi::POVDirection angle,
|
||||
wpi::EventLoop* loop) const {
|
||||
return POV(0, angle, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POV(int pov, wpi::DriverStation::POVDirection angle,
|
||||
Trigger CommandGenericHID::POV(int pov, wpi::POVDirection angle,
|
||||
wpi::EventLoop* loop) const {
|
||||
return Trigger(loop,
|
||||
[this, pov, angle] { return m_hid.GetPOV(pov) == angle; });
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVUp(wpi::EventLoop* loop) const {
|
||||
return POV(wpi::DriverStation::POVDirection::UP, loop);
|
||||
return POV(wpi::POVDirection::UP, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVUpRight(wpi::EventLoop* loop) const {
|
||||
return POV(wpi::DriverStation::POVDirection::UP_RIGHT, loop);
|
||||
return POV(wpi::POVDirection::UP_RIGHT, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVRight(wpi::EventLoop* loop) const {
|
||||
return POV(wpi::DriverStation::POVDirection::RIGHT, loop);
|
||||
return POV(wpi::POVDirection::RIGHT, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVDownRight(wpi::EventLoop* loop) const {
|
||||
return POV(wpi::DriverStation::POVDirection::DOWN_RIGHT, loop);
|
||||
return POV(wpi::POVDirection::DOWN_RIGHT, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVDown(wpi::EventLoop* loop) const {
|
||||
return POV(wpi::DriverStation::POVDirection::DOWN, loop);
|
||||
return POV(wpi::POVDirection::DOWN, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVDownLeft(wpi::EventLoop* loop) const {
|
||||
return POV(wpi::DriverStation::POVDirection::DOWN_LEFT, loop);
|
||||
return POV(wpi::POVDirection::DOWN_LEFT, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVLeft(wpi::EventLoop* loop) const {
|
||||
return POV(wpi::DriverStation::POVDirection::LEFT, loop);
|
||||
return POV(wpi::POVDirection::LEFT, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVUpLeft(wpi::EventLoop* loop) const {
|
||||
return POV(wpi::DriverStation::POVDirection::UP_LEFT, loop);
|
||||
return POV(wpi::POVDirection::UP_LEFT, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVCenter(wpi::EventLoop* loop) const {
|
||||
return POV(wpi::DriverStation::POVDirection::CENTER, loop);
|
||||
return POV(wpi::POVDirection::CENTER, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::AxisLessThan(int axis, double threshold,
|
||||
|
||||
@@ -4,22 +4,22 @@
|
||||
|
||||
#include "wpi/commands2/button/RobotModeTriggers.hpp"
|
||||
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/driverstation/RobotState.hpp"
|
||||
|
||||
using namespace wpi::cmd;
|
||||
|
||||
Trigger RobotModeTriggers::Autonomous() {
|
||||
return Trigger{&wpi::DriverStation::IsAutonomousEnabled};
|
||||
return Trigger{&wpi::RobotState::IsAutonomousEnabled};
|
||||
}
|
||||
|
||||
Trigger RobotModeTriggers::Teleop() {
|
||||
return Trigger{&wpi::DriverStation::IsTeleopEnabled};
|
||||
return Trigger{&wpi::RobotState::IsTeleopEnabled};
|
||||
}
|
||||
|
||||
Trigger RobotModeTriggers::Disabled() {
|
||||
return Trigger{&wpi::DriverStation::IsDisabled};
|
||||
return Trigger{&wpi::RobotState::IsDisabled};
|
||||
}
|
||||
|
||||
Trigger RobotModeTriggers::Test() {
|
||||
return Trigger{&wpi::DriverStation::IsTestEnabled};
|
||||
return Trigger{&wpi::RobotState::IsTestEnabled};
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
|
||||
#include "wpi/commands2/CommandScheduler.hpp"
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/POVDirection.hpp"
|
||||
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
|
||||
|
||||
namespace wpi::cmd {
|
||||
|
||||
@@ -56,7 +57,7 @@ class CommandGenericHID {
|
||||
* @param angle POV angle.
|
||||
* @return a Trigger instance based around this angle of a POV on the HID.
|
||||
*/
|
||||
Trigger POV(wpi::DriverStation::POVDirection angle,
|
||||
Trigger POV(wpi::POVDirection angle,
|
||||
wpi::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
@@ -70,7 +71,7 @@ class CommandGenericHID {
|
||||
* @param angle POV angle.
|
||||
* @return a Trigger instance based around this angle of a POV on the HID.
|
||||
*/
|
||||
Trigger POV(int pov, wpi::DriverStation::POVDirection angle,
|
||||
Trigger POV(int pov, wpi::POVDirection angle,
|
||||
wpi::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "wpi/commands2/button/Trigger.hpp"
|
||||
#include "wpi/driverstation/DriverStation.hpp"
|
||||
#include "wpi/driverstation/GenericHID.hpp"
|
||||
#include "wpi/driverstation/POVDirection.hpp"
|
||||
|
||||
namespace wpi::cmd {
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ class POVButton : public Trigger {
|
||||
* @param angle The angle of the POV corresponding to a button press.
|
||||
* @param povNumber The number of the POV on the joystick.
|
||||
*/
|
||||
POVButton(wpi::GenericHID* joystick, wpi::DriverStation::POVDirection angle,
|
||||
POVButton(wpi::GenericHID* joystick, wpi::POVDirection angle,
|
||||
int povNumber = 0)
|
||||
: Trigger([joystick, angle, povNumber] {
|
||||
return joystick->GetPOV(povNumber) == angle;
|
||||
|
||||
@@ -9,7 +9,7 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Union
|
||||
import hal
|
||||
from typing_extensions import Self
|
||||
from wpilib import (
|
||||
DriverStation,
|
||||
RobotState,
|
||||
EventLoop,
|
||||
RobotBase,
|
||||
TimedRobot,
|
||||
@@ -192,7 +192,7 @@ class CommandScheduler(Sendable):
|
||||
if self.isScheduled(command):
|
||||
return
|
||||
|
||||
if DriverStation.isDisabled() and not command.runsWhenDisabled():
|
||||
if RobotState.isDisabled() and not command.runsWhenDisabled():
|
||||
return
|
||||
|
||||
requirements = command.getRequirements()
|
||||
@@ -250,7 +250,7 @@ class CommandScheduler(Sendable):
|
||||
self._watchdog.addEpoch("buttons.run()")
|
||||
|
||||
self._inRunLoop = True
|
||||
isDisabled = DriverStation.isDisabled()
|
||||
isDisabled = RobotState.isDisabled()
|
||||
|
||||
# Run scheduled commands, remove finished commands.
|
||||
for command in self._scheduledCommands.copy():
|
||||
|
||||
Reference in New Issue
Block a user