Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
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;
Expand Down Expand Up @@ -175,7 +176,7 @@ private void initCommand(Command command, Set<Subsystem> requirements) {
*/
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) {
Expand All @@ -189,7 +190,7 @@ private void schedule(Command command) {
// run when disabled, or the command is already scheduled.
if (m_disabled
|| isScheduled(command)
|| DriverStation.isDisabled() && !command.runsWhenDisabled()) {
|| RobotState.isDisabled() && !command.runsWhenDisabled()) {
return;
}

Expand Down Expand Up @@ -269,7 +270,7 @@ public void run() {
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();
Expand Down Expand Up @@ -337,11 +338,12 @@ public void run() {
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);
Expand Down Expand Up @@ -379,11 +381,12 @@ public void unregisterAllSubsystems() {
*/
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;
}

Expand All @@ -394,7 +397,7 @@ public void setDefaultCommand(Subsystem subsystem, Command defaultCommand) {
}

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);
Expand All @@ -413,7 +416,8 @@ public void setDefaultCommand(Subsystem subsystem, Command defaultCommand) {
*/
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;
}

Expand Down Expand Up @@ -458,7 +462,7 @@ public void cancel(Command... commands) {
*/
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +20,7 @@ private 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);
}

/**
Expand All @@ -29,7 +29,7 @@ public static Trigger autonomous() {
* @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);
}

/**
Expand All @@ -38,7 +38,7 @@ public static Trigger teleop() {
* @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);
}

/**
Expand All @@ -47,6 +47,6 @@ public static Trigger disabled() {
* @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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::kUp, loop);
return POV(wpi::POVDirection::kUp, loop);
}

Trigger CommandGenericHID::POVUpRight(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kUpRight, loop);
return POV(wpi::POVDirection::kUpRight, loop);
}

Trigger CommandGenericHID::POVRight(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kRight, loop);
return POV(wpi::POVDirection::kRight, loop);
}

Trigger CommandGenericHID::POVDownRight(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kDownRight, loop);
return POV(wpi::POVDirection::kDownRight, loop);
}

Trigger CommandGenericHID::POVDown(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kDown, loop);
return POV(wpi::POVDirection::kDown, loop);
}

Trigger CommandGenericHID::POVDownLeft(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kDownLeft, loop);
return POV(wpi::POVDirection::kDownLeft, loop);
}

Trigger CommandGenericHID::POVLeft(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kLeft, loop);
return POV(wpi::POVDirection::kLeft, loop);
}

Trigger CommandGenericHID::POVUpLeft(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kUpLeft, loop);
return POV(wpi::POVDirection::kUpLeft, loop);
}

Trigger CommandGenericHID::POVCenter(wpi::EventLoop* loop) const {
return POV(wpi::DriverStation::POVDirection::kCenter, loop);
return POV(wpi::POVDirection::kCenter, loop);
}

Trigger CommandGenericHID::AxisLessThan(int axis, double threshold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.wpilib.command2.Command.InterruptionBehavior;
import org.wpilib.driverstation.DriverStation;
import org.wpilib.driverstation.RobotState;
import org.wpilib.simulation.DriverStationSim;

/** Basic setup for all {@link Command tests}. */
Expand All @@ -33,7 +33,7 @@ public void setDSEnabled(boolean enabled) {

DriverStationSim.setEnabled(enabled);
DriverStationSim.notifyNewData();
while (DriverStation.isEnabled() != enabled) {
while (RobotState.isEnabled() != enabled) {
try {
Thread.sleep(1);
} catch (InterruptedException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
#include "wpi/commands2/CommandScheduler.hpp"
#include "wpi/commands2/RunCommand.hpp"
#include "wpi/commands2/WaitUntilCommand.hpp"
#include "wpi/driverstation/DriverStation.hpp"
#include "wpi/driverstation/Joystick.hpp"
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
#include "wpi/simulation/JoystickSim.hpp"

using namespace wpi::cmd;
class POVButtonTest : public CommandTestBase {};

TEST_F(POVButtonTest, SetPOV) {
wpi::sim::JoystickSim joysim(1);
joysim.SetPOV(wpi::DriverStation::kUp);
joysim.SetPOV(wpi::POVDirection::kUp);
joysim.NotifyNewData();

auto& scheduler = CommandScheduler::GetInstance();
Expand All @@ -28,11 +28,11 @@ TEST_F(POVButtonTest, SetPOV) {
WaitUntilCommand command([&finished] { return finished; });

wpi::Joystick joy(1);
POVButton(&joy, wpi::DriverStation::kRight).OnTrue(&command);
POVButton(&joy, wpi::POVDirection::kRight).OnTrue(&command);
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));

joysim.SetPOV(wpi::DriverStation::kRight);
joysim.SetPOV(wpi::POVDirection::kRight);
joysim.NotifyNewData();

scheduler.Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "../CommandTestBase.hpp"
#include "wpi/commands2/button/Trigger.hpp"
#include "wpi/driverstation/DriverStation.hpp"
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
#include "wpi/hal/DriverStationTypes.h"
#include "wpi/simulation/DriverStationSim.hpp"

Expand Down
Loading
Loading