diff --git a/wpilibc/robotpy_pybind_build_info.bzl b/wpilibc/robotpy_pybind_build_info.bzl index 82b66a143b..391555d0f6 100644 --- a/wpilibc/robotpy_pybind_build_info.bzl +++ b/wpilibc/robotpy_pybind_build_info.bzl @@ -742,16 +742,6 @@ def wpilib_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includ ("wpi::internal::DriverStationModeThread", "wpi__internal__DriverStationModeThread.hpp"), ], ), - struct( - class_name = "LinearOpMode", - yml_file = "semiwrap/LinearOpMode.yml", - header_root = "$(execpath :robotpy-native-wpilib.copy_headers)", - header_file = "$(execpath :robotpy-native-wpilib.copy_headers)/wpi/opmode/LinearOpMode.hpp", - tmpl_class_names = [], - trampolines = [ - ("wpi::LinearOpMode", "wpi__LinearOpMode.hpp"), - ], - ), struct( class_name = "OpMode", yml_file = "semiwrap/OpMode.yml", diff --git a/wpilibc/src/main/native/cpp/opmode/LinearOpMode.cpp b/wpilibc/src/main/native/cpp/opmode/LinearOpMode.cpp deleted file mode 100644 index b0a818f6f9..0000000000 --- a/wpilibc/src/main/native/cpp/opmode/LinearOpMode.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "wpi/opmode/LinearOpMode.hpp" - -#include "wpi/driverstation/DriverStation.hpp" -#include "wpi/hal/DriverStation.h" -#include "wpi/internal/DriverStationModeThread.hpp" - -using namespace wpi; - -void LinearOpMode::OpModeRun(int64_t opModeId) { - auto word = wpi::hal::GetControlWord(); - word.SetOpModeId(opModeId); - internal::DriverStationModeThread bgThread{word}; - Run(); - - // Wait for opmode to be stopped or disabled, otherwise OpModeRobot will - // recreate and re-run the opmode immediately. - while (IsRunning() && DriverStation::IsEnabled() && - DriverStation::GetOpModeId() == opModeId) { - using namespace std::chrono_literals; - std::this_thread::sleep_for(20ms); - } -} - -void LinearOpMode::OpModeStop() { - m_running = false; -} diff --git a/wpilibc/src/main/native/include/wpi/opmode/LinearOpMode.hpp b/wpilibc/src/main/native/include/wpi/opmode/LinearOpMode.hpp deleted file mode 100644 index ccd07d38c0..0000000000 --- a/wpilibc/src/main/native/include/wpi/opmode/LinearOpMode.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include - -#include - -#include "wpi/opmode/OpMode.hpp" - -namespace wpi { - -/** - * An opmode structure for "linear" operation. The user is responsible for - * implementing any looping behavior; after Run() returns it will not be called - * again on the same object. - * - * Lifecycle: - * - * - Constructed when opmode selected on driver station - * - * - DisabledPeriodic() called periodically as long as DS is disabled - * - * - When DS transitions from disabled to enabled, Run() is called exactly once - * - * - When DS transitions from enabled to disabled, or a different opmode is - * selected on the driver station, object is destroyed and not reused - * - * The user is responsible for exiting Run() when the opmode is directed to stop - * executing. This is indicated by IsRunning() returning false. All other - * methods should be written to return as quickly as possible when IsRunning() - * returns false. - */ -class LinearOpMode : public OpMode { - public: - /** - * Called periodically while the opmode is selected on the DS and the robot is - * disabled. - */ - void DisabledPeriodic() override {} - - /** - * Called once when the robot is enabled. When it returns, it will not be - * called again on the same object. - */ - virtual void Run() = 0; - - /** - * Returns true while this opmode is selected (regardless of enable state). - * All other functions should be written to return as quickly as possible when - * this returns false. - * - * @return True if opmode selected, false otherwise - */ - bool IsRunning() const { return m_running; } - - // implements OpMode interface - void OpModeRun(int64_t opModeId) final; - - void OpModeStop() final; - - private: - std::atomic_bool m_running{true}; -}; - -} // namespace wpi diff --git a/wpilibc/src/main/native/include/wpi/opmode/OpMode.hpp b/wpilibc/src/main/native/include/wpi/opmode/OpMode.hpp index 2bac4ff0f8..dec1a8b064 100644 --- a/wpilibc/src/main/native/include/wpi/opmode/OpMode.hpp +++ b/wpilibc/src/main/native/include/wpi/opmode/OpMode.hpp @@ -10,8 +10,8 @@ namespace wpi { /** * Top-level interface for opmode classes. Users should generally extend one of - * the abstract implementations of this interface (e.g. PeriodicOpMode or - * LinearOpMode) rather than directly implementing this interface. + * the abstract implementations of this interface (e.g. PeriodicOpMode) rather + * than directly implementing this interface. */ class OpMode { public: diff --git a/wpilibc/src/main/python/pyproject.toml b/wpilibc/src/main/python/pyproject.toml index 44fdc4435e..bf23e05a1c 100644 --- a/wpilibc/src/main/python/pyproject.toml +++ b/wpilibc/src/main/python/pyproject.toml @@ -198,7 +198,6 @@ Encoder = "wpi/hardware/rotation/Encoder.hpp" DriverStationModeThread = "wpi/internal/DriverStationModeThread.hpp" # wpi/opmode -LinearOpMode = "wpi/opmode/LinearOpMode.hpp" OpMode = "wpi/opmode/OpMode.hpp" PeriodicOpMode = "wpi/opmode/PeriodicOpMode.hpp" diff --git a/wpilibc/src/main/python/semiwrap/LinearOpMode.yml b/wpilibc/src/main/python/semiwrap/LinearOpMode.yml deleted file mode 100644 index 657b8caca8..0000000000 --- a/wpilibc/src/main/python/semiwrap/LinearOpMode.yml +++ /dev/null @@ -1,8 +0,0 @@ -classes: - wpi::LinearOpMode: - methods: - DisabledPeriodic: - Run: - IsRunning: - OpModeRun: - OpModeStop: diff --git a/wpilibc/src/main/python/wpilib/__init__.py b/wpilibc/src/main/python/wpilib/__init__.py index 29c86c6e66..5c89e9fb29 100644 --- a/wpilibc/src/main/python/wpilib/__init__.py +++ b/wpilibc/src/main/python/wpilib/__init__.py @@ -39,7 +39,6 @@ from ._wpilib import ( Joystick, Koors40, LEDPattern, - LinearOpMode, MecanumDrive, Mechanism2d, MechanismLigament2d, @@ -143,7 +142,6 @@ __all__ = [ "Joystick", "Koors40", "LEDPattern", - "LinearOpMode", "MecanumDrive", "Mechanism2d", "MechanismLigament2d", diff --git a/wpilibj/src/main/java/org/wpilib/opmode/LinearOpMode.java b/wpilibj/src/main/java/org/wpilib/opmode/LinearOpMode.java deleted file mode 100644 index a70cf2e581..0000000000 --- a/wpilibj/src/main/java/org/wpilib/opmode/LinearOpMode.java +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package org.wpilib.opmode; - -import java.util.concurrent.atomic.AtomicBoolean; -import org.wpilib.driverstation.DriverStation; -import org.wpilib.hardware.hal.ControlWord; -import org.wpilib.internal.DriverStationModeThread; - -/** - * An opmode structure for "linear" operation. The user is responsible for implementing any looping - * behavior; after run() returns it will not be called again on the same object. - * - *

Lifecycle: - * - *

- * - *

The user is responsible for exiting run() when the opmode is directed to stop executing. This - * is indicated by isRunning() returning false. All other methods should be written to return as - * quickly as possible when isRunning() returns false. - */ -public abstract class LinearOpMode implements OpMode { - /** Constructor. */ - public LinearOpMode() {} - - /** Called periodically while the opmode is selected on the DS and the robot is disabled. */ - @Override - public void disabledPeriodic() {} - - /** - * Called when the opmode is de-selected on the DS. The object is not reused even if the same - * opmode is selected again (a new object will be created). - */ - public void close() {} - - /** - * Called once when the robot is enabled. It will not be called a second time on the same object. - * - * @throws InterruptedException when interrupted - */ - public abstract void run() throws InterruptedException; - - /** - * Returns true while this opmode is selected (regardless of enable state). All other functions - * should be written to return as quickly as possible when this returns false. - * - * @return True if opmode selected, false otherwise - */ - public boolean isRunning() { - return m_running.get(); - } - - // implements OpMode interface - @Override - public final void opModeRun(long opModeId) throws InterruptedException { - ControlWord word = new ControlWord(); - DriverStation.refreshControlWordFromCache(word); - word.setOpModeId(opModeId); - - try (DriverStationModeThread bgThread = new DriverStationModeThread(word)) { - run(); - - // Wait for opmode to be stopped or disabled, otherwise OpModeRobot will recreate and re-run - // the opmode immediately. - while (isRunning() && DriverStation.isEnabled() && DriverStation.getOpModeId() == opModeId) { - Thread.sleep(20); - } - } - } - - @Override - public final void opModeStop() { - m_running.set(false); - } - - @Override - public final void opModeClose() { - close(); - } - - private final AtomicBoolean m_running = new AtomicBoolean(true); -} diff --git a/wpilibj/src/main/java/org/wpilib/opmode/OpMode.java b/wpilibj/src/main/java/org/wpilib/opmode/OpMode.java index 9faed882e2..4c71f0fb15 100644 --- a/wpilibj/src/main/java/org/wpilib/opmode/OpMode.java +++ b/wpilibj/src/main/java/org/wpilib/opmode/OpMode.java @@ -6,8 +6,8 @@ package org.wpilib.opmode; /** * Top-level interface for opmode classes. Users should generally extend one of the abstract - * implementations of this interface (e.g. {@link PeriodicOpMode} or {@link LinearOpMode}) rather - * than directly implementing this interface. + * implementations of this interface (e.g. {@link PeriodicOpMode}) rather than directly implementing + * this interface. */ public interface OpMode { /**