diff --git a/hal/src/main/java/edu/wpi/first/wpilibj/util/BaseSystemNotInitializedException.java b/hal/src/main/java/edu/wpi/first/wpilibj/util/BaseSystemNotInitializedException.java deleted file mode 100644 index 546778279b..0000000000 --- a/hal/src/main/java/edu/wpi/first/wpilibj/util/BaseSystemNotInitializedException.java +++ /dev/null @@ -1,36 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.util; - - -/** - * Thrown if there is an error caused by a basic system or setting not being properly initialized - * before being used. - */ -public class BaseSystemNotInitializedException extends RuntimeException { - /** - * Create a new BaseSystemNotInitializedException. - * - * @param message the message to attach to the exception - */ - public BaseSystemNotInitializedException(String message) { - super(message); - } - - /** - * Create a new BaseSystemNotInitializedException using the offending class that was not set and - * the class that was affected. - * - * @param offender The class or interface that was not properly initialized. - * @param affected The class that was was affected by this missing initialization. - */ - public BaseSystemNotInitializedException(Class offender, Class affected) { - super("The " + offender.getSimpleName() + " for the " + affected.getSimpleName() - + " was never set."); - } -} diff --git a/wpilibc/src/main/native/cpp/Commands/Scheduler.cpp b/wpilibc/src/main/native/cpp/Commands/Scheduler.cpp index 4febcd1e3d..d4a3bf072c 100644 --- a/wpilibc/src/main/native/cpp/Commands/Scheduler.cpp +++ b/wpilibc/src/main/native/cpp/Commands/Scheduler.cpp @@ -10,9 +10,10 @@ #include #include +#include + #include "Buttons/ButtonScheduler.h" #include "Commands/Subsystem.h" -#include "HLUsageReporting.h" #include "SmartDashboard/SendableBuilder.h" #include "WPIErrors.h" @@ -166,7 +167,8 @@ void Scheduler::InitSendable(SendableBuilder& builder) { } Scheduler::Scheduler() { - HLUsageReporting::ReportScheduler(); + HAL_Report(HALUsageReporting::kResourceType_Command, + HALUsageReporting::kCommand_Scheduler); SetName("Scheduler"); } diff --git a/wpilibc/src/main/native/cpp/HLUsageReporting.cpp b/wpilibc/src/main/native/cpp/HLUsageReporting.cpp deleted file mode 100644 index da8b888e6a..0000000000 --- a/wpilibc/src/main/native/cpp/HLUsageReporting.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -#include "HLUsageReporting.h" - -using namespace frc; - -HLUsageReportingInterface* HLUsageReporting::impl = nullptr; - -void HLUsageReporting::SetImplementation(HLUsageReportingInterface* i) { - impl = i; -} - -void HLUsageReporting::ReportScheduler() { - if (impl != nullptr) { - impl->ReportScheduler(); - } -} - -void HLUsageReporting::ReportSmartDashboard() { - if (impl != nullptr) { - impl->ReportSmartDashboard(); - } -} diff --git a/wpilibc/src/main/native/cpp/Internal/HardwareHLReporting.cpp b/wpilibc/src/main/native/cpp/Internal/HardwareHLReporting.cpp deleted file mode 100644 index 39d95c726c..0000000000 --- a/wpilibc/src/main/native/cpp/Internal/HardwareHLReporting.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -#include "Internal/HardwareHLReporting.h" - -#include - -using namespace frc; - -void HardwareHLReporting::ReportScheduler() { - HAL_Report(HALUsageReporting::kResourceType_Command, - HALUsageReporting::kCommand_Scheduler); -} - -void HardwareHLReporting::ReportSmartDashboard() { - HAL_Report(HALUsageReporting::kResourceType_SmartDashboard, 0); -} diff --git a/wpilibc/src/main/native/cpp/RobotBase.cpp b/wpilibc/src/main/native/cpp/RobotBase.cpp index 0e1bfbd80e..48e8c4f4d3 100644 --- a/wpilibc/src/main/native/cpp/RobotBase.cpp +++ b/wpilibc/src/main/native/cpp/RobotBase.cpp @@ -14,8 +14,6 @@ #include "CameraServerShared.h" #include "DriverStation.h" -#include "HLUsageReporting.h" -#include "Internal/HardwareHLReporting.h" #include "LiveWindow/LiveWindow.h" #include "RobotState.h" #include "SmartDashboard/SmartDashboard.h" @@ -80,9 +78,6 @@ RobotBase::RobotBase() : m_ds(DriverStation::GetInstance()) { } m_threadId = std::this_thread::get_id(); - RobotState::SetImplementation(DriverStation::GetInstance()); - HLUsageReporting::SetImplementation(new HardwareHLReporting()); - SetupCameraServerShared(); auto inst = nt::NetworkTableInstance::GetDefault(); diff --git a/wpilibc/src/main/native/cpp/RobotState.cpp b/wpilibc/src/main/native/cpp/RobotState.cpp index 82a005d910..c706d678d5 100644 --- a/wpilibc/src/main/native/cpp/RobotState.cpp +++ b/wpilibc/src/main/native/cpp/RobotState.cpp @@ -7,52 +7,24 @@ #include "RobotState.h" -#include "Base.h" +#include "DriverStation.h" using namespace frc; -std::shared_ptr RobotState::impl; - -void RobotState::SetImplementation(RobotStateInterface& i) { - impl = std::shared_ptr( - &i, NullDeleter()); -} - -void RobotState::SetImplementation(std::shared_ptr i) { - impl = i; -} - bool RobotState::IsDisabled() { - if (impl != nullptr) { - return impl->IsDisabled(); - } - return true; + return DriverStation::GetInstance().IsDisabled(); } bool RobotState::IsEnabled() { - if (impl != nullptr) { - return impl->IsEnabled(); - } - return false; + return DriverStation::GetInstance().IsEnabled(); } bool RobotState::IsOperatorControl() { - if (impl != nullptr) { - return impl->IsOperatorControl(); - } - return true; + return DriverStation::GetInstance().IsOperatorControl(); } bool RobotState::IsAutonomous() { - if (impl != nullptr) { - return impl->IsAutonomous(); - } - return false; + return DriverStation::GetInstance().IsAutonomous(); } -bool RobotState::IsTest() { - if (impl != nullptr) { - return impl->IsTest(); - } - return false; -} +bool RobotState::IsTest() { return DriverStation::GetInstance().IsTest(); } diff --git a/wpilibc/src/main/native/cpp/SmartDashboard/SmartDashboard.cpp b/wpilibc/src/main/native/cpp/SmartDashboard/SmartDashboard.cpp index e147a9f10e..53895894de 100644 --- a/wpilibc/src/main/native/cpp/SmartDashboard/SmartDashboard.cpp +++ b/wpilibc/src/main/native/cpp/SmartDashboard/SmartDashboard.cpp @@ -7,12 +7,12 @@ #include "SmartDashboard/SmartDashboard.h" +#include #include #include #include #include -#include "HLUsageReporting.h" #include "SmartDashboard/Sendable.h" #include "SmartDashboard/SendableBuilderImpl.h" #include "WPIErrors.h" @@ -40,7 +40,7 @@ class Singleton { private: Singleton() { table = nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard"); - HLUsageReporting::ReportSmartDashboard(); + HAL_Report(HALUsageReporting::kResourceType_SmartDashboard, 0); } Singleton(const Singleton&) = delete; Singleton& operator=(const Singleton&) = delete; diff --git a/wpilibc/src/main/native/include/DriverStation.h b/wpilibc/src/main/native/include/DriverStation.h index c55bd59351..8cb8c25719 100644 --- a/wpilibc/src/main/native/include/DriverStation.h +++ b/wpilibc/src/main/native/include/DriverStation.h @@ -31,7 +31,7 @@ class MatchDataSender; * Provide access to the network communication data to / from the Driver * Station. */ -class DriverStation : public ErrorBase, public RobotStateInterface { +class DriverStation : public ErrorBase { public: enum Alliance { kRed, kBlue, kInvalid }; enum MatchType { kNone, kPractice, kQualification, kElimination }; @@ -186,35 +186,35 @@ class DriverStation : public ErrorBase, public RobotStateInterface { * * @return True if the robot is enabled and the DS is connected */ - bool IsEnabled() const override; + bool IsEnabled() const; /** * Check if the robot is disabled. * * @return True if the robot is explicitly disabled or the DS is not connected */ - bool IsDisabled() const override; + bool IsDisabled() const; /** * Check if the DS is commanding autonomous mode. * * @return True if the robot is being commanded to be in autonomous mode */ - bool IsAutonomous() const override; + bool IsAutonomous() const; /** * Check if the DS is commanding teleop mode. * * @return True if the robot is being commanded to be in teleop mode */ - bool IsOperatorControl() const override; + bool IsOperatorControl() const; /** * Check if the DS is commanding test mode. * * @return True if the robot is being commanded to be in test mode */ - bool IsTest() const override; + bool IsTest() const; /** * Check if the DS is attached. diff --git a/wpilibc/src/main/native/include/HLUsageReporting.h b/wpilibc/src/main/native/include/HLUsageReporting.h deleted file mode 100644 index a078ab2d9e..0000000000 --- a/wpilibc/src/main/native/include/HLUsageReporting.h +++ /dev/null @@ -1,29 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -#pragma once - -namespace frc { - -class HLUsageReportingInterface { - public: - virtual ~HLUsageReportingInterface() = default; - virtual void ReportScheduler() = 0; - virtual void ReportSmartDashboard() = 0; -}; - -class HLUsageReporting { - private: - static HLUsageReportingInterface* impl; - - public: - static void SetImplementation(HLUsageReportingInterface* i); - static void ReportScheduler(); - static void ReportSmartDashboard(); -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/Internal/HardwareHLReporting.h b/wpilibc/src/main/native/include/Internal/HardwareHLReporting.h deleted file mode 100644 index aef69bc6af..0000000000 --- a/wpilibc/src/main/native/include/Internal/HardwareHLReporting.h +++ /dev/null @@ -1,20 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -#pragma once - -#include "HLUsageReporting.h" - -namespace frc { - -class HardwareHLReporting : public HLUsageReportingInterface { - public: - virtual void ReportScheduler(); - virtual void ReportSmartDashboard(); -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/RobotState.h b/wpilibc/src/main/native/include/RobotState.h index 2063355348..6b916929ec 100644 --- a/wpilibc/src/main/native/include/RobotState.h +++ b/wpilibc/src/main/native/include/RobotState.h @@ -11,23 +11,8 @@ namespace frc { -class RobotStateInterface { - public: - virtual ~RobotStateInterface() = default; - virtual bool IsDisabled() const = 0; - virtual bool IsEnabled() const = 0; - virtual bool IsOperatorControl() const = 0; - virtual bool IsAutonomous() const = 0; - virtual bool IsTest() const = 0; -}; - class RobotState { - private: - static std::shared_ptr impl; - public: - static void SetImplementation(RobotStateInterface& i); - static void SetImplementation(std::shared_ptr i); static bool IsDisabled(); static bool IsEnabled(); static bool IsOperatorControl(); diff --git a/wpilibcIntegrationTests/build.gradle b/wpilibcIntegrationTests/build.gradle index 8fa54b0227..496e42599a 100644 --- a/wpilibcIntegrationTests/build.gradle +++ b/wpilibcIntegrationTests/build.gradle @@ -3,6 +3,7 @@ import org.gradle.language.base.internal.ProjectLayout apply plugin: 'cpp' apply plugin: 'visual-studio' apply plugin: 'edu.wpi.first.NativeUtils' +apply plugin: ExtraTasks apply from: '../shared/config.gradle' diff --git a/wpilibcIntegrationTests/src/main/native/cpp/command/CommandTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/command/CommandTest.cpp index 21f64e550c..ab3cfb7c49 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/command/CommandTest.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/command/CommandTest.cpp @@ -18,10 +18,7 @@ using namespace frc; class CommandTest : public testing::Test { protected: - void SetUp() override { - RobotState::SetImplementation(DriverStation::GetInstance()); - Scheduler::GetInstance()->SetEnabled(true); - } + void SetUp() override { Scheduler::GetInstance()->SetEnabled(true); } /** * Tears Down the Scheduler at the end of each test. diff --git a/wpilibcIntegrationTests/src/main/native/cpp/command/ConditionalCommandTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/command/ConditionalCommandTest.cpp index d289bc1322..785d1a3518 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/command/ConditionalCommandTest.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/command/ConditionalCommandTest.cpp @@ -27,7 +27,6 @@ class ConditionalCommandTest : public testing::Test { protected: void SetUp() override { - RobotState::SetImplementation(DriverStation::GetInstance()); Scheduler::GetInstance()->SetEnabled(true); m_subsystem = new Subsystem("MockSubsystem"); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index 56627fae13..b504cd3984 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -28,7 +28,7 @@ import edu.wpi.first.wpilibj.hal.PowerJNI; @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.ExcessiveClassLength", "PMD.ExcessivePublicCount", "PMD.GodClass", "PMD.TooManyFields", "PMD.TooManyMethods"}) -public class DriverStation implements RobotState.Interface { +public class DriverStation { /** * Number of Joystick Ports. */ @@ -630,7 +630,6 @@ public class DriverStation implements RobotState.Interface { * * @return True if the robot is enabled, false otherwise. */ - @Override public boolean isEnabled() { synchronized (m_controlWordMutex) { updateControlWord(false); @@ -643,7 +642,6 @@ public class DriverStation implements RobotState.Interface { * * @return True if the robot should be disabled, false otherwise. */ - @Override public boolean isDisabled() { return !isEnabled(); } @@ -654,7 +652,6 @@ public class DriverStation implements RobotState.Interface { * * @return True if autonomous mode should be enabled, false otherwise. */ - @Override public boolean isAutonomous() { synchronized (m_controlWordMutex) { updateControlWord(false); @@ -668,7 +665,6 @@ public class DriverStation implements RobotState.Interface { * * @return True if operator-controlled mode should be enabled, false otherwise. */ - @Override public boolean isOperatorControl() { return !(isAutonomous() || isTest()); } @@ -679,7 +675,6 @@ public class DriverStation implements RobotState.Interface { * * @return True if test mode should be enabled, false otherwise. */ - @Override public boolean isTest() { synchronized (m_controlWordMutex) { updateControlWord(false); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java deleted file mode 100644 index 8b4d9d240d..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java +++ /dev/null @@ -1,73 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException; - -/** - * Support for high level usage reporting. - */ -@SuppressWarnings("JavadocMethod") -public final class HLUsageReporting { - private static Interface impl; - - @SuppressWarnings("MethodName") - public static void SetImplementation(Interface implementation) { - impl = implementation; - } - - public static void reportScheduler() { - if (impl != null) { - impl.reportScheduler(); - } else { - throw new BaseSystemNotInitializedException(Interface.class, HLUsageReporting.class); - } - } - - public static void reportPIDController(int num) { - if (impl != null) { - impl.reportPIDController(num); - } else { - throw new BaseSystemNotInitializedException(Interface.class, HLUsageReporting.class); - } - } - - public static void reportSmartDashboard() { - if (impl != null) { - impl.reportSmartDashboard(); - } else { - throw new BaseSystemNotInitializedException(Interface.class, HLUsageReporting.class); - } - } - - public interface Interface { - void reportScheduler(); - - void reportPIDController(int num); - - void reportSmartDashboard(); - } - - public static class Null implements Interface { - @Override - public void reportScheduler() { - } - - @Override - @SuppressWarnings("PMD.UnusedFormalParameter") - public void reportPIDController(int num) { - } - - @Override - public void reportSmartDashboard() { - } - } - - private HLUsageReporting() { - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java index ace6027031..ce6d73ab3b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java @@ -10,6 +10,8 @@ package edu.wpi.first.wpilibj; import java.util.concurrent.locks.ReentrantLock; import edu.wpi.first.wpilibj.filters.LinearDigitalFilter; +import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType; +import edu.wpi.first.wpilibj.hal.HAL; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.util.BoundaryException; @@ -176,7 +178,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput { m_pidOutput = output; instances++; - HLUsageReporting.reportPIDController(instances); + HAL.report(tResourceType.kResourceType_PIDController, instances); m_tolerance = new NullTolerance(); setName("PIDController", instances); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index 5a54a7d2f4..f9afc8b1c1 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -21,8 +21,6 @@ import edu.wpi.first.wpilibj.hal.FRCNetComm.tInstances; import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType; import edu.wpi.first.wpilibj.hal.HAL; import edu.wpi.first.wpilibj.hal.HALUtil; -import edu.wpi.first.wpilibj.internal.HardwareHLUsageReporting; -import edu.wpi.first.wpilibj.internal.HardwareTimer; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.util.WPILibVersion; @@ -84,7 +82,6 @@ public abstract class RobotBase implements AutoCloseable { * to put this code into it's own task that loads on boot so ensure that it runs. */ protected RobotBase() { - initializeHardwareConfiguration(); NetworkTableInstance inst = NetworkTableInstance.getDefault(); setupCameraServerShared(); inst.setNetworkIdentity("Robot"); @@ -198,24 +195,6 @@ public abstract class RobotBase implements AutoCloseable { } } - /** - * Common initialization for all robot programs. - */ - public static void initializeHardwareConfiguration() { - if (!HAL.initialize(500, 0)) { - throw new IllegalStateException("Failed to initialize. Terminating"); - } - - // Set some implementations so that the static methods work properly - Timer.SetImplementation(new HardwareTimer()); - HLUsageReporting.SetImplementation(new HardwareHLUsageReporting()); - RobotState.SetImplementation(DriverStation.getInstance()); - - // Call a CameraServer JNI function to force OpenCV native library loading - // Needed because all the OpenCV JNI functions don't have built in loading - CameraServerJNI.enumerateSinks(); - } - /** * Starting point for the applications. */ @@ -226,6 +205,10 @@ public abstract class RobotBase implements AutoCloseable { throw new IllegalStateException("Failed to initialize. Terminating"); } + // Call a CameraServer JNI function to force OpenCV native library loading + // Needed because all the OpenCV JNI functions don't have built in loading + CameraServerJNI.enumerateSinks(); + HAL.report(tResourceType.kResourceType_Language, tInstances.kLanguage_Java); String robotName = ""; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java index 652106859b..0f384ee288 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java @@ -7,67 +7,26 @@ package edu.wpi.first.wpilibj; -import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException; - @SuppressWarnings("JavadocMethod") public final class RobotState { - private static Interface m_impl; - - @SuppressWarnings("MethodName") - public static void SetImplementation(Interface implementation) { - m_impl = implementation; - } - public static boolean isDisabled() { - if (m_impl != null) { - return m_impl.isDisabled(); - } else { - throw new BaseSystemNotInitializedException(Interface.class, RobotState.class); - } + return DriverStation.getInstance().isDisabled(); } public static boolean isEnabled() { - if (m_impl != null) { - return m_impl.isEnabled(); - } else { - throw new BaseSystemNotInitializedException(Interface.class, RobotState.class); - } + return DriverStation.getInstance().isEnabled(); } public static boolean isOperatorControl() { - if (m_impl != null) { - return m_impl.isOperatorControl(); - } else { - throw new BaseSystemNotInitializedException(Interface.class, RobotState.class); - } + return DriverStation.getInstance().isOperatorControl(); } public static boolean isAutonomous() { - if (m_impl != null) { - return m_impl.isAutonomous(); - } else { - throw new BaseSystemNotInitializedException(Interface.class, RobotState.class); - } + return DriverStation.getInstance().isAutonomous(); } public static boolean isTest() { - if (m_impl != null) { - return m_impl.isTest(); - } else { - throw new BaseSystemNotInitializedException(Interface.class, RobotState.class); - } - } - - interface Interface { - boolean isDisabled(); - - boolean isEnabled(); - - boolean isOperatorControl(); - - boolean isAutonomous(); - - boolean isTest(); + return DriverStation.getInstance().isTest(); } private RobotState() { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Timer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Timer.java index 71841157c6..7f830f45db 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Timer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Timer.java @@ -7,16 +7,7 @@ package edu.wpi.first.wpilibj; -import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException; - public class Timer { - private static StaticInterface impl; - - @SuppressWarnings("MethodName") - public static void SetImplementation(StaticInterface ti) { - impl = ti; - } - /** * Return the system clock time in seconds. Return the time from the FPGA hardware clock in * seconds since the FPGA started. @@ -25,11 +16,7 @@ public class Timer { */ @SuppressWarnings("AbbreviationAsWordInName") public static double getFPGATimestamp() { - if (impl != null) { - return impl.getFPGATimestamp(); - } else { - throw new BaseSystemNotInitializedException(StaticInterface.class, Timer.class); - } + return RobotController.getFPGATime() / 1000000.0; } /** @@ -42,11 +29,7 @@ public class Timer { * @return Time remaining in current match period (auto or teleop) in seconds */ public static double getMatchTime() { - if (impl != null) { - return impl.getMatchTime(); - } else { - throw new BaseSystemNotInitializedException(StaticInterface.class, Timer.class); - } + return DriverStation.getInstance().getMatchTime(); } /** @@ -58,34 +41,24 @@ public class Timer { * @param seconds Length of time to pause */ public static void delay(final double seconds) { - if (impl != null) { - impl.delay(seconds); - } else { - throw new BaseSystemNotInitializedException(StaticInterface.class, Timer.class); + try { + Thread.sleep((long) (seconds * 1e3)); + } catch (final InterruptedException ex) { + Thread.currentThread().interrupt(); } } - public interface StaticInterface { - @SuppressWarnings("AbbreviationAsWordInName") - double getFPGATimestamp(); - - double getMatchTime(); - - void delay(double seconds); - - @SuppressWarnings("JavadocMethod") - Interface newTimer(); - } - - private final Interface m_timer; + private double m_startTime; + private double m_accumulatedTime; + private boolean m_running; @SuppressWarnings("JavadocMethod") public Timer() { - if (impl != null) { - m_timer = impl.newTimer(); - } else { - throw new BaseSystemNotInitializedException(StaticInterface.class, Timer.class); - } + reset(); + } + + private double getMsClock() { + return RobotController.getFPGATime() / 1000.0; } /** @@ -95,24 +68,30 @@ public class Timer { * * @return Current time value for this timer in seconds */ - public double get() { - return m_timer.get(); + public synchronized double get() { + if (m_running) { + return ((getMsClock() - m_startTime) + m_accumulatedTime) / 1000.0; + } else { + return m_accumulatedTime; + } } /** * Reset the timer by setting the time to 0. Make the timer startTime the current time so new * requests will be relative now */ - public void reset() { - m_timer.reset(); + public synchronized void reset() { + m_accumulatedTime = 0; + m_startTime = getMsClock(); } /** * Start the timer running. Just set the running flag to true indicating that all time requests * should be relative to the system clock. */ - public void start() { - m_timer.start(); + public synchronized void start() { + m_startTime = getMsClock(); + m_running = true; } /** @@ -120,8 +99,10 @@ public class Timer { * subsequent time requests to be read from the accumulated time rather than looking at the system * clock. */ - public void stop() { - m_timer.stop(); + public synchronized void stop() { + final double temp = get(); + m_accumulatedTime = temp; + m_running = false; } /** @@ -132,48 +113,13 @@ public class Timer { * @param period The period to check for (in seconds). * @return If the period has passed. */ - public boolean hasPeriodPassed(double period) { - return m_timer.hasPeriodPassed(period); - } - - public interface Interface { - /** - * Get the current time from the timer. If the clock is running it is derived from the current - * system clock the start time stored in the timer class. If the clock is not running, then - * return the time when it was last stopped. - * - * @return Current time value for this timer in seconds - */ - double get(); - - /** - * Reset the timer by setting the time to 0. Make the timer startTime the current time so new - * requests will be relative now - */ - void reset(); - - /** - * Start the timer running. Just set the running flag to true indicating that all time requests - * should be relative to the system clock. - */ - void start(); - - /** - * Stop the timer. This computes the time as of now and clears the running flag, causing all - * subsequent time requests to be read from the accumulated time rather than looking at the - * system clock. - */ - void stop(); - - - /** - * Check if the period specified has passed and if it has, advance the start time by that - * period. This is useful to decide if it's time to do periodic work without drifting later by - * the time it took to get around to checking. - * - * @param period The period to check for (in seconds). - * @return If the period has passed. - */ - boolean hasPeriodPassed(double period); + public synchronized boolean hasPeriodPassed(double period) { + if (get() > period) { + // Advance the start time by the period. + // Don't set it to the current time... we want to avoid drift. + m_startTime += period * 1000; + return true; + } + return false; } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java index a71e477374..a384f7e239 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java @@ -12,9 +12,11 @@ import java.util.Hashtable; import java.util.Vector; import edu.wpi.first.networktables.NetworkTableEntry; -import edu.wpi.first.wpilibj.HLUsageReporting; import edu.wpi.first.wpilibj.SendableBase; import edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler; +import edu.wpi.first.wpilibj.hal.FRCNetComm.tInstances; +import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType; +import edu.wpi.first.wpilibj.hal.HAL; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; /** @@ -92,7 +94,7 @@ public final class Scheduler extends SendableBase { * Instantiates a {@link Scheduler}. */ private Scheduler() { - HLUsageReporting.reportScheduler(); + HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand_Scheduler); setName("Scheduler"); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java deleted file mode 100644 index c2865b384b..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java +++ /dev/null @@ -1,30 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.internal; - -import edu.wpi.first.wpilibj.HLUsageReporting; -import edu.wpi.first.wpilibj.hal.FRCNetComm.tInstances; -import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType; -import edu.wpi.first.wpilibj.hal.HAL; - -public class HardwareHLUsageReporting implements HLUsageReporting.Interface { - @Override - public void reportScheduler() { - HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand_Scheduler); - } - - @Override - public void reportPIDController(int num) { - HAL.report(tResourceType.kResourceType_PIDController, num); - } - - @Override - public void reportSmartDashboard() { - HAL.report(tResourceType.kResourceType_SmartDashboard, 0); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java deleted file mode 100644 index 35e29689a2..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java +++ /dev/null @@ -1,143 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.internal; - -import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj.RobotController; -import edu.wpi.first.wpilibj.Timer; - -/** - * Timer objects measure accumulated time in milliseconds. The timer object functions like a - * stopwatch. It can be started, stopped, and cleared. When the timer is running its value counts - * up in milliseconds. When stopped, the timer holds the current value. The implementation simply - * records the time when started and subtracts the current time whenever the value is requested. - */ -public class HardwareTimer implements Timer.StaticInterface { - /** - * Pause the thread for a specified time. Pause the execution of the thread for a specified period - * of time given in seconds. Motors will continue to run at their last assigned values, and - * sensors will continue to update. Only the task containing the wait will pause until the wait - * time is expired. - * - * @param seconds Length of time to pause - */ - @Override - public void delay(final double seconds) { - try { - Thread.sleep((long) (seconds * 1e3)); - } catch (final InterruptedException ex) { - Thread.currentThread().interrupt(); - } - } - - /** - * Return the system clock time in seconds. Return the time from the FPGA hardware clock in - * seconds since the FPGA started. - * - * @return Robot running time in seconds. - */ - @Override - public double getFPGATimestamp() { - return RobotController.getFPGATime() / 1000000.0; - } - - @Override - public double getMatchTime() { - return DriverStation.getInstance().getMatchTime(); - } - - @Override - public Timer.Interface newTimer() { - return new TimerImpl(); - } - - class TimerImpl implements Timer.Interface { - private double m_startTime; - private double m_accumulatedTime; - private boolean m_running; - - /** - * Create a new timer object. Create a new timer object and reset the time to zero. The timer is - * initially not running and must be started. - */ - TimerImpl() { - reset(); - } - - private double getMsClock() { - return RobotController.getFPGATime() / 1000.0; - } - - /** - * Get the current time from the timer. If the clock is running it is derived from the current - * system clock the start time stored in the timer class. If the clock is not running, then - * return the time when it was last stopped. - * - * @return Current time value for this timer in seconds - */ - @Override - public synchronized double get() { - if (m_running) { - return ((getMsClock() - m_startTime) + m_accumulatedTime) / 1000.0; - } else { - return m_accumulatedTime; - } - } - - /** - * Reset the timer by setting the time to 0. Make the timer start time the current time so new - * requests will be relative now - */ - @Override - public synchronized void reset() { - m_accumulatedTime = 0; - m_startTime = getMsClock(); - } - - /** - * Start the timer running. Just set the running flag to true indicating that all time - * requests should be relative to the system clock. - */ - @Override - public synchronized void start() { - m_startTime = getMsClock(); - m_running = true; - } - - /** - * Stop the timer. This computes the time as of now and clears the running flag, causing all - * subsequent time requests to be read from the accumulated time rather than looking at the - * system clock. - */ - @Override - public synchronized void stop() { - final double temp = get(); - m_accumulatedTime = temp; - m_running = false; - } - - /** - * Check if the period specified has passed and if it has, advance the start time by that - * period. This is useful to decide if it's time to do periodic work without drifting later by - * the time it took to get around to checking. - * - * @param period The period to check for (in seconds). - * @return If the period has passed. - */ - @Override - public synchronized boolean hasPeriodPassed(double period) { - if (get() > period) { - // Advance the start time by the period. - // Don't set it to the current time... we want to avoid drift. - m_startTime += period * 1000; - return true; - } - return false; - } - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java index d8a64722eb..f52b48b58d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java @@ -15,8 +15,10 @@ import java.util.Set; import edu.wpi.first.networktables.NetworkTable; import edu.wpi.first.networktables.NetworkTableEntry; import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.wpilibj.HLUsageReporting; +import edu.wpi.first.wpilibj.NamedSendable; import edu.wpi.first.wpilibj.Sendable; +import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType; +import edu.wpi.first.wpilibj.hal.HAL; /** * The {@link SmartDashboard} class is the bridge between robot programs and the SmartDashboard on @@ -50,7 +52,7 @@ public class SmartDashboard { private static final Map tablesToData = new HashMap<>(); static { - HLUsageReporting.reportSmartDashboard(); + HAL.report(tResourceType.kResourceType_SmartDashboard, 0); } private SmartDashboard() { diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockHardwareExtension.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockHardwareExtension.java index cf281c6e7c..2d9d460926 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockHardwareExtension.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockHardwareExtension.java @@ -7,16 +7,12 @@ package edu.wpi.first.wpilibj; -import java.util.concurrent.TimeUnit; - -import com.google.common.base.Stopwatch; - import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ExtensionContext.Namespace; import edu.wpi.first.wpilibj.hal.HAL; -import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException; +import edu.wpi.first.wpilibj.sim.DriverStationSim; public final class MockHardwareExtension implements BeforeAllCallback { private static ExtensionContext getRoot(ExtensionContext context) { @@ -33,72 +29,12 @@ public final class MockHardwareExtension implements BeforeAllCallback { private void initializeHardware() { HAL.initialize(500, 0); - try { - // Check to see if this has been setup - Timer.getFPGATimestamp(); - } catch (BaseSystemNotInitializedException ex) { - // If it hasn't been then do this setup + DriverStationSim dsSim = new DriverStationSim(); + dsSim.setDsAttached(true); + dsSim.setAutonomous(false); + dsSim.setEnabled(true); + dsSim.setTest(true); - HLUsageReporting.SetImplementation(new HLUsageReporting.Null()); - RobotState.SetImplementation(new MockRobotStateInterface()); - Timer.SetImplementation(new Timer.StaticInterface() { - @Override - public double getFPGATimestamp() { - return System.currentTimeMillis() / 1000.0; - } - @Override - public double getMatchTime() { - return 0; - } - - @Override - public void delay(double seconds) { - try { - Thread.sleep((long) (seconds * 1e3)); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - } - - @Override - public Timer.Interface newTimer() { - return new Timer.Interface() { - private final Stopwatch m_stopwatch = Stopwatch.createUnstarted(); - - @Override - public double get() { - return m_stopwatch.elapsed(TimeUnit.SECONDS); - } - - @Override - public void reset() { - m_stopwatch.reset(); - } - - @Override - public void start() { - m_stopwatch.start(); - } - - @Override - public void stop() { - m_stopwatch.stop(); - } - - @Override - public boolean hasPeriodPassed(double period) { - if (get() > period) { - // Advance the start time by the period. - // Don't set it to the current time... we want to avoid drift. - m_stopwatch.reset().start(); - return true; - } - return false; - } - }; - } - }); - } } } diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockRobotStateInterface.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockRobotStateInterface.java deleted file mode 100644 index 7c3ab10ff4..0000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockRobotStateInterface.java +++ /dev/null @@ -1,38 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -/** - * A concrete implementation of the robot state interface that can be used in UnitTests. - */ -public class MockRobotStateInterface implements RobotState.Interface { - @Override - public boolean isDisabled() { - return false; - } - - @Override - public boolean isEnabled() { - return true; - } - - @Override - public boolean isOperatorControl() { - return false; - } - - @Override - public boolean isAutonomous() { - return false; - } - - @Override - public boolean isTest() { - return true; - } -} diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractComsSetup.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractComsSetup.java index 0ce5a565b3..e089f7dff7 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractComsSetup.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractComsSetup.java @@ -18,7 +18,6 @@ import org.junit.runners.model.MultipleFailureException; import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.MockDS; -import edu.wpi.first.wpilibj.RobotBase; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.hal.HAL; import edu.wpi.first.wpilibj.livewindow.LiveWindow; @@ -48,7 +47,7 @@ public abstract class AbstractComsSetup { if (!initialized) { try { // Set some implementations so that the static methods work properly - RobotBase.initializeHardwareConfiguration(); + HAL.initialize(500, 0); HAL.observeUserProgramStarting(); DriverStation.getInstance().getAlliance();