diff --git a/CMakeLists.txt b/CMakeLists.txt index f0e6bc0884..348e0d9797 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,6 +187,7 @@ if (WITH_GUI) add_subdirectory(imgui) add_subdirectory(wpigui) add_subdirectory(glass) + add_subdirectory(outlineviewer) endif() if (WITH_CSCORE) diff --git a/cameraserver/multiCameraServer/src/main/java/edu/wpi/Main.java b/cameraserver/multiCameraServer/src/main/java/edu/wpi/Main.java index 3366b39979..f488487c55 100644 --- a/cameraserver/multiCameraServer/src/main/java/edu/wpi/Main.java +++ b/cameraserver/multiCameraServer/src/main/java/edu/wpi/Main.java @@ -10,8 +10,8 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import edu.wpi.cscore.VideoSource; import edu.wpi.first.cameraserver.CameraServer; +import edu.wpi.first.cscore.VideoSource; import edu.wpi.first.networktables.NetworkTableInstance; import java.io.IOException; import java.nio.file.Files; diff --git a/cameraserver/multiCameraServer/src/main/native/cpp/main.cpp b/cameraserver/multiCameraServer/src/main/native/cpp/main.cpp index df408dee2a..e030fd9f22 100644 --- a/cameraserver/multiCameraServer/src/main/native/cpp/main.cpp +++ b/cameraserver/multiCameraServer/src/main/native/cpp/main.cpp @@ -158,7 +158,7 @@ bool ReadConfig() { void StartCamera(const CameraConfig& config) { wpi::outs() << "Starting camera '" << config.name << "' on " << config.path << '\n'; - auto camera = frc::CameraServer::GetInstance()->StartAutomaticCapture( + auto camera = frc::CameraServer::GetInstance().StartAutomaticCapture( config.name, config.path); camera.SetConfigJson(config.config); diff --git a/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java b/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java index 6867d5f9ec..b994749577 100644 --- a/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java +++ b/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java @@ -4,20 +4,20 @@ package edu.wpi.first.cameraserver; -import edu.wpi.cscore.AxisCamera; -import edu.wpi.cscore.CameraServerJNI; -import edu.wpi.cscore.CvSink; -import edu.wpi.cscore.CvSource; -import edu.wpi.cscore.MjpegServer; -import edu.wpi.cscore.UsbCamera; -import edu.wpi.cscore.VideoEvent; -import edu.wpi.cscore.VideoException; -import edu.wpi.cscore.VideoListener; -import edu.wpi.cscore.VideoMode; -import edu.wpi.cscore.VideoMode.PixelFormat; -import edu.wpi.cscore.VideoProperty; -import edu.wpi.cscore.VideoSink; -import edu.wpi.cscore.VideoSource; +import edu.wpi.first.cscore.AxisCamera; +import edu.wpi.first.cscore.CameraServerJNI; +import edu.wpi.first.cscore.CvSink; +import edu.wpi.first.cscore.CvSource; +import edu.wpi.first.cscore.MjpegServer; +import edu.wpi.first.cscore.UsbCamera; +import edu.wpi.first.cscore.VideoEvent; +import edu.wpi.first.cscore.VideoException; +import edu.wpi.first.cscore.VideoListener; +import edu.wpi.first.cscore.VideoMode; +import edu.wpi.first.cscore.VideoMode.PixelFormat; +import edu.wpi.first.cscore.VideoProperty; +import edu.wpi.first.cscore.VideoSink; +import edu.wpi.first.cscore.VideoSource; import edu.wpi.first.networktables.EntryListenerFlags; import edu.wpi.first.networktables.NetworkTable; import edu.wpi.first.networktables.NetworkTableEntry; diff --git a/cameraserver/src/main/java/edu/wpi/first/vision/VisionRunner.java b/cameraserver/src/main/java/edu/wpi/first/vision/VisionRunner.java index 2a1275791c..ab7072f6c9 100644 --- a/cameraserver/src/main/java/edu/wpi/first/vision/VisionRunner.java +++ b/cameraserver/src/main/java/edu/wpi/first/vision/VisionRunner.java @@ -4,9 +4,9 @@ package edu.wpi.first.vision; -import edu.wpi.cscore.CvSink; -import edu.wpi.cscore.VideoSource; import edu.wpi.first.cameraserver.CameraServerSharedStore; +import edu.wpi.first.cscore.CvSink; +import edu.wpi.first.cscore.VideoSource; import org.opencv.core.Mat; /** diff --git a/cameraserver/src/main/java/edu/wpi/first/vision/VisionThread.java b/cameraserver/src/main/java/edu/wpi/first/vision/VisionThread.java index 5ce896dbf9..6f1a1e35b5 100644 --- a/cameraserver/src/main/java/edu/wpi/first/vision/VisionThread.java +++ b/cameraserver/src/main/java/edu/wpi/first/vision/VisionThread.java @@ -4,7 +4,7 @@ package edu.wpi.first.vision; -import edu.wpi.cscore.VideoSource; +import edu.wpi.first.cscore.VideoSource; /** * A vision thread is a special thread that runs a vision pipeline. It is a daemon thread; it diff --git a/cameraserver/src/main/java/edu/wpi/first/vision/package-info.java b/cameraserver/src/main/java/edu/wpi/first/vision/package-info.java index 758ea2889d..b7bab9c35c 100644 --- a/cameraserver/src/main/java/edu/wpi/first/vision/package-info.java +++ b/cameraserver/src/main/java/edu/wpi/first/vision/package-info.java @@ -13,7 +13,7 @@ * implements VisionRunner.Listener<MyFindTotePipeline> { * * // A USB camera connected to the roboRIO. - * private {@link edu.wpi.cscore.VideoSource VideoSource} usbCamera; + * private {@link edu.wpi.first.cscore.VideoSource VideoSource} usbCamera; * * // A vision pipeline. This could be handwritten or generated by GRIP. * // This has to implement {@link edu.wpi.first.vision.VisionPipeline}. diff --git a/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp b/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp index fa18a8e14b..b258d3bbf9 100644 --- a/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp +++ b/cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp @@ -45,7 +45,7 @@ struct CameraServer::Impl { std::vector m_addresses; }; -CameraServer* CameraServer::GetInstance() { +CameraServer& CameraServer::GetInstance() { struct Creator { static void* call() { return new CameraServer{}; } }; @@ -53,7 +53,7 @@ CameraServer* CameraServer::GetInstance() { static void call(void* ptr) { delete static_cast(ptr); } }; static wpi::ManagedStatic instance; - return &(*instance); + return *instance; } static wpi::StringRef MakeSourceValue(CS_Source source, diff --git a/cameraserver/src/main/native/include/cameraserver/CameraServer.h b/cameraserver/src/main/native/include/cameraserver/CameraServer.h index ce620ed1b8..2cf73e8fa4 100644 --- a/cameraserver/src/main/native/include/cameraserver/CameraServer.h +++ b/cameraserver/src/main/native/include/cameraserver/CameraServer.h @@ -32,7 +32,7 @@ class CameraServer { /** * Get the CameraServer instance. */ - static CameraServer* GetInstance(); + static CameraServer& GetInstance(); /** * Start automatically capturing images to send to the dashboard. diff --git a/cscore/src/dev/java/edu/wpi/cscore/DevMain.java b/cscore/src/dev/java/edu/wpi/first/cscore/DevMain.java similarity index 94% rename from cscore/src/dev/java/edu/wpi/cscore/DevMain.java rename to cscore/src/dev/java/edu/wpi/first/cscore/DevMain.java index 69198cb247..5ccbed722b 100644 --- a/cscore/src/dev/java/edu/wpi/cscore/DevMain.java +++ b/cscore/src/dev/java/edu/wpi/first/cscore/DevMain.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; import edu.wpi.first.wpiutil.RuntimeDetector; diff --git a/cscore/src/main/java/edu/wpi/cscore/AxisCamera.java b/cscore/src/main/java/edu/wpi/first/cscore/AxisCamera.java similarity index 97% rename from cscore/src/main/java/edu/wpi/cscore/AxisCamera.java rename to cscore/src/main/java/edu/wpi/first/cscore/AxisCamera.java index c219517ee5..296bd6bd14 100644 --- a/cscore/src/main/java/edu/wpi/cscore/AxisCamera.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/AxisCamera.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** A source that represents an Axis IP camera. */ public class AxisCamera extends HttpCamera { diff --git a/cscore/src/main/java/edu/wpi/cscore/CameraServerCvJNI.java b/cscore/src/main/java/edu/wpi/first/cscore/CameraServerCvJNI.java similarity index 98% rename from cscore/src/main/java/edu/wpi/cscore/CameraServerCvJNI.java rename to cscore/src/main/java/edu/wpi/first/cscore/CameraServerCvJNI.java index 34fcfc22c5..6d382c87db 100644 --- a/cscore/src/main/java/edu/wpi/cscore/CameraServerCvJNI.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/CameraServerCvJNI.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; import edu.wpi.first.wpiutil.RuntimeLoader; import java.io.IOException; diff --git a/cscore/src/main/java/edu/wpi/cscore/CameraServerJNI.java b/cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java similarity index 99% rename from cscore/src/main/java/edu/wpi/cscore/CameraServerJNI.java rename to cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java index 2672a90ecd..b7a9216e82 100644 --- a/cscore/src/main/java/edu/wpi/cscore/CameraServerJNI.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/CameraServerJNI.java @@ -2,9 +2,9 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; -import edu.wpi.cscore.raw.RawFrame; +import edu.wpi.first.cscore.raw.RawFrame; import edu.wpi.first.wpiutil.RuntimeLoader; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/cscore/src/main/java/edu/wpi/cscore/CvSink.java b/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java similarity index 98% rename from cscore/src/main/java/edu/wpi/cscore/CvSink.java rename to cscore/src/main/java/edu/wpi/first/cscore/CvSink.java index 5e3489ca12..28f0dd13a8 100644 --- a/cscore/src/main/java/edu/wpi/cscore/CvSink.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/CvSink.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; import org.opencv.core.Mat; diff --git a/cscore/src/main/java/edu/wpi/cscore/CvSource.java b/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java similarity index 98% rename from cscore/src/main/java/edu/wpi/cscore/CvSource.java rename to cscore/src/main/java/edu/wpi/first/cscore/CvSource.java index 09f551b7c6..3934a09c0b 100644 --- a/cscore/src/main/java/edu/wpi/cscore/CvSource.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/CvSource.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; import org.opencv.core.Mat; diff --git a/cscore/src/main/java/edu/wpi/cscore/HttpCamera.java b/cscore/src/main/java/edu/wpi/first/cscore/HttpCamera.java similarity index 99% rename from cscore/src/main/java/edu/wpi/cscore/HttpCamera.java rename to cscore/src/main/java/edu/wpi/first/cscore/HttpCamera.java index 1caeb338ac..9758f90436 100644 --- a/cscore/src/main/java/edu/wpi/cscore/HttpCamera.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/HttpCamera.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** A source that represents a MJPEG-over-HTTP (IP) camera. */ public class HttpCamera extends VideoCamera { diff --git a/cscore/src/main/java/edu/wpi/cscore/ImageSink.java b/cscore/src/main/java/edu/wpi/first/cscore/ImageSink.java similarity index 97% rename from cscore/src/main/java/edu/wpi/cscore/ImageSink.java rename to cscore/src/main/java/edu/wpi/first/cscore/ImageSink.java index 8907ee1106..55318da1cb 100644 --- a/cscore/src/main/java/edu/wpi/cscore/ImageSink.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/ImageSink.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; public abstract class ImageSink extends VideoSink { protected ImageSink(int handle) { diff --git a/cscore/src/main/java/edu/wpi/cscore/ImageSource.java b/cscore/src/main/java/edu/wpi/first/cscore/ImageSource.java similarity index 99% rename from cscore/src/main/java/edu/wpi/cscore/ImageSource.java rename to cscore/src/main/java/edu/wpi/first/cscore/ImageSource.java index 93f994c250..431e75cfa4 100644 --- a/cscore/src/main/java/edu/wpi/cscore/ImageSource.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/ImageSource.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; public abstract class ImageSource extends VideoSource { protected ImageSource(int handle) { diff --git a/cscore/src/main/java/edu/wpi/cscore/MjpegServer.java b/cscore/src/main/java/edu/wpi/first/cscore/MjpegServer.java similarity index 99% rename from cscore/src/main/java/edu/wpi/cscore/MjpegServer.java rename to cscore/src/main/java/edu/wpi/first/cscore/MjpegServer.java index 29619d27d3..a1ffb6331d 100644 --- a/cscore/src/main/java/edu/wpi/cscore/MjpegServer.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/MjpegServer.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** A sink that acts as a MJPEG-over-HTTP network server. */ public class MjpegServer extends VideoSink { diff --git a/cscore/src/main/java/edu/wpi/cscore/UsbCamera.java b/cscore/src/main/java/edu/wpi/first/cscore/UsbCamera.java similarity index 98% rename from cscore/src/main/java/edu/wpi/cscore/UsbCamera.java rename to cscore/src/main/java/edu/wpi/first/cscore/UsbCamera.java index 144a4aadb5..2b5cf5a41a 100644 --- a/cscore/src/main/java/edu/wpi/cscore/UsbCamera.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/UsbCamera.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** A source that represents a USB camera. */ public class UsbCamera extends VideoCamera { diff --git a/cscore/src/main/java/edu/wpi/cscore/UsbCameraInfo.java b/cscore/src/main/java/edu/wpi/first/cscore/UsbCameraInfo.java similarity index 98% rename from cscore/src/main/java/edu/wpi/cscore/UsbCameraInfo.java rename to cscore/src/main/java/edu/wpi/first/cscore/UsbCameraInfo.java index 4899c77828..df856e8d2d 100644 --- a/cscore/src/main/java/edu/wpi/cscore/UsbCameraInfo.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/UsbCameraInfo.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** USB camera information. */ public class UsbCameraInfo { diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoCamera.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoCamera.java similarity index 98% rename from cscore/src/main/java/edu/wpi/cscore/VideoCamera.java rename to cscore/src/main/java/edu/wpi/first/cscore/VideoCamera.java index 2a93112a9c..ca3b09e642 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoCamera.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoCamera.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** A source that represents a video camera. */ public class VideoCamera extends VideoSource { diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoEvent.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoEvent.java similarity index 99% rename from cscore/src/main/java/edu/wpi/cscore/VideoEvent.java rename to cscore/src/main/java/edu/wpi/first/cscore/VideoEvent.java index c2731fdc78..ca38109b47 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoEvent.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoEvent.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** Video event. */ public class VideoEvent { diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoException.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoException.java similarity index 94% rename from cscore/src/main/java/edu/wpi/cscore/VideoException.java rename to cscore/src/main/java/edu/wpi/first/cscore/VideoException.java index 1142c0f8d7..1c445c6f77 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoException.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoException.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** An exception raised by the camera server. */ public class VideoException extends RuntimeException { diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoListener.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoListener.java similarity index 99% rename from cscore/src/main/java/edu/wpi/cscore/VideoListener.java rename to cscore/src/main/java/edu/wpi/first/cscore/VideoListener.java index cfaeb9da2a..0d77461432 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoListener.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoListener.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; import java.util.HashMap; import java.util.Map; diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoMode.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java similarity index 98% rename from cscore/src/main/java/edu/wpi/cscore/VideoMode.java rename to cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java index b7191eeb40..af7fb8f1cb 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoMode.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** Video mode. */ public class VideoMode { diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoProperty.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoProperty.java similarity index 98% rename from cscore/src/main/java/edu/wpi/cscore/VideoProperty.java rename to cscore/src/main/java/edu/wpi/first/cscore/VideoProperty.java index 53a24ad7fa..8179ba3c3d 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoProperty.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoProperty.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** A source or sink property. */ public class VideoProperty { diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoSink.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java similarity index 99% rename from cscore/src/main/java/edu/wpi/cscore/VideoSink.java rename to cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java index 098f9cb4bf..ea65d0e54a 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoSink.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** * A source for video that provides a sequence of frames. Each frame may consist of multiple images diff --git a/cscore/src/main/java/edu/wpi/cscore/VideoSource.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java similarity index 99% rename from cscore/src/main/java/edu/wpi/cscore/VideoSource.java rename to cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java index fc115c7924..047503a1e3 100644 --- a/cscore/src/main/java/edu/wpi/cscore/VideoSource.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; /** * A source for video that provides a sequence of frames. Each frame may consist of multiple images diff --git a/cscore/src/main/java/edu/wpi/cscore/raw/RawFrame.java b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawFrame.java similarity index 97% rename from cscore/src/main/java/edu/wpi/cscore/raw/RawFrame.java rename to cscore/src/main/java/edu/wpi/first/cscore/raw/RawFrame.java index 18da73dc3a..1919d6b2dd 100644 --- a/cscore/src/main/java/edu/wpi/cscore/raw/RawFrame.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawFrame.java @@ -2,9 +2,9 @@ // 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 edu.wpi.cscore.raw; +package edu.wpi.first.cscore.raw; -import edu.wpi.cscore.CameraServerJNI; +import edu.wpi.first.cscore.CameraServerJNI; import java.nio.ByteBuffer; /** diff --git a/cscore/src/main/java/edu/wpi/cscore/raw/RawSink.java b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSink.java similarity index 94% rename from cscore/src/main/java/edu/wpi/cscore/raw/RawSink.java rename to cscore/src/main/java/edu/wpi/first/cscore/raw/RawSink.java index e9854136b7..64afae2b64 100644 --- a/cscore/src/main/java/edu/wpi/cscore/raw/RawSink.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSink.java @@ -2,10 +2,10 @@ // 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 edu.wpi.cscore.raw; +package edu.wpi.first.cscore.raw; -import edu.wpi.cscore.CameraServerJNI; -import edu.wpi.cscore.ImageSink; +import edu.wpi.first.cscore.CameraServerJNI; +import edu.wpi.first.cscore.ImageSink; /** * A sink for user code to accept video frames as raw bytes. diff --git a/cscore/src/main/java/edu/wpi/cscore/raw/RawSource.java b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSource.java similarity index 93% rename from cscore/src/main/java/edu/wpi/cscore/raw/RawSource.java rename to cscore/src/main/java/edu/wpi/first/cscore/raw/RawSource.java index 89cb257670..f1be05065b 100644 --- a/cscore/src/main/java/edu/wpi/cscore/raw/RawSource.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/raw/RawSource.java @@ -2,11 +2,11 @@ // 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 edu.wpi.cscore.raw; +package edu.wpi.first.cscore.raw; -import edu.wpi.cscore.CameraServerJNI; -import edu.wpi.cscore.ImageSource; -import edu.wpi.cscore.VideoMode; +import edu.wpi.first.cscore.CameraServerJNI; +import edu.wpi.first.cscore.ImageSource; +import edu.wpi.first.cscore.VideoMode; /** * A source for user code to provide video frames as raw bytes. diff --git a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp index 62ab2b29da..a603fbf820 100644 --- a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp +++ b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp @@ -12,7 +12,7 @@ #include "cscore_cpp.h" #include "cscore_cv.h" #include "cscore_raw.h" -#include "edu_wpi_cscore_CameraServerJNI.h" +#include "edu_wpi_first_cscore_CameraServerJNI.h" namespace cv { class Mat; @@ -39,13 +39,13 @@ static JException exceptionEx; static JNIEnv* listenerEnv = nullptr; static const JClassInit classes[] = { - {"edu/wpi/cscore/UsbCameraInfo", &usbCameraInfoCls}, - {"edu/wpi/cscore/VideoMode", &videoModeCls}, - {"edu/wpi/cscore/VideoEvent", &videoEventCls}, - {"edu/wpi/cscore/raw/RawFrame", &rawFrameCls}}; + {"edu/wpi/first/cscore/UsbCameraInfo", &usbCameraInfoCls}, + {"edu/wpi/first/cscore/VideoMode", &videoModeCls}, + {"edu/wpi/first/cscore/VideoEvent", &videoEventCls}, + {"edu/wpi/first/cscore/raw/RawFrame", &rawFrameCls}}; static const JExceptionInit exceptions[] = { - {"edu/wpi/cscore/VideoException", &videoEx}, + {"edu/wpi/first/cscore/VideoException", &videoEx}, {"java/lang/InterruptedException", &interruptedEx}, {"java/lang/NullPointerException", &nullPointerEx}, {"java/lang/UnsupportedOperationException", &unsupportedEx}, @@ -308,12 +308,12 @@ static jobjectArray MakeJObject(JNIEnv* env, wpi::ArrayRef arr) { extern "C" { /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getPropertyKind * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getPropertyKind +Java_edu_wpi_first_cscore_CameraServerJNI_getPropertyKind (JNIEnv* env, jclass, jint property) { CS_Status status = 0; @@ -323,12 +323,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getPropertyKind } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getPropertyName * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getPropertyName +Java_edu_wpi_first_cscore_CameraServerJNI_getPropertyName (JNIEnv* env, jclass, jint property) { CS_Status status = 0; @@ -341,12 +341,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getPropertyName } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getProperty * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getProperty +Java_edu_wpi_first_cscore_CameraServerJNI_getProperty (JNIEnv* env, jclass, jint property) { CS_Status status = 0; @@ -356,12 +356,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getProperty } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setProperty * Signature: (II)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setProperty +Java_edu_wpi_first_cscore_CameraServerJNI_setProperty (JNIEnv* env, jclass, jint property, jint value) { CS_Status status = 0; @@ -370,12 +370,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setProperty } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getPropertyMin * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getPropertyMin +Java_edu_wpi_first_cscore_CameraServerJNI_getPropertyMin (JNIEnv* env, jclass, jint property) { CS_Status status = 0; @@ -385,12 +385,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getPropertyMin } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getPropertyMax * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getPropertyMax +Java_edu_wpi_first_cscore_CameraServerJNI_getPropertyMax (JNIEnv* env, jclass, jint property) { CS_Status status = 0; @@ -400,12 +400,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getPropertyMax } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getPropertyStep * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getPropertyStep +Java_edu_wpi_first_cscore_CameraServerJNI_getPropertyStep (JNIEnv* env, jclass, jint property) { CS_Status status = 0; @@ -415,12 +415,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getPropertyStep } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getPropertyDefault * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getPropertyDefault +Java_edu_wpi_first_cscore_CameraServerJNI_getPropertyDefault (JNIEnv* env, jclass, jint property) { CS_Status status = 0; @@ -430,12 +430,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getPropertyDefault } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getStringProperty * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getStringProperty +Java_edu_wpi_first_cscore_CameraServerJNI_getStringProperty (JNIEnv* env, jclass, jint property) { CS_Status status = 0; @@ -448,12 +448,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getStringProperty } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setStringProperty * Signature: (ILjava/lang/String;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setStringProperty +Java_edu_wpi_first_cscore_CameraServerJNI_setStringProperty (JNIEnv* env, jclass, jint property, jstring value) { if (!value) { @@ -466,12 +466,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setStringProperty } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getEnumPropertyChoices * Signature: (I)[Ljava/lang/Object; */ JNIEXPORT jobjectArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getEnumPropertyChoices +Java_edu_wpi_first_cscore_CameraServerJNI_getEnumPropertyChoices (JNIEnv* env, jclass, jint property) { CS_Status status = 0; @@ -483,12 +483,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getEnumPropertyChoices } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createUsbCameraDev * Signature: (Ljava/lang/String;I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraDev +Java_edu_wpi_first_cscore_CameraServerJNI_createUsbCameraDev (JNIEnv* env, jclass, jstring name, jint dev) { if (!name) { @@ -502,12 +502,12 @@ Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraDev } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createUsbCameraPath * Signature: (Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraPath +Java_edu_wpi_first_cscore_CameraServerJNI_createUsbCameraPath (JNIEnv* env, jclass, jstring name, jstring path) { if (!name) { @@ -526,12 +526,12 @@ Java_edu_wpi_cscore_CameraServerJNI_createUsbCameraPath } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createHttpCamera * Signature: (Ljava/lang/String;Ljava/lang/String;I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_createHttpCamera +Java_edu_wpi_first_cscore_CameraServerJNI_createHttpCamera (JNIEnv* env, jclass, jstring name, jstring url, jint kind) { if (!name) { @@ -551,12 +551,12 @@ Java_edu_wpi_cscore_CameraServerJNI_createHttpCamera } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createHttpCameraMulti * Signature: (Ljava/lang/String;[Ljava/lang/Object;I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_createHttpCameraMulti +Java_edu_wpi_first_cscore_CameraServerJNI_createHttpCameraMulti (JNIEnv* env, jclass, jstring name, jobjectArray urls, jint kind) { if (!name) { @@ -588,12 +588,12 @@ Java_edu_wpi_cscore_CameraServerJNI_createHttpCameraMulti } /* - * Class: edu_wpi_cscore_CameraServerCvJNI + * Class: edu_wpi_first_cscore_CameraServerCvJNI * Method: createCvSource * Signature: (Ljava/lang/String;IIII)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerCvJNI_createCvSource +Java_edu_wpi_first_cscore_CameraServerCvJNI_createCvSource (JNIEnv* env, jclass, jstring name, jint pixelFormat, jint width, jint height, jint fps) { @@ -613,12 +613,12 @@ Java_edu_wpi_cscore_CameraServerCvJNI_createCvSource } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createRawSource * Signature: (Ljava/lang/String;IIII)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_createRawSource +Java_edu_wpi_first_cscore_CameraServerJNI_createRawSource (JNIEnv* env, jclass, jstring name, jint pixelFormat, jint width, jint height, jint fps) { @@ -638,12 +638,12 @@ Java_edu_wpi_cscore_CameraServerJNI_createRawSource } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSourceKind * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSourceKind +Java_edu_wpi_first_cscore_CameraServerJNI_getSourceKind (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -653,12 +653,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSourceKind } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSourceName * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSourceName +Java_edu_wpi_first_cscore_CameraServerJNI_getSourceName (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -671,12 +671,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSourceName } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSourceDescription * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSourceDescription +Java_edu_wpi_first_cscore_CameraServerJNI_getSourceDescription (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -689,12 +689,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSourceDescription } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSourceLastFrameTime * Signature: (I)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSourceLastFrameTime +Java_edu_wpi_first_cscore_CameraServerJNI_getSourceLastFrameTime (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -704,12 +704,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSourceLastFrameTime } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSourceConnectionStrategy * Signature: (II)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSourceConnectionStrategy +Java_edu_wpi_first_cscore_CameraServerJNI_setSourceConnectionStrategy (JNIEnv* env, jclass, jint source, jint strategy) { CS_Status status = 0; @@ -719,12 +719,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourceConnectionStrategy } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: isSourceConnected * Signature: (I)Z */ JNIEXPORT jboolean JNICALL -Java_edu_wpi_cscore_CameraServerJNI_isSourceConnected +Java_edu_wpi_first_cscore_CameraServerJNI_isSourceConnected (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -734,12 +734,12 @@ Java_edu_wpi_cscore_CameraServerJNI_isSourceConnected } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: isSourceEnabled * Signature: (I)Z */ JNIEXPORT jboolean JNICALL -Java_edu_wpi_cscore_CameraServerJNI_isSourceEnabled +Java_edu_wpi_first_cscore_CameraServerJNI_isSourceEnabled (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -749,12 +749,12 @@ Java_edu_wpi_cscore_CameraServerJNI_isSourceEnabled } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSourceProperty * Signature: (ILjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSourceProperty +Java_edu_wpi_first_cscore_CameraServerJNI_getSourceProperty (JNIEnv* env, jclass, jint source, jstring name) { if (!name) { @@ -769,12 +769,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSourceProperty } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: enumerateSourceProperties * Signature: (I)[I */ JNIEXPORT jintArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_enumerateSourceProperties +Java_edu_wpi_first_cscore_CameraServerJNI_enumerateSourceProperties (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -787,12 +787,12 @@ Java_edu_wpi_cscore_CameraServerJNI_enumerateSourceProperties } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSourceVideoMode * Signature: (I)Ljava/lang/Object; */ JNIEXPORT jobject JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSourceVideoMode +Java_edu_wpi_first_cscore_CameraServerJNI_getSourceVideoMode (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -804,12 +804,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSourceVideoMode } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSourceVideoMode * Signature: (IIIII)Z */ JNIEXPORT jboolean JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSourceVideoMode +Java_edu_wpi_first_cscore_CameraServerJNI_setSourceVideoMode (JNIEnv* env, jclass, jint source, jint pixelFormat, jint width, jint height, jint fps) { @@ -824,12 +824,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourceVideoMode } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSourcePixelFormat * Signature: (II)Z */ JNIEXPORT jboolean JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSourcePixelFormat +Java_edu_wpi_first_cscore_CameraServerJNI_setSourcePixelFormat (JNIEnv* env, jclass, jint source, jint pixelFormat) { CS_Status status = 0; @@ -840,12 +840,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourcePixelFormat } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSourceResolution * Signature: (III)Z */ JNIEXPORT jboolean JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSourceResolution +Java_edu_wpi_first_cscore_CameraServerJNI_setSourceResolution (JNIEnv* env, jclass, jint source, jint width, jint height) { CS_Status status = 0; @@ -855,12 +855,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourceResolution } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSourceFPS * Signature: (II)Z */ JNIEXPORT jboolean JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSourceFPS +Java_edu_wpi_first_cscore_CameraServerJNI_setSourceFPS (JNIEnv* env, jclass, jint source, jint fps) { CS_Status status = 0; @@ -870,12 +870,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourceFPS } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSourceConfigJson * Signature: (ILjava/lang/String;)Z */ JNIEXPORT jboolean JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSourceConfigJson +Java_edu_wpi_first_cscore_CameraServerJNI_setSourceConfigJson (JNIEnv* env, jclass, jint source, jstring config) { CS_Status status = 0; @@ -885,12 +885,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourceConfigJson } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSourceConfigJson * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSourceConfigJson +Java_edu_wpi_first_cscore_CameraServerJNI_getSourceConfigJson (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -900,12 +900,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSourceConfigJson } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: enumerateSourceVideoModes * Signature: (I)[Ljava/lang/Object; */ JNIEXPORT jobjectArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_enumerateSourceVideoModes +Java_edu_wpi_first_cscore_CameraServerJNI_enumerateSourceVideoModes (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -925,12 +925,12 @@ Java_edu_wpi_cscore_CameraServerJNI_enumerateSourceVideoModes } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: enumerateSourceSinks * Signature: (I)[I */ JNIEXPORT jintArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_enumerateSourceSinks +Java_edu_wpi_first_cscore_CameraServerJNI_enumerateSourceSinks (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -943,12 +943,12 @@ Java_edu_wpi_cscore_CameraServerJNI_enumerateSourceSinks } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: copySource * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_copySource +Java_edu_wpi_first_cscore_CameraServerJNI_copySource (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -958,12 +958,12 @@ Java_edu_wpi_cscore_CameraServerJNI_copySource } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: releaseSource * Signature: (I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_releaseSource +Java_edu_wpi_first_cscore_CameraServerJNI_releaseSource (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -972,12 +972,12 @@ Java_edu_wpi_cscore_CameraServerJNI_releaseSource } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setCameraBrightness * Signature: (II)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setCameraBrightness +Java_edu_wpi_first_cscore_CameraServerJNI_setCameraBrightness (JNIEnv* env, jclass, jint source, jint brightness) { CS_Status status = 0; @@ -986,12 +986,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setCameraBrightness } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getCameraBrightness * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getCameraBrightness +Java_edu_wpi_first_cscore_CameraServerJNI_getCameraBrightness (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1001,12 +1001,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getCameraBrightness } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setCameraWhiteBalanceAuto * Signature: (I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setCameraWhiteBalanceAuto +Java_edu_wpi_first_cscore_CameraServerJNI_setCameraWhiteBalanceAuto (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1015,12 +1015,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setCameraWhiteBalanceAuto } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setCameraWhiteBalanceHoldCurrent * Signature: (I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setCameraWhiteBalanceHoldCurrent +Java_edu_wpi_first_cscore_CameraServerJNI_setCameraWhiteBalanceHoldCurrent (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1029,12 +1029,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setCameraWhiteBalanceHoldCurrent } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setCameraWhiteBalanceManual * Signature: (II)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setCameraWhiteBalanceManual +Java_edu_wpi_first_cscore_CameraServerJNI_setCameraWhiteBalanceManual (JNIEnv* env, jclass, jint source, jint value) { CS_Status status = 0; @@ -1043,12 +1043,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setCameraWhiteBalanceManual } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setCameraExposureAuto * Signature: (I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setCameraExposureAuto +Java_edu_wpi_first_cscore_CameraServerJNI_setCameraExposureAuto (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1057,12 +1057,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setCameraExposureAuto } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setCameraExposureHoldCurrent * Signature: (I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setCameraExposureHoldCurrent +Java_edu_wpi_first_cscore_CameraServerJNI_setCameraExposureHoldCurrent (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1071,12 +1071,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setCameraExposureHoldCurrent } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setCameraExposureManual * Signature: (II)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setCameraExposureManual +Java_edu_wpi_first_cscore_CameraServerJNI_setCameraExposureManual (JNIEnv* env, jclass, jint source, jint value) { CS_Status status = 0; @@ -1085,12 +1085,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setCameraExposureManual } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setUsbCameraPath * Signature: (ILjava/lang/String;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setUsbCameraPath +Java_edu_wpi_first_cscore_CameraServerJNI_setUsbCameraPath (JNIEnv* env, jclass, jint source, jstring path) { CS_Status status = 0; @@ -1099,12 +1099,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setUsbCameraPath } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getUsbCameraPath * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getUsbCameraPath +Java_edu_wpi_first_cscore_CameraServerJNI_getUsbCameraPath (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1116,12 +1116,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getUsbCameraPath } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getUsbCameraInfo * Signature: (I)Ljava/lang/Object; */ JNIEXPORT jobject JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getUsbCameraInfo +Java_edu_wpi_first_cscore_CameraServerJNI_getUsbCameraInfo (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1133,12 +1133,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getUsbCameraInfo } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getHttpCameraKind * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getHttpCameraKind +Java_edu_wpi_first_cscore_CameraServerJNI_getHttpCameraKind (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1150,12 +1150,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getHttpCameraKind } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setHttpCameraUrls * Signature: (I[Ljava/lang/Object;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setHttpCameraUrls +Java_edu_wpi_first_cscore_CameraServerJNI_setHttpCameraUrls (JNIEnv* env, jclass, jint source, jobjectArray urls) { if (!urls) { @@ -1180,12 +1180,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setHttpCameraUrls } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getHttpCameraUrls * Signature: (I)[Ljava/lang/Object; */ JNIEXPORT jobjectArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getHttpCameraUrls +Java_edu_wpi_first_cscore_CameraServerJNI_getHttpCameraUrls (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1197,12 +1197,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getHttpCameraUrls } /* - * Class: edu_wpi_cscore_CameraServerCvJNI + * Class: edu_wpi_first_cscore_CameraServerCvJNI * Method: putSourceFrame * Signature: (IJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerCvJNI_putSourceFrame +Java_edu_wpi_first_cscore_CameraServerCvJNI_putSourceFrame (JNIEnv* env, jclass, jint source, jlong imageNativeObj) { try { @@ -1220,12 +1220,12 @@ Java_edu_wpi_cscore_CameraServerCvJNI_putSourceFrame // int width, int height, int pixelFormat, int totalData /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: putRawSourceFrameBB * Signature: (ILjava/lang/Object;IIII)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_putRawSourceFrameBB +Java_edu_wpi_first_cscore_CameraServerJNI_putRawSourceFrameBB (JNIEnv* env, jclass, jint source, jobject byteBuffer, jint width, jint height, jint pixelFormat, jint totalData) { @@ -1242,12 +1242,12 @@ Java_edu_wpi_cscore_CameraServerJNI_putRawSourceFrameBB } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: putRawSourceFrame * Signature: (IJIIII)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_putRawSourceFrame +Java_edu_wpi_first_cscore_CameraServerJNI_putRawSourceFrame (JNIEnv* env, jclass, jint source, jlong ptr, jint width, jint height, jint pixelFormat, jint totalData) { @@ -1263,12 +1263,12 @@ Java_edu_wpi_cscore_CameraServerJNI_putRawSourceFrame } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: notifySourceError * Signature: (ILjava/lang/String;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_notifySourceError +Java_edu_wpi_first_cscore_CameraServerJNI_notifySourceError (JNIEnv* env, jclass, jint source, jstring msg) { if (!msg) { @@ -1281,12 +1281,12 @@ Java_edu_wpi_cscore_CameraServerJNI_notifySourceError } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSourceConnected * Signature: (IZ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSourceConnected +Java_edu_wpi_first_cscore_CameraServerJNI_setSourceConnected (JNIEnv* env, jclass, jint source, jboolean connected) { CS_Status status = 0; @@ -1295,12 +1295,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourceConnected } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSourceDescription * Signature: (ILjava/lang/String;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSourceDescription +Java_edu_wpi_first_cscore_CameraServerJNI_setSourceDescription (JNIEnv* env, jclass, jint source, jstring description) { if (!description) { @@ -1313,12 +1313,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourceDescription } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createSourceProperty * Signature: (ILjava/lang/String;IIIIII)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_createSourceProperty +Java_edu_wpi_first_cscore_CameraServerJNI_createSourceProperty (JNIEnv* env, jclass, jint source, jstring name, jint kind, jint minimum, jint maximum, jint step, jint defaultValue, jint value) { @@ -1331,12 +1331,12 @@ Java_edu_wpi_cscore_CameraServerJNI_createSourceProperty } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSourceEnumPropertyChoices * Signature: (II[Ljava/lang/Object;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSourceEnumPropertyChoices +Java_edu_wpi_first_cscore_CameraServerJNI_setSourceEnumPropertyChoices (JNIEnv* env, jclass, jint source, jint property, jobjectArray choices) { if (!choices) { @@ -1361,12 +1361,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSourceEnumPropertyChoices } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createMjpegServer * Signature: (Ljava/lang/String;Ljava/lang/String;I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_createMjpegServer +Java_edu_wpi_first_cscore_CameraServerJNI_createMjpegServer (JNIEnv* env, jclass, jstring name, jstring listenAddress, jint port) { if (!name) { @@ -1386,12 +1386,12 @@ Java_edu_wpi_cscore_CameraServerJNI_createMjpegServer } /* - * Class: edu_wpi_cscore_CameraServerCvJNI + * Class: edu_wpi_first_cscore_CameraServerCvJNI * Method: createCvSink * Signature: (Ljava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerCvJNI_createCvSink +Java_edu_wpi_first_cscore_CameraServerCvJNI_createCvSink (JNIEnv* env, jclass, jstring name) { if (!name) { @@ -1405,12 +1405,12 @@ Java_edu_wpi_cscore_CameraServerCvJNI_createCvSink } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createRawSink * Signature: (Ljava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_createRawSink +Java_edu_wpi_first_cscore_CameraServerJNI_createRawSink (JNIEnv* env, jclass, jstring name) { if (!name) { @@ -1424,12 +1424,12 @@ Java_edu_wpi_cscore_CameraServerJNI_createRawSink } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSinkKind * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSinkKind +Java_edu_wpi_first_cscore_CameraServerJNI_getSinkKind (JNIEnv* env, jclass, jint sink) { CS_Status status = 0; @@ -1439,12 +1439,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkKind } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSinkName * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSinkName +Java_edu_wpi_first_cscore_CameraServerJNI_getSinkName (JNIEnv* env, jclass, jint sink) { CS_Status status = 0; @@ -1457,12 +1457,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkName } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSinkDescription * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSinkDescription +Java_edu_wpi_first_cscore_CameraServerJNI_getSinkDescription (JNIEnv* env, jclass, jint sink) { CS_Status status = 0; @@ -1475,12 +1475,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkDescription } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSinkProperty * Signature: (ILjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSinkProperty +Java_edu_wpi_first_cscore_CameraServerJNI_getSinkProperty (JNIEnv* env, jclass, jint sink, jstring name) { if (!name) { @@ -1494,12 +1494,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkProperty } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: enumerateSinkProperties * Signature: (I)[I */ JNIEXPORT jintArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_enumerateSinkProperties +Java_edu_wpi_first_cscore_CameraServerJNI_enumerateSinkProperties (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1512,12 +1512,12 @@ Java_edu_wpi_cscore_CameraServerJNI_enumerateSinkProperties } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSinkConfigJson * Signature: (ILjava/lang/String;)Z */ JNIEXPORT jboolean JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSinkConfigJson +Java_edu_wpi_first_cscore_CameraServerJNI_setSinkConfigJson (JNIEnv* env, jclass, jint source, jstring config) { CS_Status status = 0; @@ -1527,12 +1527,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSinkConfigJson } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSinkConfigJson * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSinkConfigJson +Java_edu_wpi_first_cscore_CameraServerJNI_getSinkConfigJson (JNIEnv* env, jclass, jint source) { CS_Status status = 0; @@ -1542,12 +1542,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkConfigJson } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSinkSource * Signature: (II)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSinkSource +Java_edu_wpi_first_cscore_CameraServerJNI_setSinkSource (JNIEnv* env, jclass, jint sink, jint source) { CS_Status status = 0; @@ -1556,12 +1556,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSinkSource } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSinkSourceProperty * Signature: (ILjava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSinkSourceProperty +Java_edu_wpi_first_cscore_CameraServerJNI_getSinkSourceProperty (JNIEnv* env, jclass, jint sink, jstring name) { if (!name) { @@ -1576,12 +1576,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkSourceProperty } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSinkSource * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSinkSource +Java_edu_wpi_first_cscore_CameraServerJNI_getSinkSource (JNIEnv* env, jclass, jint sink) { CS_Status status = 0; @@ -1591,12 +1591,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkSource } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: copySink * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_copySink +Java_edu_wpi_first_cscore_CameraServerJNI_copySink (JNIEnv* env, jclass, jint sink) { CS_Status status = 0; @@ -1606,12 +1606,12 @@ Java_edu_wpi_cscore_CameraServerJNI_copySink } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: releaseSink * Signature: (I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_releaseSink +Java_edu_wpi_first_cscore_CameraServerJNI_releaseSink (JNIEnv* env, jclass, jint sink) { CS_Status status = 0; @@ -1620,12 +1620,12 @@ Java_edu_wpi_cscore_CameraServerJNI_releaseSink } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getMjpegServerListenAddress * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getMjpegServerListenAddress +Java_edu_wpi_first_cscore_CameraServerJNI_getMjpegServerListenAddress (JNIEnv* env, jclass, jint sink) { CS_Status status = 0; @@ -1637,12 +1637,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getMjpegServerListenAddress } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getMjpegServerPort * Signature: (I)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getMjpegServerPort +Java_edu_wpi_first_cscore_CameraServerJNI_getMjpegServerPort (JNIEnv* env, jclass, jint sink) { CS_Status status = 0; @@ -1652,12 +1652,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getMjpegServerPort } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSinkDescription * Signature: (ILjava/lang/String;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSinkDescription +Java_edu_wpi_first_cscore_CameraServerJNI_setSinkDescription (JNIEnv* env, jclass, jint sink, jstring description) { if (!description) { @@ -1670,12 +1670,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSinkDescription } /* - * Class: edu_wpi_cscore_CameraServerCvJNI + * Class: edu_wpi_first_cscore_CameraServerCvJNI * Method: grabSinkFrame * Signature: (IJ)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_cscore_CameraServerCvJNI_grabSinkFrame +Java_edu_wpi_first_cscore_CameraServerCvJNI_grabSinkFrame (JNIEnv* env, jclass, jint sink, jlong imageNativeObj) { try { @@ -1694,12 +1694,12 @@ Java_edu_wpi_cscore_CameraServerCvJNI_grabSinkFrame } /* - * Class: edu_wpi_cscore_CameraServerCvJNI + * Class: edu_wpi_first_cscore_CameraServerCvJNI * Method: grabSinkFrameTimeout * Signature: (IJD)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_cscore_CameraServerCvJNI_grabSinkFrameTimeout +Java_edu_wpi_first_cscore_CameraServerCvJNI_grabSinkFrameTimeout (JNIEnv* env, jclass, jint sink, jlong imageNativeObj, jdouble timeout) { try { @@ -1735,12 +1735,12 @@ static void SetRawFrameData(JNIEnv* env, jobject rawFrameObj, } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: grabRawSinkFrameImpl * Signature: (ILjava/lang/Object;JLjava/lang/Object;III)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_cscore_CameraServerJNI_grabRawSinkFrameImpl +Java_edu_wpi_first_cscore_CameraServerJNI_grabRawSinkFrameImpl (JNIEnv* env, jclass, jint sink, jobject rawFrameObj, jlong rawFramePtr, jobject byteBuffer, jint width, jint height, jint pixelFormat) { @@ -1760,12 +1760,12 @@ Java_edu_wpi_cscore_CameraServerJNI_grabRawSinkFrameImpl } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: grabRawSinkFrameTimeoutImpl * Signature: (ILjava/lang/Object;JLjava/lang/Object;IIID)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_cscore_CameraServerJNI_grabRawSinkFrameTimeoutImpl +Java_edu_wpi_first_cscore_CameraServerJNI_grabRawSinkFrameTimeoutImpl (JNIEnv* env, jclass, jint sink, jobject rawFrameObj, jlong rawFramePtr, jobject byteBuffer, jint width, jint height, jint pixelFormat, jdouble timeout) @@ -1787,12 +1787,12 @@ Java_edu_wpi_cscore_CameraServerJNI_grabRawSinkFrameTimeoutImpl } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getSinkError * Signature: (I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getSinkError +Java_edu_wpi_first_cscore_CameraServerJNI_getSinkError (JNIEnv* env, jclass, jint sink) { CS_Status status = 0; @@ -1805,12 +1805,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getSinkError } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setSinkEnabled * Signature: (IZ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setSinkEnabled +Java_edu_wpi_first_cscore_CameraServerJNI_setSinkEnabled (JNIEnv* env, jclass, jint sink, jboolean enabled) { CS_Status status = 0; @@ -1819,12 +1819,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setSinkEnabled } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: addListener * Signature: (Ljava/lang/Object;IZ)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_addListener +Java_edu_wpi_first_cscore_CameraServerJNI_addListener (JNIEnv* envouter, jclass, jobject listener, jint eventMask, jboolean immediateNotify) { @@ -1883,12 +1883,12 @@ Java_edu_wpi_cscore_CameraServerJNI_addListener } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: removeListener * Signature: (I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_removeListener +Java_edu_wpi_first_cscore_CameraServerJNI_removeListener (JNIEnv* env, jclass, jint handle) { CS_Status status = 0; @@ -1897,36 +1897,36 @@ Java_edu_wpi_cscore_CameraServerJNI_removeListener } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: createListenerPoller * Signature: ()I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_createListenerPoller +Java_edu_wpi_first_cscore_CameraServerJNI_createListenerPoller (JNIEnv*, jclass) { return cs::CreateListenerPoller(); } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: destroyListenerPoller * Signature: (I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_destroyListenerPoller +Java_edu_wpi_first_cscore_CameraServerJNI_destroyListenerPoller (JNIEnv*, jclass, jint poller) { cs::DestroyListenerPoller(poller); } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: addPolledListener * Signature: (IIZ)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_cscore_CameraServerJNI_addPolledListener +Java_edu_wpi_first_cscore_CameraServerJNI_addPolledListener (JNIEnv* env, jclass, jint poller, jint eventMask, jboolean immediateNotify) { CS_Status status = 0; @@ -1936,12 +1936,12 @@ Java_edu_wpi_cscore_CameraServerJNI_addPolledListener } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: pollListener * Signature: (I)[Ljava/lang/Object; */ JNIEXPORT jobjectArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_pollListener +Java_edu_wpi_first_cscore_CameraServerJNI_pollListener (JNIEnv* env, jclass, jint poller) { auto events = cs::PollListener(poller); @@ -1953,12 +1953,12 @@ Java_edu_wpi_cscore_CameraServerJNI_pollListener } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: pollListenerTimeout * Signature: (ID)[Ljava/lang/Object; */ JNIEXPORT jobjectArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_pollListenerTimeout +Java_edu_wpi_first_cscore_CameraServerJNI_pollListenerTimeout (JNIEnv* env, jclass, jint poller, jdouble timeout) { bool timed_out = false; @@ -1971,48 +1971,48 @@ Java_edu_wpi_cscore_CameraServerJNI_pollListenerTimeout } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: cancelPollListener * Signature: (I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_cancelPollListener +Java_edu_wpi_first_cscore_CameraServerJNI_cancelPollListener (JNIEnv*, jclass, jint poller) { cs::CancelPollListener(poller); } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setTelemetryPeriod * Signature: (D)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setTelemetryPeriod +Java_edu_wpi_first_cscore_CameraServerJNI_setTelemetryPeriod (JNIEnv* env, jclass, jdouble seconds) { cs::SetTelemetryPeriod(seconds); } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getTelemetryElapsedTime * Signature: ()D */ JNIEXPORT jdouble JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getTelemetryElapsedTime +Java_edu_wpi_first_cscore_CameraServerJNI_getTelemetryElapsedTime (JNIEnv* env, jclass) { return cs::GetTelemetryElapsedTime(); } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getTelemetryValue * Signature: (II)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getTelemetryValue +Java_edu_wpi_first_cscore_CameraServerJNI_getTelemetryValue (JNIEnv* env, jclass, jint handle, jint kind) { CS_Status status = 0; @@ -2023,12 +2023,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getTelemetryValue } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getTelemetryAverageValue * Signature: (II)D */ JNIEXPORT jdouble JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getTelemetryAverageValue +Java_edu_wpi_first_cscore_CameraServerJNI_getTelemetryAverageValue (JNIEnv* env, jclass, jint handle, jint kind) { CS_Status status = 0; @@ -2039,12 +2039,12 @@ Java_edu_wpi_cscore_CameraServerJNI_getTelemetryAverageValue } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: enumerateUsbCameras * Signature: ()[Ljava/lang/Object; */ JNIEXPORT jobjectArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_enumerateUsbCameras +Java_edu_wpi_first_cscore_CameraServerJNI_enumerateUsbCameras (JNIEnv* env, jclass) { CS_Status status = 0; @@ -2065,12 +2065,12 @@ Java_edu_wpi_cscore_CameraServerJNI_enumerateUsbCameras } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: enumerateSources * Signature: ()[I */ JNIEXPORT jintArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_enumerateSources +Java_edu_wpi_first_cscore_CameraServerJNI_enumerateSources (JNIEnv* env, jclass) { CS_Status status = 0; @@ -2083,12 +2083,12 @@ Java_edu_wpi_cscore_CameraServerJNI_enumerateSources } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: enumerateSinks * Signature: ()[I */ JNIEXPORT jintArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_enumerateSinks +Java_edu_wpi_first_cscore_CameraServerJNI_enumerateSinks (JNIEnv* env, jclass) { CS_Status status = 0; @@ -2101,24 +2101,24 @@ Java_edu_wpi_cscore_CameraServerJNI_enumerateSinks } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getHostname * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getHostname +Java_edu_wpi_first_cscore_CameraServerJNI_getHostname (JNIEnv* env, jclass) { return MakeJString(env, cs::GetHostname()); } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: getNetworkInterfaces * Signature: ()[Ljava/lang/Object; */ JNIEXPORT jobjectArray JNICALL -Java_edu_wpi_cscore_CameraServerJNI_getNetworkInterfaces +Java_edu_wpi_first_cscore_CameraServerJNI_getNetworkInterfaces (JNIEnv* env, jclass) { return MakeJStringArray(env, cs::GetNetworkInterfaces()); @@ -2158,12 +2158,12 @@ typedef JSingletonCallbackManager LoggerJNI; extern "C" { /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: setLogger * Signature: (Ljava/lang/Object;I)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_setLogger +Java_edu_wpi_first_cscore_CameraServerJNI_setLogger (JNIEnv* env, jclass, jobject func, jint minLevel) { if (!func) { @@ -2196,12 +2196,12 @@ Java_edu_wpi_cscore_CameraServerJNI_setLogger } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: allocateRawFrame * Signature: ()J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_cscore_CameraServerJNI_allocateRawFrame +Java_edu_wpi_first_cscore_CameraServerJNI_allocateRawFrame (JNIEnv*, jclass) { cs::RawFrame* rawFrame = new cs::RawFrame{}; @@ -2210,12 +2210,12 @@ Java_edu_wpi_cscore_CameraServerJNI_allocateRawFrame } /* - * Class: edu_wpi_cscore_CameraServerJNI + * Class: edu_wpi_first_cscore_CameraServerJNI * Method: freeRawFrame * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_cscore_CameraServerJNI_freeRawFrame +Java_edu_wpi_first_cscore_CameraServerJNI_freeRawFrame (JNIEnv*, jclass, jlong rawFrame) { cs::RawFrame* ptr = diff --git a/cscore/src/main/native/windows/UsbCameraImpl.cpp b/cscore/src/main/native/windows/UsbCameraImpl.cpp index 91944a34bd..10ce8d982a 100644 --- a/cscore/src/main/native/windows/UsbCameraImpl.cpp +++ b/cscore/src/main/native/windows/UsbCameraImpl.cpp @@ -293,32 +293,45 @@ void UsbCameraImpl::ProcessFrame(IMFSample* videoSample, return; } - bool lock2d = false; BYTE* ptr = NULL; LONG pitch = 0; - DWORD maxsize = 0, cursize = 0; + DWORD length = 0; - // "For 2-D buffers, the Lock2D method is more efficient than the Lock - // method" see IMFMediaBuffer::Lock method documentation: - // https://msdn.microsoft.com/en-us/library/windows/desktop/bb970366(v=vs.85).aspx - ComPtr buffer2d; - DWORD memLength2d = 0; - if (true) { - buffer2d = buf.As(); - if (buffer2d) { - buffer2d->GetContiguousLength(&memLength2d); - if (SUCCEEDED(buffer2d->Lock2D(&ptr, &pitch))) { - lock2d = true; + // First try to access using Lock2DSize, then try Lock2D, then fallback + // https://docs.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfmediabuffer-lock + + ComPtr buffer2d = buf.As(); + if (buffer2d) { + BYTE* scanline0 = nullptr; + HRESULT result; + ComPtr buffer2d2 = buf.As(); + if (buffer2d2) { + BYTE* datastart; + result = buffer2d2->Lock2DSize(MF2DBuffer_LockFlags_Read, &scanline0, + &pitch, &datastart, &length); + } else { + result = buffer2d->Lock2D(&scanline0, &pitch); + } + if (SUCCEEDED(result)) { + BOOL isContiguous; + if (pitch > 0 && SUCCEEDED(buffer2d->IsContiguousFormat(&isContiguous)) && + isContiguous && + (length || SUCCEEDED(buffer2d->GetContiguousLength(&length)))) { + // Use the buffer pointer. + ptr = scanline0; + } else { + // Release the buffer and fall back to Lock(). + buffer2d->Unlock2D(); } } } if (ptr == NULL) { - if (!SUCCEEDED(buf->Lock(&ptr, &maxsize, &cursize))) { + buffer2d = nullptr; + DWORD maxsize = 0; + if (!SUCCEEDED(buf->Lock(&ptr, &maxsize, &length))) { return; } } - if (!ptr) - return; cv::Mat tmpMat; std::unique_ptr dest; @@ -328,7 +341,7 @@ void UsbCameraImpl::ProcessFrame(IMFSample* videoSample, case cs::VideoMode::PixelFormat::kMJPEG: { // Special case PutFrame(VideoMode::kMJPEG, mode.width, mode.height, - wpi::StringRef(reinterpret_cast(ptr), cursize), + wpi::StringRef(reinterpret_cast(ptr), length), wpi::Now()); doFinalSet = false; break; @@ -360,10 +373,11 @@ void UsbCameraImpl::ProcessFrame(IMFSample* videoSample, PutFrame(std::move(dest), wpi::Now()); } - if (lock2d) + if (buffer2d) { buffer2d->Unlock2D(); - else + } else { buf->Unlock(); + } } LRESULT UsbCameraImpl::PumpMain(HWND hwnd, UINT uiMsg, WPARAM wParam, diff --git a/cscore/src/test/java/edu/wpi/cscore/JNITest.java b/cscore/src/test/java/edu/wpi/first/cscore/JNITest.java similarity index 92% rename from cscore/src/test/java/edu/wpi/cscore/JNITest.java rename to cscore/src/test/java/edu/wpi/first/cscore/JNITest.java index 11f93f881f..40e2584a98 100644 --- a/cscore/src/test/java/edu/wpi/cscore/JNITest.java +++ b/cscore/src/test/java/edu/wpi/first/cscore/JNITest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; import org.junit.jupiter.api.Test; diff --git a/cscore/src/test/java/edu/wpi/cscore/UsbCameraTest.java b/cscore/src/test/java/edu/wpi/first/cscore/UsbCameraTest.java similarity index 98% rename from cscore/src/test/java/edu/wpi/cscore/UsbCameraTest.java rename to cscore/src/test/java/edu/wpi/first/cscore/UsbCameraTest.java index 13a68d00db..8a790fa788 100644 --- a/cscore/src/test/java/edu/wpi/cscore/UsbCameraTest.java +++ b/cscore/src/test/java/edu/wpi/first/cscore/UsbCameraTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.cscore; +package edu.wpi.first.cscore; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; diff --git a/glass/src/app/native/mac/glass.icns b/glass/src/app/native/mac/glass.icns index 1204734761..74b6850595 100644 Binary files a/glass/src/app/native/mac/glass.icns and b/glass/src/app/native/mac/glass.icns differ diff --git a/glass/src/libnt/native/cpp/NetworkTables.cpp b/glass/src/libnt/native/cpp/NetworkTables.cpp index 7a1c6b7ed1..cea8be538f 100644 --- a/glass/src/libnt/native/cpp/NetworkTables.cpp +++ b/glass/src/libnt/native/cpp/NetworkTables.cpp @@ -741,30 +741,20 @@ void glass::DisplayNetworkTables(NetworkTablesModel* model, ImGui::Columns(); } -void NetworkTablesView::Display() { - auto& storage = GetStorage(); - auto pTreeView = - storage.GetBoolRef("tree", m_defaultFlags & NetworkTablesFlags_TreeView); - auto pShowConnections = storage.GetBoolRef( - "connections", m_defaultFlags & NetworkTablesFlags_ShowConnections); - auto pShowFlags = storage.GetBoolRef( - "flags", m_defaultFlags & NetworkTablesFlags_ShowFlags); - auto pShowTimestamp = storage.GetBoolRef( - "timestamp", m_defaultFlags & NetworkTablesFlags_ShowTimestamp); - auto pCreateNoncanonicalKeys = storage.GetBoolRef( - "createNonCanonical", - m_defaultFlags & NetworkTablesFlags_CreateNoncanonicalKeys); - - if (ImGui::BeginPopupContextItem()) { - ImGui::MenuItem("Tree View", "", pTreeView); - ImGui::MenuItem("Show Connections", "", pShowConnections); - ImGui::MenuItem("Show Flags", "", pShowFlags); - ImGui::MenuItem("Show Timestamp", "", pShowTimestamp); - ImGui::Separator(); - ImGui::MenuItem("Allow creation of non-canonical keys", "", - pCreateNoncanonicalKeys); - - ImGui::EndPopup(); +void NetworkTablesFlagsSettings::Update() { + if (!m_pTreeView) { + auto& storage = GetStorage(); + m_pTreeView = storage.GetBoolRef( + "tree", m_defaultFlags & NetworkTablesFlags_TreeView); + m_pShowConnections = storage.GetBoolRef( + "connections", m_defaultFlags & NetworkTablesFlags_ShowConnections); + m_pShowFlags = storage.GetBoolRef( + "flags", m_defaultFlags & NetworkTablesFlags_ShowFlags); + m_pShowTimestamp = storage.GetBoolRef( + "timestamp", m_defaultFlags & NetworkTablesFlags_ShowTimestamp); + m_pCreateNoncanonicalKeys = storage.GetBoolRef( + "createNonCanonical", + m_defaultFlags & NetworkTablesFlags_CreateNoncanonicalKeys); } m_flags &= @@ -772,11 +762,32 @@ void NetworkTablesView::Display() { NetworkTablesFlags_ShowFlags | NetworkTablesFlags_ShowTimestamp | NetworkTablesFlags_CreateNoncanonicalKeys); m_flags |= - (*pTreeView ? NetworkTablesFlags_TreeView : 0) | - (*pShowConnections ? NetworkTablesFlags_ShowConnections : 0) | - (*pShowFlags ? NetworkTablesFlags_ShowFlags : 0) | - (*pShowTimestamp ? NetworkTablesFlags_ShowTimestamp : 0) | - (*pCreateNoncanonicalKeys ? NetworkTablesFlags_CreateNoncanonicalKeys - : 0); - DisplayNetworkTables(m_model, m_flags); + (*m_pTreeView ? NetworkTablesFlags_TreeView : 0) | + (*m_pShowConnections ? NetworkTablesFlags_ShowConnections : 0) | + (*m_pShowFlags ? NetworkTablesFlags_ShowFlags : 0) | + (*m_pShowTimestamp ? NetworkTablesFlags_ShowTimestamp : 0) | + (*m_pCreateNoncanonicalKeys ? NetworkTablesFlags_CreateNoncanonicalKeys + : 0); +} + +void NetworkTablesFlagsSettings::DisplayMenu() { + if (!m_pTreeView) { + return; + } + ImGui::MenuItem("Tree View", "", m_pTreeView); + ImGui::MenuItem("Show Connections", "", m_pShowConnections); + ImGui::MenuItem("Show Flags", "", m_pShowFlags); + ImGui::MenuItem("Show Timestamp", "", m_pShowTimestamp); + ImGui::Separator(); + ImGui::MenuItem("Allow creation of non-canonical keys", "", + m_pCreateNoncanonicalKeys); +} + +void NetworkTablesView::Display() { + m_flags.Update(); + if (ImGui::BeginPopupContextItem()) { + m_flags.DisplayMenu(); + ImGui::EndPopup(); + } + DisplayNetworkTables(m_model, m_flags.GetFlags()); } diff --git a/glass/src/libnt/native/include/glass/networktables/NetworkTables.h b/glass/src/libnt/native/include/glass/networktables/NetworkTables.h index f515764f42..e7dbbece83 100644 --- a/glass/src/libnt/native/include/glass/networktables/NetworkTables.h +++ b/glass/src/libnt/native/include/glass/networktables/NetworkTables.h @@ -104,19 +104,39 @@ void DisplayNetworkTables( NetworkTablesModel* model, NetworkTablesFlags flags = NetworkTablesFlags_Default); +class NetworkTablesFlagsSettings { + public: + explicit NetworkTablesFlagsSettings( + NetworkTablesFlags defaultFlags = NetworkTablesFlags_Default) + : m_defaultFlags{defaultFlags}, m_flags{defaultFlags} {} + + void Update(); + void DisplayMenu(); + + NetworkTablesFlags GetFlags() const { return m_flags; } + + private: + bool* m_pTreeView = nullptr; + bool* m_pShowConnections = nullptr; + bool* m_pShowFlags = nullptr; + bool* m_pShowTimestamp = nullptr; + bool* m_pCreateNoncanonicalKeys = nullptr; + NetworkTablesFlags m_defaultFlags; // NOLINT + NetworkTablesFlags m_flags; // NOLINT +}; + class NetworkTablesView : public View { public: explicit NetworkTablesView( NetworkTablesModel* model, NetworkTablesFlags defaultFlags = NetworkTablesFlags_Default) - : m_model{model}, m_defaultFlags{defaultFlags}, m_flags{defaultFlags} {} + : m_model{model}, m_flags{defaultFlags} {} void Display() override; private: NetworkTablesModel* m_model; - NetworkTablesFlags m_defaultFlags; - NetworkTablesFlags m_flags; + NetworkTablesFlagsSettings m_flags; }; } // namespace glass diff --git a/hal/src/main/java/edu/wpi/first/hal/HAL.java b/hal/src/main/java/edu/wpi/first/hal/HAL.java index fb51ac02a4..6fd6910aab 100644 --- a/hal/src/main/java/edu/wpi/first/hal/HAL.java +++ b/hal/src/main/java/edu/wpi/first/hal/HAL.java @@ -28,7 +28,36 @@ public final class HAL extends JNIWrapper { private static native void simPeriodicBeforeNative(); - public static final List s_simPeriodicBefore = new ArrayList<>(); + private static final List s_simPeriodicBefore = new ArrayList<>(); + + public static class SimPeriodicBeforeCallback implements AutoCloseable { + private SimPeriodicBeforeCallback(Runnable r) { + m_run = r; + } + + @Override + public void close() { + synchronized (s_simPeriodicBefore) { + s_simPeriodicBefore.remove(m_run); + } + } + + private final Runnable m_run; + } + + /** + * Registers a callback to be run by IterativeRobotBase prior to the user's simulationPeriodic + * code. + * + * @param r runnable + * @return Callback object (must be retained for callback to stay active). + */ + public static SimPeriodicBeforeCallback registerSimPeriodicBeforeCallback(Runnable r) { + synchronized (s_simPeriodicBefore) { + s_simPeriodicBefore.add(r); + } + return new SimPeriodicBeforeCallback(r); + } /** * Runs SimPeriodicBefore callbacks. IterativeRobotBase calls this prior to the user's @@ -45,7 +74,35 @@ public final class HAL extends JNIWrapper { private static native void simPeriodicAfterNative(); - public static final List s_simPeriodicAfter = new ArrayList<>(); + private static final List s_simPeriodicAfter = new ArrayList<>(); + + public static class SimPeriodicAfterCallback implements AutoCloseable { + private SimPeriodicAfterCallback(Runnable r) { + m_run = r; + } + + @Override + public void close() { + synchronized (s_simPeriodicAfter) { + s_simPeriodicAfter.remove(m_run); + } + } + + private final Runnable m_run; + } + + /** + * Registers a callback to be run by IterativeRobotBase after the user's simulationPeriodic code. + * + * @param r runnable + * @return Callback object (must be retained for callback to stay active). + */ + public static SimPeriodicAfterCallback registerSimPeriodicAfterCallback(Runnable r) { + synchronized (s_simPeriodicAfter) { + s_simPeriodicAfter.add(r); + } + return new SimPeriodicAfterCallback(r); + } /** * Runs SimPeriodicAfter callbacks. IterativeRobotBase calls this after the user's diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java b/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java index 36d3388000..33c1bac477 100644 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java @@ -47,17 +47,11 @@ public class SimDeviceDataJNI extends JNIWrapper { public static native int registerSimValueCreatedCallback( int device, SimValueCallback callback, boolean initialNotify); - public static native int registerSimValueCreatedCallback2( - int device, SimValueCallback2 callback, boolean initialNotify); - public static native void cancelSimValueCreatedCallback(int uid); public static native int registerSimValueChangedCallback( int handle, SimValueCallback callback, boolean initialNotify); - public static native int registerSimValueChangedCallback2( - int handle, SimValueCallback2 callback, boolean initialNotify); - public static native void cancelSimValueChangedCallback(int uid); /** @@ -69,7 +63,7 @@ public class SimDeviceDataJNI extends JNIWrapper { * @param initialNotify ignored (present for consistency) */ public static native int registerSimValueResetCallback( - int handle, SimValueCallback2 callback, boolean initialNotify); + int handle, SimValueCallback callback, boolean initialNotify); public static native void cancelSimValueResetCallback(int uid); diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback.java b/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback.java index c586210459..4f9da942cc 100644 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback.java +++ b/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback.java @@ -8,10 +8,10 @@ import edu.wpi.first.hal.HALValue; @FunctionalInterface public interface SimValueCallback { - void callback(String name, int handle, boolean readonly, HALValue value); + void callback(String name, int handle, int direction, HALValue value); default void callbackNative( - String name, int handle, boolean readonly, int type, long value1, double value2) { - callback(name, handle, readonly, HALValue.fromNative(type, value1, value2)); + String name, int handle, int direction, int type, long value1, double value2) { + callback(name, handle, direction, HALValue.fromNative(type, value1, value2)); } } diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback2.java b/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback2.java deleted file mode 100644 index f575c7f42c..0000000000 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback2.java +++ /dev/null @@ -1,17 +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 edu.wpi.first.hal.simulation; - -import edu.wpi.first.hal.HALValue; - -@FunctionalInterface -public interface SimValueCallback2 { - void callback(String name, int handle, int direction, HALValue value); - - default void callbackNative( - String name, int handle, int direction, int type, long value1, double value2) { - callback(name, handle, direction, HALValue.fromNative(type, value1, value2)); - } -} diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/SimulatorJNI.java b/hal/src/main/java/edu/wpi/first/hal/simulation/SimulatorJNI.java index f3c61d7634..3dfeb068a9 100644 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/SimulatorJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/simulation/SimulatorJNI.java @@ -4,7 +4,6 @@ package edu.wpi.first.hal.simulation; -import edu.wpi.first.hal.HAL; import edu.wpi.first.hal.JNIWrapper; public class SimulatorJNI extends JNIWrapper { @@ -29,48 +28,4 @@ public class SimulatorJNI extends JNIWrapper { public static native void stepTimingAsync(long delta); public static native void resetHandles(); - - public static class SimPeriodicBeforeCallback implements AutoCloseable { - private SimPeriodicBeforeCallback(Runnable r) { - m_run = r; - } - - @Override - public void close() { - synchronized (HAL.s_simPeriodicBefore) { - HAL.s_simPeriodicBefore.remove(m_run); - } - } - - private Runnable m_run; - } - - public static SimPeriodicBeforeCallback registerSimPeriodicBeforeCallback(Runnable r) { - synchronized (HAL.s_simPeriodicBefore) { - HAL.s_simPeriodicBefore.add(r); - } - return new SimPeriodicBeforeCallback(r); - } - - public static class SimPeriodicAfterCallback implements AutoCloseable { - private SimPeriodicAfterCallback(Runnable r) { - m_run = r; - } - - @Override - public void close() { - synchronized (HAL.s_simPeriodicAfter) { - HAL.s_simPeriodicAfter.remove(m_run); - } - } - - private Runnable m_run; - } - - public static SimPeriodicAfterCallback registerSimPeriodicAfterCallback(Runnable r) { - synchronized (HAL.s_simPeriodicAfter) { - HAL.s_simPeriodicAfter.add(r); - } - return new SimPeriodicAfterCallback(r); - } } diff --git a/hal/src/main/native/athena/AddressableLED.cpp b/hal/src/main/native/athena/AddressableLED.cpp index 39db71c039..864c08ce07 100644 --- a/hal/src/main/native/athena/AddressableLED.cpp +++ b/hal/src/main/native/athena/AddressableLED.cpp @@ -11,6 +11,7 @@ #include "ConstantsInternal.h" #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/AddressableLEDTypes.h" #include "hal/ChipObject.h" @@ -142,8 +143,11 @@ void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle, return; } - if (length > HAL_kAddressableLEDMaxLength) { + if (length > HAL_kAddressableLEDMaxLength || length < 0) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "LED length must be less than or equal to " + + wpi::Twine(HAL_kAddressableLEDMaxLength) + + ". " + wpi::Twine(length) + " was requested"); return; } @@ -173,8 +177,11 @@ void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle, return; } - if (length > led->stringLength) { + if (length > led->stringLength || length < 0) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Data length must be less than or equal to " + + wpi::Twine(led->stringLength) + ". " + + wpi::Twine(length) + " was requested"); return; } diff --git a/hal/src/main/native/athena/AnalogGyro.cpp b/hal/src/main/native/athena/AnalogGyro.cpp index b8f4add6e2..83bc42f0be 100644 --- a/hal/src/main/native/athena/AnalogGyro.cpp +++ b/hal/src/main/native/athena/AnalogGyro.cpp @@ -4,12 +4,14 @@ #include "hal/AnalogGyro.h" +#include #include #include #include "AnalogInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "hal/AnalogAccumulator.h" #include "hal/AnalogInput.h" #include "hal/handles/IndexedHandleResource.h" @@ -21,6 +23,7 @@ struct AnalogGyro { double voltsPerDegreePerSecond; double offset; int32_t center; + std::string previousAllocation; }; } // namespace @@ -55,36 +58,43 @@ static void Wait(double seconds) { extern "C" { HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analogHandle, + const char* allocationLocation, int32_t* status) { hal::init::CheckInit(); + // Handle will be type checked by HAL_IsAccumulatorChannel + int16_t channel = getHandleIndex(analogHandle); if (!HAL_IsAccumulatorChannel(analogHandle, status)) { if (*status == 0) { *status = HAL_INVALID_ACCUMULATOR_CHANNEL; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Gyro", + 0, kNumAccumulators, channel); } return HAL_kInvalidHandle; } - // handle known to be correct, so no need to type check - int16_t channel = getHandleIndex(analogHandle); - - auto handle = analogGyroHandles->Allocate(channel, status); + HAL_GyroHandle handle; + auto gyro = analogGyroHandles->Allocate(channel, &handle, status); if (*status != 0) { + if (gyro) { + hal::SetLastErrorPreviouslyAllocated(status, "Analog Gyro", channel, + gyro->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Gyro", + 0, kNumAccumulators, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } // Initialize port structure - auto gyro = analogGyroHandles->Get(handle); - if (gyro == nullptr) { // would only error on thread issue - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } gyro->handle = analogHandle; gyro->voltsPerDegreePerSecond = 0; gyro->offset = 0; gyro->center = 0; + gyro->previousAllocation = allocationLocation ? allocationLocation : ""; + return handle; } diff --git a/hal/src/main/native/athena/AnalogInput.cpp b/hal/src/main/native/athena/AnalogInput.cpp index 4fd77a654d..6b3add10e9 100644 --- a/hal/src/main/native/athena/AnalogInput.cpp +++ b/hal/src/main/native/athena/AnalogInput.cpp @@ -9,6 +9,7 @@ #include "AnalogInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/AnalogAccumulator.h" #include "hal/handles/HandlesInternal.h" @@ -21,8 +22,9 @@ using namespace hal; extern "C" { -HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle, - int32_t* status) { +HAL_AnalogInputHandle HAL_InitializeAnalogInputPort( + HAL_PortHandle portHandle, const char* allocationLocation, + int32_t* status) { hal::init::CheckInit(); initializeAnalog(status); @@ -31,23 +33,28 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle, } int16_t channel = getPortHandleChannel(portHandle); - if (channel == InvalidHandleIndex) { - *status = PARAMETER_OUT_OF_RANGE; + if (channel == InvalidHandleIndex || channel >= kNumAnalogInputs) { + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input", + 0, kNumAnalogInputs, channel); return HAL_kInvalidHandle; } - HAL_AnalogInputHandle handle = analogInputHandles->Allocate(channel, status); + HAL_AnalogInputHandle handle; + auto analog_port = analogInputHandles->Allocate(channel, &handle, status); if (*status != 0) { + if (analog_port) { + hal::SetLastErrorPreviouslyAllocated(status, "Analog Input", channel, + analog_port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input", + 0, kNumAnalogInputs, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } // Initialize port structure - auto analog_port = analogInputHandles->Get(handle); - if (analog_port == nullptr) { // would only error on thread issue - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } analog_port->channel = static_cast(channel); if (HAL_IsAccumulatorChannel(handle, status)) { analog_port->accumulator.reset(tAccumulator::create(channel, status)); @@ -59,6 +66,8 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle, analogInputSystem->writeScanList(channel, channel, status); HAL_SetAnalogAverageBits(handle, kDefaultAverageBits, status); HAL_SetAnalogOversampleBits(handle, kDefaultOversampleBits, status); + analog_port->previousAllocation = + allocationLocation ? allocationLocation : ""; return handle; } diff --git a/hal/src/main/native/athena/AnalogInternal.h b/hal/src/main/native/athena/AnalogInternal.h index d3403648f0..431c6242b7 100644 --- a/hal/src/main/native/athena/AnalogInternal.h +++ b/hal/src/main/native/athena/AnalogInternal.h @@ -7,6 +7,7 @@ #include #include +#include #include @@ -31,6 +32,7 @@ extern bool analogSampleRateSet; struct AnalogPort { uint8_t channel; std::unique_ptr accumulator; + std::string previousAllocation; }; extern IndexedHandleResource + #include "AnalogInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/Errors.h" #include "hal/handles/HandlesInternal.h" @@ -17,6 +20,7 @@ namespace { struct AnalogOutput { uint8_t channel; + std::string previousAllocation; }; } // namespace @@ -36,8 +40,9 @@ void InitializeAnalogOutput() { extern "C" { -HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle, - int32_t* status) { +HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort( + HAL_PortHandle portHandle, const char* allocationLocation, + int32_t* status) { hal::init::CheckInit(); initializeAnalog(status); @@ -46,25 +51,31 @@ HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle, } int16_t channel = getPortHandleChannel(portHandle); - if (channel == InvalidHandleIndex) { - *status = PARAMETER_OUT_OF_RANGE; + if (channel == InvalidHandleIndex || channel >= kNumAnalogOutputs) { + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Output", + 0, kNumAnalogOutputs, channel); return HAL_kInvalidHandle; } - HAL_AnalogOutputHandle handle = - analogOutputHandles->Allocate(channel, status); + HAL_AnalogOutputHandle handle; + auto port = analogOutputHandles->Allocate(channel, &handle, status); if (*status != 0) { + if (port) { + hal::SetLastErrorPreviouslyAllocated(status, "Analog Output", channel, + port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, + "Invalid Index for Analog Output", 0, + kNumAnalogOutputs, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - auto port = analogOutputHandles->Get(handle); - if (port == nullptr) { // would only error on thread issue - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - port->channel = static_cast(channel); + port->previousAllocation = allocationLocation ? allocationLocation : ""; + return handle; } diff --git a/hal/src/main/native/athena/AnalogTrigger.cpp b/hal/src/main/native/athena/AnalogTrigger.cpp index 7d438572e8..d9e2b9251c 100644 --- a/hal/src/main/native/athena/AnalogTrigger.cpp +++ b/hal/src/main/native/athena/AnalogTrigger.cpp @@ -7,6 +7,7 @@ #include "AnalogInternal.h" #include "DutyCycleInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/AnalogInput.h" #include "hal/DutyCycle.h" @@ -138,6 +139,11 @@ void HAL_SetAnalogTriggerLimitsDutyCycle( if (lower < 0.0 || upper > 1.0) { *status = PARAMETER_OUT_OF_RANGE; + auto lowerStr = std::to_string(lower); + auto upperStr = std::to_string(upper); + hal::SetLastError( + status, "Lower must be >= 0 and upper must be <=1. Requested lower " + + lowerStr + " Requested upper " + upperStr); return; } diff --git a/hal/src/main/native/athena/Counter.cpp b/hal/src/main/native/athena/Counter.cpp index 2605279ed3..d6a278ce74 100644 --- a/hal/src/main/native/athena/Counter.cpp +++ b/hal/src/main/native/athena/Counter.cpp @@ -7,6 +7,7 @@ #include "ConstantsInternal.h" #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/HAL.h" #include "hal/handles/LimitedHandleResource.h" @@ -146,6 +147,9 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle, // TODO: wpi_setWPIErrorWithContext(ParameterOutOfRange, "Counter only // supports DownSource in TwoPulse and ExternalDirection modes."); *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, + "Counter only supports DownSource in TwoPulse and " + "ExternalDirection mode."); return; } @@ -260,6 +264,11 @@ void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle, } if (samplesToAverage < 1 || samplesToAverage > 127) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError( + status, + "Samples to average must be between 1 and 127 inclusive. Requested " + + wpi::Twine(samplesToAverage)); + return; } counter->counter->writeTimerConfig_AverageSize(samplesToAverage, status); } diff --git a/hal/src/main/native/athena/DIO.cpp b/hal/src/main/native/athena/DIO.cpp index 23c5ab331b..75909a0702 100644 --- a/hal/src/main/native/athena/DIO.cpp +++ b/hal/src/main/native/athena/DIO.cpp @@ -11,6 +11,7 @@ #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/cpp/fpga_clock.h" #include "hal/handles/HandlesInternal.h" @@ -38,7 +39,9 @@ void InitializeDIO() { extern "C" { HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle, - HAL_Bool input, int32_t* status) { + HAL_Bool input, + const char* allocationLocation, + int32_t* status) { hal::init::CheckInit(); initializeDigital(status); @@ -48,23 +51,28 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle, int16_t channel = getPortHandleChannel(portHandle); if (channel == InvalidHandleIndex || channel >= kNumDigitalChannels) { - *status = PARAMETER_OUT_OF_RANGE; + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0, + kNumDigitalChannels, channel); return HAL_kInvalidHandle; } - auto handle = - digitalChannelHandles->Allocate(channel, HAL_HandleEnum::DIO, status); + HAL_DigitalHandle handle; + + auto port = digitalChannelHandles->Allocate(channel, HAL_HandleEnum::DIO, + &handle, status); if (*status != 0) { + if (port) { + hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel, + port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0, + kNumDigitalChannels, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::DIO); - if (port == nullptr) { // would only occur on thread issue. - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - port->channel = static_cast(channel); std::scoped_lock lock(digitalDIOMutex); @@ -114,6 +122,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle, } digitalSystem->writeOutputEnable(outputEnable, status); + port->previousAllocation = allocationLocation ? allocationLocation : ""; return handle; } @@ -191,8 +200,8 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) { if (*status != 0) { return; } - uint16_t pwmPeriodPower = static_cast( - std::log(1.0 / (16 * 1.0E-6 * rate)) / std::log(2.0) + 0.5); + uint16_t pwmPeriodPower = + std::lround(std::log(1.0 / (16 * 1.0E-6 * rate)) / std::log(2.0)); digitalSystem->writePWMPeriodPower(pwmPeriodPower, status); } diff --git a/hal/src/main/native/athena/DMA.cpp b/hal/src/main/native/athena/DMA.cpp index 31ca1c27bc..40eaca6f4b 100644 --- a/hal/src/main/native/athena/DMA.cpp +++ b/hal/src/main/native/athena/DMA.cpp @@ -13,6 +13,7 @@ #include "AnalogInternal.h" #include "DigitalInternal.h" #include "EncoderInternal.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/AnalogAccumulator.h" #include "hal/AnalogGyro.h" @@ -528,6 +529,9 @@ void HAL_SetDMAExternalTrigger(HAL_DMAHandle handle, if (!success) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, + "Digital Source unabled to be mapped properly. Likely " + "invalid handle passed."); return; } diff --git a/hal/src/main/native/athena/DigitalInternal.cpp b/hal/src/main/native/athena/DigitalInternal.cpp index d47cedfb45..c75c66b3ba 100644 --- a/hal/src/main/native/athena/DigitalInternal.cpp +++ b/hal/src/main/native/athena/DigitalInternal.cpp @@ -5,6 +5,7 @@ #include "DigitalInternal.h" #include +#include #include #include @@ -108,10 +109,10 @@ void initializeDigital(int32_t* status) { double loopTime = pwmSystem->readLoopTiming(status) / (kSystemClockTicksPerMicrosecond * 1e3); - pwmSystem->writeConfig_Period( - static_cast(kDefaultPwmPeriod / loopTime + 0.5), status); - uint16_t minHigh = static_cast( - (kDefaultPwmCenter - kDefaultPwmStepsDown * loopTime) / loopTime + 0.5); + pwmSystem->writeConfig_Period(std::lround(kDefaultPwmPeriod / loopTime), + status); + uint16_t minHigh = std::lround( + (kDefaultPwmCenter - kDefaultPwmStepsDown * loopTime) / loopTime); pwmSystem->writeConfig_MinHigh(minHigh, status); // Ensure that PWM output values are set to OFF for (uint8_t pwmIndex = 0; pwmIndex < kNumPWMChannels; pwmIndex++) { diff --git a/hal/src/main/native/athena/DigitalInternal.h b/hal/src/main/native/athena/DigitalInternal.h index 79656ad5e2..6b1e9097b8 100644 --- a/hal/src/main/native/athena/DigitalInternal.h +++ b/hal/src/main/native/athena/DigitalInternal.h @@ -7,6 +7,7 @@ #include #include +#include #include @@ -70,6 +71,7 @@ struct DigitalPort { int32_t centerPwm = 0; int32_t deadbandMinPwm = 0; int32_t minPwm = 0; + std::string previousAllocation; }; extern DigitalHandleResource(encodingType)) + + " invalid."); return; } } @@ -181,6 +185,10 @@ void Encoder::SetReverseDirection(bool reverseDirection, int32_t* status) { void Encoder::SetSamplesToAverage(int32_t samplesToAverage, int32_t* status) { if (samplesToAverage < 1 || samplesToAverage > 127) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError( + status, + "Samples to average must be between 1 and 127 inclusive. Requested " + + wpi::Twine(samplesToAverage)); return; } if (m_counter) { diff --git a/hal/src/main/native/athena/FPGAEncoder.cpp b/hal/src/main/native/athena/FPGAEncoder.cpp index 8709139924..3bfe9d9a41 100644 --- a/hal/src/main/native/athena/FPGAEncoder.cpp +++ b/hal/src/main/native/athena/FPGAEncoder.cpp @@ -8,6 +8,7 @@ #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/handles/LimitedHandleResource.h" @@ -193,6 +194,11 @@ void HAL_SetFPGAEncoderSamplesToAverage(HAL_FPGAEncoderHandle fpgaEncoderHandle, } if (samplesToAverage < 1 || samplesToAverage > 127) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError( + status, + "Samples to average must be between 1 and 127 inclusive. Requested " + + wpi::Twine(samplesToAverage)); + return; } encoder->encoder->writeTimerConfig_AverageSize(samplesToAverage, status); } diff --git a/hal/src/main/native/athena/HAL.cpp b/hal/src/main/native/athena/HAL.cpp index fcee49897f..eefe34c9a2 100644 --- a/hal/src/main/native/athena/HAL.cpp +++ b/hal/src/main/native/athena/HAL.cpp @@ -233,6 +233,8 @@ const char* HAL_GetErrorMessage(int32_t code) { return HAL_CAN_BUFFER_OVERRUN_MESSAGE; case HAL_LED_CHANNEL_ERROR: return HAL_LED_CHANNEL_ERROR_MESSAGE; + case HAL_USE_LAST_ERROR: + return HAL_USE_LAST_ERROR_MESSAGE; default: return "Unknown error status"; } diff --git a/hal/src/main/native/athena/HALInternal.h b/hal/src/main/native/athena/HALInternal.h index b9f284ff6a..b1a2d1dfd5 100644 --- a/hal/src/main/native/athena/HALInternal.h +++ b/hal/src/main/native/athena/HALInternal.h @@ -6,7 +6,15 @@ #include +#include + namespace hal { void ReleaseFPGAInterrupt(int32_t interruptNumber); - +void SetLastError(int32_t* status, const wpi::Twine& value); +void SetLastErrorIndexOutOfRange(int32_t* status, const wpi::Twine& message, + int32_t minimum, int32_t maximum, + int32_t channel); +void SetLastErrorPreviouslyAllocated(int32_t* status, const wpi::Twine& message, + int32_t channel, + const wpi::Twine& previousAllocation); } // namespace hal diff --git a/hal/src/main/native/athena/I2C.cpp b/hal/src/main/native/athena/I2C.cpp index 17d6e9fbb3..9af13ed46f 100644 --- a/hal/src/main/native/athena/I2C.cpp +++ b/hal/src/main/native/athena/I2C.cpp @@ -67,11 +67,11 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) { return; } if ((i2CMXPDigitalHandle1 = HAL_InitializeDIOPort( - HAL_GetPort(24), false, status)) == HAL_kInvalidHandle) { + HAL_GetPort(24), false, nullptr, status)) == HAL_kInvalidHandle) { return; } if ((i2CMXPDigitalHandle2 = HAL_InitializeDIOPort( - HAL_GetPort(25), false, status)) == HAL_kInvalidHandle) { + HAL_GetPort(25), false, nullptr, status)) == HAL_kInvalidHandle) { HAL_FreeDIOPort(i2CMXPDigitalHandle1); // free the first port allocated return; } diff --git a/hal/src/main/native/athena/PDP.cpp b/hal/src/main/native/athena/PDP.cpp index 7db4dd2db5..0cdf30f831 100644 --- a/hal/src/main/native/athena/PDP.cpp +++ b/hal/src/main/native/athena/PDP.cpp @@ -7,6 +7,7 @@ #include #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/CANAPI.h" #include "hal/Errors.h" @@ -117,6 +118,7 @@ HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) { hal::init::CheckInit(); if (!HAL_CheckPDPModule(module)) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Invalid pdp module " + wpi::Twine(module)); return HAL_kInvalidHandle; } @@ -192,6 +194,7 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel, int32_t* status) { if (!HAL_CheckPDPChannel(channel)) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Invalid pdp channel " + wpi::Twine(channel)); return 0; } diff --git a/hal/src/main/native/athena/PWM.cpp b/hal/src/main/native/athena/PWM.cpp index 873d447ee4..bf9773a6a2 100644 --- a/hal/src/main/native/athena/PWM.cpp +++ b/hal/src/main/native/athena/PWM.cpp @@ -12,6 +12,7 @@ #include "ConstantsInternal.h" #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/cpp/fpga_clock.h" #include "hal/handles/HandlesInternal.h" @@ -65,6 +66,7 @@ void InitializePWM() {} extern "C" { HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, + const char* allocationLocation, int32_t* status) { hal::init::CheckInit(); initializeDigital(status); @@ -75,7 +77,9 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, int16_t channel = getPortHandleChannel(portHandle); if (channel == InvalidHandleIndex || channel >= kNumPWMChannels) { - *status = PARAMETER_OUT_OF_RANGE; + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0, + kNumPWMChannels, channel); return HAL_kInvalidHandle; } @@ -87,19 +91,22 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, channel = remapMXPPWMChannel(channel) + 10; // remap MXP to proper channel } - auto handle = - digitalChannelHandles->Allocate(channel, HAL_HandleEnum::PWM, status); + HAL_DigitalHandle handle; + + auto port = digitalChannelHandles->Allocate(channel, HAL_HandleEnum::PWM, + &handle, status); if (*status != 0) { + if (port) { + hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel, + port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0, + kNumPWMChannels, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::PWM); - if (port == nullptr) { // would only occur on thread issue. - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - port->channel = origChannel; if (port->channel > tPWM::kNumHdrRegisters - 1) { @@ -113,6 +120,8 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, // Defaults to allow an always valid config. HAL_SetPWMConfig(handle, 2.0, 1.501, 1.5, 1.499, 1.0, status); + port->previousAllocation = allocationLocation ? allocationLocation : ""; + return handle; } void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status) { @@ -277,13 +286,13 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed, if (speed == 0.0) { rawValue = GetCenterPwm(dPort); } else if (speed > 0.0) { - rawValue = static_cast( - speed * static_cast(GetPositiveScaleFactor(dPort)) + - static_cast(GetMinPositivePwm(dPort)) + 0.5); + rawValue = + std::lround(speed * static_cast(GetPositiveScaleFactor(dPort)) + + static_cast(GetMinPositivePwm(dPort))); } else { - rawValue = static_cast( - speed * static_cast(GetNegativeScaleFactor(dPort)) + - static_cast(GetMaxNegativePwm(dPort)) + 0.5); + rawValue = + std::lround(speed * static_cast(GetNegativeScaleFactor(dPort)) + + static_cast(GetMaxNegativePwm(dPort))); } if (!((rawValue >= GetMinNegativePwm(dPort)) && diff --git a/hal/src/main/native/athena/Relay.cpp b/hal/src/main/native/athena/Relay.cpp index 368ce1b730..a01dd9d52b 100644 --- a/hal/src/main/native/athena/Relay.cpp +++ b/hal/src/main/native/athena/Relay.cpp @@ -4,8 +4,11 @@ #include "hal/Relay.h" +#include + #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/handles/IndexedHandleResource.h" @@ -16,6 +19,7 @@ namespace { struct Relay { uint8_t channel; bool fwd; + std::string previousAllocation; }; } // namespace @@ -38,6 +42,7 @@ void InitializeRelay() { extern "C" { HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, + const char* allocationLocation, int32_t* status) { hal::init::CheckInit(); initializeDigital(status); @@ -47,8 +52,10 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, } int16_t channel = getPortHandleChannel(portHandle); - if (channel == InvalidHandleIndex) { - *status = PARAMETER_OUT_OF_RANGE; + if (channel == InvalidHandleIndex || channel >= kNumRelayChannels) { + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Relay", 0, + kNumRelayChannels, channel); return HAL_kInvalidHandle; } @@ -56,18 +63,20 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, channel += kNumRelayHeaders; // add 4 to reverse channels } - auto handle = relayHandles->Allocate(channel, status); + HAL_RelayHandle handle; + auto port = relayHandles->Allocate(channel, &handle, status); if (*status != 0) { + if (port) { + hal::SetLastErrorPreviouslyAllocated(status, "Relay", channel, + port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Relay", 0, + kNumRelayChannels, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - auto port = relayHandles->Get(handle); - if (port == nullptr) { // would only occur on thread issue. - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - if (!fwd) { // Subtract number of headers to put channel in range channel -= kNumRelayHeaders; @@ -78,6 +87,7 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, } port->channel = static_cast(channel); + port->previousAllocation = allocationLocation ? allocationLocation : ""; return handle; } diff --git a/hal/src/main/native/athena/SPI.cpp b/hal/src/main/native/athena/SPI.cpp index a237f668ea..090c53378e 100644 --- a/hal/src/main/native/athena/SPI.cpp +++ b/hal/src/main/native/athena/SPI.cpp @@ -18,6 +18,7 @@ #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "hal/DIO.h" #include "hal/HAL.h" #include "hal/handles/HandlesInternal.h" @@ -75,14 +76,14 @@ static void CommonSPIPortInit(int32_t* status) { } // MISO if ((digitalHandles[3] = HAL_InitializeDIOPort(createPortHandleForSPI(29), - false, status)) == + false, nullptr, status)) == HAL_kInvalidHandle) { std::printf("Failed to allocate DIO 29 (MISO)\n"); return; } // MOSI if ((digitalHandles[4] = HAL_InitializeDIOPort(createPortHandleForSPI(30), - false, status)) == + false, nullptr, status)) == HAL_kInvalidHandle) { std::printf("Failed to allocate DIO 30 (MOSI)\n"); HAL_FreeDIOPort(digitalHandles[3]); // free the first port allocated @@ -103,6 +104,9 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) { hal::init::CheckInit(); if (port < 0 || port >= kSpiMaxHandles) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Serial port must be between 0 and " + + wpi::Twine(kSpiMaxHandles) + ". Requested " + + wpi::Twine(static_cast(port))); return; } @@ -133,7 +137,7 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) { } // CS1, Allocate if ((digitalHandles[0] = HAL_InitializeDIOPort(createPortHandleForSPI(26), - false, status)) == + false, nullptr, status)) == HAL_kInvalidHandle) { std::printf("Failed to allocate DIO 26 (CS1)\n"); CommonSPIPortFree(); @@ -156,7 +160,7 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) { } // CS2, Allocate if ((digitalHandles[1] = HAL_InitializeDIOPort(createPortHandleForSPI(27), - false, status)) == + false, nullptr, status)) == HAL_kInvalidHandle) { std::printf("Failed to allocate DIO 27 (CS2)\n"); CommonSPIPortFree(); @@ -179,7 +183,7 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) { } // CS3, Allocate if ((digitalHandles[2] = HAL_InitializeDIOPort(createPortHandleForSPI(28), - false, status)) == + false, nullptr, status)) == HAL_kInvalidHandle) { std::printf("Failed to allocate DIO 28 (CS3)\n"); CommonSPIPortFree(); @@ -201,20 +205,20 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) { return; } if ((digitalHandles[5] = HAL_InitializeDIOPort(createPortHandleForSPI(14), - false, status)) == + false, nullptr, status)) == HAL_kInvalidHandle) { wpi::outs() << "Failed to allocate DIO 14\n"; return; } if ((digitalHandles[6] = HAL_InitializeDIOPort(createPortHandleForSPI(15), - false, status)) == + false, nullptr, status)) == HAL_kInvalidHandle) { wpi::outs() << "Failed to allocate DIO 15\n"; HAL_FreeDIOPort(digitalHandles[5]); // free the first port allocated return; } if ((digitalHandles[7] = HAL_InitializeDIOPort(createPortHandleForSPI(16), - false, status)) == + false, nullptr, status)) == HAL_kInvalidHandle) { wpi::outs() << "Failed to allocate DIO 16\n"; HAL_FreeDIOPort(digitalHandles[5]); // free the first port allocated @@ -222,7 +226,7 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) { return; } if ((digitalHandles[8] = HAL_InitializeDIOPort(createPortHandleForSPI(17), - false, status)) == + false, nullptr, status)) == HAL_kInvalidHandle) { wpi::outs() << "Failed to allocate DIO 17\n"; HAL_FreeDIOPort(digitalHandles[5]); // free the first port allocated @@ -246,6 +250,8 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) { break; default: *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError( + status, "Invalid SPI port " + wpi::Twine(static_cast(port))); break; } } @@ -374,6 +380,9 @@ void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst, void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) { if (port < 0 || port >= kSpiMaxHandles) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Serial port must be between 0 and " + + wpi::Twine(kSpiMaxHandles) + ". Requested " + + wpi::Twine(static_cast(port))); return; } @@ -389,6 +398,9 @@ void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) { void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status) { if (port < 0 || port >= kSpiMaxHandles) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Serial port must be between 0 and " + + wpi::Twine(kSpiMaxHandles) + ". Requested " + + wpi::Twine(static_cast(port))); return; } @@ -453,6 +465,9 @@ void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle) { void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t* status) { if (port < 0 || port >= kSpiMaxHandles) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Serial port must be between 0 and " + + wpi::Twine(kSpiMaxHandles) + ". Requested " + + wpi::Twine(static_cast(port))); return; } @@ -484,6 +499,9 @@ void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t* status) { void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t* status) { if (port < 0 || port >= kSpiMaxHandles) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Serial port must be between 0 and " + + wpi::Twine(kSpiMaxHandles) + ". Requested " + + wpi::Twine(static_cast(port))); return; } @@ -586,11 +604,17 @@ void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend, int32_t* status) { if (dataSize < 0 || dataSize > 32) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError( + status, "Data size must be between 0 and 32 inclusive. Requested " + + wpi::Twine(dataSize)); return; } if (zeroSize < 0 || zeroSize > 127) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError( + status, "Zero size must be between 0 and 127 inclusive. Requested " + + wpi::Twine(zeroSize)); return; } diff --git a/hal/src/main/native/athena/SerialPort.cpp b/hal/src/main/native/athena/SerialPort.cpp index 27f17397ed..dfacbecc7c 100644 --- a/hal/src/main/native/athena/SerialPort.cpp +++ b/hal/src/main/native/athena/SerialPort.cpp @@ -19,6 +19,7 @@ #include #include +#include "HALInternal.h" #include "hal/cpp/SerialHelper.h" #include "hal/handles/HandlesInternal.h" #include "hal/handles/IndexedHandleResource.h" @@ -70,19 +71,14 @@ HAL_SerialPortHandle HAL_InitializeSerialPort(HAL_SerialPort port, HAL_SerialPortHandle HAL_InitializeSerialPortDirect(HAL_SerialPort port, const char* portName, int32_t* status) { - auto handle = serialPortHandles->Allocate(static_cast(port), status); + HAL_SerialPortHandle handle; + auto serialPort = + serialPortHandles->Allocate(static_cast(port), &handle, status); if (*status != 0) { return HAL_kInvalidHandle; } - auto serialPort = serialPortHandles->Get(handle); - - if (serialPort == nullptr) { - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - serialPort->portId = open(portName, O_RDWR | O_NOCTTY); if (serialPort->portId < 0) { *status = errno; @@ -188,6 +184,7 @@ void HAL_SetSerialBaudRate(HAL_SerialPortHandle handle, int32_t baud, BAUDCASE(4000000) default: *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Invalid BaudRate: " + wpi::Twine(baud)); return; } int err = cfsetospeed(&port->tty, static_cast(port->baudRate)); @@ -230,6 +227,7 @@ void HAL_SetSerialDataBits(HAL_SerialPortHandle handle, int32_t bits, break; default: *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Invalid data bits: " + wpi::Twine(bits)); return; } @@ -277,6 +275,7 @@ void HAL_SetSerialParity(HAL_SerialPortHandle handle, int32_t parity, break; default: *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Invalid parity bits: " + wpi::Twine(parity)); return; } @@ -304,6 +303,7 @@ void HAL_SetSerialStopBits(HAL_SerialPortHandle handle, int32_t stopBits, break; default: *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Invalid stop bits: " + wpi::Twine(stopBits)); return; } @@ -339,6 +339,7 @@ void HAL_SetSerialFlowControl(HAL_SerialPortHandle handle, int32_t flow, break; default: *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Invalid fc bits: " + wpi::Twine(flow)); return; } diff --git a/hal/src/main/native/athena/Solenoid.cpp b/hal/src/main/native/athena/Solenoid.cpp index 669b87674f..b12d8bf1a7 100644 --- a/hal/src/main/native/athena/Solenoid.cpp +++ b/hal/src/main/native/athena/Solenoid.cpp @@ -60,16 +60,12 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle, return HAL_kInvalidHandle; } - auto handle = solenoidHandles->Allocate( - module * kNumSolenoidChannels + channel, status); + HAL_SolenoidHandle handle; + auto solenoidPort = solenoidHandles->Allocate( + module * kNumSolenoidChannels + channel, &handle, status); if (*status != 0) { return HAL_kInvalidHandle; } - auto solenoidPort = solenoidHandles->Get(handle); - if (solenoidPort == nullptr) { // would only occur on thread issues - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } solenoidPort->module = static_cast(module); solenoidPort->channel = static_cast(channel); diff --git a/hal/src/main/native/cpp/ErrorHandling.cpp b/hal/src/main/native/cpp/ErrorHandling.cpp new file mode 100644 index 0000000000..fa54e4676e --- /dev/null +++ b/hal/src/main/native/cpp/ErrorHandling.cpp @@ -0,0 +1,61 @@ +// 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 +#include + +#include "hal/Errors.h" +#include "hal/HALBase.h" + +namespace { +struct LastErrorStorage { + int32_t status; + wpi::SmallString<512> message; +}; +} // namespace + +static LastErrorStorage& GetThreadLastError() { + thread_local LastErrorStorage lastError; + return lastError; +} + +namespace hal { +void SetLastError(int32_t* status, const wpi::Twine& value) { + LastErrorStorage& lastError = GetThreadLastError(); + lastError.message.clear(); + value.toVector(lastError.message); + lastError.status = *status; + *status = HAL_USE_LAST_ERROR; +} + +void SetLastErrorIndexOutOfRange(int32_t* status, const wpi::Twine& message, + int32_t minimum, int32_t maximum, + int32_t requested) { + SetLastError(status, message + "\n Status: " + wpi::Twine(*status) + + "\n Minimum: " + wpi::Twine(minimum) + + " Maximum: " + wpi::Twine(maximum) + + " Reequested: " + wpi::Twine(requested)); +} + +void SetLastErrorPreviouslyAllocated(int32_t* status, const wpi::Twine& message, + int32_t channel, + const wpi::Twine& previousAllocation) { + hal::SetLastError( + status, + message + " " + wpi::Twine(channel) + + " previously allocated.\nLocation of the previous allocation:\n" + + previousAllocation + "\nLocation of the current allocation:"); +} +} // namespace hal + +extern "C" { +const char* HAL_GetLastError(int32_t* status) { + if (*status == HAL_USE_LAST_ERROR) { + LastErrorStorage& lastError = GetThreadLastError(); + *status = lastError.status; + return lastError.message.c_str(); + } + return HAL_GetErrorMessage(*status); +} +} // extern "C" diff --git a/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp b/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp index 8a6b131837..154301f8e7 100644 --- a/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp +++ b/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp @@ -6,6 +6,8 @@ #include +#include + #include "HALUtil.h" #include "edu_wpi_first_hal_AnalogGyroJNI.h" #include "hal/AnalogGyro.h" @@ -24,8 +26,9 @@ Java_edu_wpi_first_hal_AnalogGyroJNI_initializeAnalogGyro (JNIEnv* env, jclass, jint id) { int32_t status = 0; - HAL_GyroHandle handle = - HAL_InitializeAnalogGyro((HAL_AnalogInputHandle)id, &status); + auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first"); + HAL_GyroHandle handle = HAL_InitializeAnalogGyro((HAL_AnalogInputHandle)id, + stack.c_str(), &status); // Analog input does range checking, so we don't need to do so. CheckStatusForceThrow(env, status); return (jint)handle; diff --git a/hal/src/main/native/cpp/jni/AnalogJNI.cpp b/hal/src/main/native/cpp/jni/AnalogJNI.cpp index 04ec3a405e..5f0abce6be 100644 --- a/hal/src/main/native/cpp/jni/AnalogJNI.cpp +++ b/hal/src/main/native/cpp/jni/AnalogJNI.cpp @@ -6,6 +6,8 @@ #include +#include + #include "HALUtil.h" #include "edu_wpi_first_hal_AnalogJNI.h" #include "hal/AnalogAccumulator.h" @@ -29,9 +31,10 @@ Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogInputPort (JNIEnv* env, jclass, jint id) { int32_t status = 0; - auto analog = HAL_InitializeAnalogInputPort((HAL_PortHandle)id, &status); - CheckStatusRange(env, status, 0, HAL_GetNumAnalogInputs(), - hal::getPortHandleChannel((HAL_PortHandle)id)); + auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first"); + auto analog = + HAL_InitializeAnalogInputPort((HAL_PortHandle)id, stack.c_str(), &status); + CheckStatusForceThrow(env, status); return (jint)analog; } @@ -57,10 +60,10 @@ Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogOutputPort (JNIEnv* env, jclass, jint id) { int32_t status = 0; - HAL_AnalogOutputHandle analog = - HAL_InitializeAnalogOutputPort((HAL_PortHandle)id, &status); - CheckStatusRange(env, status, 0, HAL_GetNumAnalogOutputs(), - hal::getPortHandleChannel((HAL_PortHandle)id)); + auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first"); + HAL_AnalogOutputHandle analog = HAL_InitializeAnalogOutputPort( + (HAL_PortHandle)id, stack.c_str(), &status); + CheckStatusForceThrow(env, status); return (jlong)analog; } diff --git a/hal/src/main/native/cpp/jni/CounterJNI.cpp b/hal/src/main/native/cpp/jni/CounterJNI.cpp index 07718a6cd5..0565d5b847 100644 --- a/hal/src/main/native/cpp/jni/CounterJNI.cpp +++ b/hal/src/main/native/cpp/jni/CounterJNI.cpp @@ -119,12 +119,6 @@ Java_edu_wpi_first_hal_CounterJNI_setCounterDownSource HAL_SetCounterDownSource((HAL_CounterHandle)id, (HAL_Handle)digitalSourceHandle, (HAL_AnalogTriggerType)analogTriggerType, &status); - if (status == PARAMETER_OUT_OF_RANGE) { - ThrowIllegalArgumentException(env, - "Counter only supports DownSource in " - "TwoPulse and ExternalDirection modes."); - return; - } CheckStatus(env, status); } @@ -240,10 +234,6 @@ Java_edu_wpi_first_hal_CounterJNI_setCounterSamplesToAverage { int32_t status = 0; HAL_SetCounterSamplesToAverage((HAL_CounterHandle)id, value, &status); - if (status == PARAMETER_OUT_OF_RANGE) { - ThrowBoundaryException(env, value, 1, 127); - return; - } CheckStatus(env, status); } diff --git a/hal/src/main/native/cpp/jni/DIOJNI.cpp b/hal/src/main/native/cpp/jni/DIOJNI.cpp index 5dc59c8bda..236754169e 100644 --- a/hal/src/main/native/cpp/jni/DIOJNI.cpp +++ b/hal/src/main/native/cpp/jni/DIOJNI.cpp @@ -6,6 +6,8 @@ #include +#include + #include "HALUtil.h" #include "edu_wpi_first_hal_DIOJNI.h" #include "hal/DIO.h" @@ -27,10 +29,10 @@ Java_edu_wpi_first_hal_DIOJNI_initializeDIOPort (JNIEnv* env, jclass, jint id, jboolean input) { int32_t status = 0; - auto dio = HAL_InitializeDIOPort((HAL_PortHandle)id, - static_cast(input), &status); - CheckStatusRange(env, status, 0, HAL_GetNumDigitalChannels(), - hal::getPortHandleChannel((HAL_PortHandle)id)); + auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first"); + auto dio = HAL_InitializeDIOPort( + (HAL_PortHandle)id, static_cast(input), stack.c_str(), &status); + CheckStatusForceThrow(env, status); return (jint)dio; } diff --git a/hal/src/main/native/cpp/jni/EncoderJNI.cpp b/hal/src/main/native/cpp/jni/EncoderJNI.cpp index 80673ab49e..f93e064ac4 100644 --- a/hal/src/main/native/cpp/jni/EncoderJNI.cpp +++ b/hal/src/main/native/cpp/jni/EncoderJNI.cpp @@ -267,10 +267,6 @@ Java_edu_wpi_first_hal_EncoderJNI_setEncoderSamplesToAverage { int32_t status = 0; HAL_SetEncoderSamplesToAverage((HAL_EncoderHandle)id, value, &status); - if (status == PARAMETER_OUT_OF_RANGE) { - ThrowBoundaryException(env, value, 1, 127); - return; - } CheckStatus(env, status); } diff --git a/hal/src/main/native/cpp/jni/HALUtil.cpp b/hal/src/main/native/cpp/jni/HALUtil.cpp index fc37e9dd56..9894942f12 100644 --- a/hal/src/main/native/cpp/jni/HALUtil.cpp +++ b/hal/src/main/native/cpp/jni/HALUtil.cpp @@ -83,20 +83,18 @@ void ThrowUncleanStatusException(JNIEnv* env, wpi::StringRef msg, env->Throw(static_cast(exception)); } -void ThrowAllocationException(JNIEnv* env, int32_t minRange, int32_t maxRange, - int32_t requestedValue, int32_t status) { - const char* message = HAL_GetErrorMessage(status); +void ThrowAllocationException(JNIEnv* env, const char* lastError, + int32_t status) { wpi::SmallString<1024> buf; wpi::raw_svector_ostream oss(buf); - oss << " Code: " << status << ". " << message - << ", Minimum Value: " << minRange << ", Maximum Value: " << maxRange - << ", Requested Value: " << requestedValue; - env->ThrowNew(allocationExCls, buf.c_str()); + + oss << "Code: " << status << '\n' << lastError; + allocationExCls.Throw(env, buf.c_str()); } void ThrowHalHandleException(JNIEnv* env, int32_t status) { - const char* message = HAL_GetErrorMessage(status); + const char* message = HAL_GetLastError(&status); wpi::SmallString<1024> buf; wpi::raw_svector_ostream oss(buf); oss << " Code: " << status << ". " << message; @@ -107,10 +105,11 @@ void ReportError(JNIEnv* env, int32_t status, bool doThrow) { if (status == 0) { return; } + const char* message = HAL_GetLastError(&status); if (status == HAL_HANDLE_ERROR) { ThrowHalHandleException(env, status); + return; } - const char* message = HAL_GetErrorMessage(status); if (doThrow && status < 0) { wpi::SmallString<1024> buf; wpi::raw_svector_ostream oss(buf); @@ -119,7 +118,11 @@ void ReportError(JNIEnv* env, int32_t status, bool doThrow) { } else { std::string func; auto stack = GetJavaStackTrace(env, &func, "edu.wpi.first"); - HAL_SendError(1, status, 0, message, func.c_str(), stack.c_str(), 1); + // Make a copy of message for safety, calling back into the HAL might + // invalidate the string. + wpi::SmallString<256> lastMessage{wpi::StringRef{message}}; + HAL_SendError(1, status, 0, lastMessage.c_str(), func.c_str(), + stack.c_str(), 1); } } @@ -128,17 +131,19 @@ void ThrowError(JNIEnv* env, int32_t status, int32_t minRange, int32_t maxRange, if (status == 0) { return; } + const char* lastError = HAL_GetLastError(&status); if (status == NO_AVAILABLE_RESOURCES || status == RESOURCE_IS_ALLOCATED || status == RESOURCE_OUT_OF_RANGE) { - ThrowAllocationException(env, minRange, maxRange, requestedValue, status); + ThrowAllocationException(env, lastError, status); + return; } if (status == HAL_HANDLE_ERROR) { ThrowHalHandleException(env, status); + return; } - const char* message = HAL_GetErrorMessage(status); wpi::SmallString<1024> buf; wpi::raw_svector_ostream oss(buf); - oss << " Code: " << status << ". " << message; + oss << " Code: " << status << ". " << lastError; ThrowUncleanStatusException(env, buf.c_str(), status); } diff --git a/hal/src/main/native/cpp/jni/PWMJNI.cpp b/hal/src/main/native/cpp/jni/PWMJNI.cpp index 5099dba7d9..e83f11bcdf 100644 --- a/hal/src/main/native/cpp/jni/PWMJNI.cpp +++ b/hal/src/main/native/cpp/jni/PWMJNI.cpp @@ -6,6 +6,8 @@ #include +#include + #include "HALUtil.h" #include "edu_wpi_first_hal_PWMJNI.h" #include "hal/DIO.h" @@ -27,9 +29,9 @@ Java_edu_wpi_first_hal_PWMJNI_initializePWMPort (JNIEnv* env, jclass, jint id) { int32_t status = 0; - auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, &status); - CheckStatusRange(env, status, 0, HAL_GetNumPWMChannels(), - hal::getPortHandleChannel((HAL_PortHandle)id)); + auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first"); + auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, stack.c_str(), &status); + CheckStatusForceThrow(env, status); return (jint)pwm; } diff --git a/hal/src/main/native/cpp/jni/RelayJNI.cpp b/hal/src/main/native/cpp/jni/RelayJNI.cpp index 0bb7fa45e8..9e31a9da10 100644 --- a/hal/src/main/native/cpp/jni/RelayJNI.cpp +++ b/hal/src/main/native/cpp/jni/RelayJNI.cpp @@ -6,6 +6,8 @@ #include +#include + #include "HALUtil.h" #include "edu_wpi_first_hal_RelayJNI.h" #include "hal/Ports.h" @@ -26,10 +28,10 @@ Java_edu_wpi_first_hal_RelayJNI_initializeRelayPort (JNIEnv* env, jclass, jint id, jboolean fwd) { int32_t status = 0; + auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first"); HAL_RelayHandle handle = HAL_InitializeRelayPort( - (HAL_PortHandle)id, static_cast(fwd), &status); - CheckStatusRange(env, status, 0, HAL_GetNumRelayChannels(), - hal::getPortHandleChannel((HAL_PortHandle)id)); + (HAL_PortHandle)id, static_cast(fwd), stack.c_str(), &status); + CheckStatusForceThrow(env, status); return (jint)handle; } diff --git a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp index 5f02ebcbc1..a07e8af15c 100644 --- a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp +++ b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp @@ -109,8 +109,6 @@ class DeviceCallbackStore { class ValueCallbackStore { public: - explicit ValueCallbackStore(bool dirCallback) : m_dirCallback{dirCallback} {} - void create(JNIEnv* env, jobject obj) { m_call = JGlobal(env, obj); } void performCallback(const char* name, HAL_SimValueHandle handle, int32_t direction, const HAL_Value& value); @@ -121,7 +119,6 @@ class ValueCallbackStore { private: wpi::java::JGlobal m_call; int32_t m_callbackId; - bool m_dirCallback; }; } // namespace @@ -181,17 +178,9 @@ void ValueCallbackStore::performCallback(const char* name, } auto [value1, value2] = ToValue12(value); - if (m_dirCallback) { - env->CallVoidMethod(m_call, simValueCallbackCallback, - MakeJString(env, name), static_cast(handle), - static_cast(direction), - static_cast(value.type), value1, value2); - } else { - env->CallVoidMethod(m_call, simValueCallbackCallback, - MakeJString(env, name), static_cast(handle), - static_cast(direction == HAL_SimValueOutput), - static_cast(value.type), value1, value2); - } + env->CallVoidMethod(m_call, simValueCallbackCallback, MakeJString(env, name), + static_cast(handle), static_cast(direction), + static_cast(value.type), value1, value2); if (env->ExceptionCheck()) { env->ExceptionDescribe(); @@ -266,12 +255,11 @@ using FreeValueCallbackFunc = void (*)(int32_t uid); template static SIM_JniHandle AllocateValueCallback( - JNIEnv* env, THandle h, jobject callback, bool dirCallback, - jboolean initialNotify, + JNIEnv* env, THandle h, jobject callback, jboolean initialNotify, int32_t (*createCallback)(THandle handle, void* param, HALSIM_SimValueCallback callback, HAL_Bool initialNotify)) { - auto callbackStore = std::make_shared(dirCallback); + auto callbackStore = std::make_shared(); auto handle = valueCallbackHandles->Allocate(callbackStore); @@ -345,7 +333,7 @@ bool InitializeSimDeviceDataJNI(JNIEnv* env) { } simValueCallbackCallback = env->GetMethodID( - simValueCallbackCls, "callbackNative", "(Ljava/lang/String;IZIJD)V"); + simValueCallbackCls, "callbackNative", "(Ljava/lang/String;IIIJD)V"); if (!simValueCallbackCallback) { return false; } @@ -530,21 +518,7 @@ Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueCreatedCallba (JNIEnv* env, jclass, jint device, jobject callback, jboolean initialNotify) { return AllocateValueCallback(env, static_cast(device), - callback, false, initialNotify, - &HALSIM_RegisterSimValueCreatedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI - * Method: registerSimValueCreatedCallback2 - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueCreatedCallback2 - (JNIEnv* env, jclass, jint device, jobject callback, jboolean initialNotify) -{ - return AllocateValueCallback(env, static_cast(device), - callback, true, initialNotify, + callback, initialNotify, &HALSIM_RegisterSimValueCreatedCallback); } @@ -570,21 +544,7 @@ Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueChangedCallba (JNIEnv* env, jclass, jint handle, jobject callback, jboolean initialNotify) { return AllocateValueCallback(env, static_cast(handle), - callback, false, initialNotify, - &HALSIM_RegisterSimValueChangedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI - * Method: registerSimValueChangedCallback2 - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueChangedCallback2 - (JNIEnv* env, jclass, jint handle, jobject callback, jboolean initialNotify) -{ - return AllocateValueCallback(env, static_cast(handle), - callback, true, initialNotify, + callback, initialNotify, &HALSIM_RegisterSimValueChangedCallback); } @@ -610,7 +570,7 @@ Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueResetCallback (JNIEnv* env, jclass, jint handle, jobject callback, jboolean initialNotify) { return AllocateValueCallback(env, static_cast(handle), - callback, true, initialNotify, + callback, initialNotify, &HALSIM_RegisterSimValueResetCallback); } diff --git a/hal/src/main/native/include/hal/AnalogGyro.h b/hal/src/main/native/include/hal/AnalogGyro.h index 79e0f7d16e..16171b1384 100644 --- a/hal/src/main/native/include/hal/AnalogGyro.h +++ b/hal/src/main/native/include/hal/AnalogGyro.h @@ -22,9 +22,12 @@ extern "C" { * Initializes an analog gyro. * * @param handle handle to the analog port + * @param allocationLocation the location where the allocation is occuring + * (can be null) * @return the initialized gyro handle */ HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle handle, + const char* allocationLocation, int32_t* status); /** diff --git a/hal/src/main/native/include/hal/AnalogInput.h b/hal/src/main/native/include/hal/AnalogInput.h index bcfc633000..8275ea26d1 100644 --- a/hal/src/main/native/include/hal/AnalogInput.h +++ b/hal/src/main/native/include/hal/AnalogInput.h @@ -22,10 +22,12 @@ extern "C" { * Initializes the analog input port using the given port object. * * @param portHandle Handle to the port to initialize. + * @param allocationLocation the location where the allocation is occuring + * (can be null) * @return the created analog input handle */ -HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle, - int32_t* status); +HAL_AnalogInputHandle HAL_InitializeAnalogInputPort( + HAL_PortHandle portHandle, const char* allocationLocation, int32_t* status); /** * Frees an analog input port. diff --git a/hal/src/main/native/include/hal/AnalogOutput.h b/hal/src/main/native/include/hal/AnalogOutput.h index b104315b39..ef013af95e 100644 --- a/hal/src/main/native/include/hal/AnalogOutput.h +++ b/hal/src/main/native/include/hal/AnalogOutput.h @@ -22,10 +22,12 @@ extern "C" { * Initializes the analog output port using the given port object. * * @param handle handle to the port + * @param allocationLocation the location where the allocation is occuring + * (can be null) * @return the created analog output handle */ -HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle, - int32_t* status); +HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort( + HAL_PortHandle portHandle, const char* allocationLocation, int32_t* status); /** * Frees an analog output port. diff --git a/hal/src/main/native/include/hal/DIO.h b/hal/src/main/native/include/hal/DIO.h index cdfdd354bd..306321478e 100644 --- a/hal/src/main/native/include/hal/DIO.h +++ b/hal/src/main/native/include/hal/DIO.h @@ -21,12 +21,16 @@ extern "C" { /** * Creates a new instance of a digital port. * - * @param portHandle the port handle to create from - * @param input true for input, false for output - * @return the created digital handle + * @param portHandle the port handle to create from + * @param input true for input, false for output + * @param allocationLocation the location where the allocation is occuring + * (can be null) + * @return the created digital handle */ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle, - HAL_Bool input, int32_t* status); + HAL_Bool input, + const char* allocationLocation, + int32_t* status); /** * Checks if a DIO channel is valid. diff --git a/hal/src/main/native/include/hal/Errors.h b/hal/src/main/native/include/hal/Errors.h index b2e4b081b0..6444ea6c9e 100644 --- a/hal/src/main/native/include/hal/Errors.h +++ b/hal/src/main/native/include/hal/Errors.h @@ -41,6 +41,8 @@ #define ERR_FRCSystem_NoDSConnection_MESSAGE \ "FRCSystem: No driver station connected" +#define HAL_SUCCESS 0 + #define SAMPLE_RATE_TOO_HIGH 1001 #define SAMPLE_RATE_TOO_HIGH_MESSAGE \ "HAL: Analog module sample rate is too high" @@ -125,6 +127,10 @@ #define HAL_SIM_NOT_SUPPORTED -1155 #define HAL_SIM_NOT_SUPPORTED_MESSAGE "HAL: Method not supported in sim" +#define HAL_USE_LAST_ERROR -1156 +#define HAL_USE_LAST_ERROR_MESSAGE \ + "HAL: Use HAL_GetLastError(status) to get last error" + #define HAL_CAN_BUFFER_OVERRUN -35007 #define HAL_CAN_BUFFER_OVERRUN_MESSAGE \ "HAL: CAN Output Buffer Full. Ensure a device is attached" diff --git a/hal/src/main/native/include/hal/HALBase.h b/hal/src/main/native/include/hal/HALBase.h index dbbf15d803..ce2a420711 100644 --- a/hal/src/main/native/include/hal/HALBase.h +++ b/hal/src/main/native/include/hal/HALBase.h @@ -22,6 +22,19 @@ HAL_ENUM(HAL_RuntimeType) { HAL_Athena, HAL_Mock }; extern "C" { #endif +/** + * Gets the last error set on this thread, or the message for the status code. + * + * If passed HAL_USE_LAST_ERROR, the last error set on the thread will be + * returned. + * + * @param code the status code, set to the error status code if input is + * HAL_USE_LAST_ERROR + * @return the error message for the code. This does not need to be freed, + * but can be overwritten by another hal call on the same thread. + */ +const char* HAL_GetLastError(int32_t* status); + /** * Gets the error message for a specific status code. * diff --git a/hal/src/main/native/include/hal/PWM.h b/hal/src/main/native/include/hal/PWM.h index e0fa945c44..04bfc4f73e 100644 --- a/hal/src/main/native/include/hal/PWM.h +++ b/hal/src/main/native/include/hal/PWM.h @@ -22,9 +22,12 @@ extern "C" { * Initializes a PWM port. * * @param portHandle the port to initialize + * @param allocationLocation the location where the allocation is occuring + * (can be null) * @return the created pwm handle */ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, + const char* allocationLocation, int32_t* status); /** diff --git a/hal/src/main/native/include/hal/Relay.h b/hal/src/main/native/include/hal/Relay.h index 5fa714ac9f..d59da0a669 100644 --- a/hal/src/main/native/include/hal/Relay.h +++ b/hal/src/main/native/include/hal/Relay.h @@ -26,9 +26,12 @@ extern "C" { * * @param portHandle the port handle to initialize * @param fwd true for the forward port, false for the reverse port + * @param allocationLocation the location where the allocation is occuring + * (can be null) * @return the created relay handle */ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, + const char* allocationLocation, int32_t* status); /** diff --git a/hal/src/main/native/include/hal/handles/DigitalHandleResource.h b/hal/src/main/native/include/hal/handles/DigitalHandleResource.h index 85a14a7d62..5154a43aad 100644 --- a/hal/src/main/native/include/hal/handles/DigitalHandleResource.h +++ b/hal/src/main/native/include/hal/handles/DigitalHandleResource.h @@ -22,7 +22,7 @@ namespace hal { * allows a limited number of handles that are allocated by index. * The enum value is separate, as 2 enum values are allowed per handle * Because they are allocated by index, each individual index holds its own - * mutex, which reduces contention heavily.] + * mutex, which reduces contention heavily. * * @tparam THandle The Handle Type (Must be typedefed from HAL_Handle) * @tparam TStruct The struct type held by this resource @@ -38,7 +38,8 @@ class DigitalHandleResource : public HandleBase { DigitalHandleResource(const DigitalHandleResource&) = delete; DigitalHandleResource& operator=(const DigitalHandleResource&) = delete; - THandle Allocate(int16_t index, HAL_HandleEnum enumValue, int32_t* status); + std::shared_ptr Allocate(int16_t index, HAL_HandleEnum enumValue, + THandle* handle, int32_t* status); int16_t GetIndex(THandle handle, HAL_HandleEnum enumValue) { return getHandleTypedIndex(handle, enumValue, m_version); } @@ -52,21 +53,27 @@ class DigitalHandleResource : public HandleBase { }; template -THandle DigitalHandleResource::Allocate( - int16_t index, HAL_HandleEnum enumValue, int32_t* status) { +std::shared_ptr +DigitalHandleResource::Allocate( + int16_t index, HAL_HandleEnum enumValue, THandle* handle, int32_t* status) { // don't acquire the lock if we can fail early. if (index < 0 || index >= size) { + *handle = HAL_kInvalidHandle; *status = RESOURCE_OUT_OF_RANGE; - return HAL_kInvalidHandle; + return nullptr; } std::scoped_lock lock(m_handleMutexes[index]); // check for allocation, otherwise allocate and return a valid handle if (m_structures[index] != nullptr) { + *handle = HAL_kInvalidHandle; *status = RESOURCE_IS_ALLOCATED; - return HAL_kInvalidHandle; + return m_structures[index]; } m_structures[index] = std::make_shared(); - return static_cast(hal::createHandle(index, enumValue, m_version)); + *handle = + static_cast(hal::createHandle(index, enumValue, m_version)); + *status = HAL_SUCCESS; + return m_structures[index]; } template diff --git a/hal/src/main/native/include/hal/handles/IndexedHandleResource.h b/hal/src/main/native/include/hal/handles/IndexedHandleResource.h index 2f158e1913..2e921eebcf 100644 --- a/hal/src/main/native/include/hal/handles/IndexedHandleResource.h +++ b/hal/src/main/native/include/hal/handles/IndexedHandleResource.h @@ -39,7 +39,8 @@ class IndexedHandleResource : public HandleBase { IndexedHandleResource(const IndexedHandleResource&) = delete; IndexedHandleResource& operator=(const IndexedHandleResource&) = delete; - THandle Allocate(int16_t index, int32_t* status); + std::shared_ptr Allocate(int16_t index, THandle* handle, + int32_t* status); int16_t GetIndex(THandle handle) { return getHandleTypedIndex(handle, enumValue, m_version); } @@ -54,21 +55,27 @@ class IndexedHandleResource : public HandleBase { template -THandle IndexedHandleResource::Allocate( - int16_t index, int32_t* status) { +std::shared_ptr +IndexedHandleResource::Allocate( + int16_t index, THandle* handle, int32_t* status) { // don't acquire the lock if we can fail early. if (index < 0 || index >= size) { *status = RESOURCE_OUT_OF_RANGE; - return HAL_kInvalidHandle; + *handle = HAL_kInvalidHandle; + return nullptr; } std::scoped_lock lock(m_handleMutexes[index]); // check for allocation, otherwise allocate and return a valid handle if (m_structures[index] != nullptr) { *status = RESOURCE_IS_ALLOCATED; - return HAL_kInvalidHandle; + *handle = HAL_kInvalidHandle; + return m_structures[index]; } m_structures[index] = std::make_shared(); - return static_cast(hal::createHandle(index, enumValue, m_version)); + *handle = + static_cast(hal::createHandle(index, enumValue, m_version)); + *status = HAL_SUCCESS; + return m_structures[index]; } template HAL_kAddressableLEDMaxLength) { + if (length > HAL_kAddressableLEDMaxLength || length < 0) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "LED length must be less than or equal to " + + wpi::Twine(HAL_kAddressableLEDMaxLength) + + ". " + wpi::Twine(length) + " was requested"); return; } SimAddressableLEDData[led->index].length = length; @@ -127,6 +131,10 @@ void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle, } if (length > SimAddressableLEDData[led->index].length) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, + "Data length must be less than or equal to " + + wpi::Twine(SimAddressableLEDData[led->index].length) + + ". " + wpi::Twine(length) + " was requested"); return; } SimAddressableLEDData[led->index].SetData(data, length); diff --git a/hal/src/main/native/sim/AnalogGyro.cpp b/hal/src/main/native/sim/AnalogGyro.cpp index 3324333e9b..3efca200e7 100644 --- a/hal/src/main/native/sim/AnalogGyro.cpp +++ b/hal/src/main/native/sim/AnalogGyro.cpp @@ -4,7 +4,10 @@ #include "hal/AnalogGyro.h" +#include + #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/AnalogAccumulator.h" #include "hal/Errors.h" @@ -15,6 +18,7 @@ namespace { struct AnalogGyro { HAL_AnalogInputHandle handle; uint8_t index; + std::string previousAllocation; }; } // namespace @@ -34,36 +38,41 @@ void InitializeAnalogGyro() { extern "C" { HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analogHandle, + const char* allocationLocation, int32_t* status) { hal::init::CheckInit(); + // Handle will be type checked by HAL_IsAccumulatorChannel + int16_t channel = getHandleIndex(analogHandle); if (!HAL_IsAccumulatorChannel(analogHandle, status)) { if (*status == 0) { *status = HAL_INVALID_ACCUMULATOR_CHANNEL; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Gyro", + 0, kNumAccumulators, channel); } return HAL_kInvalidHandle; } - // handle known to be correct, so no need to type check - int16_t channel = getHandleIndex(analogHandle); - - auto handle = analogGyroHandles->Allocate(channel, status); + HAL_GyroHandle handle; + auto gyro = analogGyroHandles->Allocate(channel, &handle, status); if (*status != 0) { + if (gyro) { + hal::SetLastErrorPreviouslyAllocated(status, "Analog Gyro", channel, + gyro->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Gyro", + 0, kNumAccumulators, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - // Initialize port structure - auto gyro = analogGyroHandles->Get(handle); - if (gyro == nullptr) { // would only error on thread issue - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - gyro->handle = analogHandle; gyro->index = channel; SimAnalogGyroData[channel].initialized = true; + gyro->previousAllocation = allocationLocation ? allocationLocation : ""; + return handle; } diff --git a/hal/src/main/native/sim/AnalogInput.cpp b/hal/src/main/native/sim/AnalogInput.cpp index 3a9f572f05..4697dc2493 100644 --- a/hal/src/main/native/sim/AnalogInput.cpp +++ b/hal/src/main/native/sim/AnalogInput.cpp @@ -6,6 +6,7 @@ #include "AnalogInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/AnalogAccumulator.h" #include "hal/handles/HandlesInternal.h" @@ -18,28 +19,32 @@ void InitializeAnalogInput() {} } // namespace hal::init extern "C" { -HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle, - int32_t* status) { +HAL_AnalogInputHandle HAL_InitializeAnalogInputPort( + HAL_PortHandle portHandle, const char* allocationLocation, + int32_t* status) { hal::init::CheckInit(); int16_t channel = getPortHandleChannel(portHandle); - if (channel == InvalidHandleIndex) { - *status = PARAMETER_OUT_OF_RANGE; + if (channel == InvalidHandleIndex || channel >= kNumAnalogInputs) { + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input", + 0, kNumAnalogInputs, channel); return HAL_kInvalidHandle; } - HAL_AnalogInputHandle handle = analogInputHandles->Allocate(channel, status); + HAL_AnalogInputHandle handle; + auto analog_port = analogInputHandles->Allocate(channel, &handle, status); if (*status != 0) { + if (analog_port) { + hal::SetLastErrorPreviouslyAllocated(status, "Analog Input", channel, + analog_port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Input", + 0, kNumAnalogInputs, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - // Initialize port structure - auto analog_port = analogInputHandles->Get(handle); - if (analog_port == nullptr) { // would only error on thread issue - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - analog_port->channel = static_cast(channel); if (HAL_IsAccumulatorChannel(handle, status)) { analog_port->isAccumulator = true; @@ -51,6 +56,9 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle, SimAnalogInData[channel].accumulatorInitialized = false; SimAnalogInData[channel].simDevice = 0; + analog_port->previousAllocation = + allocationLocation ? allocationLocation : ""; + return handle; } void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle) { diff --git a/hal/src/main/native/sim/AnalogInternal.h b/hal/src/main/native/sim/AnalogInternal.h index 835fddd8f1..89cb3593c3 100644 --- a/hal/src/main/native/sim/AnalogInternal.h +++ b/hal/src/main/native/sim/AnalogInternal.h @@ -6,6 +6,8 @@ #include +#include + #include "PortsInternal.h" #include "hal/handles/HandlesInternal.h" #include "hal/handles/IndexedHandleResource.h" @@ -20,6 +22,7 @@ static constexpr uint32_t kAccumulatorChannels[] = {0, 1}; struct AnalogPort { uint8_t channel; bool isAccumulator; + std::string previousAllocation; }; extern IndexedHandleResource + #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/Errors.h" #include "hal/handles/HandlesInternal.h" @@ -16,6 +19,7 @@ using namespace hal; namespace { struct AnalogOutput { uint8_t channel; + std::string previousAllocation; }; } // namespace @@ -33,32 +37,39 @@ void InitializeAnalogOutput() { } // namespace hal::init extern "C" { -HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle, - int32_t* status) { +HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort( + HAL_PortHandle portHandle, const char* allocationLocation, + int32_t* status) { hal::init::CheckInit(); int16_t channel = getPortHandleChannel(portHandle); - if (channel == InvalidHandleIndex) { - *status = PARAMETER_OUT_OF_RANGE; + if (channel == InvalidHandleIndex || channel >= kNumAnalogOutputs) { + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Output", + 0, kNumAnalogOutputs, channel); return HAL_kInvalidHandle; } - HAL_AnalogOutputHandle handle = - analogOutputHandles->Allocate(channel, status); + HAL_AnalogOutputHandle handle; + auto port = analogOutputHandles->Allocate(channel, &handle, status); if (*status != 0) { + if (port) { + hal::SetLastErrorPreviouslyAllocated(status, "Analog Output", channel, + port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, + "Invalid Index for Analog Output", 0, + kNumAnalogOutputs, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - auto port = analogOutputHandles->Get(handle); - if (port == nullptr) { // would only error on thread issue - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - port->channel = static_cast(channel); // Initialize sim analog input SimAnalogOutData[channel].initialized = true; + + port->previousAllocation = allocationLocation ? allocationLocation : ""; return handle; } diff --git a/hal/src/main/native/sim/DIO.cpp b/hal/src/main/native/sim/DIO.cpp index 4cb3d38810..0b85cd83dc 100644 --- a/hal/src/main/native/sim/DIO.cpp +++ b/hal/src/main/native/sim/DIO.cpp @@ -6,6 +6,7 @@ #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/handles/HandlesInternal.h" #include "hal/handles/LimitedHandleResource.h" @@ -31,36 +32,41 @@ void InitializeDIO() { extern "C" { HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle, - HAL_Bool input, int32_t* status) { + HAL_Bool input, + const char* allocationLocation, + int32_t* status) { hal::init::CheckInit(); - if (*status != 0) { - return HAL_kInvalidHandle; - } int16_t channel = getPortHandleChannel(portHandle); if (channel == InvalidHandleIndex) { - *status = PARAMETER_OUT_OF_RANGE; + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0, + kNumDigitalChannels, channel); return HAL_kInvalidHandle; } - auto handle = - digitalChannelHandles->Allocate(channel, HAL_HandleEnum::DIO, status); + HAL_DigitalHandle handle; + + auto port = digitalChannelHandles->Allocate(channel, HAL_HandleEnum::DIO, + &handle, status); if (*status != 0) { + if (port) { + hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel, + port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for DIO", 0, + kNumDigitalChannels, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::DIO); - if (port == nullptr) { // would only occur on thread issue. - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - port->channel = static_cast(channel); SimDIOData[channel].initialized = true; SimDIOData[channel].isInput = input; SimDIOData[channel].simDevice = 0; + port->previousAllocation = allocationLocation ? allocationLocation : ""; return handle; } diff --git a/hal/src/main/native/sim/DigitalInternal.h b/hal/src/main/native/sim/DigitalInternal.h index 080eb6fbe8..cd1ac5fcb5 100644 --- a/hal/src/main/native/sim/DigitalInternal.h +++ b/hal/src/main/native/sim/DigitalInternal.h @@ -6,6 +6,8 @@ #include +#include + #include "PortsInternal.h" #include "hal/AnalogTrigger.h" #include "hal/handles/DigitalHandleResource.h" @@ -56,6 +58,7 @@ struct DigitalPort { int32_t centerPwm = 0; int32_t deadbandMinPwm = 0; int32_t minPwm = 0; + std::string previousAllocation; }; extern DigitalHandleResourcedistancePerPulse = distancePerPulse; diff --git a/hal/src/main/native/sim/HAL.cpp b/hal/src/main/native/sim/HAL.cpp index 97ad1b9bba..09409bc1fb 100644 --- a/hal/src/main/native/sim/HAL.cpp +++ b/hal/src/main/native/sim/HAL.cpp @@ -250,6 +250,8 @@ const char* HAL_GetErrorMessage(int32_t code) { return HAL_CAN_BUFFER_OVERRUN_MESSAGE; case HAL_LED_CHANNEL_ERROR: return HAL_LED_CHANNEL_ERROR_MESSAGE; + case HAL_USE_LAST_ERROR: + return HAL_USE_LAST_ERROR_MESSAGE; default: return "Unknown error status"; } diff --git a/hal/src/main/native/sim/HALInternal.h b/hal/src/main/native/sim/HALInternal.h new file mode 100644 index 0000000000..28dcdc293a --- /dev/null +++ b/hal/src/main/native/sim/HALInternal.h @@ -0,0 +1,19 @@ +// 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 + +namespace hal { +void SetLastError(int32_t* status, const wpi::Twine& value); +void SetLastErrorIndexOutOfRange(int32_t* status, const wpi::Twine& message, + int32_t minimum, int32_t maximum, + int32_t channel); +void SetLastErrorPreviouslyAllocated(int32_t* status, const wpi::Twine& message, + int32_t channel, + const wpi::Twine& previousAllocation); +} // namespace hal diff --git a/hal/src/main/native/sim/PDP.cpp b/hal/src/main/native/sim/PDP.cpp index 36fb50e45d..aa08ca0dfa 100644 --- a/hal/src/main/native/sim/PDP.cpp +++ b/hal/src/main/native/sim/PDP.cpp @@ -6,6 +6,7 @@ #include "CANAPIInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/CANAPI.h" #include "hal/Errors.h" @@ -27,6 +28,7 @@ extern "C" { HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) { if (!HAL_CheckPDPModule(module)) { *status = PARAMETER_OUT_OF_RANGE; + hal::SetLastError(status, "Invalid pdp module " + wpi::Twine(module)); return HAL_kInvalidHandle; } hal::init::CheckInit(); diff --git a/hal/src/main/native/sim/PWM.cpp b/hal/src/main/native/sim/PWM.cpp index 06105e9981..698769fede 100644 --- a/hal/src/main/native/sim/PWM.cpp +++ b/hal/src/main/native/sim/PWM.cpp @@ -7,6 +7,7 @@ #include "ConstantsInternal.h" #include "DigitalInternal.h" #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/handles/HandlesInternal.h" #include "mockdata/PWMDataInternal.h" @@ -20,15 +21,15 @@ void InitializePWM() {} extern "C" { HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, + const char* allocationLocation, int32_t* status) { hal::init::CheckInit(); - if (*status != 0) { - return HAL_kInvalidHandle; - } int16_t channel = getPortHandleChannel(portHandle); if (channel == InvalidHandleIndex) { - *status = PARAMETER_OUT_OF_RANGE; + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0, + kNumPWMChannels, channel); return HAL_kInvalidHandle; } @@ -40,19 +41,22 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, channel = remapMXPPWMChannel(channel) + 10; // remap MXP to proper channel } - auto handle = - digitalChannelHandles->Allocate(channel, HAL_HandleEnum::PWM, status); + HAL_DigitalHandle handle; + + auto port = digitalChannelHandles->Allocate(channel, HAL_HandleEnum::PWM, + &handle, status); if (*status != 0) { + if (port) { + hal::SetLastErrorPreviouslyAllocated(status, "PWM or DIO", channel, + port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for PWM", 0, + kNumPWMChannels, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::PWM); - if (port == nullptr) { // would only occur on thread issue. - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - port->channel = origChannel; SimPWMData[origChannel].initialized = true; @@ -60,6 +64,8 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle, // Defaults to allow an always valid config. HAL_SetPWMConfig(handle, 2.0, 1.501, 1.5, 1.499, 1.0, status); + port->previousAllocation = allocationLocation ? allocationLocation : ""; + return handle; } void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status) { diff --git a/hal/src/main/native/sim/Relay.cpp b/hal/src/main/native/sim/Relay.cpp index 7ba0438d50..4dfcdaf2a4 100644 --- a/hal/src/main/native/sim/Relay.cpp +++ b/hal/src/main/native/sim/Relay.cpp @@ -4,7 +4,10 @@ #include "hal/Relay.h" +#include + #include "HALInitializer.h" +#include "HALInternal.h" #include "PortsInternal.h" #include "hal/handles/IndexedHandleResource.h" #include "mockdata/RelayDataInternal.h" @@ -15,6 +18,7 @@ namespace { struct Relay { uint8_t channel; bool fwd; + std::string previousAllocation; }; } // namespace @@ -32,6 +36,7 @@ void InitializeRelay() { extern "C" { HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, + const char* allocationLocation, int32_t* status) { hal::init::CheckInit(); if (*status != 0) { @@ -39,8 +44,10 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, } int16_t channel = getPortHandleChannel(portHandle); - if (channel == InvalidHandleIndex) { - *status = PARAMETER_OUT_OF_RANGE; + if (channel == InvalidHandleIndex || channel >= kNumRelayChannels) { + *status = RESOURCE_OUT_OF_RANGE; + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Relay", 0, + kNumRelayChannels, channel); return HAL_kInvalidHandle; } @@ -48,18 +55,20 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, channel += kNumRelayHeaders; // add 4 to reverse channels } - auto handle = relayHandles->Allocate(channel, status); + HAL_RelayHandle handle; + auto port = relayHandles->Allocate(channel, &handle, status); if (*status != 0) { + if (port) { + hal::SetLastErrorPreviouslyAllocated(status, "Relay", channel, + port->previousAllocation); + } else { + hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Relay", 0, + kNumRelayChannels, channel); + } return HAL_kInvalidHandle; // failed to allocate. Pass error back. } - auto port = relayHandles->Get(handle); - if (port == nullptr) { // would only occur on thread issue. - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - if (!fwd) { // Subtract number of headers to put channel in range channel -= kNumRelayHeaders; @@ -73,6 +82,7 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd, } port->channel = static_cast(channel); + port->previousAllocation = allocationLocation ? allocationLocation : ""; return handle; } diff --git a/hal/src/main/native/sim/Solenoid.cpp b/hal/src/main/native/sim/Solenoid.cpp index 81be01a351..e59b393562 100644 --- a/hal/src/main/native/sim/Solenoid.cpp +++ b/hal/src/main/native/sim/Solenoid.cpp @@ -55,17 +55,13 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle, return HAL_kInvalidHandle; } - auto handle = solenoidHandles->Allocate( - module * kNumSolenoidChannels + channel, status); + HAL_SolenoidHandle handle; + auto solenoidPort = solenoidHandles->Allocate( + module * kNumSolenoidChannels + channel, &handle, status); if (handle == HAL_kInvalidHandle) { // out of resources *status = NO_AVAILABLE_RESOURCES; return HAL_kInvalidHandle; } - auto solenoidPort = solenoidHandles->Get(handle); - if (solenoidPort == nullptr) { // would only occur on thread issues - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } solenoidPort->module = static_cast(module); solenoidPort->channel = static_cast(channel); diff --git a/hal/src/test/native/cpp/mockdata/AnalogInDataTests.cpp b/hal/src/test/native/cpp/mockdata/AnalogInDataTests.cpp index d9fbe01389..c657ebe36d 100644 --- a/hal/src/test/native/cpp/mockdata/AnalogInDataTests.cpp +++ b/hal/src/test/native/cpp/mockdata/AnalogInDataTests.cpp @@ -36,16 +36,18 @@ TEST(AnalogInSimTests, TestAnalogInInitialization) { status = 0; portHandle = 8000; gTestAnalogInCallbackName = "Unset"; - analogInHandle = HAL_InitializeAnalogInputPort(portHandle, &status); + analogInHandle = HAL_InitializeAnalogInputPort(portHandle, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, analogInHandle); - EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); + EXPECT_EQ(RESOURCE_OUT_OF_RANGE, status); EXPECT_STREQ("Unset", gTestAnalogInCallbackName.c_str()); // Successful setup status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestAnalogInCallbackName = "Unset"; - analogInHandle = HAL_InitializeAnalogInputPort(portHandle, &status); + analogInHandle = HAL_InitializeAnalogInputPort(portHandle, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != analogInHandle); EXPECT_EQ(0, status); EXPECT_STREQ("Initialized", gTestAnalogInCallbackName.c_str()); @@ -54,8 +56,10 @@ TEST(AnalogInSimTests, TestAnalogInInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestAnalogInCallbackName = "Unset"; - analogInHandle = HAL_InitializeAnalogInputPort(portHandle, &status); + analogInHandle = HAL_InitializeAnalogInputPort(portHandle, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, analogInHandle); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); EXPECT_EQ(RESOURCE_IS_ALLOCATED, status); EXPECT_STREQ("Unset", gTestAnalogInCallbackName.c_str()); @@ -69,7 +73,7 @@ TEST(AnalogInSimTests, TestAnalogInInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestAnalogInCallbackName = "Unset"; - analogInHandle = HAL_InitializeAnalogInputPort(portHandle, &status); + analogInHandle = HAL_InitializeAnalogInputPort(portHandle, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != analogInHandle); EXPECT_EQ(0, status); EXPECT_STREQ("Initialized", gTestAnalogInCallbackName.c_str()); diff --git a/hal/src/test/native/cpp/mockdata/AnalogOutDataTests.cpp b/hal/src/test/native/cpp/mockdata/AnalogOutDataTests.cpp index 16e1d9d957..1ec14f4f19 100644 --- a/hal/src/test/native/cpp/mockdata/AnalogOutDataTests.cpp +++ b/hal/src/test/native/cpp/mockdata/AnalogOutDataTests.cpp @@ -36,16 +36,20 @@ TEST(AnalogOutSimTests, TestAnalogOutInitialization) { status = 0; portHandle = 8000; gTestAnalogOutCallbackName = "Unset"; - analogOutHandle = HAL_InitializeAnalogOutputPort(portHandle, &status); + analogOutHandle = + HAL_InitializeAnalogOutputPort(portHandle, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, analogOutHandle); - EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); + EXPECT_EQ(RESOURCE_OUT_OF_RANGE, status); EXPECT_STREQ("Unset", gTestAnalogOutCallbackName.c_str()); // Successful setup status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestAnalogOutCallbackName = "Unset"; - analogOutHandle = HAL_InitializeAnalogOutputPort(portHandle, &status); + analogOutHandle = + HAL_InitializeAnalogOutputPort(portHandle, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != analogOutHandle); EXPECT_EQ(0, status); EXPECT_STREQ("Initialized", gTestAnalogOutCallbackName.c_str()); @@ -54,8 +58,11 @@ TEST(AnalogOutSimTests, TestAnalogOutInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestAnalogOutCallbackName = "Unset"; - analogOutHandle = HAL_InitializeAnalogOutputPort(portHandle, &status); + analogOutHandle = + HAL_InitializeAnalogOutputPort(portHandle, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, analogOutHandle); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); EXPECT_EQ(RESOURCE_IS_ALLOCATED, status); EXPECT_STREQ("Unset", gTestAnalogOutCallbackName.c_str()); @@ -69,7 +76,8 @@ TEST(AnalogOutSimTests, TestAnalogOutInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestAnalogOutCallbackName = "Unset"; - analogOutHandle = HAL_InitializeAnalogOutputPort(portHandle, &status); + analogOutHandle = + HAL_InitializeAnalogOutputPort(portHandle, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != analogOutHandle); EXPECT_EQ(0, status); EXPECT_STREQ("Initialized", gTestAnalogOutCallbackName.c_str()); diff --git a/hal/src/test/native/cpp/mockdata/DIODataTests.cpp b/hal/src/test/native/cpp/mockdata/DIODataTests.cpp index d584b45ec0..bc1345b091 100644 --- a/hal/src/test/native/cpp/mockdata/DIODataTests.cpp +++ b/hal/src/test/native/cpp/mockdata/DIODataTests.cpp @@ -36,16 +36,18 @@ TEST(DigitalIoSimTests, TestDigitalIoInitialization) { status = 0; portHandle = 8000; gTestDigitalIoCallbackName = "Unset"; - digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, &status); + digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, digitalIoHandle); - EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); + EXPECT_EQ(RESOURCE_OUT_OF_RANGE, status); EXPECT_STREQ("Unset", gTestDigitalIoCallbackName.c_str()); // Successful setup status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestDigitalIoCallbackName = "Unset"; - digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, &status); + digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != digitalIoHandle); EXPECT_EQ(0, status); EXPECT_STREQ("Initialized", gTestDigitalIoCallbackName.c_str()); @@ -54,8 +56,10 @@ TEST(DigitalIoSimTests, TestDigitalIoInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestDigitalIoCallbackName = "Unset"; - digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, &status); + digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, digitalIoHandle); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); EXPECT_EQ(RESOURCE_IS_ALLOCATED, status); EXPECT_STREQ("Unset", gTestDigitalIoCallbackName.c_str()); @@ -69,7 +73,7 @@ TEST(DigitalIoSimTests, TestDigitalIoInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestDigitalIoCallbackName = "Unset"; - digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, &status); + digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != digitalIoHandle); EXPECT_EQ(0, status); EXPECT_STREQ("Initialized", gTestDigitalIoCallbackName.c_str()); diff --git a/hal/src/test/native/cpp/mockdata/PWMDataTests.cpp b/hal/src/test/native/cpp/mockdata/PWMDataTests.cpp index fb717971ac..c0bb7f0b31 100644 --- a/hal/src/test/native/cpp/mockdata/PWMDataTests.cpp +++ b/hal/src/test/native/cpp/mockdata/PWMDataTests.cpp @@ -35,16 +35,18 @@ TEST(PWMSimTests, TestPwmInitialization) { status = 0; portHandle = 8000; gTestPwmCallbackName = "Unset"; - pwmHandle = HAL_InitializePWMPort(portHandle, &status); + pwmHandle = HAL_InitializePWMPort(portHandle, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, pwmHandle); - EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); + EXPECT_EQ(RESOURCE_OUT_OF_RANGE, status); EXPECT_STREQ("Unset", gTestPwmCallbackName.c_str()); // Successful setup status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestPwmCallbackName = "Unset"; - pwmHandle = HAL_InitializePWMPort(portHandle, &status); + pwmHandle = HAL_InitializePWMPort(portHandle, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != pwmHandle); EXPECT_EQ(0, status); EXPECT_STREQ("Initialized", gTestPwmCallbackName.c_str()); @@ -53,8 +55,10 @@ TEST(PWMSimTests, TestPwmInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestPwmCallbackName = "Unset"; - pwmHandle = HAL_InitializePWMPort(portHandle, &status); + pwmHandle = HAL_InitializePWMPort(portHandle, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, pwmHandle); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); EXPECT_EQ(RESOURCE_IS_ALLOCATED, status); EXPECT_STREQ("Unset", gTestPwmCallbackName.c_str()); @@ -67,7 +71,7 @@ TEST(PWMSimTests, TestPwmInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestPwmCallbackName = "Unset"; - pwmHandle = HAL_InitializePWMPort(portHandle, &status); + pwmHandle = HAL_InitializePWMPort(portHandle, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != pwmHandle); EXPECT_EQ(0, status); EXPECT_STREQ("Initialized", gTestPwmCallbackName.c_str()); diff --git a/hal/src/test/native/cpp/mockdata/RelayDataTests.cpp b/hal/src/test/native/cpp/mockdata/RelayDataTests.cpp index 6e5004667d..af85318006 100644 --- a/hal/src/test/native/cpp/mockdata/RelayDataTests.cpp +++ b/hal/src/test/native/cpp/mockdata/RelayDataTests.cpp @@ -35,16 +35,18 @@ TEST(RelaySimTests, TestRelayInitialization) { status = 0; portHandle = 8000; gTestRelayCallbackName = "Unset"; - pdpHandle = HAL_InitializeRelayPort(portHandle, true, &status); + pdpHandle = HAL_InitializeRelayPort(portHandle, true, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, pdpHandle); - EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); + EXPECT_EQ(RESOURCE_OUT_OF_RANGE, status); EXPECT_STREQ("Unset", gTestRelayCallbackName.c_str()); // Successful setup status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestRelayCallbackName = "Unset"; - pdpHandle = HAL_InitializeRelayPort(portHandle, true, &status); + pdpHandle = HAL_InitializeRelayPort(portHandle, true, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != pdpHandle); EXPECT_EQ(0, status); EXPECT_STREQ("InitializedForward", gTestRelayCallbackName.c_str()); @@ -53,8 +55,10 @@ TEST(RelaySimTests, TestRelayInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestRelayCallbackName = "Unset"; - pdpHandle = HAL_InitializeRelayPort(portHandle, true, &status); + pdpHandle = HAL_InitializeRelayPort(portHandle, true, nullptr, &status); EXPECT_EQ(HAL_kInvalidHandle, pdpHandle); + EXPECT_EQ(HAL_USE_LAST_ERROR, status); + HAL_GetLastError(&status); EXPECT_EQ(RESOURCE_IS_ALLOCATED, status); EXPECT_STREQ("Unset", gTestRelayCallbackName.c_str()); @@ -67,7 +71,7 @@ TEST(RelaySimTests, TestRelayInitialization) { status = 0; portHandle = HAL_GetPort(INDEX_TO_TEST); gTestRelayCallbackName = "Unset"; - pdpHandle = HAL_InitializeRelayPort(portHandle, true, &status); + pdpHandle = HAL_InitializeRelayPort(portHandle, true, nullptr, &status); EXPECT_TRUE(HAL_kInvalidHandle != pdpHandle); EXPECT_EQ(0, status); EXPECT_STREQ("InitializedForward", gTestRelayCallbackName.c_str()); diff --git a/ntcore/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java b/ntcore/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java deleted file mode 100644 index e5affb2958..0000000000 --- a/ntcore/src/main/java/edu/wpi/first/wpilibj/networktables/NetworkTable.java +++ /dev/null @@ -1,1108 +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 edu.wpi.first.wpilibj.networktables; - -import edu.wpi.first.networktables.ConnectionInfo; -import edu.wpi.first.networktables.ConnectionNotification; -import edu.wpi.first.networktables.EntryInfo; -import edu.wpi.first.networktables.EntryNotification; -import edu.wpi.first.networktables.NetworkTableEntry; -import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.networktables.NetworkTableType; -import edu.wpi.first.networktables.NetworkTableValue; -import edu.wpi.first.networktables.NetworkTablesJNI; -import edu.wpi.first.networktables.PersistentException; -import edu.wpi.first.wpilibj.tables.IRemote; -import edu.wpi.first.wpilibj.tables.IRemoteConnectionListener; -import edu.wpi.first.wpilibj.tables.ITable; -import edu.wpi.first.wpilibj.tables.ITableListener; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.function.Consumer; - -/** - * A network table that knows its subtable path. - * - * @deprecated Use {@link edu.wpi.first.networktables.NetworkTable} instead. - */ -@Deprecated -@SuppressWarnings("checkstyle:all") -public class NetworkTable implements ITable, IRemote { - /** The path separator for sub-tables and keys */ - public static final char PATH_SEPARATOR = '/'; - /** The default port that network tables operates on */ - public static final int DEFAULT_PORT = 1735; - - private static boolean client = false; - private static boolean enableDS = true; - private static boolean running = false; - private static int port = DEFAULT_PORT; - private static String persistentFilename = "networktables.ini"; - - private static synchronized void checkInit() { - if (running) throw new IllegalStateException("Network tables has already been initialized"); - } - - /** - * initializes network tables - * - * @deprecated Use {@link NetworkTableInstance#startServer()} or {@link - * NetworkTableInstance#startClient()} instead. - */ - @Deprecated - public static synchronized void initialize() { - if (running) shutdown(); - NetworkTableInstance inst = NetworkTableInstance.getDefault(); - if (client) { - inst.startClient(); - if (enableDS) inst.startDSClient(port); - } else inst.startServer(persistentFilename, "", port); - running = true; - } - - /** - * shuts down network tables - * - * @deprecated Use {@link NetworkTableInstance#stopServer()} or {@link - * NetworkTableInstance#stopClient()} instead. - */ - @Deprecated - public static synchronized void shutdown() { - if (!running) return; - NetworkTableInstance inst = NetworkTableInstance.getDefault(); - if (client) { - inst.stopDSClient(); - inst.stopClient(); - } else inst.stopServer(); - running = false; - } - - /** - * set that network tables should be a server This must be called before initialize or getTable - * - * @deprecated Use {@link NetworkTableInstance#startServer()} instead. - */ - @Deprecated - public static synchronized void setServerMode() { - if (!client) return; - checkInit(); - client = false; - } - - /** - * set that network tables should be a client This must be called before initialize or getTable - * - * @deprecated Use {@link NetworkTableInstance#startClient()} instead. - */ - @Deprecated - public static synchronized void setClientMode() { - if (client) return; - checkInit(); - client = true; - } - - /** - * set the team the robot is configured for (this will set the mdns address that network tables - * will connect to in client mode) This must be called before initialize or getTable - * - * @param team the team number - * @deprecated Use {@link NetworkTableInstance#setServerTeam(int)} or {@link - * NetworkTableInstance#startClientTeam(int)} instead. - */ - @Deprecated - public static synchronized void setTeam(int team) { - NetworkTableInstance inst = NetworkTableInstance.getDefault(); - inst.setServerTeam(team, port); - if (enableDS) inst.startDSClient(port); - } - - /** - * @param address the address that network tables will connect to in client mode - * @deprecated Use {@link NetworkTableInstance#setServer(String)} or {@link - * NetworkTableInstance#startClient(String)} instead. - */ - @Deprecated - public static synchronized void setIPAddress(final String address) { - String[] addresses = new String[1]; - addresses[0] = address; - setIPAddress(addresses); - } - - /** - * @param addresses the adresses that network tables will connect to in client mode (in round - * robin order) - * @deprecated Use {@link NetworkTableInstance#setServer(String[])} or {@link - * NetworkTableInstance#startClient(String[])} instead. - */ - @Deprecated - public static synchronized void setIPAddress(final String[] addresses) { - NetworkTableInstance inst = NetworkTableInstance.getDefault(); - inst.setServer(addresses, port); - - // Stop the DS client if we're explicitly connecting to localhost - if (addresses.length > 0 - && (addresses[0].equals("localhost") || addresses[0].equals("127.0.0.1"))) - inst.stopDSClient(); - else if (enableDS) inst.startDSClient(port); - } - - /** - * Set the port number that network tables will connect to in client mode or listen to in server - * mode. - * - * @param aport the port number - * @deprecated Use the appropriate parameters to {@link NetworkTableInstance#setServer(String, - * int)}, {@link NetworkTableInstance#startClient(String, int)}, {@link - * NetworkTableInstance#startServer(String, String, int)}, and {@link - * NetworkTableInstance#startDSClient(int)} instead. - */ - @Deprecated - public static synchronized void setPort(int aport) { - if (port == aport) return; - checkInit(); - port = aport; - } - - /** - * Enable requesting the server address from the Driver Station. - * - * @param enabled whether to enable the connection to the local DS - * @deprecated Use {@link NetworkTableInstance#startDSClient()} and {@link - * NetworkTableInstance#stopDSClient()} instead. - */ - @Deprecated - public static synchronized void setDSClientEnabled(boolean enabled) { - NetworkTableInstance inst = NetworkTableInstance.getDefault(); - enableDS = enabled; - if (enableDS) inst.startDSClient(port); - else inst.stopDSClient(); - } - - /** - * Sets the persistent filename. - * - * @param filename the filename that the network tables server uses for automatic loading and - * saving of persistent values - * @deprecated Use the appropriate parameter to {@link NetworkTableInstance#startServer()} - * instead. - */ - @Deprecated - public static synchronized void setPersistentFilename(final String filename) { - if (persistentFilename.equals(filename)) return; - checkInit(); - persistentFilename = filename; - } - - /** - * Sets the network identity. This is provided in the connection info on the remote end. - * - * @param name identity - * @deprecated Use {@link NetworkTableInstance#setNetworkIdentity(String)} instead. - */ - @Deprecated - public static void setNetworkIdentity(String name) { - NetworkTableInstance.getDefault().setNetworkIdentity(name); - } - - public static boolean[] toNative(Boolean[] arr) { - boolean[] out = new boolean[arr.length]; - for (int i = 0; i < arr.length; i++) out[i] = arr[i]; - return out; - } - - public static double[] toNative(Number[] arr) { - double[] out = new double[arr.length]; - for (int i = 0; i < arr.length; i++) out[i] = arr[i].doubleValue(); - return out; - } - - public static Boolean[] fromNative(boolean[] arr) { - Boolean[] out = new Boolean[arr.length]; - for (int i = 0; i < arr.length; i++) out[i] = arr[i]; - return out; - } - - public static Double[] fromNative(double[] arr) { - Double[] out = new Double[arr.length]; - for (int i = 0; i < arr.length; i++) out[i] = arr[i]; - return out; - } - - /** - * Gets the table with the specified key. If the table does not exist, a new table will be - * created.
- * This will automatically initialize network tables if it has not been already - * - * @deprecated Use {@link NetworkTableInstance#getTable(String)} instead. - * @param key the key name - * @return the network table requested - */ - @Deprecated - public static synchronized NetworkTable getTable(String key) { - if (!running) initialize(); - String theKey; - if (key.isEmpty() || key.equals("/")) { - theKey = ""; - } else if (key.charAt(0) == NetworkTable.PATH_SEPARATOR) { - theKey = key; - } else { - theKey = NetworkTable.PATH_SEPARATOR + key; - } - return new NetworkTable(NetworkTableInstance.getDefault(), theKey); - } - - private final String path; - private final String pathWithSep; - private final NetworkTableInstance inst; - - NetworkTable(NetworkTableInstance inst, String path) { - this.path = path; - this.pathWithSep = path + PATH_SEPARATOR; - this.inst = inst; - } - - @Override - public String toString() { - return "NetworkTable: " + path; - } - - private final ConcurrentMap entries = - new ConcurrentHashMap(); - - /** - * Gets the entry for a subkey. - * - * @param key the key name - * @return Network table entry. - */ - private NetworkTableEntry getEntry(String key) { - NetworkTableEntry entry = entries.get(key); - if (entry == null) { - entry = inst.getEntry(pathWithSep + key); - entries.putIfAbsent(key, entry); - } - return entry; - } - - /** - * Gets the current network connections. - * - * @return An array of connection information. - * @deprecated Use {@link NetworkTableInstance#getConnections()} instead. - */ - @Deprecated - public static ConnectionInfo[] connections() { - return NetworkTableInstance.getDefault().getConnections(); - } - - /** - * Determine whether or not a network connection is active. - * - * @return True if connected, false if not connected. - * @deprecated Use {@link NetworkTableInstance#isConnected()} instead. - */ - @Override - @Deprecated - public boolean isConnected() { - return inst.isConnected(); - } - - /** - * Determine whether NetworkTables is operating as a server or as a client. - * - * @return True if operating as a server, false otherwise. - * @deprecated Use {@link NetworkTableInstance#getNetworkMode()} instead. - */ - @Override - @Deprecated - public boolean isServer() { - return (inst.getNetworkMode() & NetworkTableInstance.kNetModeServer) != 0; - } - - /* Backwards compatibility shims for IRemoteConnectionListener */ - private static class ConnectionListenerAdapter implements Consumer { - public int uid; - private final IRemote targetSource; - private final IRemoteConnectionListener targetListener; - - public ConnectionListenerAdapter( - IRemote targetSource, IRemoteConnectionListener targetListener) { - this.targetSource = targetSource; - this.targetListener = targetListener; - } - - @Override - public void accept(ConnectionNotification event) { - if (event.connected) targetListener.connectedEx(targetSource, event.conn); - else targetListener.disconnectedEx(targetSource, event.conn); - } - } - - private static final HashMap - globalConnectionListenerMap = - new HashMap(); - - private static IRemote staticRemote = - new IRemote() { - @Override - public void addConnectionListener( - IRemoteConnectionListener listener, boolean immediateNotify) { - NetworkTable.addGlobalConnectionListener(listener, immediateNotify); - } - - @Override - public void removeConnectionListener(IRemoteConnectionListener listener) { - NetworkTable.removeGlobalConnectionListener(listener); - } - - @Override - public boolean isConnected() { - ConnectionInfo[] conns = NetworkTableInstance.getDefault().getConnections(); - return conns.length > 0; - } - - @Override - public boolean isServer() { - return (NetworkTableInstance.getDefault().getNetworkMode() - & NetworkTableInstance.kNetModeServer) - != 0; - } - }; - - private final HashMap - connectionListenerMap = new HashMap(); - - /** - * Add a connection listener. - * - * @param listener connection listener - * @param immediateNotify call listener immediately for all existing connections - * @deprecated Use {@link NetworkTableInstance#addConnectionListener(Consumer, boolean)} instead. - */ - @Deprecated - public static synchronized void addGlobalConnectionListener( - IRemoteConnectionListener listener, boolean immediateNotify) { - ConnectionListenerAdapter adapter = new ConnectionListenerAdapter(staticRemote, listener); - if (globalConnectionListenerMap.putIfAbsent(listener, adapter) != null) { - throw new IllegalStateException("Cannot add the same listener twice"); - } - adapter.uid = NetworkTableInstance.getDefault().addConnectionListener(adapter, immediateNotify); - } - - /** - * Remove a connection listener. - * - * @param listener connection listener - * @deprecated Use {@link NetworkTableInstance#removeConnectionListener(int)} instead. - */ - @Deprecated - public static synchronized void removeGlobalConnectionListener( - IRemoteConnectionListener listener) { - ConnectionListenerAdapter adapter = globalConnectionListenerMap.remove(listener); - if (adapter != null) { - NetworkTableInstance.getDefault().removeConnectionListener(adapter.uid); - } - } - - /** - * Add a connection listener. - * - * @param listener connection listener - * @param immediateNotify call listener immediately for all existing connections - * @deprecated Use {@link NetworkTableInstance#addConnectionListener(Consumer, boolean)} instead. - */ - @Override - @Deprecated - public synchronized void addConnectionListener( - IRemoteConnectionListener listener, boolean immediateNotify) { - ConnectionListenerAdapter adapter = new ConnectionListenerAdapter(this, listener); - if (connectionListenerMap.putIfAbsent(listener, adapter) != null) { - throw new IllegalStateException("Cannot add the same listener twice"); - } - adapter.uid = inst.addConnectionListener(adapter, immediateNotify); - } - - /** - * Remove a connection listener. - * - * @param listener connection listener - * @deprecated Use {@link NetworkTableInstance#removeConnectionListener(int)} instead. - */ - @Override - @Deprecated - public synchronized void removeConnectionListener(IRemoteConnectionListener listener) { - ConnectionListenerAdapter adapter = connectionListenerMap.get(listener); - if (adapter != null && connectionListenerMap.remove(listener, adapter)) { - inst.removeConnectionListener(adapter.uid); - } - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link - * edu.wpi.first.networktables.NetworkTable#addEntryListener(TableEntryListener, int)} instead - * (with flags value of NOTIFY_NEW | NOTIFY_UPDATE). - */ - @Override - @Deprecated - public void addTableListener(ITableListener listener) { - addTableListenerEx(listener, NOTIFY_NEW | NOTIFY_UPDATE); - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link - * edu.wpi.first.networktables.NetworkTable#addEntryListener(TableEntryListener, int)} instead - * (with flags value of NOTIFY_NEW | NOTIFY_UPDATE | NOTIFY_IMMEDIATE). - */ - @Override - @Deprecated - public void addTableListener(ITableListener listener, boolean immediateNotify) { - int flags = NOTIFY_NEW | NOTIFY_UPDATE; - if (immediateNotify) flags |= NOTIFY_IMMEDIATE; - addTableListenerEx(listener, flags); - } - - /* Base class for listeners; stores uid to implement remove functions */ - private static class ListenerBase { - public int uid; - } - - private static class OldTableListenerAdapter extends ListenerBase - implements Consumer { - private final int prefixLen; - private final ITable targetSource; - private final ITableListener targetListener; - - public OldTableListenerAdapter( - int prefixLen, ITable targetSource, ITableListener targetListener) { - this.prefixLen = prefixLen; - this.targetSource = targetSource; - this.targetListener = targetListener; - } - - @Override - public void accept(EntryNotification event) { - String relativeKey = event.name.substring(prefixLen); - if (relativeKey.indexOf(PATH_SEPARATOR) != -1) return; - targetListener.valueChangedEx(targetSource, relativeKey, event.value.getValue(), event.flags); - } - } - - private final HashMap> oldListenerMap = - new HashMap>(); - - /** - * {@inheritDoc} - * - * @deprecated Use {@link - * edu.wpi.first.networktables.NetworkTable#addEntryListener(TableEntryListener, int)} - * instead. - */ - @Override - @Deprecated - public synchronized void addTableListenerEx(ITableListener listener, int flags) { - List adapters = oldListenerMap.get(listener); - if (adapters == null) { - adapters = new ArrayList(); - oldListenerMap.put(listener, adapters); - } - OldTableListenerAdapter adapter = - new OldTableListenerAdapter(path.length() + 1, this, listener); - adapter.uid = inst.addEntryListener(pathWithSep, adapter, flags); - adapters.add(adapter); - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link edu.wpi.first.networktables.NetworkTable#addEntryListener(String, - * TableEntryListener, int)} or {@link NetworkTableEntry#addListener(Consumer, int)} instead. - */ - @Override - @Deprecated - public void addTableListener(String key, ITableListener listener, boolean immediateNotify) { - int flags = NOTIFY_NEW | NOTIFY_UPDATE; - if (immediateNotify) flags |= NOTIFY_IMMEDIATE; - addTableListenerEx(key, listener, flags); - } - - private static class OldKeyListenerAdapter extends ListenerBase - implements Consumer { - private final String relativeKey; - private final ITable targetSource; - private final ITableListener targetListener; - - public OldKeyListenerAdapter( - String relativeKey, ITable targetSource, ITableListener targetListener) { - this.relativeKey = relativeKey; - this.targetSource = targetSource; - this.targetListener = targetListener; - } - - @Override - public void accept(EntryNotification event) { - targetListener.valueChangedEx(targetSource, relativeKey, event.value.getValue(), event.flags); - } - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link edu.wpi.first.networktables.NetworkTable#addEntryListener(String, - * TableEntryListener, int)} or {@link NetworkTableEntry#addListener(Consumer, int)} instead. - */ - @Override - @Deprecated - public synchronized void addTableListenerEx(String key, ITableListener listener, int flags) { - List adapters = oldListenerMap.get(listener); - if (adapters == null) { - adapters = new ArrayList(); - oldListenerMap.put(listener, adapters); - } - OldKeyListenerAdapter adapter = new OldKeyListenerAdapter(key, this, listener); - adapter.uid = inst.addEntryListener(getEntry(key), adapter, flags); - adapters.add(adapter); - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link - * edu.wpi.first.networktables.NetworkTable#addSubTableListener(TableListener, boolean)} - * instead. - */ - @Override - @Deprecated - public void addSubTableListener(final ITableListener listener) { - addSubTableListener(listener, false); - } - - private static class OldSubListenerAdapter extends ListenerBase - implements Consumer { - private final int prefixLen; - private final ITable targetSource; - private final ITableListener targetListener; - private final Set notifiedTables = new HashSet(); - - public OldSubListenerAdapter( - int prefixLen, ITable targetSource, ITableListener targetListener) { - this.prefixLen = prefixLen; - this.targetSource = targetSource; - this.targetListener = targetListener; - } - - @Override - public void accept(EntryNotification event) { - String relativeKey = event.name.substring(prefixLen); - int endSubTable = relativeKey.indexOf(PATH_SEPARATOR); - if (endSubTable == -1) return; - String subTableKey = relativeKey.substring(0, endSubTable); - if (notifiedTables.contains(subTableKey)) return; - notifiedTables.add(subTableKey); - targetListener.valueChangedEx( - targetSource, subTableKey, targetSource.getSubTable(subTableKey), event.flags); - } - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link - * edu.wpi.first.networktables.NetworkTable#addSubTableListener(TableListener, boolean)} - * instead. - */ - @Override - @Deprecated - public synchronized void addSubTableListener(final ITableListener listener, boolean localNotify) { - List adapters = oldListenerMap.get(listener); - if (adapters == null) { - adapters = new ArrayList(); - oldListenerMap.put(listener, adapters); - } - OldSubListenerAdapter adapter = new OldSubListenerAdapter(path.length() + 1, this, listener); - int flags = NOTIFY_NEW | NOTIFY_IMMEDIATE; - if (localNotify) flags |= NOTIFY_LOCAL; - adapter.uid = inst.addEntryListener(pathWithSep, adapter, flags); - adapters.add(adapter); - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link edu.wpi.first.networktables.NetworkTable#removeTableListener(int)} - * instead. - */ - @Override - @Deprecated - public synchronized void removeTableListener(ITableListener listener) { - List adapters = oldListenerMap.remove(listener); - if (adapters != null) { - for (ListenerBase adapter : adapters) inst.removeEntryListener(adapter.uid); - } - } - - /** {@inheritDoc} */ - @Override - public ITable getSubTable(String key) { - return new NetworkTable(inst, pathWithSep + key); - } - - /** {@inheritDoc} */ - @Override - public boolean containsKey(String key) { - return getEntry(key).exists(); - } - - @Override - public boolean containsSubTable(String key) { - int[] handles = - NetworkTablesJNI.getEntries(inst.getHandle(), pathWithSep + key + PATH_SEPARATOR, 0); - return handles.length != 0; - } - - /** - * @param types bitmask of types; 0 is treated as a "don't care". - * @return keys currently in the table - */ - @Override - public Set getKeys(int types) { - Set keys = new HashSet(); - int prefixLen = path.length() + 1; - for (EntryInfo info : inst.getEntryInfo(pathWithSep, types)) { - String relativeKey = info.name.substring(prefixLen); - if (relativeKey.indexOf(PATH_SEPARATOR) != -1) continue; - keys.add(relativeKey); - // populate entries as we go - if (entries.get(relativeKey) == null) { - entries.putIfAbsent(relativeKey, new NetworkTableEntry(inst, info.entry)); - } - } - return keys; - } - - /** {@inheritDoc} */ - @Override - public Set getKeys() { - return getKeys(0); - } - - /** {@inheritDoc} */ - @Override - public Set getSubTables() { - Set keys = new HashSet(); - int prefixLen = path.length() + 1; - for (EntryInfo info : inst.getEntryInfo(pathWithSep, 0)) { - String relativeKey = info.name.substring(prefixLen); - int endSubTable = relativeKey.indexOf(PATH_SEPARATOR); - if (endSubTable == -1) continue; - keys.add(relativeKey.substring(0, endSubTable)); - } - return keys; - } - - /** {@inheritDoc} */ - @Override - public boolean putNumber(String key, double value) { - return getEntry(key).setNumber(value); - } - - /** {@inheritDoc} */ - @Override - public boolean setDefaultNumber(String key, double defaultValue) { - return getEntry(key).setDefaultDouble(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public double getNumber(String key, double defaultValue) { - return getEntry(key).getDouble(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean putString(String key, String value) { - return getEntry(key).setString(value); - } - - /** {@inheritDoc} */ - @Override - public boolean setDefaultString(String key, String defaultValue) { - return getEntry(key).setDefaultString(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public String getString(String key, String defaultValue) { - return getEntry(key).getString(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean putBoolean(String key, boolean value) { - return getEntry(key).setBoolean(value); - } - - /** {@inheritDoc} */ - @Override - public boolean setDefaultBoolean(String key, boolean defaultValue) { - return getEntry(key).setDefaultBoolean(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean getBoolean(String key, boolean defaultValue) { - return getEntry(key).getBoolean(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean putBooleanArray(String key, boolean[] value) { - return getEntry(key).setBooleanArray(value); - } - - /** {@inheritDoc} */ - @Override - public boolean putBooleanArray(String key, Boolean[] value) { - return getEntry(key).setBooleanArray(value); - } - - /** {@inheritDoc} */ - @Override - public boolean setDefaultBooleanArray(String key, boolean[] defaultValue) { - return getEntry(key).setDefaultBooleanArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue) { - return getEntry(key).setDefaultBooleanArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean[] getBooleanArray(String key, boolean[] defaultValue) { - return getEntry(key).getBooleanArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public Boolean[] getBooleanArray(String key, Boolean[] defaultValue) { - return getEntry(key).getBooleanArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean putNumberArray(String key, double[] value) { - return getEntry(key).setDoubleArray(value); - } - - /** {@inheritDoc} */ - @Override - public boolean putNumberArray(String key, Double[] value) { - return getEntry(key).setNumberArray(value); - } - - /** {@inheritDoc} */ - @Override - public boolean setDefaultNumberArray(String key, double[] defaultValue) { - return getEntry(key).setDefaultDoubleArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean setDefaultNumberArray(String key, Double[] defaultValue) { - return getEntry(key).setDefaultNumberArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public double[] getNumberArray(String key, double[] defaultValue) { - return getEntry(key).getDoubleArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public Double[] getNumberArray(String key, Double[] defaultValue) { - return getEntry(key).getDoubleArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean putStringArray(String key, String[] value) { - return getEntry(key).setStringArray(value); - } - - /** {@inheritDoc} */ - @Override - public boolean setDefaultStringArray(String key, String[] defaultValue) { - return getEntry(key).setDefaultStringArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public String[] getStringArray(String key, String[] defaultValue) { - return getEntry(key).getStringArray(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean putRaw(String key, byte[] value) { - return getEntry(key).setRaw(value); - } - - /** {@inheritDoc} */ - @Override - public boolean setDefaultRaw(String key, byte[] defaultValue) { - return getEntry(key).setDefaultRaw(defaultValue); - } - - /** {@inheritDoc} */ - @Override - public boolean putRaw(String key, ByteBuffer value, int len) { - return getEntry(key).setRaw(value, len); - } - - /** {@inheritDoc} */ - @Override - public byte[] getRaw(String key, byte[] defaultValue) { - return getEntry(key).getRaw(defaultValue); - } - - /** - * Put a value in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putValue(String key, NetworkTableValue value) { - return getEntry(key).setValue(value); - } - - /** - * Sets the current value in the table if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultValue(String key, NetworkTableValue defaultValue) { - return getEntry(key).setDefaultValue(defaultValue); - } - - /** - * Gets the value associated with a key as a NetworkTableValue object. - * - * @param key the key of the value to look up - * @return the value associated with the given key - */ - public NetworkTableValue getValue(String key) { - return getEntry(key).getValue(); - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link edu.wpi.first.networktables.NetworkTableEntry#setValue(Object)} instead, - * e.g. `NetworkTable.getEntry(key).setValue(NetworkTableEntry.makeBoolean(false));` or - * `NetworkTable.getEntry(key).setValue(new Boolean(false));` - */ - @Override - @Deprecated - public boolean putValue(String key, Object value) throws IllegalArgumentException { - if (value instanceof Boolean) return putBoolean(key, ((Boolean) value).booleanValue()); - else if (value instanceof Number) return putDouble(key, ((Number) value).doubleValue()); - else if (value instanceof String) return putString(key, (String) value); - else if (value instanceof byte[]) return putRaw(key, (byte[]) value); - else if (value instanceof boolean[]) return putBooleanArray(key, (boolean[]) value); - else if (value instanceof double[]) return putNumberArray(key, (double[]) value); - else if (value instanceof Boolean[]) return putBooleanArray(key, toNative((Boolean[]) value)); - else if (value instanceof Number[]) return putNumberArray(key, toNative((Number[]) value)); - else if (value instanceof String[]) return putStringArray(key, (String[]) value); - else if (value instanceof NetworkTableValue) - return getEntry(key).setValue((NetworkTableValue) value); - else - throw new IllegalArgumentException( - "Value of type " + value.getClass().getName() + " cannot be put into a table"); - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link edu.wpi.first.networktables.NetworkTableEntry#getValue()} instead, e.g. - * `NetworkTable.getEntry(key).getValue();` - */ - @Override - @Deprecated - public Object getValue(String key, Object defaultValue) { - NetworkTableValue value = getValue(key); - if (value.getType() == NetworkTableType.kUnassigned) { - return defaultValue; - } - return value.getValue(); - } - - /** The persistent flag value. */ - public static final int PERSISTENT = 1; - - /** {@inheritDoc} */ - @Override - public void setPersistent(String key) { - getEntry(key).setPersistent(); - } - - /** {@inheritDoc} */ - @Override - public void clearPersistent(String key) { - getEntry(key).clearPersistent(); - } - - /** {@inheritDoc} */ - @Override - public boolean isPersistent(String key) { - return getEntry(key).isPersistent(); - } - - /** {@inheritDoc} */ - @Override - public void setFlags(String key, int flags) { - getEntry(key).setFlags(flags); - } - - /** {@inheritDoc} */ - @Override - public void clearFlags(String key, int flags) { - getEntry(key).clearFlags(flags); - } - - /** {@inheritDoc} */ - @Override - public int getFlags(String key) { - return getEntry(key).getFlags(); - } - - /** {@inheritDoc} */ - @Override - public void delete(String key) { - getEntry(key).delete(); - } - - /** - * Deletes ALL keys in ALL subtables. Use with caution! - * - * @deprecated Use {@link NetworkTableInstance#deleteAllEntries()} instead. - */ - @Deprecated - public static void globalDeleteAll() { - NetworkTableInstance.getDefault().deleteAllEntries(); - } - - /** - * Flushes all updated values immediately to the network. Note: This is rate-limited to protect - * the network from flooding. This is primarily useful for synchronizing network updates with user - * code. - * - * @deprecated Use {@link NetworkTableInstance#flush()} instead. - */ - @Deprecated - public static void flush() { - NetworkTableInstance.getDefault().flush(); - } - - /** - * Set the periodic update rate. - * - * @param interval update interval in seconds (range 0.01 to 1.0) - * @deprecated Use {@link NetworkTableInstance#setUpdateRate(double)} instead. - */ - @Deprecated - public static void setUpdateRate(double interval) { - NetworkTableInstance.getDefault().setUpdateRate(interval); - } - - /** - * Saves persistent keys to a file. The server does this automatically. - * - * @param filename file name - * @throws PersistentException if error saving file - * @deprecated Use {@link NetworkTableInstance#savePersistent(String)} instead. - */ - @Deprecated - public static void savePersistent(String filename) throws PersistentException { - NetworkTableInstance.getDefault().savePersistent(filename); - } - - /** - * Loads persistent keys from a file. The server does this automatically. - * - * @param filename file name - * @return List of warnings (errors result in an exception instead) - * @throws PersistentException if error reading file - * @deprecated Use {@link NetworkTableInstance#loadPersistent(String)} instead. - */ - @Deprecated - public static String[] loadPersistent(String filename) throws PersistentException { - return NetworkTableInstance.getDefault().loadPersistent(filename); - } - - /* - * Deprecated Methods - */ - - /** - * {@inheritDoc} - * - * @deprecated Use {@link #putNumber(String, double)} instead. - */ - @Override - @Deprecated - public boolean putDouble(String key, double value) { - return putNumber(key, value); - } - - /** - * {@inheritDoc} - * - * @deprecated Use {@link #getNumber(String, double)} instead. - */ - @Override - @Deprecated - public double getDouble(String key, double defaultValue) { - return getNumber(key, defaultValue); - } - - /** {@inheritDoc} */ - @Override - public String getPath() { - return path; - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof NetworkTable)) { - return false; - } - NetworkTable other = (NetworkTable) o; - return inst.equals(other.inst) && path.equals(other.path); - } - - @Override - public int hashCode() { - return Objects.hash(inst, path); - } -} diff --git a/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/IRemote.java b/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/IRemote.java deleted file mode 100644 index 508e8812b5..0000000000 --- a/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/IRemote.java +++ /dev/null @@ -1,44 +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 edu.wpi.first.wpilibj.tables; - -/** - * Represents an object that has a remote connection. - * - * @deprecated Use {@link edu.wpi.first.networktables.NetworkTableInstance}. - */ -@Deprecated -@SuppressWarnings("checkstyle:all") -public interface IRemote { - /** - * Register an object to listen for connection and disconnection events - * - * @param listener the listener to be register - * @param immediateNotify if the listener object should be notified of the current connection - * state - */ - public void addConnectionListener(IRemoteConnectionListener listener, boolean immediateNotify); - - /** - * Unregister a listener from connection events - * - * @param listener the listener to be unregistered - */ - public void removeConnectionListener(IRemoteConnectionListener listener); - - /** - * Get the current state of the objects connection - * - * @return the current connection state - */ - public boolean isConnected(); - - /** - * If the object is acting as a server - * - * @return if the object is a server - */ - public boolean isServer(); -} diff --git a/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/IRemoteConnectionListener.java b/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/IRemoteConnectionListener.java deleted file mode 100644 index ed5d02b8b6..0000000000 --- a/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/IRemoteConnectionListener.java +++ /dev/null @@ -1,49 +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 edu.wpi.first.wpilibj.tables; - -import edu.wpi.first.networktables.ConnectionInfo; - -/** - * A listener that listens for connection changes in a {@link IRemote} object. - * - * @deprecated Use Consumer<{@link edu.wpi.first.networktables.ConnectionNotification}>. - */ -@Deprecated -@SuppressWarnings("checkstyle:all") -public interface IRemoteConnectionListener { - /** - * Called when an IRemote is connected - * - * @param remote the object that connected - */ - public void connected(IRemote remote); - /** - * Called when an IRemote is disconnected - * - * @param remote the object that disconnected - */ - public void disconnected(IRemote remote); - /** - * Extended version of connected called when an IRemote is connected. Contains the connection info - * of the connected remote - * - * @param remote the object that connected - * @param info the connection info for the connected remote - */ - public default void connectedEx(IRemote remote, ConnectionInfo info) { - connected(remote); - } - /** - * Extended version of connected called when an IRemote is disconnected. Contains the connection - * info of the disconnected remote - * - * @param remote the object that disconnected - * @param info the connection info for the disconnected remote - */ - public default void disconnectedEx(IRemote remote, ConnectionInfo info) { - disconnected(remote); - } -} diff --git a/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java b/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java deleted file mode 100644 index 330484a73d..0000000000 --- a/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/ITable.java +++ /dev/null @@ -1,513 +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 edu.wpi.first.wpilibj.tables; - -import java.nio.ByteBuffer; -import java.util.Set; - -/** - * A table whose values can be read and written to. - * - * @deprecated Use {@link edu.wpi.first.networktables.NetworkTable}. - */ -@Deprecated -@SuppressWarnings("checkstyle:all") -public interface ITable { - - /** - * Checks the table and tells if it contains the specified key - * - * @param key the key to search for - * @return true if the table as a value assigned to the given key - */ - public boolean containsKey(String key); - - /** - * @param key the key to search for - * @return true if there is a subtable with the key which contains at least one key/subtable of - * its own - */ - public boolean containsSubTable(String key); - - /** - * Returns the table at the specified key. If there is no table at the specified key, it will - * create a new table - * - * @param key the name of the table relative to this one - * @return a sub table relative to this one - */ - public ITable getSubTable(String key); - - /** - * Gets all keys in the table (not including sub-tables). - * - * @param types bitmask of types; 0 is treated as a "don't care". - * @return keys currently in the table - */ - public Set getKeys(int types); - - /** - * Gets all keys in the table (not including sub-tables). - * - * @return keys currently in the table - */ - public Set getKeys(); - - /** - * Gets the names of all subtables in the table. - * - * @return subtables currently in the table - */ - public Set getSubTables(); - - /** - * Makes a key's value persistent through program restarts. The key cannot be null. - * - * @param key the key name - */ - public void setPersistent(String key); - - /** - * Stop making a key's value persistent through program restarts. The key cannot be null. - * - * @param key the key name - */ - public void clearPersistent(String key); - - /** - * Returns whether the value is persistent through program restarts. The key cannot be null. - * - * @param key the key name - * @return True if the value is persistent. - */ - public boolean isPersistent(String key); - - /** - * Sets flags on the specified key in this table. The key can not be null. - * - * @param key the key name - * @param flags the flags to set (bitmask) - */ - public void setFlags(String key, int flags); - - /** - * Clears flags on the specified key in this table. The key can not be null. - * - * @param key the key name - * @param flags the flags to clear (bitmask) - */ - public void clearFlags(String key, int flags); - - /** - * Returns the flags for the specified key. - * - * @param key the key name - * @return the flags, or 0 if the key is not defined - */ - public int getFlags(String key); - - /** - * Deletes the specified key in this table. The key can not be null. - * - * @param key the key name - */ - public void delete(String key); - - /** - * Gets the value associated with a key as an object. NOTE: If the value is a double, it will - * return a Double object, not a primitive. To get the primitive, use {@link #getDouble(String, - * double)}. - * - * @param key the key of the value to look up - * @param defaultValue the default value if the key is null - * @return the value associated with the given key - */ - public Object getValue(String key, Object defaultValue); - - /** - * Put a value in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - * @throws IllegalArgumentException when the value is not supported by the table - */ - public boolean putValue(String key, Object value) throws IllegalArgumentException; - - /** - * Put a number in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putNumber(String key, double value); - - /** - * Gets the current value in the table, setting it if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultNumber(String key, double defaultValue); - - /** - * Returns the number the key maps to. If the key does not exist or is of different type, it will - * return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value if there is no value - * associated with the key - */ - public double getNumber(String key, double defaultValue); - - /** - * Put a string in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putString(String key, String value); - - /** - * Gets the current value in the table, setting it if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultString(String key, String defaultValue); - - /** - * Returns the string the key maps to. If the key does not exist or is of different type, it will - * return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value if there is no value - * associated with the key - */ - public String getString(String key, String defaultValue); - - /** - * Put a boolean in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putBoolean(String key, boolean value); - - /** - * Gets the current value in the table, setting it if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultBoolean(String key, boolean defaultValue); - - /** - * Returns the boolean the key maps to. If the key does not exist or is of different type, it will - * return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value if there is no value - * associated with the key - */ - public boolean getBoolean(String key, boolean defaultValue); - - /** - * Put a boolean array in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putBooleanArray(String key, boolean[] value); - - /** - * Gets the current value in the table, setting it if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultBooleanArray(String key, boolean[] defaultValue); - - /** - * Put a boolean array in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putBooleanArray(String key, Boolean[] value); - - /** - * Gets the current value in the table, setting it if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue); - - /** - * Returns the boolean array the key maps to. If the key does not exist or is of different type, - * it will return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value if there is no value - * associated with the key - */ - public boolean[] getBooleanArray(String key, boolean[] defaultValue); - /** - * Returns the boolean array the key maps to. If the key does not exist or is of different type, - * it will return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value if there is no value - * associated with the key - */ - public Boolean[] getBooleanArray(String key, Boolean[] defaultValue); - - /** - * Put a number array in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putNumberArray(String key, double[] value); - - /** - * Gets the current value in the table, setting it if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultNumberArray(String key, double[] defaultValue); - - /** - * Put a number array in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putNumberArray(String key, Double[] value); - - /** - * Gets the current value in the table, setting it if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultNumberArray(String key, Double[] defaultValue); - - /** - * Returns the number array the key maps to. If the key does not exist or is of different type, it - * will return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value if there is no value - * associated with the key - */ - public double[] getNumberArray(String key, double[] defaultValue); - /** - * Returns the number array the key maps to. If the key does not exist or is of different type, it - * will return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value if there is no value - * associated with the key - */ - public Double[] getNumberArray(String key, Double[] defaultValue); - - /** - * Put a string array in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putStringArray(String key, String[] value); - - /** - * Gets the current value in the table, setting it if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultStringArray(String key, String[] defaultValue); - - /** - * Returns the string array the key maps to. If the key does not exist or is of different type, it - * will return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value if there is no value - * associated with the key - */ - public String[] getStringArray(String key, String[] defaultValue); - - /** - * Put a raw value (byte array) in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - public boolean putRaw(String key, byte[] value); - - /** - * Gets the current value in the table, setting it if it does not exist. - * - * @param key the key - * @param defaultValue the default value to set if key doens't exist. - * @return False if the table key exists with a different type - */ - public boolean setDefaultRaw(String key, byte[] defaultValue); - - /** - * Put a raw value (bytes from a byte buffer) in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @param len the length of the value - * @return False if the table key already exists with a different type - */ - public boolean putRaw(String key, ByteBuffer value, int len); - - /** - * Returns the raw value (byte array) the key maps to. If the key does not exist or is of - * different type, it will return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value if there is no value - * associated with the key - */ - public byte[] getRaw(String key, byte[] defaultValue); - - /** Notifier flag values. */ - public static final int NOTIFY_IMMEDIATE = 0x01; - - public static final int NOTIFY_LOCAL = 0x02; - public static final int NOTIFY_NEW = 0x04; - public static final int NOTIFY_DELETE = 0x08; - public static final int NOTIFY_UPDATE = 0x10; - public static final int NOTIFY_FLAGS = 0x20; - - /** - * Add a listener for changes to the table - * - * @param listener the listener to add - */ - public void addTableListener(ITableListener listener); - /** - * Add a listener for changes to the table - * - * @param listener the listener to add - * @param immediateNotify if true then this listener will be notified of all current entries - * (marked as new) - */ - public void addTableListener(ITableListener listener, boolean immediateNotify); - /** - * Add a listener for changes to the table - * - * @param listener the listener to add - * @param flags bitmask specifying desired notifications - */ - public void addTableListenerEx(ITableListener listener, int flags); - - /** - * Add a listener for changes to a specific key the table - * - * @param key the key to listen for - * @param listener the listener to add - * @param immediateNotify if true then this listener will be notified of all current entries - * (marked as new) - */ - public void addTableListener(String key, ITableListener listener, boolean immediateNotify); - /** - * Add a listener for changes to a specific key the table - * - * @param key the key to listen for - * @param listener the listener to add - * @param flags bitmask specifying desired notifications - */ - public void addTableListenerEx(String key, ITableListener listener, int flags); - /** - * This will immediately notify the listener of all current sub tables - * - * @param listener the listener to notify - */ - public void addSubTableListener(final ITableListener listener); - /** - * This will immediately notify the listener of all current sub tables - * - * @param listener the listener to notify - * @param localNotify if true then this listener will be notified of all local changes in addition - * to all remote changes - */ - public void addSubTableListener(final ITableListener listener, boolean localNotify); - /** - * Remove a listener from receiving table events - * - * @param listener the listener to be removed - */ - public void removeTableListener(ITableListener listener); - - /* - * Deprecated Methods - */ - - /** - * Maps the specified key to the specified value in this table. The key can not be null. The value - * can be retrieved by calling the get method with a key that is equal to the original key. - * - * @param key the key - * @param value the value - * @return False if the table key already exists with a different type - * @throws IllegalArgumentException if key is null - * @deprecated Use {@link #putNumber(String, double)} instead. - */ - @Deprecated - public boolean putDouble(String key, double value); - - /** - * Returns the value at the specified key. - * - * @param key the key - * @param defaultValue the value returned if the key is undefined - * @return the value - * @throws IllegalArgumentException if the value mapped to by the key is not a double - * @throws IllegalArgumentException if the key is null - * @deprecated Use {@link #getNumber(String, double)} instead. - */ - @Deprecated - public double getDouble(String key, double defaultValue); - - /** - * Gets the full path of this table. Does not include the trailing "/". - * - * @return The path to this table (e.g. "", "/foo"). - */ - public String getPath(); -} diff --git a/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/ITableListener.java b/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/ITableListener.java deleted file mode 100644 index 3ff81f17ec..0000000000 --- a/ntcore/src/main/java/edu/wpi/first/wpilibj/tables/ITableListener.java +++ /dev/null @@ -1,43 +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 edu.wpi.first.wpilibj.tables; - -/** - * A listener that listens to changes in values in a {@link ITable}. - * - * @deprecated Use Consumer<{@link edu.wpi.first.networktables.EntryNotification}>, {@link - * edu.wpi.first.networktables.TableEntryListener}, or {@link - * edu.wpi.first.networktables.TableListener} as appropriate. - */ -@FunctionalInterface -@Deprecated -@SuppressWarnings("checkstyle:all") -public interface ITableListener { - /** - * Called when a key-value pair is changed in a {@link ITable} - * - * @param source the table the key-value pair exists in - * @param key the key associated with the value that changed - * @param value the new value - * @param isNew true if the key did not previously exist in the table, otherwise it is false - */ - public void valueChanged(ITable source, String key, Object value, boolean isNew); - - /** - * Extended version of valueChanged. Called when a key-value pair is changed in a {@link ITable}. - * The default implementation simply calls valueChanged(). If this is overridden, valueChanged() - * will not be called. - * - * @param source the table the key-value pair exists in - * @param key the key associated with the value that changed - * @param value the new value - * @param flags update flags; for example, NOTIFY_NEW if the key did not previously exist in the - * table - */ - public default void valueChangedEx(ITable source, String key, Object value, int flags) { - // NOTIFY_NEW = 0x04 - valueChanged(source, key, value, (flags & 0x04) != 0); - } -} diff --git a/ntcore/src/main/native/cpp/Dispatcher.cpp b/ntcore/src/main/native/cpp/Dispatcher.cpp index ce6df31e59..839faeb1f2 100644 --- a/ntcore/src/main/native/cpp/Dispatcher.cpp +++ b/ntcore/src/main/native/cpp/Dispatcher.cpp @@ -18,9 +18,9 @@ using namespace nt; -void Dispatcher::StartServer(const Twine& persist_filename, +void Dispatcher::StartServer(const wpi::Twine& persist_filename, const char* listen_address, unsigned int port) { - std::string listen_address_copy(StringRef(listen_address).trim()); + std::string listen_address_copy(wpi::StringRef(listen_address).trim()); DispatcherBase::StartServer( persist_filename, std::unique_ptr(new wpi::TCPAcceptor( @@ -28,7 +28,7 @@ void Dispatcher::StartServer(const Twine& persist_filename, } void Dispatcher::SetServer(const char* server_name, unsigned int port) { - std::string server_name_copy(StringRef(server_name).trim()); + std::string server_name_copy(wpi::StringRef(server_name).trim()); SetConnector([=]() -> std::unique_ptr { return wpi::TCPConnector::connect(server_name_copy.c_str(), static_cast(port), m_logger, 1); @@ -36,7 +36,7 @@ void Dispatcher::SetServer(const char* server_name, unsigned int port) { } void Dispatcher::SetServer( - ArrayRef> servers) { + wpi::ArrayRef> servers) { wpi::SmallVector, 16> servers_copy; for (const auto& server : servers) { servers_copy.emplace_back(std::string{server.first.trim()}, @@ -53,7 +53,7 @@ void Dispatcher::SetServer( } void Dispatcher::SetServerTeam(unsigned int team, unsigned int port) { - std::pair servers[5]; + std::pair servers[5]; // 10.te.am.2 wpi::SmallString<32> fixed; @@ -95,7 +95,7 @@ void Dispatcher::SetServerTeam(unsigned int team, unsigned int port) { } void Dispatcher::SetServerOverride(const char* server_name, unsigned int port) { - std::string server_name_copy(StringRef(server_name).trim()); + std::string server_name_copy(wpi::StringRef(server_name).trim()); SetConnectorOverride([=]() -> std::unique_ptr { return wpi::TCPConnector::connect(server_name_copy.c_str(), static_cast(port), m_logger, 1); @@ -134,7 +134,7 @@ void DispatcherBase::StartLocal() { } void DispatcherBase::StartServer( - const Twine& persist_filename, + const wpi::Twine& persist_filename, std::unique_ptr acceptor) { { std::scoped_lock lock(m_user_mutex); @@ -230,7 +230,7 @@ void DispatcherBase::SetUpdateRate(double interval) { m_update_rate = static_cast(interval * 1000); } -void DispatcherBase::SetIdentity(const Twine& name) { +void DispatcherBase::SetIdentity(const wpi::Twine& name) { std::scoped_lock lock(m_user_mutex); m_identity = name.str(); } diff --git a/ntcore/src/main/native/cpp/Dispatcher.h b/ntcore/src/main/native/cpp/Dispatcher.h index f5767d04dc..020f737a17 100644 --- a/ntcore/src/main/native/cpp/Dispatcher.h +++ b/ntcore/src/main/native/cpp/Dispatcher.h @@ -45,12 +45,12 @@ class DispatcherBase : public IDispatcher { unsigned int GetNetworkMode() const; void StartLocal(); - void StartServer(const Twine& persist_filename, + void StartServer(const wpi::Twine& persist_filename, std::unique_ptr acceptor); void StartClient(); void Stop(); void SetUpdateRate(double interval); - void SetIdentity(const Twine& name); + void SetIdentity(const wpi::Twine& name); void Flush(); std::vector GetConnections() const; bool IsConnected() const; @@ -132,11 +132,12 @@ class Dispatcher : public DispatcherBase { wpi::Logger& logger) : DispatcherBase(storage, notifier, logger) {} - void StartServer(const Twine& persist_filename, const char* listen_address, - unsigned int port); + void StartServer(const wpi::Twine& persist_filename, + const char* listen_address, unsigned int port); void SetServer(const char* server_name, unsigned int port); - void SetServer(ArrayRef> servers); + void SetServer( + wpi::ArrayRef> servers); void SetServerTeam(unsigned int team, unsigned int port); void SetServerOverride(const char* server_name, unsigned int port); diff --git a/ntcore/src/main/native/cpp/EntryNotifier.cpp b/ntcore/src/main/native/cpp/EntryNotifier.cpp index 81861dfd98..fb05cd9470 100644 --- a/ntcore/src/main/native/cpp/EntryNotifier.cpp +++ b/ntcore/src/main/native/cpp/EntryNotifier.cpp @@ -59,7 +59,7 @@ bool impl::EntryNotifierThread::Matches(const EntryListenerData& listener, unsigned int EntryNotifier::Add( std::function callback, - StringRef prefix, unsigned int flags) { + wpi::StringRef prefix, unsigned int flags) { if ((flags & NT_NOTIFY_LOCAL) != 0) { m_local_notifiers = true; } @@ -93,7 +93,7 @@ unsigned int EntryNotifier::AddPolled(unsigned int poller_uid, return DoAdd(poller_uid, Handle(m_inst, local_id, Handle::kEntry), flags); } -void EntryNotifier::NotifyEntry(unsigned int local_id, StringRef name, +void EntryNotifier::NotifyEntry(unsigned int local_id, wpi::StringRef name, std::shared_ptr value, unsigned int flags, unsigned int only_listener) { diff --git a/ntcore/src/main/native/cpp/EntryNotifier.h b/ntcore/src/main/native/cpp/EntryNotifier.h index c80fc627d0..bfc77f7025 100644 --- a/ntcore/src/main/native/cpp/EntryNotifier.h +++ b/ntcore/src/main/native/cpp/EntryNotifier.h @@ -29,13 +29,13 @@ struct EntryListenerData EntryListenerData() = default; EntryListenerData( std::function callback_, - StringRef prefix_, unsigned int flags_) + wpi::StringRef prefix_, unsigned int flags_) : CallbackListenerData(callback_), prefix(prefix_), flags(flags_) {} EntryListenerData( std::function callback_, NT_Entry entry_, unsigned int flags_) : CallbackListenerData(callback_), entry(entry_), flags(flags_) {} - EntryListenerData(unsigned int poller_uid_, StringRef prefix_, + EntryListenerData(unsigned int poller_uid_, wpi::StringRef prefix_, unsigned int flags_) : CallbackListenerData(poller_uid_), prefix(prefix_), flags(flags_) {} EntryListenerData(unsigned int poller_uid_, NT_Entry entry_, @@ -93,7 +93,7 @@ class EntryNotifier unsigned int AddPolled(unsigned int poller_uid, unsigned int local_id, unsigned int flags) override; - void NotifyEntry(unsigned int local_id, StringRef name, + void NotifyEntry(unsigned int local_id, wpi::StringRef name, std::shared_ptr value, unsigned int flags, unsigned int only_listener = UINT_MAX) override; diff --git a/ntcore/src/main/native/cpp/IEntryNotifier.h b/ntcore/src/main/native/cpp/IEntryNotifier.h index 031621ff4b..bfc6da34b9 100644 --- a/ntcore/src/main/native/cpp/IEntryNotifier.h +++ b/ntcore/src/main/native/cpp/IEntryNotifier.h @@ -31,7 +31,7 @@ class IEntryNotifier { virtual unsigned int AddPolled(unsigned int poller_uid, unsigned int local_id, unsigned int flags) = 0; - virtual void NotifyEntry(unsigned int local_id, StringRef name, + virtual void NotifyEntry(unsigned int local_id, wpi::StringRef name, std::shared_ptr value, unsigned int flags, unsigned int only_listener = UINT_MAX) = 0; }; diff --git a/ntcore/src/main/native/cpp/IRpcServer.h b/ntcore/src/main/native/cpp/IRpcServer.h index 4d90a3751d..1abce862f4 100644 --- a/ntcore/src/main/native/cpp/IRpcServer.h +++ b/ntcore/src/main/native/cpp/IRpcServer.h @@ -14,7 +14,7 @@ namespace nt { class IRpcServer { public: - typedef std::function SendResponseFunc; + typedef std::function SendResponseFunc; IRpcServer() = default; IRpcServer(const IRpcServer&) = delete; @@ -24,7 +24,7 @@ class IRpcServer { virtual void RemoveRpc(unsigned int rpc_uid) = 0; virtual void ProcessRpc(unsigned int local_id, unsigned int call_uid, - StringRef name, StringRef params, + wpi::StringRef name, wpi::StringRef params, const ConnectionInfo& conn, SendResponseFunc send_response, unsigned int rpc_uid) = 0; diff --git a/ntcore/src/main/native/cpp/IStorage.h b/ntcore/src/main/native/cpp/IStorage.h index e4c97b52e5..47b3b50b01 100644 --- a/ntcore/src/main/native/cpp/IStorage.h +++ b/ntcore/src/main/native/cpp/IStorage.h @@ -50,10 +50,10 @@ class IStorage { // Filename-based save/load functions. Used both by periodic saves and // accessible directly via the user API. - virtual const char* SavePersistent(const Twine& filename, + virtual const char* SavePersistent(const wpi::Twine& filename, bool periodic) const = 0; virtual const char* LoadPersistent( - const Twine& filename, + const wpi::Twine& filename, std::function warn) = 0; }; diff --git a/ntcore/src/main/native/cpp/NetworkConnection.cpp b/ntcore/src/main/native/cpp/NetworkConnection.cpp index 85957e2318..84c8d981e8 100644 --- a/ntcore/src/main/native/cpp/NetworkConnection.cpp +++ b/ntcore/src/main/native/cpp/NetworkConnection.cpp @@ -142,7 +142,7 @@ std::string NetworkConnection::remote_id() const { return m_remote_id; } -void NetworkConnection::set_remote_id(StringRef remote_id) { +void NetworkConnection::set_remote_id(wpi::StringRef remote_id) { std::scoped_lock lock(m_remote_id_mutex); m_remote_id = remote_id; } diff --git a/ntcore/src/main/native/cpp/NetworkConnection.h b/ntcore/src/main/native/cpp/NetworkConnection.h index c7c659993e..69015054c0 100644 --- a/ntcore/src/main/native/cpp/NetworkConnection.h +++ b/ntcore/src/main/native/cpp/NetworkConnection.h @@ -76,7 +76,7 @@ class NetworkConnection : public INetworkConnection { void set_state(State state) final; std::string remote_id() const; - void set_remote_id(StringRef remote_id); + void set_remote_id(wpi::StringRef remote_id); uint64_t last_update() const { return m_last_update; } diff --git a/ntcore/src/main/native/cpp/RpcServer.cpp b/ntcore/src/main/native/cpp/RpcServer.cpp index d413cd8438..88a53b796d 100644 --- a/ntcore/src/main/native/cpp/RpcServer.cpp +++ b/ntcore/src/main/native/cpp/RpcServer.cpp @@ -27,7 +27,7 @@ void RpcServer::RemoveRpc(unsigned int rpc_uid) { } void RpcServer::ProcessRpc(unsigned int local_id, unsigned int call_uid, - StringRef name, StringRef params, + wpi::StringRef name, wpi::StringRef params, const ConnectionInfo& conn, SendResponseFunc send_response, unsigned int rpc_uid) { diff --git a/ntcore/src/main/native/cpp/RpcServer.h b/ntcore/src/main/native/cpp/RpcServer.h index 4d20c50686..e4d1b1d63d 100644 --- a/ntcore/src/main/native/cpp/RpcServer.h +++ b/ntcore/src/main/native/cpp/RpcServer.h @@ -22,8 +22,8 @@ namespace impl { typedef std::pair RpcIdPair; struct RpcNotifierData : public RpcAnswer { - RpcNotifierData(NT_Entry entry_, NT_RpcCall call_, StringRef name_, - StringRef params_, const ConnectionInfo& conn_, + RpcNotifierData(NT_Entry entry_, NT_RpcCall call_, wpi::StringRef name_, + wpi::StringRef params_, const ConnectionInfo& conn_, IRpcServer::SendResponseFunc send_response_) : RpcAnswer{entry_, call_, name_, params_, conn_}, send_response{std::move(send_response_)} {} @@ -93,9 +93,9 @@ class RpcServer unsigned int AddPolled(unsigned int poller_uid); void RemoveRpc(unsigned int rpc_uid) override; - void ProcessRpc(unsigned int local_id, unsigned int call_uid, StringRef name, - StringRef params, const ConnectionInfo& conn, - SendResponseFunc send_response, + void ProcessRpc(unsigned int local_id, unsigned int call_uid, + wpi::StringRef name, wpi::StringRef params, + const ConnectionInfo& conn, SendResponseFunc send_response, unsigned int rpc_uid) override; bool PostRpcResponse(unsigned int local_id, unsigned int call_uid, diff --git a/ntcore/src/main/native/cpp/Storage.cpp b/ntcore/src/main/native/cpp/Storage.cpp index 63929fc175..f666976053 100644 --- a/ntcore/src/main/native/cpp/Storage.cpp +++ b/ntcore/src/main/native/cpp/Storage.cpp @@ -91,7 +91,7 @@ void Storage::ProcessIncomingEntryAssign(std::shared_ptr msg, INetworkConnection* conn) { std::unique_lock lock(m_mutex); unsigned int id = msg->id(); - StringRef name = msg->str(); + wpi::StringRef name = msg->str(); Entry* entry; bool may_need_update = false; SequenceNumber seq_num(msg->seq_num_uid()); @@ -359,7 +359,7 @@ void Storage::ProcessIncomingExecuteRpc( unsigned int call_uid = msg->seq_num_uid(); m_rpc_server.ProcessRpc( entry->local_id, call_uid, entry->name, msg->str(), conn_info, - [=](StringRef result) { + [=](wpi::StringRef result) { auto c = conn_weak.lock(); if (c) { c->QueueOutgoing(Message::RpcResponse(id, call_uid, result)); @@ -442,7 +442,7 @@ void Storage::ApplyInitialAssignments( } SequenceNumber seq_num(msg->seq_num_uid()); - StringRef name = msg->str(); + wpi::StringRef name = msg->str(); Entry* entry = GetOrNew(name); entry->seq_num = seq_num; @@ -509,7 +509,7 @@ void Storage::ApplyInitialAssignments( } } -std::shared_ptr Storage::GetEntryValue(StringRef name) const { +std::shared_ptr Storage::GetEntryValue(wpi::StringRef name) const { std::scoped_lock lock(m_mutex); auto i = m_entries.find(name); if (i == m_entries.end()) { @@ -526,7 +526,7 @@ std::shared_ptr Storage::GetEntryValue(unsigned int local_id) const { return m_localmap[local_id]->value; } -bool Storage::SetDefaultEntryValue(StringRef name, +bool Storage::SetDefaultEntryValue(wpi::StringRef name, std::shared_ptr value) { if (name.empty()) { return false; @@ -566,7 +566,7 @@ bool Storage::SetDefaultEntryValue(unsigned int local_id, return true; } -bool Storage::SetEntryValue(StringRef name, std::shared_ptr value) { +bool Storage::SetEntryValue(wpi::StringRef name, std::shared_ptr value) { if (name.empty()) { return true; } @@ -664,7 +664,8 @@ void Storage::SetEntryValueImpl(Entry* entry, std::shared_ptr value, } } -void Storage::SetEntryTypeValue(StringRef name, std::shared_ptr value) { +void Storage::SetEntryTypeValue(wpi::StringRef name, + std::shared_ptr value) { if (name.empty()) { return; } @@ -694,7 +695,7 @@ void Storage::SetEntryTypeValue(unsigned int local_id, SetEntryValueImpl(entry, value, lock, true); } -void Storage::SetEntryFlags(StringRef name, unsigned int flags) { +void Storage::SetEntryFlags(wpi::StringRef name, unsigned int flags) { if (name.empty()) { return; } @@ -746,7 +747,7 @@ void Storage::SetEntryFlagsImpl(Entry* entry, unsigned int flags, } } -unsigned int Storage::GetEntryFlags(StringRef name) const { +unsigned int Storage::GetEntryFlags(wpi::StringRef name) const { std::scoped_lock lock(m_mutex); auto i = m_entries.find(name); if (i == m_entries.end()) { @@ -763,7 +764,7 @@ unsigned int Storage::GetEntryFlags(unsigned int local_id) const { return m_localmap[local_id]->flags; } -void Storage::DeleteEntry(StringRef name) { +void Storage::DeleteEntry(wpi::StringRef name) { std::unique_lock lock(m_mutex); auto i = m_entries.find(name); if (i == m_entries.end()) { @@ -872,9 +873,9 @@ void Storage::DeleteAllEntries() { dispatcher->QueueOutgoing(Message::ClearEntries(), nullptr, nullptr); } -Storage::Entry* Storage::GetOrNew(const Twine& name) { +Storage::Entry* Storage::GetOrNew(const wpi::Twine& name) { wpi::SmallString<128> nameBuf; - StringRef nameStr = name.toStringRef(nameBuf); + wpi::StringRef nameStr = name.toStringRef(nameBuf); auto& entry = m_entries[nameStr]; if (!entry) { m_localmap.emplace_back(new Entry(nameStr)); @@ -884,7 +885,7 @@ Storage::Entry* Storage::GetOrNew(const Twine& name) { return entry; } -unsigned int Storage::GetEntry(const Twine& name) { +unsigned int Storage::GetEntry(const wpi::Twine& name) { if (name.isTriviallyEmpty() || (name.isSingleStringRef() && name.getSingleStringRef().empty())) { return UINT_MAX; @@ -893,10 +894,10 @@ unsigned int Storage::GetEntry(const Twine& name) { return GetOrNew(name)->local_id; } -std::vector Storage::GetEntries(const Twine& prefix, +std::vector Storage::GetEntries(const wpi::Twine& prefix, unsigned int types) { wpi::SmallString<128> prefixBuf; - StringRef prefixStr = prefix.toStringRef(prefixBuf); + wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf); std::scoped_lock lock(m_mutex); std::vector ids; for (auto& i : m_entries) { @@ -969,10 +970,10 @@ uint64_t Storage::GetEntryLastChange(unsigned int local_id) const { return entry->value->last_change(); } -std::vector Storage::GetEntryInfo(int inst, const Twine& prefix, +std::vector Storage::GetEntryInfo(int inst, const wpi::Twine& prefix, unsigned int types) { wpi::SmallString<128> prefixBuf; - StringRef prefixStr = prefix.toStringRef(prefixBuf); + wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf); std::scoped_lock lock(m_mutex); std::vector infos; for (auto& i : m_entries) { @@ -996,11 +997,11 @@ std::vector Storage::GetEntryInfo(int inst, const Twine& prefix, } unsigned int Storage::AddListener( - const Twine& prefix, + const wpi::Twine& prefix, std::function callback, unsigned int flags) const { wpi::SmallString<128> prefixBuf; - StringRef prefixStr = prefix.toStringRef(prefixBuf); + wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf); std::scoped_lock lock(m_mutex); unsigned int uid = m_notifier.Add(callback, prefixStr, flags); // perform immediate notifications @@ -1036,10 +1037,10 @@ unsigned int Storage::AddListener( } unsigned int Storage::AddPolledListener(unsigned int poller, - const Twine& prefix, + const wpi::Twine& prefix, unsigned int flags) const { wpi::SmallString<128> prefixBuf; - StringRef prefixStr = prefix.toStringRef(prefixBuf); + wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf); std::scoped_lock lock(m_mutex); unsigned int uid = m_notifier.AddPolled(poller, prefixStr, flags); // perform immediate notifications @@ -1110,11 +1111,11 @@ bool Storage::GetPersistentEntries( } bool Storage::GetEntries( - const Twine& prefix, + const wpi::Twine& prefix, std::vector>>* entries) const { wpi::SmallString<128> prefixBuf; - StringRef prefixStr = prefix.toStringRef(prefixBuf); + wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf); // copy values out of storage as quickly as possible so lock isn't held { std::scoped_lock lock(m_mutex); @@ -1138,7 +1139,7 @@ bool Storage::GetEntries( return true; } -void Storage::CreateRpc(unsigned int local_id, StringRef def, +void Storage::CreateRpc(unsigned int local_id, wpi::StringRef def, unsigned int rpc_uid) { std::unique_lock lock(m_mutex); if (local_id >= m_localmap.size()) { @@ -1183,7 +1184,7 @@ void Storage::CreateRpc(unsigned int local_id, StringRef def, } } -unsigned int Storage::CallRpc(unsigned int local_id, StringRef params) { +unsigned int Storage::CallRpc(unsigned int local_id, wpi::StringRef params) { std::unique_lock lock(m_mutex); if (local_id >= m_localmap.size()) { return 0; @@ -1201,7 +1202,7 @@ unsigned int Storage::CallRpc(unsigned int local_id, StringRef params) { unsigned int call_uid = entry->rpc_call_uid; auto msg = Message::ExecuteRpc(entry->id, call_uid, params); - StringRef name{entry->name}; + wpi::StringRef name{entry->name}; if (m_server) { // RPCs are unlikely to be used locally on the server, but handle it @@ -1217,7 +1218,7 @@ unsigned int Storage::CallRpc(unsigned int local_id, StringRef params) { unsigned int call_uid = msg->seq_num_uid(); m_rpc_server.ProcessRpc( local_id, call_uid, name, msg->str(), conn_info, - [=](StringRef result) { + [=](wpi::StringRef result) { std::scoped_lock lock(m_mutex); m_rpc_results.insert( std::make_pair(RpcIdPair{local_id, call_uid}, result)); diff --git a/ntcore/src/main/native/cpp/Storage.h b/ntcore/src/main/native/cpp/Storage.h index 73bc0c617c..96968b4573 100644 --- a/ntcore/src/main/native/cpp/Storage.h +++ b/ntcore/src/main/native/cpp/Storage.h @@ -72,35 +72,35 @@ class Storage : public IStorage { // User functions. These are the actual implementations of the corresponding // user API functions in ntcore_cpp. - std::shared_ptr GetEntryValue(StringRef name) const; + std::shared_ptr GetEntryValue(wpi::StringRef name) const; std::shared_ptr GetEntryValue(unsigned int local_id) const; - bool SetDefaultEntryValue(StringRef name, std::shared_ptr value); + bool SetDefaultEntryValue(wpi::StringRef name, std::shared_ptr value); bool SetDefaultEntryValue(unsigned int local_id, std::shared_ptr value); - bool SetEntryValue(StringRef name, std::shared_ptr value); + bool SetEntryValue(wpi::StringRef name, std::shared_ptr value); bool SetEntryValue(unsigned int local_id, std::shared_ptr value); - void SetEntryTypeValue(StringRef name, std::shared_ptr value); + void SetEntryTypeValue(wpi::StringRef name, std::shared_ptr value); void SetEntryTypeValue(unsigned int local_id, std::shared_ptr value); - void SetEntryFlags(StringRef name, unsigned int flags); + void SetEntryFlags(wpi::StringRef name, unsigned int flags); void SetEntryFlags(unsigned int local_id, unsigned int flags); - unsigned int GetEntryFlags(StringRef name) const; + unsigned int GetEntryFlags(wpi::StringRef name) const; unsigned int GetEntryFlags(unsigned int local_id) const; - void DeleteEntry(StringRef name); + void DeleteEntry(wpi::StringRef name); void DeleteEntry(unsigned int local_id); void DeleteAllEntries(); - std::vector GetEntryInfo(int inst, const Twine& prefix, + std::vector GetEntryInfo(int inst, const wpi::Twine& prefix, unsigned int types); unsigned int AddListener( - const Twine& prefix, + const wpi::Twine& prefix, std::function callback, unsigned int flags) const; unsigned int AddListener( @@ -108,14 +108,16 @@ class Storage : public IStorage { std::function callback, unsigned int flags) const; - unsigned int AddPolledListener(unsigned int poller_uid, const Twine& prefix, + unsigned int AddPolledListener(unsigned int poller_uid, + const wpi::Twine& prefix, unsigned int flags) const; unsigned int AddPolledListener(unsigned int poller_uid, unsigned int local_id, unsigned int flags) const; // Index-only - unsigned int GetEntry(const Twine& name); - std::vector GetEntries(const Twine& prefix, unsigned int types); + unsigned int GetEntry(const wpi::Twine& name); + std::vector GetEntries(const wpi::Twine& prefix, + unsigned int types); EntryInfo GetEntryInfo(int inst, unsigned int local_id) const; std::string GetEntryName(unsigned int local_id) const; NT_Type GetEntryType(unsigned int local_id) const; @@ -123,29 +125,32 @@ class Storage : public IStorage { // Filename-based save/load functions. Used both by periodic saves and // accessible directly via the user API. - const char* SavePersistent(const Twine& filename, + const char* SavePersistent(const wpi::Twine& filename, bool periodic) const override; const char* LoadPersistent( - const Twine& filename, + const wpi::Twine& filename, std::function warn) override; - const char* SaveEntries(const Twine& filename, const Twine& prefix) const; + const char* SaveEntries(const wpi::Twine& filename, + const wpi::Twine& prefix) const; const char* LoadEntries( - const Twine& filename, const Twine& prefix, + const wpi::Twine& filename, const wpi::Twine& prefix, std::function warn); // Stream-based save/load functions (exposed for testing purposes). These // implement the guts of the filename-based functions. void SavePersistent(wpi::raw_ostream& os, bool periodic) const; - bool LoadEntries(wpi::raw_istream& is, const Twine& prefix, bool persistent, + bool LoadEntries(wpi::raw_istream& is, const wpi::Twine& prefix, + bool persistent, std::function warn); - void SaveEntries(wpi::raw_ostream& os, const Twine& prefix) const; + void SaveEntries(wpi::raw_ostream& os, const wpi::Twine& prefix) const; // RPC configuration needs to come through here as RPC definitions are // actually special Storage value types. - void CreateRpc(unsigned int local_id, StringRef def, unsigned int rpc_uid); - unsigned int CallRpc(unsigned int local_id, StringRef params); + void CreateRpc(unsigned int local_id, wpi::StringRef def, + unsigned int rpc_uid); + unsigned int CallRpc(unsigned int local_id, wpi::StringRef params); bool GetRpcResult(unsigned int local_id, unsigned int call_uid, std::string* result); bool GetRpcResult(unsigned int local_id, unsigned int call_uid, @@ -237,7 +242,7 @@ class Storage : public IStorage { bool periodic, std::vector>>* entries) const; - bool GetEntries(const Twine& prefix, + bool GetEntries(const wpi::Twine& prefix, std::vector>>* entries) const; void SetEntryValueImpl(Entry* entry, std::shared_ptr value, @@ -251,7 +256,7 @@ class Storage : public IStorage { template void DeleteAllEntriesImpl(bool local, F should_delete); void DeleteAllEntriesImpl(bool local); - Entry* GetOrNew(const Twine& name); + Entry* GetOrNew(const wpi::Twine& name); }; } // namespace nt diff --git a/ntcore/src/main/native/cpp/Storage_load.cpp b/ntcore/src/main/native/cpp/Storage_load.cpp index 956321d60f..04904aaa03 100644 --- a/ntcore/src/main/native/cpp/Storage_load.cpp +++ b/ntcore/src/main/native/cpp/Storage_load.cpp @@ -27,7 +27,7 @@ class LoadPersistentImpl { LoadPersistentImpl(wpi::raw_istream& is, WarnFunc warn) : m_is(is), m_warn(std::move(warn)) {} - bool Load(StringRef prefix, std::vector* entries); + bool Load(wpi::StringRef prefix, std::vector* entries); private: bool ReadLine(); @@ -138,7 +138,8 @@ static wpi::StringRef UnescapeString(wpi::StringRef source, return wpi::StringRef{buf.data(), buf.size()}; } -bool LoadPersistentImpl::Load(StringRef prefix, std::vector* entries) { +bool LoadPersistentImpl::Load(wpi::StringRef prefix, + std::vector* entries) { if (!ReadHeader()) { return false; // header } @@ -373,10 +374,10 @@ std::shared_ptr LoadPersistentImpl::ReadStringArrayValue() { } bool Storage::LoadEntries( - wpi::raw_istream& is, const Twine& prefix, bool persistent, + wpi::raw_istream& is, const wpi::Twine& prefix, bool persistent, std::function warn) { wpi::SmallString<128> prefixBuf; - StringRef prefixStr = prefix.toStringRef(prefixBuf); + wpi::StringRef prefixStr = prefix.toStringRef(prefixBuf); // entries to add std::vector entries; @@ -456,7 +457,7 @@ bool Storage::LoadEntries( } const char* Storage::LoadPersistent( - const Twine& filename, + const wpi::Twine& filename, std::function warn) { std::error_code ec; wpi::raw_fd_istream is(filename, ec); @@ -470,7 +471,7 @@ const char* Storage::LoadPersistent( } const char* Storage::LoadEntries( - const Twine& filename, const Twine& prefix, + const wpi::Twine& filename, const wpi::Twine& prefix, std::function warn) { std::error_code ec; wpi::raw_fd_istream is(filename, ec); diff --git a/ntcore/src/main/native/cpp/Storage_save.cpp b/ntcore/src/main/native/cpp/Storage_save.cpp index 113cd4a5ba..e6eff1862d 100644 --- a/ntcore/src/main/native/cpp/Storage_save.cpp +++ b/ntcore/src/main/native/cpp/Storage_save.cpp @@ -190,7 +190,7 @@ void Storage::SavePersistent(wpi::raw_ostream& os, bool periodic) const { SavePersistentImpl(os).Save(entries); } -const char* Storage::SavePersistent(const Twine& filename, +const char* Storage::SavePersistent(const wpi::Twine& filename, bool periodic) const { wpi::SmallString<128> fn; filename.toVector(fn); @@ -240,7 +240,8 @@ done: return err; } -void Storage::SaveEntries(wpi::raw_ostream& os, const Twine& prefix) const { +void Storage::SaveEntries(wpi::raw_ostream& os, + const wpi::Twine& prefix) const { std::vector entries; if (!GetEntries(prefix, &entries)) { return; @@ -248,8 +249,8 @@ void Storage::SaveEntries(wpi::raw_ostream& os, const Twine& prefix) const { SavePersistentImpl(os).Save(entries); } -const char* Storage::SaveEntries(const Twine& filename, - const Twine& prefix) const { +const char* Storage::SaveEntries(const wpi::Twine& filename, + const wpi::Twine& prefix) const { wpi::SmallString<128> fn; filename.toVector(fn); wpi::SmallString<128> tmp = fn; diff --git a/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp b/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp index f28adeca4e..75f9c713eb 100644 --- a/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp +++ b/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp @@ -1549,7 +1549,7 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_startClient__I_3Ljava_lang_Str } std::vector names; - std::vector> servers; + std::vector> servers; names.reserve(len); servers.reserve(len); for (int i = 0; i < len; ++i) { @@ -1561,7 +1561,7 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_startClient__I_3Ljava_lang_Str } names.emplace_back(JStringRef{env, elem}.str()); servers.emplace_back( - std::make_pair(nt::StringRef(names.back()), portInts[i])); + std::make_pair(wpi::StringRef(names.back()), portInts[i])); } env->ReleaseIntArrayElements(ports, portInts, JNI_ABORT); nt::StartClient(inst, servers); @@ -1636,7 +1636,7 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_setServer__I_3Ljava_lang_Strin } std::vector names; - std::vector> servers; + std::vector> servers; names.reserve(len); servers.reserve(len); for (int i = 0; i < len; ++i) { @@ -1648,7 +1648,7 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_setServer__I_3Ljava_lang_Strin } names.emplace_back(JStringRef{env, elem}.str()); servers.emplace_back( - std::make_pair(nt::StringRef(names.back()), portInts[i])); + std::make_pair(wpi::StringRef(names.back()), portInts[i])); } env->ReleaseIntArrayElements(ports, portInts, JNI_ABORT); nt::SetServer(inst, servers); diff --git a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp index f4a9bd52ac..d4839009ee 100644 --- a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp +++ b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp @@ -12,48 +12,34 @@ #include "networktables/NetworkTableInstance.h" #include "ntcore.h" -#include "tables/ITableListener.h" using namespace nt; -#ifdef __GNUC__ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#elif _WIN32 -#pragma warning(disable : 4996) -#endif - -const char NetworkTable::PATH_SEPARATOR_CHAR = '/'; -std::string NetworkTable::s_persistent_filename = "networktables.ini"; -bool NetworkTable::s_client = false; -bool NetworkTable::s_enable_ds = true; -bool NetworkTable::s_running = false; -unsigned int NetworkTable::s_port = NT_DEFAULT_PORT; - -StringRef NetworkTable::BasenameKey(StringRef key) { +wpi::StringRef NetworkTable::BasenameKey(wpi::StringRef key) { size_t slash = key.rfind(PATH_SEPARATOR_CHAR); - if (slash == StringRef::npos) { + if (slash == wpi::StringRef::npos) { return key; } return key.substr(slash + 1); } -std::string NetworkTable::NormalizeKey(const Twine& key, +std::string NetworkTable::NormalizeKey(const wpi::Twine& key, bool withLeadingSlash) { wpi::SmallString<128> buf; return NormalizeKey(key, buf, withLeadingSlash); } -StringRef NetworkTable::NormalizeKey(const Twine& key, - wpi::SmallVectorImpl& buf, - bool withLeadingSlash) { +wpi::StringRef NetworkTable::NormalizeKey(const wpi::Twine& key, + wpi::SmallVectorImpl& buf, + bool withLeadingSlash) { buf.clear(); if (withLeadingSlash) { buf.push_back(PATH_SEPARATOR_CHAR); } // for each path element, add it with a slash following wpi::SmallString<128> keyBuf; - StringRef keyStr = key.toStringRef(keyBuf); - wpi::SmallVector parts; + wpi::StringRef keyStr = key.toStringRef(keyBuf); + wpi::SmallVector parts; keyStr.split(parts, PATH_SEPARATOR_CHAR, -1, false); for (auto i = parts.begin(); i != parts.end(); ++i) { buf.append(i->begin(), i->end()); @@ -63,17 +49,17 @@ StringRef NetworkTable::NormalizeKey(const Twine& key, if (!keyStr.empty() && keyStr.back() != PATH_SEPARATOR_CHAR) { buf.pop_back(); } - return StringRef(buf.data(), buf.size()); + return wpi::StringRef(buf.data(), buf.size()); } -std::vector NetworkTable::GetHierarchy(const Twine& key) { +std::vector NetworkTable::GetHierarchy(const wpi::Twine& key) { std::vector hierarchy; hierarchy.emplace_back(1, PATH_SEPARATOR_CHAR); // for each path element, add it to the end of what we built previously wpi::SmallString<128> keyBuf; - StringRef keyStr = key.toStringRef(keyBuf); + wpi::StringRef keyStr = key.toStringRef(keyBuf); wpi::SmallString<128> path; - wpi::SmallVector parts; + wpi::SmallVector parts; keyStr.split(parts, PATH_SEPARATOR_CHAR, -1, false); if (!parts.empty()) { for (auto i = parts.begin(); i != parts.end(); ++i) { @@ -90,141 +76,12 @@ std::vector NetworkTable::GetHierarchy(const Twine& key) { return hierarchy; } -void NetworkTable::Initialize() { - if (s_running) { - Shutdown(); - } - auto inst = NetworkTableInstance::GetDefault(); - if (s_client) { - inst.StartClient(); - if (s_enable_ds) { - inst.StartDSClient(s_port); - } - } else { - inst.StartServer(s_persistent_filename, "", s_port); - } - s_running = true; -} - -void NetworkTable::Shutdown() { - if (!s_running) { - return; - } - auto inst = NetworkTableInstance::GetDefault(); - if (s_client) { - inst.StopDSClient(); - inst.StopClient(); - } else { - inst.StopServer(); - } - s_running = false; -} - -void NetworkTable::SetClientMode() { - s_client = true; -} - -void NetworkTable::SetServerMode() { - s_client = false; -} - -void NetworkTable::SetTeam(int team) { - auto inst = NetworkTableInstance::GetDefault(); - inst.SetServerTeam(team, s_port); - if (s_enable_ds) { - inst.StartDSClient(s_port); - } -} - -void NetworkTable::SetIPAddress(StringRef address) { - auto inst = NetworkTableInstance::GetDefault(); - wpi::SmallString<32> addr_copy{address}; - inst.SetServer(addr_copy.c_str(), s_port); - - // Stop the DS client if we're explicitly connecting to localhost - if (address == "localhost" || address == "127.0.0.1") { - inst.StopDSClient(); - } else if (s_enable_ds) { - inst.StartDSClient(s_port); - } -} - -void NetworkTable::SetIPAddress(ArrayRef addresses) { - auto inst = NetworkTableInstance::GetDefault(); - wpi::SmallVector servers; - for (const auto& ip_address : addresses) { - servers.emplace_back(ip_address); - } - inst.SetServer(servers, s_port); - - // Stop the DS client if we're explicitly connecting to localhost - if (!addresses.empty() && - (addresses[0] == "localhost" || addresses[0] == "127.0.0.1")) { - inst.StopDSClient(); - } else if (s_enable_ds) { - inst.StartDSClient(s_port); - } -} - -void NetworkTable::SetPort(unsigned int port) { - s_port = port; -} - -void NetworkTable::SetDSClientEnabled(bool enabled) { - auto inst = NetworkTableInstance::GetDefault(); - s_enable_ds = enabled; - if (s_enable_ds) { - inst.StartDSClient(s_port); - } else { - inst.StopDSClient(); - } -} - -void NetworkTable::SetPersistentFilename(StringRef filename) { - s_persistent_filename = filename; -} - -void NetworkTable::SetNetworkIdentity(StringRef name) { - NetworkTableInstance::GetDefault().SetNetworkIdentity(name); -} - -void NetworkTable::GlobalDeleteAll() { - NetworkTableInstance::GetDefault().DeleteAllEntries(); -} - -void NetworkTable::Flush() { - NetworkTableInstance::GetDefault().Flush(); -} - -void NetworkTable::SetUpdateRate(double interval) { - NetworkTableInstance::GetDefault().SetUpdateRate(interval); -} - -const char* NetworkTable::SavePersistent(StringRef filename) { - return NetworkTableInstance::GetDefault().SavePersistent(filename); -} - -const char* NetworkTable::LoadPersistent( - StringRef filename, - std::function warn) { - return NetworkTableInstance::GetDefault().LoadPersistent(filename, warn); -} - -std::shared_ptr NetworkTable::GetTable(StringRef key) { - if (!s_running) { - Initialize(); - } - return NetworkTableInstance::GetDefault().GetTable(key); -} - -NetworkTable::NetworkTable(NT_Inst inst, const Twine& path, const private_init&) +NetworkTable::NetworkTable(NT_Inst inst, const wpi::Twine& path, + const private_init&) : m_inst(inst), m_path(path.str()) {} NetworkTable::~NetworkTable() { - for (auto& i : m_listeners) { - RemoveEntryListener(i.second); - } - for (auto i : m_lambdaListeners) { + for (auto i : m_listeners) { RemoveEntryListener(i); } } @@ -233,13 +90,14 @@ NetworkTableInstance NetworkTable::GetInstance() const { return NetworkTableInstance{m_inst}; } -NetworkTableEntry NetworkTable::GetEntry(const Twine& key) const { +NetworkTableEntry NetworkTable::GetEntry(const wpi::Twine& key) const { wpi::SmallString<128> keyBuf; - StringRef keyStr = key.toStringRef(keyBuf); + wpi::StringRef keyStr = key.toStringRef(keyBuf); std::scoped_lock lock(m_mutex); NT_Entry& entry = m_entries[keyStr]; if (entry == 0) { - entry = nt::GetEntry(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR) + keyStr); + entry = + nt::GetEntry(m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR) + keyStr); } return NetworkTableEntry{entry}; } @@ -248,10 +106,10 @@ NT_EntryListener NetworkTable::AddEntryListener(TableEntryListener listener, unsigned int flags) const { size_t prefix_len = m_path.size() + 1; return nt::AddEntryListener( - m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), + m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR), [=](const EntryNotification& event) { - StringRef relative_key = event.name.substr(prefix_len); - if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) { + wpi::StringRef relative_key = event.name.substr(prefix_len); + if (relative_key.find(PATH_SEPARATOR_CHAR) != wpi::StringRef::npos) { return; } listener(const_cast(this), relative_key, @@ -260,7 +118,7 @@ NT_EntryListener NetworkTable::AddEntryListener(TableEntryListener listener, flags); } -NT_EntryListener NetworkTable::AddEntryListener(const Twine& key, +NT_EntryListener NetworkTable::AddEntryListener(const wpi::Twine& key, TableEntryListener listener, unsigned int flags) const { size_t prefix_len = m_path.size() + 1; @@ -278,66 +136,6 @@ void NetworkTable::RemoveEntryListener(NT_EntryListener listener) const { nt::RemoveEntryListener(listener); } -void NetworkTable::AddTableListener(ITableListener* listener) { - AddTableListenerEx(listener, NT_NOTIFY_NEW | NT_NOTIFY_UPDATE); -} - -void NetworkTable::AddTableListener(ITableListener* listener, - bool immediateNotify) { - unsigned int flags = NT_NOTIFY_NEW | NT_NOTIFY_UPDATE; - if (immediateNotify) { - flags |= NT_NOTIFY_IMMEDIATE; - } - AddTableListenerEx(listener, flags); -} - -void NetworkTable::AddTableListenerEx(ITableListener* listener, - unsigned int flags) { - std::scoped_lock lock(m_mutex); - wpi::SmallString<128> path(m_path); - path += PATH_SEPARATOR_CHAR; - size_t prefix_len = path.size(); - NT_EntryListener id = nt::AddEntryListener( - m_inst, path, - [=](const EntryNotification& event) { - StringRef relative_key = event.name.substr(prefix_len); - if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) { - return; - } - listener->ValueChangedEx(this, relative_key, event.value, event.flags); - }, - flags); - m_listeners.emplace_back(listener, id); -} - -void NetworkTable::AddTableListener(StringRef key, ITableListener* listener, - bool immediateNotify) { - unsigned int flags = NT_NOTIFY_NEW | NT_NOTIFY_UPDATE; - if (immediateNotify) { - flags |= NT_NOTIFY_IMMEDIATE; - } - AddTableListenerEx(key, listener, flags); -} - -void NetworkTable::AddTableListenerEx(StringRef key, ITableListener* listener, - unsigned int flags) { - std::scoped_lock lock(m_mutex); - size_t prefix_len = m_path.size() + 1; - auto entry = GetEntry(key); - NT_EntryListener id = nt::AddEntryListener( - entry.GetHandle(), - [=](const EntryNotification& event) { - listener->ValueChangedEx(this, event.name.substr(prefix_len), - event.value, event.flags); - }, - flags); - m_listeners.emplace_back(listener, id); -} - -void NetworkTable::AddSubTableListener(ITableListener* listener) { - AddSubTableListener(listener, false); -} - NT_EntryListener NetworkTable::AddSubTableListener(TableListener listener, bool localNotify) { size_t prefix_len = m_path.size() + 1; @@ -351,14 +149,14 @@ NT_EntryListener NetworkTable::AddSubTableListener(TableListener listener, flags |= NT_NOTIFY_LOCAL; } NT_EntryListener id = nt::AddEntryListener( - m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), + m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR), [=](const EntryNotification& event) { - StringRef relative_key = event.name.substr(prefix_len); + wpi::StringRef relative_key = event.name.substr(prefix_len); auto end_sub_table = relative_key.find(PATH_SEPARATOR_CHAR); - if (end_sub_table == StringRef::npos) { + if (end_sub_table == wpi::StringRef::npos) { return; } - StringRef sub_table_key = relative_key.substr(0, end_sub_table); + wpi::StringRef sub_table_key = relative_key.substr(0, end_sub_table); if (notified_tables->find(sub_table_key) == notified_tables->end()) { return; } @@ -366,68 +164,24 @@ NT_EntryListener NetworkTable::AddSubTableListener(TableListener listener, listener(this, sub_table_key, this->GetSubTable(sub_table_key)); }, flags); - m_lambdaListeners.emplace_back(id); + m_listeners.emplace_back(id); return id; } void NetworkTable::RemoveTableListener(NT_EntryListener listener) { nt::RemoveEntryListener(listener); auto matches_begin = - std::remove(m_lambdaListeners.begin(), m_lambdaListeners.end(), listener); - m_lambdaListeners.erase(matches_begin, m_lambdaListeners.end()); -} - -void NetworkTable::AddSubTableListener(ITableListener* listener, - bool localNotify) { - std::scoped_lock lock(m_mutex); - size_t prefix_len = m_path.size() + 1; - - // The lambda needs to be copyable, but StringMap is not, so use - // a shared_ptr to it. - auto notified_tables = std::make_shared>(); - - unsigned int flags = NT_NOTIFY_NEW | NT_NOTIFY_IMMEDIATE; - if (localNotify) { - flags |= NT_NOTIFY_LOCAL; - } - NT_EntryListener id = nt::AddEntryListener( - m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), - [=](const EntryNotification& event) { - StringRef relative_key = event.name.substr(prefix_len); - auto end_sub_table = relative_key.find(PATH_SEPARATOR_CHAR); - if (end_sub_table == StringRef::npos) { - return; - } - StringRef sub_table_key = relative_key.substr(0, end_sub_table); - if (notified_tables->find(sub_table_key) == notified_tables->end()) { - return; - } - notified_tables->insert(std::make_pair(sub_table_key, '\0')); - listener->ValueChangedEx(this, sub_table_key, nullptr, event.flags); - }, - flags); - m_listeners.emplace_back(listener, id); -} - -void NetworkTable::RemoveTableListener(ITableListener* listener) { - std::scoped_lock lock(m_mutex); - auto matches_begin = - std::remove_if(m_listeners.begin(), m_listeners.end(), - [=](const Listener& x) { return x.first == listener; }); - - for (auto i = matches_begin; i != m_listeners.end(); ++i) { - RemoveEntryListener(i->second); - } + std::remove(m_listeners.begin(), m_listeners.end(), listener); m_listeners.erase(matches_begin, m_listeners.end()); } std::shared_ptr NetworkTable::GetSubTable( - const Twine& key) const { + const wpi::Twine& key) const { return std::make_shared( - m_inst, m_path + Twine(PATH_SEPARATOR_CHAR) + key, private_init{}); + m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR) + key, private_init{}); } -bool NetworkTable::ContainsKey(const Twine& key) const { +bool NetworkTable::ContainsKey(const wpi::Twine& key) const { if (key.isTriviallyEmpty() || (key.isSingleStringRef() && key.getSingleStringRef().empty())) { return false; @@ -435,10 +189,10 @@ bool NetworkTable::ContainsKey(const Twine& key) const { return GetEntry(key).Exists(); } -bool NetworkTable::ContainsSubTable(const Twine& key) const { +bool NetworkTable::ContainsSubTable(const wpi::Twine& key) const { return !GetEntryInfo(m_inst, - m_path + Twine(PATH_SEPARATOR_CHAR) + key + - Twine(PATH_SEPARATOR_CHAR), + m_path + wpi::Twine(PATH_SEPARATOR_CHAR) + key + + wpi::Twine(PATH_SEPARATOR_CHAR), 0) .empty(); } @@ -446,11 +200,12 @@ bool NetworkTable::ContainsSubTable(const Twine& key) const { std::vector NetworkTable::GetKeys(int types) const { std::vector keys; size_t prefix_len = m_path.size() + 1; - auto infos = GetEntryInfo(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), types); + auto infos = + GetEntryInfo(m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR), types); std::scoped_lock lock(m_mutex); for (auto& info : infos) { - auto relative_key = StringRef(info.name).substr(prefix_len); - if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) { + auto relative_key = wpi::StringRef(info.name).substr(prefix_len); + if (relative_key.find(PATH_SEPARATOR_CHAR) != wpi::StringRef::npos) { continue; } keys.push_back(relative_key); @@ -463,10 +218,10 @@ std::vector NetworkTable::GetSubTables() const { std::vector keys; size_t prefix_len = m_path.size() + 1; for (auto& entry : - GetEntryInfo(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), 0)) { - auto relative_key = StringRef(entry.name).substr(prefix_len); + GetEntryInfo(m_inst, m_path + wpi::Twine(PATH_SEPARATOR_CHAR), 0)) { + auto relative_key = wpi::StringRef(entry.name).substr(prefix_len); size_t end_subtable = relative_key.find(PATH_SEPARATOR_CHAR); - if (end_subtable == StringRef::npos) { + if (end_subtable == wpi::StringRef::npos) { continue; } keys.push_back(relative_key.substr(0, end_subtable)); @@ -474,149 +229,157 @@ std::vector NetworkTable::GetSubTables() const { return keys; } -void NetworkTable::SetPersistent(StringRef key) { +void NetworkTable::SetPersistent(wpi::StringRef key) { GetEntry(key).SetPersistent(); } -void NetworkTable::ClearPersistent(StringRef key) { +void NetworkTable::ClearPersistent(wpi::StringRef key) { GetEntry(key).ClearPersistent(); } -bool NetworkTable::IsPersistent(StringRef key) const { +bool NetworkTable::IsPersistent(wpi::StringRef key) const { return GetEntry(key).IsPersistent(); } -void NetworkTable::SetFlags(StringRef key, unsigned int flags) { +void NetworkTable::SetFlags(wpi::StringRef key, unsigned int flags) { GetEntry(key).SetFlags(flags); } -void NetworkTable::ClearFlags(StringRef key, unsigned int flags) { +void NetworkTable::ClearFlags(wpi::StringRef key, unsigned int flags) { GetEntry(key).ClearFlags(flags); } -unsigned int NetworkTable::GetFlags(StringRef key) const { +unsigned int NetworkTable::GetFlags(wpi::StringRef key) const { return GetEntry(key).GetFlags(); } -void NetworkTable::Delete(const Twine& key) { +void NetworkTable::Delete(const wpi::Twine& key) { GetEntry(key).Delete(); } -bool NetworkTable::PutNumber(StringRef key, double value) { +bool NetworkTable::PutNumber(wpi::StringRef key, double value) { return GetEntry(key).SetDouble(value); } -bool NetworkTable::SetDefaultNumber(StringRef key, double defaultValue) { +bool NetworkTable::SetDefaultNumber(wpi::StringRef key, double defaultValue) { return GetEntry(key).SetDefaultDouble(defaultValue); } -double NetworkTable::GetNumber(StringRef key, double defaultValue) const { +double NetworkTable::GetNumber(wpi::StringRef key, double defaultValue) const { return GetEntry(key).GetDouble(defaultValue); } -bool NetworkTable::PutString(StringRef key, StringRef value) { +bool NetworkTable::PutString(wpi::StringRef key, wpi::StringRef value) { return GetEntry(key).SetString(value); } -bool NetworkTable::SetDefaultString(StringRef key, StringRef defaultValue) { +bool NetworkTable::SetDefaultString(wpi::StringRef key, + wpi::StringRef defaultValue) { return GetEntry(key).SetDefaultString(defaultValue); } -std::string NetworkTable::GetString(StringRef key, - StringRef defaultValue) const { +std::string NetworkTable::GetString(wpi::StringRef key, + wpi::StringRef defaultValue) const { return GetEntry(key).GetString(defaultValue); } -bool NetworkTable::PutBoolean(StringRef key, bool value) { +bool NetworkTable::PutBoolean(wpi::StringRef key, bool value) { return GetEntry(key).SetBoolean(value); } -bool NetworkTable::SetDefaultBoolean(StringRef key, bool defaultValue) { +bool NetworkTable::SetDefaultBoolean(wpi::StringRef key, bool defaultValue) { return GetEntry(key).SetDefaultBoolean(defaultValue); } -bool NetworkTable::GetBoolean(StringRef key, bool defaultValue) const { +bool NetworkTable::GetBoolean(wpi::StringRef key, bool defaultValue) const { return GetEntry(key).GetBoolean(defaultValue); } -bool NetworkTable::PutBooleanArray(StringRef key, ArrayRef value) { +bool NetworkTable::PutBooleanArray(wpi::StringRef key, + wpi::ArrayRef value) { return GetEntry(key).SetBooleanArray(value); } -bool NetworkTable::SetDefaultBooleanArray(StringRef key, - ArrayRef defaultValue) { +bool NetworkTable::SetDefaultBooleanArray(wpi::StringRef key, + wpi::ArrayRef defaultValue) { return GetEntry(key).SetDefaultBooleanArray(defaultValue); } std::vector NetworkTable::GetBooleanArray( - StringRef key, ArrayRef defaultValue) const { + wpi::StringRef key, wpi::ArrayRef defaultValue) const { return GetEntry(key).GetBooleanArray(defaultValue); } -bool NetworkTable::PutNumberArray(StringRef key, ArrayRef value) { +bool NetworkTable::PutNumberArray(wpi::StringRef key, + wpi::ArrayRef value) { return GetEntry(key).SetDoubleArray(value); } -bool NetworkTable::SetDefaultNumberArray(StringRef key, - ArrayRef defaultValue) { +bool NetworkTable::SetDefaultNumberArray(wpi::StringRef key, + wpi::ArrayRef defaultValue) { return GetEntry(key).SetDefaultDoubleArray(defaultValue); } std::vector NetworkTable::GetNumberArray( - StringRef key, ArrayRef defaultValue) const { + wpi::StringRef key, wpi::ArrayRef defaultValue) const { return GetEntry(key).GetDoubleArray(defaultValue); } -bool NetworkTable::PutStringArray(StringRef key, ArrayRef value) { +bool NetworkTable::PutStringArray(wpi::StringRef key, + wpi::ArrayRef value) { return GetEntry(key).SetStringArray(value); } -bool NetworkTable::SetDefaultStringArray(StringRef key, - ArrayRef defaultValue) { +bool NetworkTable::SetDefaultStringArray( + wpi::StringRef key, wpi::ArrayRef defaultValue) { return GetEntry(key).SetDefaultStringArray(defaultValue); } std::vector NetworkTable::GetStringArray( - StringRef key, ArrayRef defaultValue) const { + wpi::StringRef key, wpi::ArrayRef defaultValue) const { return GetEntry(key).GetStringArray(defaultValue); } -bool NetworkTable::PutRaw(StringRef key, StringRef value) { +bool NetworkTable::PutRaw(wpi::StringRef key, wpi::StringRef value) { return GetEntry(key).SetRaw(value); } -bool NetworkTable::SetDefaultRaw(StringRef key, StringRef defaultValue) { +bool NetworkTable::SetDefaultRaw(wpi::StringRef key, + wpi::StringRef defaultValue) { return GetEntry(key).SetDefaultRaw(defaultValue); } -std::string NetworkTable::GetRaw(StringRef key, StringRef defaultValue) const { +std::string NetworkTable::GetRaw(wpi::StringRef key, + wpi::StringRef defaultValue) const { return GetEntry(key).GetRaw(defaultValue); } -bool NetworkTable::PutValue(const Twine& key, std::shared_ptr value) { +bool NetworkTable::PutValue(const wpi::Twine& key, + std::shared_ptr value) { return GetEntry(key).SetValue(value); } -bool NetworkTable::SetDefaultValue(const Twine& key, +bool NetworkTable::SetDefaultValue(const wpi::Twine& key, std::shared_ptr defaultValue) { return GetEntry(key).SetDefaultValue(defaultValue); } -std::shared_ptr NetworkTable::GetValue(const Twine& key) const { +std::shared_ptr NetworkTable::GetValue(const wpi::Twine& key) const { return GetEntry(key).GetValue(); } -StringRef NetworkTable::GetPath() const { +wpi::StringRef NetworkTable::GetPath() const { return m_path; } -const char* NetworkTable::SaveEntries(const Twine& filename) const { - return nt::SaveEntries(m_inst, filename, m_path + Twine(PATH_SEPARATOR_CHAR)); +const char* NetworkTable::SaveEntries(const wpi::Twine& filename) const { + return nt::SaveEntries(m_inst, filename, + m_path + wpi::Twine(PATH_SEPARATOR_CHAR)); } const char* NetworkTable::LoadEntries( - const Twine& filename, + const wpi::Twine& filename, std::function warn) { - return nt::LoadEntries(m_inst, filename, m_path + Twine(PATH_SEPARATOR_CHAR), - warn); + return nt::LoadEntries(m_inst, filename, + m_path + wpi::Twine(PATH_SEPARATOR_CHAR), warn); } diff --git a/ntcore/src/main/native/cpp/networktables/NetworkTableInstance.cpp b/ntcore/src/main/native/cpp/networktables/NetworkTableInstance.cpp index 6697602eea..8a3d985dc6 100644 --- a/ntcore/src/main/native/cpp/networktables/NetworkTableInstance.cpp +++ b/ntcore/src/main/native/cpp/networktables/NetworkTableInstance.cpp @@ -9,8 +9,8 @@ using namespace nt; std::shared_ptr NetworkTableInstance::GetTable( - const Twine& key) const { - StringRef simple; + const wpi::Twine& key) const { + wpi::StringRef simple; bool isSimple = key.isSingleStringRef(); if (isSimple) { simple = key.getSingleStringRef(); @@ -23,23 +23,23 @@ std::shared_ptr NetworkTableInstance::GetTable( NetworkTable::private_init{}); } else { return std::make_shared( - m_handle, Twine(NetworkTable::PATH_SEPARATOR_CHAR) + key, + m_handle, wpi::Twine(NetworkTable::PATH_SEPARATOR_CHAR) + key, NetworkTable::private_init{}); } } -void NetworkTableInstance::StartClient(ArrayRef servers, +void NetworkTableInstance::StartClient(wpi::ArrayRef servers, unsigned int port) { - wpi::SmallVector, 8> server_ports; + wpi::SmallVector, 8> server_ports; for (const auto& server : servers) { server_ports.emplace_back(std::make_pair(server, port)); } StartClient(server_ports); } -void NetworkTableInstance::SetServer(ArrayRef servers, +void NetworkTableInstance::SetServer(wpi::ArrayRef servers, unsigned int port) { - wpi::SmallVector, 8> server_ports; + wpi::SmallVector, 8> server_ports; for (const auto& server : servers) { server_ports.emplace_back(std::make_pair(server, port)); } @@ -47,7 +47,7 @@ void NetworkTableInstance::SetServer(ArrayRef servers, } NT_EntryListener NetworkTableInstance::AddEntryListener( - const Twine& prefix, + const wpi::Twine& prefix, std::function callback, unsigned int flags) const { return ::nt::AddEntryListener(m_handle, prefix, callback, flags); diff --git a/ntcore/src/main/native/cpp/ntcore_c.cpp b/ntcore/src/main/native/cpp/ntcore_c.cpp index 07b5bc4889..d41fc9774c 100644 --- a/ntcore/src/main/native/cpp/ntcore_c.cpp +++ b/ntcore/src/main/native/cpp/ntcore_c.cpp @@ -192,12 +192,12 @@ NT_Inst NT_GetInstanceFromHandle(NT_Handle handle) { */ NT_Entry NT_GetEntry(NT_Inst inst, const char* name, size_t name_len) { - return nt::GetEntry(inst, StringRef(name, name_len)); + return nt::GetEntry(inst, wpi::StringRef(name, name_len)); } NT_Entry* NT_GetEntries(NT_Inst inst, const char* prefix, size_t prefix_len, unsigned int types, size_t* count) { - auto info_v = nt::GetEntries(inst, StringRef(prefix, prefix_len), types); + auto info_v = nt::GetEntries(inst, wpi::StringRef(prefix, prefix_len), types); *count = info_v.size(); if (info_v.size() == 0) { return nullptr; @@ -266,7 +266,8 @@ void NT_DeleteAllEntries(NT_Inst inst) { struct NT_EntryInfo* NT_GetEntryInfo(NT_Inst inst, const char* prefix, size_t prefix_len, unsigned int types, size_t* count) { - auto info_v = nt::GetEntryInfo(inst, StringRef(prefix, prefix_len), types); + auto info_v = + nt::GetEntryInfo(inst, wpi::StringRef(prefix, prefix_len), types); return ConvertToC(info_v, count); } @@ -288,7 +289,7 @@ NT_EntryListener NT_AddEntryListener(NT_Inst inst, const char* prefix, NT_EntryListenerCallback callback, unsigned int flags) { return nt::AddEntryListener( - inst, StringRef(prefix, prefix_len), + inst, wpi::StringRef(prefix, prefix_len), [=](const EntryNotification& event) { NT_EntryNotification c_event; ConvertToC(event, &c_event); @@ -324,7 +325,7 @@ NT_EntryListener NT_AddPolledEntryListener(NT_EntryListenerPoller poller, const char* prefix, size_t prefix_len, unsigned int flags) { - return nt::AddPolledEntryListener(poller, StringRef(prefix, prefix_len), + return nt::AddPolledEntryListener(poller, wpi::StringRef(prefix, prefix_len), flags); } @@ -421,12 +422,13 @@ NT_Bool NT_WaitForConnectionListenerQueue(NT_Inst inst, double timeout) { void NT_CreateRpc(NT_Entry entry, const char* def, size_t def_len, void* data, NT_RpcCallback callback) { - nt::CreateRpc(entry, StringRef(def, def_len), [=](const RpcAnswer& answer) { - NT_RpcAnswer answer_c; - ConvertToC(answer, &answer_c); - callback(data, &answer_c); - NT_DisposeRpcAnswer(&answer_c); - }); + nt::CreateRpc(entry, wpi::StringRef(def, def_len), + [=](const RpcAnswer& answer) { + NT_RpcAnswer answer_c; + ConvertToC(answer, &answer_c); + callback(data, &answer_c); + NT_DisposeRpcAnswer(&answer_c); + }); } NT_RpcCallPoller NT_CreateRpcCallPoller(NT_Inst inst) { @@ -439,7 +441,7 @@ void NT_DestroyRpcCallPoller(NT_RpcCallPoller poller) { void NT_CreatePolledRpc(NT_Entry entry, const char* def, size_t def_len, NT_RpcCallPoller poller) { - nt::CreatePolledRpc(entry, StringRef(def, def_len), poller); + nt::CreatePolledRpc(entry, wpi::StringRef(def, def_len), poller); } NT_RpcAnswer* NT_PollRpc(NT_RpcCallPoller poller, size_t* len) { @@ -465,11 +467,11 @@ NT_Bool NT_WaitForRpcCallQueue(NT_Inst inst, double timeout) { NT_Bool NT_PostRpcResponse(NT_Entry entry, NT_RpcCall call, const char* result, size_t result_len) { - return nt::PostRpcResponse(entry, call, StringRef(result, result_len)); + return nt::PostRpcResponse(entry, call, wpi::StringRef(result, result_len)); } NT_RpcCall NT_CallRpc(NT_Entry entry, const char* params, size_t params_len) { - return nt::CallRpc(entry, StringRef(params, params_len)); + return nt::CallRpc(entry, wpi::StringRef(params, params_len)); } char* NT_GetRpcResult(NT_Entry entry, NT_RpcCall call, size_t* result_len) { @@ -520,7 +522,7 @@ char* NT_PackRpcDefinition(const NT_RpcDefinition* def, size_t* packed_len) { NT_Bool NT_UnpackRpcDefinition(const char* packed, size_t packed_len, NT_RpcDefinition* def) { nt::RpcDefinition def_v; - if (!nt::UnpackRpcDefinition(StringRef(packed, packed_len), &def_v)) { + if (!nt::UnpackRpcDefinition(wpi::StringRef(packed, packed_len), &def_v)) { return 0; } @@ -550,8 +552,8 @@ char* NT_PackRpcValues(const NT_Value** values, size_t values_len, NT_Value** NT_UnpackRpcValues(const char* packed, size_t packed_len, const NT_Type* types, size_t types_len) { - auto values_v = nt::UnpackRpcValues(StringRef(packed, packed_len), - ArrayRef(types, types_len)); + auto values_v = nt::UnpackRpcValues(wpi::StringRef(packed, packed_len), + wpi::ArrayRef(types, types_len)); if (values_v.size() == 0) { return nullptr; } @@ -571,7 +573,7 @@ NT_Value** NT_UnpackRpcValues(const char* packed, size_t packed_len, */ void NT_SetNetworkIdentity(NT_Inst inst, const char* name, size_t name_len) { - nt::SetNetworkIdentity(inst, StringRef(name, name_len)); + nt::SetNetworkIdentity(inst, wpi::StringRef(name, name_len)); } unsigned int NT_GetNetworkMode(NT_Inst inst) { @@ -605,7 +607,7 @@ void NT_StartClient(NT_Inst inst, const char* server_name, unsigned int port) { void NT_StartClientMulti(NT_Inst inst, size_t count, const char** server_names, const unsigned int* ports) { - std::vector> servers; + std::vector> servers; servers.reserve(count); for (size_t i = 0; i < count; ++i) { servers.emplace_back(std::make_pair(server_names[i], ports[i])); @@ -627,7 +629,7 @@ void NT_SetServer(NT_Inst inst, const char* server_name, unsigned int port) { void NT_SetServerMulti(NT_Inst inst, size_t count, const char** server_names, const unsigned int* ports) { - std::vector> servers; + std::vector> servers; servers.reserve(count); for (size_t i = 0; i < count; ++i) { servers.emplace_back(std::make_pair(server_names[i], ports[i])); @@ -679,13 +681,14 @@ const char* NT_LoadPersistent(NT_Inst inst, const char* filename, const char* NT_SaveEntries(NT_Inst inst, const char* filename, const char* prefix, size_t prefix_len) { - return nt::SaveEntries(inst, filename, StringRef(prefix, prefix_len)); + return nt::SaveEntries(inst, filename, wpi::StringRef(prefix, prefix_len)); } const char* NT_LoadEntries(NT_Inst inst, const char* filename, const char* prefix, size_t prefix_len, void (*warn)(size_t line, const char* msg)) { - return nt::LoadEntries(inst, filename, StringRef(prefix, prefix_len), warn); + return nt::LoadEntries(inst, filename, wpi::StringRef(prefix, prefix_len), + warn); } /* @@ -951,23 +954,24 @@ NT_Bool NT_SetEntryBoolean(NT_Entry entry, uint64_t time, NT_Bool v_boolean, NT_Bool NT_SetEntryString(NT_Entry entry, uint64_t time, const char* str, size_t str_len, NT_Bool force) { if (force != 0) { - nt::SetEntryTypeValue(entry, - Value::MakeString(StringRef(str, str_len), time)); + nt::SetEntryTypeValue( + entry, Value::MakeString(wpi::StringRef(str, str_len), time)); return 1; } else { - return nt::SetEntryValue(entry, - Value::MakeString(StringRef(str, str_len), time)); + return nt::SetEntryValue( + entry, Value::MakeString(wpi::StringRef(str, str_len), time)); } } NT_Bool NT_SetEntryRaw(NT_Entry entry, uint64_t time, const char* raw, size_t raw_len, NT_Bool force) { if (force != 0) { - nt::SetEntryTypeValue(entry, Value::MakeRaw(StringRef(raw, raw_len), time)); + nt::SetEntryTypeValue(entry, + Value::MakeRaw(wpi::StringRef(raw, raw_len), time)); return 1; } else { - return nt::SetEntryValue(entry, - Value::MakeRaw(StringRef(raw, raw_len), time)); + return nt::SetEntryValue( + entry, Value::MakeRaw(wpi::StringRef(raw, raw_len), time)); } } @@ -1128,13 +1132,14 @@ NT_Bool NT_SetDefaultEntryString(NT_Entry entry, uint64_t time, const char* default_value, size_t default_len) { return nt::SetDefaultEntryValue( - entry, Value::MakeString(StringRef(default_value, default_len), time)); + entry, + Value::MakeString(wpi::StringRef(default_value, default_len), time)); } NT_Bool NT_SetDefaultEntryRaw(NT_Entry entry, uint64_t time, const char* default_value, size_t default_len) { return nt::SetDefaultEntryValue( - entry, Value::MakeRaw(StringRef(default_value, default_len), time)); + entry, Value::MakeRaw(wpi::StringRef(default_value, default_len), time)); } NT_Bool NT_SetDefaultEntryBooleanArray(NT_Entry entry, uint64_t time, diff --git a/ntcore/src/main/native/cpp/ntcore_cpp.cpp b/ntcore/src/main/native/cpp/ntcore_cpp.cpp index db190837fb..cf1a7d5c16 100644 --- a/ntcore/src/main/native/cpp/ntcore_cpp.cpp +++ b/ntcore/src/main/native/cpp/ntcore_cpp.cpp @@ -53,7 +53,7 @@ NT_Inst GetInstanceFromHandle(NT_Handle handle) { * Table Functions */ -NT_Entry GetEntry(NT_Inst inst, const Twine& name) { +NT_Entry GetEntry(NT_Inst inst, const wpi::Twine& name) { int i = Handle{inst}.GetTypedInst(Handle::kInstance); auto ii = InstanceImpl::Get(i); if (!ii) { @@ -67,7 +67,7 @@ NT_Entry GetEntry(NT_Inst inst, const Twine& name) { return Handle(i, id, Handle::kEntry); } -std::vector GetEntries(NT_Inst inst, const Twine& prefix, +std::vector GetEntries(NT_Inst inst, const wpi::Twine& prefix, unsigned int types) { int i = Handle{inst}.GetTypedInst(Handle::kInstance); auto ii = InstanceImpl::Get(i); @@ -116,10 +116,6 @@ uint64_t GetEntryLastChange(NT_Entry entry) { return ii->storage.GetEntryLastChange(id); } -std::shared_ptr GetEntryValue(StringRef name) { - return InstanceImpl::GetDefault()->storage.GetEntryValue(name); -} - std::shared_ptr GetEntryValue(NT_Entry entry) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); @@ -131,10 +127,6 @@ std::shared_ptr GetEntryValue(NT_Entry entry) { return ii->storage.GetEntryValue(id); } -bool SetDefaultEntryValue(StringRef name, std::shared_ptr value) { - return InstanceImpl::GetDefault()->storage.SetDefaultEntryValue(name, value); -} - bool SetDefaultEntryValue(NT_Entry entry, std::shared_ptr value) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); @@ -146,10 +138,6 @@ bool SetDefaultEntryValue(NT_Entry entry, std::shared_ptr value) { return ii->storage.SetDefaultEntryValue(id, value); } -bool SetEntryValue(StringRef name, std::shared_ptr value) { - return InstanceImpl::GetDefault()->storage.SetEntryValue(name, value); -} - bool SetEntryValue(NT_Entry entry, std::shared_ptr value) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); @@ -161,10 +149,6 @@ bool SetEntryValue(NT_Entry entry, std::shared_ptr value) { return ii->storage.SetEntryValue(id, value); } -void SetEntryTypeValue(StringRef name, std::shared_ptr value) { - InstanceImpl::GetDefault()->storage.SetEntryTypeValue(name, value); -} - void SetEntryTypeValue(NT_Entry entry, std::shared_ptr value) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); @@ -176,10 +160,6 @@ void SetEntryTypeValue(NT_Entry entry, std::shared_ptr value) { ii->storage.SetEntryTypeValue(id, value); } -void SetEntryFlags(StringRef name, unsigned int flags) { - InstanceImpl::GetDefault()->storage.SetEntryFlags(name, flags); -} - void SetEntryFlags(NT_Entry entry, unsigned int flags) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); @@ -191,10 +171,6 @@ void SetEntryFlags(NT_Entry entry, unsigned int flags) { ii->storage.SetEntryFlags(id, flags); } -unsigned int GetEntryFlags(StringRef name) { - return InstanceImpl::GetDefault()->storage.GetEntryFlags(name); -} - unsigned int GetEntryFlags(NT_Entry entry) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); @@ -206,10 +182,6 @@ unsigned int GetEntryFlags(NT_Entry entry) { return ii->storage.GetEntryFlags(id); } -void DeleteEntry(StringRef name) { - InstanceImpl::GetDefault()->storage.DeleteEntry(name); -} - void DeleteEntry(NT_Entry entry) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); @@ -221,10 +193,6 @@ void DeleteEntry(NT_Entry entry) { ii->storage.DeleteEntry(id); } -void DeleteAllEntries() { - InstanceImpl::GetDefault()->storage.DeleteAllEntries(); -} - void DeleteAllEntries(NT_Inst inst) { int i = Handle{inst}.GetTypedInst(Handle::kInstance); auto ii = InstanceImpl::Get(i); @@ -235,11 +203,7 @@ void DeleteAllEntries(NT_Inst inst) { ii->storage.DeleteAllEntries(); } -std::vector GetEntryInfo(StringRef prefix, unsigned int types) { - return InstanceImpl::GetDefault()->storage.GetEntryInfo(0, prefix, types); -} - -std::vector GetEntryInfo(NT_Inst inst, const Twine& prefix, +std::vector GetEntryInfo(NT_Inst inst, const wpi::Twine& prefix, unsigned int types) { int i = Handle{inst}.GetTypedInst(Handle::kInstance); auto ii = InstanceImpl::Get(i); @@ -271,19 +235,8 @@ EntryInfo GetEntryInfo(NT_Entry entry) { * Callback Creation Functions */ -NT_EntryListener AddEntryListener(StringRef prefix, - EntryListenerCallback callback, - unsigned int flags) { - return AddEntryListener( - Handle(InstanceImpl::GetDefaultIndex(), 0, Handle::kInstance), prefix, - [=](const EntryNotification& event) { - callback(event.listener, event.name, event.value, event.flags); - }, - flags); -} - NT_EntryListener AddEntryListener( - NT_Inst inst, const Twine& prefix, + NT_Inst inst, const wpi::Twine& prefix, std::function callback, unsigned int flags) { int i = Handle{inst}.GetTypedInst(Handle::kInstance); @@ -335,7 +288,7 @@ void DestroyEntryListenerPoller(NT_EntryListenerPoller poller) { } NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller, - const Twine& prefix, + const wpi::Twine& prefix, unsigned int flags) { Handle handle{poller}; int id = handle.GetTypedIndex(Handle::kEntryListenerPoller); @@ -430,16 +383,6 @@ bool WaitForEntryListenerQueue(NT_Inst inst, double timeout) { return ii->entry_notifier.WaitForQueue(timeout); } -NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback, - bool immediate_notify) { - return AddConnectionListener( - Handle(InstanceImpl::GetDefaultIndex(), 0, Handle::kInstance), - [=](const ConnectionNotification& event) { - callback(event.listener, event.connected, event.conn); - }, - immediate_notify); -} - NT_ConnectionListener AddConnectionListener( NT_Inst inst, std::function callback, @@ -551,7 +494,7 @@ bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout) { * Remote Procedure Call Functions */ -void CreateRpc(NT_Entry entry, StringRef def, +void CreateRpc(NT_Entry entry, wpi::StringRef def, std::function callback) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); @@ -592,7 +535,8 @@ void DestroyRpcCallPoller(NT_RpcCallPoller poller) { ii->rpc_server.RemovePoller(id); } -void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller) { +void CreatePolledRpc(NT_Entry entry, wpi::StringRef def, + NT_RpcCallPoller poller) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); auto ii = InstanceImpl::Get(handle.GetInst()); @@ -664,7 +608,7 @@ bool WaitForRpcCallQueue(NT_Inst inst, double timeout) { return ii->rpc_server.WaitForQueue(timeout); } -bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result) { +bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, wpi::StringRef result) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); auto ii = InstanceImpl::Get(handle.GetInst()); @@ -684,7 +628,7 @@ bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result) { return ii->rpc_server.PostRpcResponse(id, call_uid, result); } -NT_RpcCall CallRpc(NT_Entry entry, StringRef params) { +NT_RpcCall CallRpc(NT_Entry entry, wpi::StringRef params) { Handle handle{entry}; int id = handle.GetTypedIndex(Handle::kEntry); int i = handle.GetInst(); @@ -793,7 +737,7 @@ std::string PackRpcDefinition(const RpcDefinition& def) { return enc.ToStringRef(); } -bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def) { +bool UnpackRpcDefinition(wpi::StringRef packed, RpcDefinition* def) { wpi::raw_mem_istream is(packed.data(), packed.size()); wpi::Logger logger; WireDecoder dec(is, 0x0300, logger); @@ -848,7 +792,7 @@ bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def) { return true; } -std::string PackRpcValues(ArrayRef> values) { +std::string PackRpcValues(wpi::ArrayRef> values) { WireEncoder enc(0x0300); for (auto& value : values) { enc.WriteValue(*value); @@ -856,8 +800,8 @@ std::string PackRpcValues(ArrayRef> values) { return enc.ToStringRef(); } -std::vector> UnpackRpcValues(StringRef packed, - ArrayRef types) { +std::vector> UnpackRpcValues( + wpi::StringRef packed, wpi::ArrayRef types) { wpi::raw_mem_istream is(packed.data(), packed.size()); wpi::Logger logger; WireDecoder dec(is, 0x0300, logger); @@ -880,11 +824,7 @@ uint64_t Now() { * Client/Server Functions */ -void SetNetworkIdentity(StringRef name) { - InstanceImpl::GetDefault()->dispatcher.SetIdentity(name); -} - -void SetNetworkIdentity(NT_Inst inst, const Twine& name) { +void SetNetworkIdentity(NT_Inst inst, const wpi::Twine& name) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { return; @@ -893,10 +833,6 @@ void SetNetworkIdentity(NT_Inst inst, const Twine& name) { ii->dispatcher.SetIdentity(name); } -unsigned int GetNetworkMode() { - return InstanceImpl::GetDefault()->dispatcher.GetNetworkMode(); -} - unsigned int GetNetworkMode(NT_Inst inst) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -924,13 +860,7 @@ void StopLocal(NT_Inst inst) { ii->dispatcher.Stop(); } -void StartServer(StringRef persist_filename, const char* listen_address, - unsigned int port) { - auto ii = InstanceImpl::GetDefault(); - ii->dispatcher.StartServer(persist_filename, listen_address, port); -} - -void StartServer(NT_Inst inst, const Twine& persist_filename, +void StartServer(NT_Inst inst, const wpi::Twine& persist_filename, const char* listen_address, unsigned int port) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -940,10 +870,6 @@ void StartServer(NT_Inst inst, const Twine& persist_filename, ii->dispatcher.StartServer(persist_filename, listen_address, port); } -void StopServer() { - InstanceImpl::GetDefault()->dispatcher.Stop(); -} - void StopServer(NT_Inst inst) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -953,10 +879,6 @@ void StopServer(NT_Inst inst) { ii->dispatcher.Stop(); } -void StartClient() { - InstanceImpl::GetDefault()->dispatcher.StartClient(); -} - void StartClient(NT_Inst inst) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -966,12 +888,6 @@ void StartClient(NT_Inst inst) { ii->dispatcher.StartClient(); } -void StartClient(const char* server_name, unsigned int port) { - auto ii = InstanceImpl::GetDefault(); - ii->dispatcher.SetServer(server_name, port); - ii->dispatcher.StartClient(); -} - void StartClient(NT_Inst inst, const char* server_name, unsigned int port) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -982,14 +898,9 @@ void StartClient(NT_Inst inst, const char* server_name, unsigned int port) { ii->dispatcher.StartClient(); } -void StartClient(ArrayRef> servers) { - auto ii = InstanceImpl::GetDefault(); - ii->dispatcher.SetServer(servers); - ii->dispatcher.StartClient(); -} - -void StartClient(NT_Inst inst, - ArrayRef> servers) { +void StartClient( + NT_Inst inst, + wpi::ArrayRef> servers) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { return; @@ -1009,10 +920,6 @@ void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port) { ii->dispatcher.StartClient(); } -void StopClient() { - InstanceImpl::GetDefault()->dispatcher.Stop(); -} - void StopClient(NT_Inst inst) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -1022,10 +929,6 @@ void StopClient(NT_Inst inst) { ii->dispatcher.Stop(); } -void SetServer(const char* server_name, unsigned int port) { - InstanceImpl::GetDefault()->dispatcher.SetServer(server_name, port); -} - void SetServer(NT_Inst inst, const char* server_name, unsigned int port) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -1035,12 +938,8 @@ void SetServer(NT_Inst inst, const char* server_name, unsigned int port) { ii->dispatcher.SetServer(server_name, port); } -void SetServer(ArrayRef> servers) { - InstanceImpl::GetDefault()->dispatcher.SetServer(servers); -} - void SetServer(NT_Inst inst, - ArrayRef> servers) { + wpi::ArrayRef> servers) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { return; @@ -1058,10 +957,6 @@ void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port) { ii->dispatcher.SetServerTeam(team, port); } -void StartDSClient(unsigned int port) { - InstanceImpl::GetDefault()->ds_client.Start(port); -} - void StartDSClient(NT_Inst inst, unsigned int port) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -1071,10 +966,6 @@ void StartDSClient(NT_Inst inst, unsigned int port) { ii->ds_client.Start(port); } -void StopDSClient() { - InstanceImpl::GetDefault()->ds_client.Stop(); -} - void StopDSClient(NT_Inst inst) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -1084,10 +975,6 @@ void StopDSClient(NT_Inst inst) { ii->ds_client.Stop(); } -void SetUpdateRate(double interval) { - InstanceImpl::GetDefault()->dispatcher.SetUpdateRate(interval); -} - void SetUpdateRate(NT_Inst inst, double interval) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -1097,10 +984,6 @@ void SetUpdateRate(NT_Inst inst, double interval) { ii->dispatcher.SetUpdateRate(interval); } -void Flush() { - InstanceImpl::GetDefault()->dispatcher.Flush(); -} - void Flush(NT_Inst inst) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -1110,10 +993,6 @@ void Flush(NT_Inst inst) { ii->dispatcher.Flush(); } -std::vector GetConnections() { - return InstanceImpl::GetDefault()->dispatcher.GetConnections(); -} - std::vector GetConnections(NT_Inst inst) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -1136,11 +1015,7 @@ bool IsConnected(NT_Inst inst) { * Persistent Functions */ -const char* SavePersistent(StringRef filename) { - return InstanceImpl::GetDefault()->storage.SavePersistent(filename, false); -} - -const char* SavePersistent(NT_Inst inst, const Twine& filename) { +const char* SavePersistent(NT_Inst inst, const wpi::Twine& filename) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { return "invalid instance handle"; @@ -1150,13 +1025,7 @@ const char* SavePersistent(NT_Inst inst, const Twine& filename) { } const char* LoadPersistent( - StringRef filename, - std::function warn) { - return InstanceImpl::GetDefault()->storage.LoadPersistent(filename, warn); -} - -const char* LoadPersistent( - NT_Inst inst, const Twine& filename, + NT_Inst inst, const wpi::Twine& filename, std::function warn) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -1166,8 +1035,8 @@ const char* LoadPersistent( return ii->storage.LoadPersistent(filename, warn); } -const char* SaveEntries(NT_Inst inst, const Twine& filename, - const Twine& prefix) { +const char* SaveEntries(NT_Inst inst, const wpi::Twine& filename, + const wpi::Twine& prefix) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { return "invalid instance handle"; @@ -1177,7 +1046,7 @@ const char* SaveEntries(NT_Inst inst, const Twine& filename, } const char* LoadEntries( - NT_Inst inst, const Twine& filename, const Twine& prefix, + NT_Inst inst, const wpi::Twine& filename, const wpi::Twine& prefix, std::function warn) { auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance)); if (!ii) { @@ -1187,21 +1056,6 @@ const char* LoadEntries( return ii->storage.LoadEntries(filename, prefix, warn); } -void SetLogger(LogFunc func, unsigned int min_level) { - auto ii = InstanceImpl::GetDefault(); - static wpi::mutex mutex; - static unsigned int logger = 0; - std::scoped_lock lock(mutex); - if (logger != 0) { - ii->logger_impl.Remove(logger); - } - logger = ii->logger_impl.Add( - [=](const LogMessage& msg) { - func(msg.level, msg.filename, msg.line, msg.message.c_str()); - }, - min_level, UINT_MAX); -} - NT_Logger AddLogger(NT_Inst inst, std::function func, unsigned int min_level, unsigned int max_level) { diff --git a/ntcore/src/main/native/cpp/tables/ITableListener.cpp b/ntcore/src/main/native/cpp/tables/ITableListener.cpp deleted file mode 100644 index a6dd569b5c..0000000000 --- a/ntcore/src/main/native/cpp/tables/ITableListener.cpp +++ /dev/null @@ -1,13 +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 "tables/ITableListener.h" - -#include "ntcore_c.h" - -void ITableListener::ValueChangedEx(ITable* source, wpi::StringRef key, - std::shared_ptr value, - unsigned int flags) { - ValueChanged(source, key, value, (flags & NT_NOTIFY_NEW) != 0); -} diff --git a/ntcore/src/main/native/include/networktables/NetworkTable.h b/ntcore/src/main/native/include/networktables/NetworkTable.h index 91d1aa28aa..664c98b563 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTable.h +++ b/ntcore/src/main/native/include/networktables/NetworkTable.h @@ -20,24 +20,11 @@ #include "networktables/TableEntryListener.h" #include "networktables/TableListener.h" #include "ntcore_c.h" -#include "tables/ITable.h" namespace nt { -using wpi::ArrayRef; -using wpi::StringRef; -using wpi::Twine; - class NetworkTableInstance; -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#elif _WIN32 -#pragma warning(push) -#pragma warning(disable : 4996) -#endif - /** * @defgroup ntcore_cpp_api ntcore C++ object-oriented API * @@ -48,22 +35,13 @@ class NetworkTableInstance; * A network table that knows its subtable path. * @ingroup ntcore_cpp_api */ -class NetworkTable final : public ITable { +class NetworkTable final { private: NT_Inst m_inst; std::string m_path; mutable wpi::mutex m_mutex; mutable wpi::StringMap m_entries; - typedef std::pair Listener; - std::vector m_listeners; - std::vector m_lambdaListeners; - - static std::vector s_ip_addresses; - static std::string s_persistent_filename; - static bool s_client; - static bool s_enable_ds; - static bool s_running; - static unsigned int s_port; + std::vector m_listeners; struct private_init {}; friend class NetworkTableInstance; @@ -76,7 +54,7 @@ class NetworkTable final : public ITable { * @param key key * @return base name */ - static StringRef BasenameKey(StringRef key); + static wpi::StringRef BasenameKey(wpi::StringRef key); /** * Normalizes an network table key to contain no consecutive slashes and @@ -94,12 +72,12 @@ class NetworkTable final : public ITable { * with a leading slash * @return normalized key */ - static std::string NormalizeKey(const Twine& key, + static std::string NormalizeKey(const wpi::Twine& key, bool withLeadingSlash = true); - static StringRef NormalizeKey(const Twine& key, - wpi::SmallVectorImpl& buf, - bool withLeadingSlash = true); + static wpi::StringRef NormalizeKey(const wpi::Twine& key, + wpi::SmallVectorImpl& buf, + bool withLeadingSlash = true); /** * Gets a list of the names of all the super tables of a given key. For @@ -109,13 +87,13 @@ class NetworkTable final : public ITable { * @param key the key * @return List of super tables */ - static std::vector GetHierarchy(const Twine& key); + static std::vector GetHierarchy(const wpi::Twine& key); /** * Constructor. Use NetworkTableInstance::GetTable() or GetSubTable() * instead. */ - NetworkTable(NT_Inst inst, const Twine& path, const private_init&); + NetworkTable(NT_Inst inst, const wpi::Twine& path, const private_init&); virtual ~NetworkTable(); /** @@ -128,169 +106,7 @@ class NetworkTable final : public ITable { /** * The path separator for sub-tables and keys */ - static const char PATH_SEPARATOR_CHAR; - - /** - * Initializes network tables - */ - WPI_DEPRECATED( - "use NetworkTableInstance::StartServer() or " - "NetworkTableInstance::StartClient() instead") - static void Initialize(); - - /** - * Shuts down network tables - */ - WPI_DEPRECATED( - "use NetworkTableInstance::StopServer() or " - "NetworkTableInstance::StopClient() instead") - static void Shutdown(); - - /** - * set that network tables should be a client - * This must be called before initialize or GetTable - */ - WPI_DEPRECATED("use NetworkTableInstance::StartClient() instead") - static void SetClientMode(); - - /** - * set that network tables should be a server - * This must be called before initialize or GetTable - */ - WPI_DEPRECATED("use NetworkTableInstance::StartServer() instead") - static void SetServerMode(); - - /** - * set the team the robot is configured for (this will set the mdns address - * that network tables will connect to in client mode) - * This must be called before initialize or GetTable - * - * @param team the team number - */ - WPI_DEPRECATED( - "use NetworkTableInstance::SetServerTeam() or " - "NetworkTableInstance::StartClientTeam() instead") - static void SetTeam(int team); - - /** - * @param address the address that network tables will connect to in client - * mode - */ - WPI_DEPRECATED( - "use NetworkTableInstance::SetServer() or " - "NetworkTableInstance::StartClient() instead") - static void SetIPAddress(StringRef address); - - /** - * @param addresses the addresses that network tables will connect to in - * client mode (in round robin order) - */ - WPI_DEPRECATED( - "use NetworkTableInstance::SetServer() or " - "NetworkTableInstance::StartClient() instead") - static void SetIPAddress(ArrayRef addresses); - - /** - * Set the port number that network tables will connect to in client - * mode or listen to in server mode. - * - * @param port the port number - */ - WPI_DEPRECATED( - "use the appropriate parameters to NetworkTableInstance::SetServer(), " - "NetworkTableInstance::StartClient(), " - "NetworkTableInstance::StartServer(), and " - "NetworkTableInstance::StartDSClient() instead") - static void SetPort(unsigned int port); - - /** - * Enable requesting the server address from the Driver Station. - * - * @param enabled whether to enable the connection to the local DS - */ - WPI_DEPRECATED( - "use NetworkTableInstance::StartDSClient() and " - "NetworkTableInstance::StopDSClient() instead") - static void SetDSClientEnabled(bool enabled); - - /** - * Sets the persistent filename. - * - * @param filename the filename that the network tables server uses for - * automatic loading and saving of persistent values - */ - WPI_DEPRECATED( - "use the appropriate parameter to NetworkTableInstance::StartServer() " - "instead") - static void SetPersistentFilename(StringRef filename); - - /** - * Sets the network identity. - * This is provided in the connection info on the remote end. - * - * @param name identity - */ - WPI_DEPRECATED("use NetworkTableInstance::SetNetworkIdentity() instead") - static void SetNetworkIdentity(StringRef name); - - /** - * Deletes ALL keys in ALL subtables. Use with caution! - */ - WPI_DEPRECATED("use NetworkTableInstance::DeleteAllEntries() instead") - static void GlobalDeleteAll(); - - /** - * Flushes all updated values immediately to the network. - * Note: This is rate-limited to protect the network from flooding. - * This is primarily useful for synchronizing network updates with - * user code. - */ - WPI_DEPRECATED("use NetworkTableInstance::Flush() instead") - static void Flush(); - - /** - * Set the periodic update rate. - * Sets how frequently updates are sent to other nodes over the network. - * - * @param interval update interval in seconds (range 0.01 to 1.0) - */ - WPI_DEPRECATED("use NetworkTableInstance::SetUpdateRate() instead") - static void SetUpdateRate(double interval); - - /** - * Saves persistent keys to a file. The server does this automatically. - * - * @param filename file name - * @return Error (or nullptr). - */ - WPI_DEPRECATED("use NetworkTableInstance::SavePersistent() instead") - static const char* SavePersistent(StringRef filename); - - /** - * Loads persistent keys from a file. The server does this automatically. - * - * @param filename file name - * @param warn callback function called for warnings - * @return Error (or nullptr). - */ - WPI_DEPRECATED("use NetworkTableInstance::LoadPersistent() instead") - static const char* LoadPersistent( - StringRef filename, - std::function warn); - - /** - * Gets the table with the specified key. If the table does not exist, a new - * table will be created.
- * This will automatically initialize network tables if it has not been - * already. - * - * @param key the key name - * @return the network table requested - */ - WPI_DEPRECATED( - "use NetworkTableInstance::GetTable() or " - "NetworkTableInstance::GetEntry() instead") - static std::shared_ptr GetTable(StringRef key); + static constexpr char PATH_SEPARATOR_CHAR = '/'; /** * Gets the entry for a subkey. @@ -298,7 +114,7 @@ class NetworkTable final : public ITable { * @param key the key name * @return Network table entry. */ - NetworkTableEntry GetEntry(const Twine& key) const; + NetworkTableEntry GetEntry(const wpi::Twine& key) const; /** * Listen to keys only within this table. @@ -318,7 +134,7 @@ class NetworkTable final : public ITable { * @param flags EntryListenerFlags bitmask * @return Listener handle */ - NT_EntryListener AddEntryListener(const Twine& key, + NT_EntryListener AddEntryListener(const wpi::Twine& key, TableEntryListener listener, unsigned int flags) const; @@ -348,38 +164,6 @@ class NetworkTable final : public ITable { */ void RemoveTableListener(NT_EntryListener listener); - WPI_DEPRECATED( - "use AddEntryListener() instead with flags value of NT_NOTIFY_NEW | " - "NT_NOTIFY_UPDATE") - void AddTableListener(ITableListener* listener) override; - - WPI_DEPRECATED( - "use AddEntryListener() instead with flags value of NT_NOTIFY_NEW | " - "NT_NOTIFY_UPDATE | NT_NOTIFY_IMMEDIATE") - void AddTableListener(ITableListener* listener, - bool immediateNotify) override; - - WPI_DEPRECATED("use AddEntryListener() instead") - void AddTableListenerEx(ITableListener* listener, - unsigned int flags) override; - - WPI_DEPRECATED("use AddEntryListener() instead") - void AddTableListener(StringRef key, ITableListener* listener, - bool immediateNotify) override; - - WPI_DEPRECATED("use AddEntryListener() instead") - void AddTableListenerEx(StringRef key, ITableListener* listener, - unsigned int flags) override; - - WPI_DEPRECATED("use AddSubTableListener(TableListener, bool) instead") - void AddSubTableListener(ITableListener* listener) override; - - WPI_DEPRECATED("use AddSubTableListener(TableListener, bool) instead") - void AddSubTableListener(ITableListener* listener, bool localNotify) override; - - WPI_DEPRECATED("use RemoveTableListener(NT_EntryListener) instead") - void RemoveTableListener(ITableListener* listener) override; - /** * Returns the table at the specified key. If there is no table at the * specified key, it will create a new table @@ -387,7 +171,7 @@ class NetworkTable final : public ITable { * @param key the key name * @return the networktable to be returned */ - std::shared_ptr GetSubTable(const Twine& key) const override; + std::shared_ptr GetSubTable(const wpi::Twine& key) const; /** * Determines whether the given key is in this table. @@ -395,7 +179,7 @@ class NetworkTable final : public ITable { * @param key the key to search for * @return true if the table as a value assigned to the given key */ - bool ContainsKey(const Twine& key) const override; + bool ContainsKey(const wpi::Twine& key) const; /** * Determines whether there exists a non-empty subtable for this key @@ -405,7 +189,7 @@ class NetworkTable final : public ITable { * @return true if there is a subtable with the key which contains at least * one key/subtable of its own */ - bool ContainsSubTable(const Twine& key) const override; + bool ContainsSubTable(const wpi::Twine& key) const; /** * Gets all keys in the table (not including sub-tables). @@ -413,21 +197,21 @@ class NetworkTable final : public ITable { * @param types bitmask of types; 0 is treated as a "don't care". * @return keys currently in the table */ - std::vector GetKeys(int types = 0) const override; + std::vector GetKeys(int types = 0) const; /** * Gets the names of all subtables in the table. * * @return subtables currently in the table */ - std::vector GetSubTables() const override; + std::vector GetSubTables() const; /** * Makes a key's value persistent through program restarts. * * @param key the key to make persistent */ - void SetPersistent(StringRef key) override; + void SetPersistent(wpi::StringRef key); /** * Stop making a key's value persistent through program restarts. @@ -435,7 +219,7 @@ class NetworkTable final : public ITable { * * @param key the key name */ - void ClearPersistent(StringRef key) override; + void ClearPersistent(wpi::StringRef key); /** * Returns whether the value is persistent through program restarts. @@ -443,7 +227,7 @@ class NetworkTable final : public ITable { * * @param key the key name */ - bool IsPersistent(StringRef key) const override; + bool IsPersistent(wpi::StringRef key) const; /** * Sets flags on the specified key in this table. The key can @@ -452,7 +236,7 @@ class NetworkTable final : public ITable { * @param key the key name * @param flags the flags to set (bitmask) */ - void SetFlags(StringRef key, unsigned int flags) override; + void SetFlags(wpi::StringRef key, unsigned int flags); /** * Clears flags on the specified key in this table. The key can @@ -461,7 +245,7 @@ class NetworkTable final : public ITable { * @param key the key name * @param flags the flags to clear (bitmask) */ - void ClearFlags(StringRef key, unsigned int flags) override; + void ClearFlags(wpi::StringRef key, unsigned int flags); /** * Returns the flags for the specified key. @@ -469,14 +253,14 @@ class NetworkTable final : public ITable { * @param key the key name * @return the flags, or 0 if the key is not defined */ - unsigned int GetFlags(StringRef key) const override; + unsigned int GetFlags(wpi::StringRef key) const; /** * Deletes the specified key in this table. * * @param key the key name */ - void Delete(const Twine& key) override; + void Delete(const wpi::Twine& key); /** * Put a number in the table @@ -485,7 +269,7 @@ class NetworkTable final : public ITable { * @param value the value that will be assigned * @return False if the table key already exists with a different type */ - bool PutNumber(StringRef key, double value) override; + bool PutNumber(wpi::StringRef key, double value); /** * Gets the current value in the table, setting it if it does not exist. @@ -494,7 +278,7 @@ class NetworkTable final : public ITable { * @param defaultValue the default value to set if key doesn't exist. * @returns False if the table key exists with a different type */ - bool SetDefaultNumber(StringRef key, double defaultValue) override; + bool SetDefaultNumber(wpi::StringRef key, double defaultValue); /** * Gets the number associated with the given name. @@ -504,7 +288,7 @@ class NetworkTable final : public ITable { * @return the value associated with the given key or the given default value * if there is no value associated with the key */ - double GetNumber(StringRef key, double defaultValue) const override; + double GetNumber(wpi::StringRef key, double defaultValue) const; /** * Put a string in the table @@ -513,7 +297,7 @@ class NetworkTable final : public ITable { * @param value the value that will be assigned * @return False if the table key already exists with a different type */ - bool PutString(StringRef key, StringRef value) override; + bool PutString(wpi::StringRef key, wpi::StringRef value); /** * Gets the current value in the table, setting it if it does not exist. @@ -522,7 +306,7 @@ class NetworkTable final : public ITable { * @param defaultValue the default value to set if key doesn't exist. * @returns False if the table key exists with a different type */ - bool SetDefaultString(StringRef key, StringRef defaultValue) override; + bool SetDefaultString(wpi::StringRef key, wpi::StringRef defaultValue); /** * Gets the string associated with the given name. If the key does not @@ -533,7 +317,7 @@ class NetworkTable final : public ITable { * @return the value associated with the given key or the given default value * if there is no value associated with the key */ - std::string GetString(StringRef key, StringRef defaultValue) const override; + std::string GetString(wpi::StringRef key, wpi::StringRef defaultValue) const; /** * Put a boolean in the table @@ -542,7 +326,7 @@ class NetworkTable final : public ITable { * @param value the value that will be assigned * @return False if the table key already exists with a different type */ - bool PutBoolean(StringRef key, bool value) override; + bool PutBoolean(wpi::StringRef key, bool value); /** * Gets the current value in the table, setting it if it does not exist. @@ -551,7 +335,7 @@ class NetworkTable final : public ITable { * @param defaultValue the default value to set if key doesn't exist. * @returns False if the table key exists with a different type */ - bool SetDefaultBoolean(StringRef key, bool defaultValue) override; + bool SetDefaultBoolean(wpi::StringRef key, bool defaultValue); /** * Gets the boolean associated with the given name. If the key does not @@ -562,7 +346,7 @@ class NetworkTable final : public ITable { * @return the value associated with the given key or the given default value * if there is no value associated with the key */ - bool GetBoolean(StringRef key, bool defaultValue) const override; + bool GetBoolean(wpi::StringRef key, bool defaultValue) const; /** * Put a boolean array in the table @@ -575,7 +359,7 @@ class NetworkTable final : public ITable { * std::vector is special-cased in C++. 0 is false, any * non-zero value is true. */ - bool PutBooleanArray(StringRef key, ArrayRef value) override; + bool PutBooleanArray(wpi::StringRef key, wpi::ArrayRef value); /** * Gets the current value in the table, setting it if it does not exist. @@ -584,8 +368,8 @@ class NetworkTable final : public ITable { * @param defaultValue the default value to set if key doesn't exist. * @return False if the table key exists with a different type */ - bool SetDefaultBooleanArray(StringRef key, - ArrayRef defaultValue) override; + bool SetDefaultBooleanArray(wpi::StringRef key, + wpi::ArrayRef defaultValue); /** * Returns the boolean array the key maps to. If the key does not exist or is @@ -603,8 +387,8 @@ class NetworkTable final : public ITable { * because std::vector is special-cased in C++. 0 is false, any * non-zero value is true. */ - std::vector GetBooleanArray(StringRef key, - ArrayRef defaultValue) const override; + std::vector GetBooleanArray(wpi::StringRef key, + wpi::ArrayRef defaultValue) const; /** * Put a number array in the table @@ -613,7 +397,7 @@ class NetworkTable final : public ITable { * @param value the value that will be assigned * @return False if the table key already exists with a different type */ - bool PutNumberArray(StringRef key, ArrayRef value) override; + bool PutNumberArray(wpi::StringRef key, wpi::ArrayRef value); /** * Gets the current value in the table, setting it if it does not exist. @@ -622,8 +406,8 @@ class NetworkTable final : public ITable { * @param defaultValue the default value to set if key doesn't exist. * @returns False if the table key exists with a different type */ - bool SetDefaultNumberArray(StringRef key, - ArrayRef defaultValue) override; + bool SetDefaultNumberArray(wpi::StringRef key, + wpi::ArrayRef defaultValue); /** * Returns the number array the key maps to. If the key does not exist or is @@ -637,8 +421,8 @@ class NetworkTable final : public ITable { * @note This makes a copy of the array. If the overhead of this is a * concern, use GetValue() instead. */ - std::vector GetNumberArray( - StringRef key, ArrayRef defaultValue) const override; + std::vector GetNumberArray(wpi::StringRef key, + wpi::ArrayRef defaultValue) const; /** * Put a string array in the table @@ -647,7 +431,7 @@ class NetworkTable final : public ITable { * @param value the value that will be assigned * @return False if the table key already exists with a different type */ - bool PutStringArray(StringRef key, ArrayRef value) override; + bool PutStringArray(wpi::StringRef key, wpi::ArrayRef value); /** * Gets the current value in the table, setting it if it does not exist. @@ -656,8 +440,8 @@ class NetworkTable final : public ITable { * @param defaultValue the default value to set if key doesn't exist. * @returns False if the table key exists with a different type */ - bool SetDefaultStringArray(StringRef key, - ArrayRef defaultValue) override; + bool SetDefaultStringArray(wpi::StringRef key, + wpi::ArrayRef defaultValue); /** * Returns the string array the key maps to. If the key does not exist or is @@ -672,7 +456,7 @@ class NetworkTable final : public ITable { * concern, use GetValue() instead. */ std::vector GetStringArray( - StringRef key, ArrayRef defaultValue) const override; + wpi::StringRef key, wpi::ArrayRef defaultValue) const; /** * Put a raw value (byte array) in the table @@ -681,7 +465,7 @@ class NetworkTable final : public ITable { * @param value the value that will be assigned * @return False if the table key already exists with a different type */ - bool PutRaw(StringRef key, StringRef value) override; + bool PutRaw(wpi::StringRef key, wpi::StringRef value); /** * Gets the current value in the table, setting it if it does not exist. @@ -690,7 +474,7 @@ class NetworkTable final : public ITable { * @param defaultValue the default value to set if key doesn't exist. * @return False if the table key exists with a different type */ - bool SetDefaultRaw(StringRef key, StringRef defaultValue) override; + bool SetDefaultRaw(wpi::StringRef key, wpi::StringRef defaultValue); /** * Returns the raw value (byte array) the key maps to. If the key does not @@ -704,7 +488,7 @@ class NetworkTable final : public ITable { * @note This makes a copy of the raw contents. If the overhead of this is a * concern, use GetValue() instead. */ - std::string GetRaw(StringRef key, StringRef defaultValue) const override; + std::string GetRaw(wpi::StringRef key, wpi::StringRef defaultValue) const; /** * Put a value in the table @@ -713,7 +497,7 @@ class NetworkTable final : public ITable { * @param value the value that will be assigned * @return False if the table key already exists with a different type */ - bool PutValue(const Twine& key, std::shared_ptr value) override; + bool PutValue(const wpi::Twine& key, std::shared_ptr value); /** * Gets the current value in the table, setting it if it does not exist. @@ -722,8 +506,8 @@ class NetworkTable final : public ITable { * @param defaultValue the default value to set if key doesn't exist. * @return False if the table key exists with a different type */ - bool SetDefaultValue(const Twine& key, - std::shared_ptr defaultValue) override; + bool SetDefaultValue(const wpi::Twine& key, + std::shared_ptr defaultValue); /** * Gets the value associated with a key as an object @@ -732,14 +516,14 @@ class NetworkTable final : public ITable { * @return the value associated with the given key, or nullptr if the key * does not exist */ - std::shared_ptr GetValue(const Twine& key) const override; + std::shared_ptr GetValue(const wpi::Twine& key) const; /** * Gets the full path of this table. Does not include the trailing "/". * * @return The path (e.g "", "/foo"). */ - StringRef GetPath() const override; + wpi::StringRef GetPath() const; /** * Save table values to a file. The file format used is identical to @@ -748,7 +532,7 @@ class NetworkTable final : public ITable { * @param filename filename * @return error string, or nullptr if successful */ - const char* SaveEntries(const Twine& filename) const; + const char* SaveEntries(const wpi::Twine& filename) const; /** * Load table values from a file. The file format used is identical to @@ -759,21 +543,10 @@ class NetworkTable final : public ITable { * @return error string, or nullptr if successful */ const char* LoadEntries( - const Twine& filename, + const wpi::Twine& filename, std::function warn); }; -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#elif _WIN32 -#pragma warning(pop) -#endif - } // namespace nt -// For backwards compatibility -#ifndef NAMESPACED_NT -using nt::NetworkTable; // NOLINT -#endif - #endif // NTCORE_NETWORKTABLES_NETWORKTABLE_H_ diff --git a/ntcore/src/main/native/include/networktables/NetworkTableEntry.h b/ntcore/src/main/native/include/networktables/NetworkTableEntry.h index e417885ce3..5b5a0fd5d7 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableEntry.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableEntry.h @@ -23,10 +23,6 @@ namespace nt { -using wpi::ArrayRef; -using wpi::StringRef; -using wpi::Twine; - class NetworkTableInstance; /** @@ -147,7 +143,7 @@ class NetworkTableEntry final { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - std::string GetString(StringRef defaultValue) const; + std::string GetString(wpi::StringRef defaultValue) const; /** * Gets the entry's value as a raw. If the entry does not exist or is of @@ -156,7 +152,7 @@ class NetworkTableEntry final { * @param defaultValue the value to be returned if no value is found * @return the entry's value or the given default value */ - std::string GetRaw(StringRef defaultValue) const; + std::string GetRaw(wpi::StringRef defaultValue) const; /** * Gets the entry's value as a boolean array. If the entry does not exist @@ -172,7 +168,7 @@ class NetworkTableEntry final { * because std::vector is special-cased in C++. 0 is false, any * non-zero value is true. */ - std::vector GetBooleanArray(ArrayRef defaultValue) const; + std::vector GetBooleanArray(wpi::ArrayRef defaultValue) const; /** * Gets the entry's value as a boolean array. If the entry does not exist @@ -201,7 +197,7 @@ class NetworkTableEntry final { * @note This makes a copy of the array. If the overhead of this is a * concern, use GetValue() instead. */ - std::vector GetDoubleArray(ArrayRef defaultValue) const; + std::vector GetDoubleArray(wpi::ArrayRef defaultValue) const; /** * Gets the entry's value as a double array. If the entry does not exist @@ -227,7 +223,7 @@ class NetworkTableEntry final { * concern, use GetValue() instead. */ std::vector GetStringArray( - ArrayRef defaultValue) const; + wpi::ArrayRef defaultValue) const; /** * Gets the entry's value as a string array. If the entry does not exist @@ -272,7 +268,7 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultString(const Twine& defaultValue); + bool SetDefaultString(const wpi::Twine& defaultValue); /** * Sets the entry's value if it does not exist. @@ -280,7 +276,7 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultRaw(StringRef defaultValue); + bool SetDefaultRaw(wpi::StringRef defaultValue); /** * Sets the entry's value if it does not exist. @@ -288,7 +284,7 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultBooleanArray(ArrayRef defaultValue); + bool SetDefaultBooleanArray(wpi::ArrayRef defaultValue); /** * Sets the entry's value if it does not exist. @@ -304,7 +300,7 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultDoubleArray(ArrayRef defaultValue); + bool SetDefaultDoubleArray(wpi::ArrayRef defaultValue); /** * Sets the entry's value if it does not exist. @@ -320,7 +316,7 @@ class NetworkTableEntry final { * @param defaultValue the default value to set * @return False if the entry exists with a different type */ - bool SetDefaultStringArray(ArrayRef defaultValue); + bool SetDefaultStringArray(wpi::ArrayRef defaultValue); /** * Sets the entry's value if it does not exist. @@ -360,7 +356,7 @@ class NetworkTableEntry final { * @param value the value to set * @return False if the entry exists with a different type */ - bool SetString(const Twine& value); + bool SetString(const wpi::Twine& value); /** * Sets the entry's value. @@ -368,7 +364,7 @@ class NetworkTableEntry final { * @param value the value to set * @return False if the entry exists with a different type */ - bool SetRaw(StringRef value); + bool SetRaw(wpi::StringRef value); /** * Sets the entry's value. @@ -376,7 +372,7 @@ class NetworkTableEntry final { * @param value the value to set * @return False if the entry exists with a different type */ - bool SetBooleanArray(ArrayRef value); + bool SetBooleanArray(wpi::ArrayRef value); /** * Sets the entry's value. @@ -392,7 +388,7 @@ class NetworkTableEntry final { * @param value the value to set * @return False if the entry exists with a different type */ - bool SetBooleanArray(ArrayRef value); + bool SetBooleanArray(wpi::ArrayRef value); /** * Sets the entry's value. @@ -408,7 +404,7 @@ class NetworkTableEntry final { * @param value the value to set * @return False if the entry exists with a different type */ - bool SetDoubleArray(ArrayRef value); + bool SetDoubleArray(wpi::ArrayRef value); /** * Sets the entry's value. @@ -424,7 +420,7 @@ class NetworkTableEntry final { * @param value the value to set * @return False if the entry exists with a different type */ - bool SetStringArray(ArrayRef value); + bool SetStringArray(wpi::ArrayRef value); /** * Sets the entry's value. @@ -464,7 +460,7 @@ class NetworkTableEntry final { * * @param value the value to set */ - void ForceSetString(const Twine& value); + void ForceSetString(const wpi::Twine& value); /** * Sets the entry's value. If the value is of different type, the type is @@ -472,7 +468,7 @@ class NetworkTableEntry final { * * @param value the value to set */ - void ForceSetRaw(StringRef value); + void ForceSetRaw(wpi::StringRef value); /** * Sets the entry's value. If the value is of different type, the type is @@ -480,7 +476,7 @@ class NetworkTableEntry final { * * @param value the value to set */ - void ForceSetBooleanArray(ArrayRef value); + void ForceSetBooleanArray(wpi::ArrayRef value); /** * Sets the entry's value. If the value is of different type, the type is @@ -496,7 +492,7 @@ class NetworkTableEntry final { * * @param value the value to set */ - void ForceSetBooleanArray(ArrayRef value); + void ForceSetBooleanArray(wpi::ArrayRef value); /** * Sets the entry's value. If the value is of different type, the type is @@ -512,7 +508,7 @@ class NetworkTableEntry final { * * @param value the value to set */ - void ForceSetDoubleArray(ArrayRef value); + void ForceSetDoubleArray(wpi::ArrayRef value); /** * Sets the entry's value. If the value is of different type, the type is @@ -528,7 +524,7 @@ class NetworkTableEntry final { * * @param value the value to set */ - void ForceSetStringArray(ArrayRef value); + void ForceSetStringArray(wpi::ArrayRef value); /** * Sets the entry's value. If the value is of different type, the type is @@ -600,7 +596,7 @@ class NetworkTableEntry final { * @param params parameter * @return RPC call object. */ - RpcCall CallRpc(StringRef params); + RpcCall CallRpc(wpi::StringRef params); /** * Add a listener for changes to this entry. diff --git a/ntcore/src/main/native/include/networktables/NetworkTableEntry.inl b/ntcore/src/main/native/include/networktables/NetworkTableEntry.inl index c63250f5dc..8afbb45daf 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableEntry.inl +++ b/ntcore/src/main/native/include/networktables/NetworkTableEntry.inl @@ -66,7 +66,8 @@ inline double NetworkTableEntry::GetDouble(double defaultValue) const { return value->GetDouble(); } -inline std::string NetworkTableEntry::GetString(StringRef defaultValue) const { +inline std::string NetworkTableEntry::GetString( + wpi::StringRef defaultValue) const { auto value = GetEntryValue(m_handle); if (!value || value->type() != NT_STRING) { return defaultValue; @@ -74,7 +75,8 @@ inline std::string NetworkTableEntry::GetString(StringRef defaultValue) const { return value->GetString(); } -inline std::string NetworkTableEntry::GetRaw(StringRef defaultValue) const { +inline std::string NetworkTableEntry::GetRaw( + wpi::StringRef defaultValue) const { auto value = GetEntryValue(m_handle); if (!value || value->type() != NT_RAW) { return defaultValue; @@ -83,7 +85,7 @@ inline std::string NetworkTableEntry::GetRaw(StringRef defaultValue) const { } inline std::vector NetworkTableEntry::GetBooleanArray( - ArrayRef defaultValue) const { + wpi::ArrayRef defaultValue) const { auto value = GetEntryValue(m_handle); if (!value || value->type() != NT_BOOLEAN_ARRAY) { return defaultValue; @@ -98,7 +100,7 @@ inline std::vector NetworkTableEntry::GetBooleanArray( } inline std::vector NetworkTableEntry::GetDoubleArray( - ArrayRef defaultValue) const { + wpi::ArrayRef defaultValue) const { auto value = GetEntryValue(m_handle); if (!value || value->type() != NT_DOUBLE_ARRAY) { return defaultValue; @@ -113,7 +115,7 @@ inline std::vector NetworkTableEntry::GetDoubleArray( } inline std::vector NetworkTableEntry::GetStringArray( - ArrayRef defaultValue) const { + wpi::ArrayRef defaultValue) const { auto value = GetEntryValue(m_handle); if (!value || value->type() != NT_STRING_ARRAY) { return defaultValue; @@ -139,16 +141,17 @@ inline bool NetworkTableEntry::SetDefaultDouble(double defaultValue) { return SetDefaultEntryValue(m_handle, Value::MakeDouble(defaultValue)); } -inline bool NetworkTableEntry::SetDefaultString(const Twine& defaultValue) { +inline bool NetworkTableEntry::SetDefaultString( + const wpi::Twine& defaultValue) { return SetDefaultEntryValue(m_handle, Value::MakeString(defaultValue)); } -inline bool NetworkTableEntry::SetDefaultRaw(StringRef defaultValue) { +inline bool NetworkTableEntry::SetDefaultRaw(wpi::StringRef defaultValue) { return SetDefaultEntryValue(m_handle, Value::MakeRaw(defaultValue)); } inline bool NetworkTableEntry::SetDefaultBooleanArray( - ArrayRef defaultValue) { + wpi::ArrayRef defaultValue) { return SetDefaultEntryValue(m_handle, Value::MakeBooleanArray(defaultValue)); } @@ -158,7 +161,7 @@ inline bool NetworkTableEntry::SetDefaultBooleanArray( } inline bool NetworkTableEntry::SetDefaultDoubleArray( - ArrayRef defaultValue) { + wpi::ArrayRef defaultValue) { return SetDefaultEntryValue(m_handle, Value::MakeDoubleArray(defaultValue)); } @@ -168,7 +171,7 @@ inline bool NetworkTableEntry::SetDefaultDoubleArray( } inline bool NetworkTableEntry::SetDefaultStringArray( - ArrayRef defaultValue) { + wpi::ArrayRef defaultValue) { return SetDefaultEntryValue(m_handle, Value::MakeStringArray(defaultValue)); } @@ -189,15 +192,15 @@ inline bool NetworkTableEntry::SetDouble(double value) { return SetEntryValue(m_handle, Value::MakeDouble(value)); } -inline bool NetworkTableEntry::SetString(const Twine& value) { +inline bool NetworkTableEntry::SetString(const wpi::Twine& value) { return SetEntryValue(m_handle, Value::MakeString(value)); } -inline bool NetworkTableEntry::SetRaw(StringRef value) { +inline bool NetworkTableEntry::SetRaw(wpi::StringRef value) { return SetEntryValue(m_handle, Value::MakeRaw(value)); } -inline bool NetworkTableEntry::SetBooleanArray(ArrayRef value) { +inline bool NetworkTableEntry::SetBooleanArray(wpi::ArrayRef value) { return SetEntryValue(m_handle, Value::MakeBooleanArray(value)); } @@ -206,7 +209,7 @@ inline bool NetworkTableEntry::SetBooleanArray( return SetEntryValue(m_handle, Value::MakeBooleanArray(value)); } -inline bool NetworkTableEntry::SetBooleanArray(ArrayRef value) { +inline bool NetworkTableEntry::SetBooleanArray(wpi::ArrayRef value) { return SetEntryValue(m_handle, Value::MakeBooleanArray(value)); } @@ -215,7 +218,7 @@ inline bool NetworkTableEntry::SetBooleanArray( return SetEntryValue(m_handle, Value::MakeBooleanArray(value)); } -inline bool NetworkTableEntry::SetDoubleArray(ArrayRef value) { +inline bool NetworkTableEntry::SetDoubleArray(wpi::ArrayRef value) { return SetEntryValue(m_handle, Value::MakeDoubleArray(value)); } @@ -224,7 +227,8 @@ inline bool NetworkTableEntry::SetDoubleArray( return SetEntryValue(m_handle, Value::MakeDoubleArray(value)); } -inline bool NetworkTableEntry::SetStringArray(ArrayRef value) { +inline bool NetworkTableEntry::SetStringArray( + wpi::ArrayRef value) { return SetEntryValue(m_handle, Value::MakeStringArray(value)); } @@ -245,15 +249,15 @@ inline void NetworkTableEntry::ForceSetDouble(double value) { SetEntryTypeValue(m_handle, Value::MakeDouble(value)); } -inline void NetworkTableEntry::ForceSetString(const Twine& value) { +inline void NetworkTableEntry::ForceSetString(const wpi::Twine& value) { SetEntryTypeValue(m_handle, Value::MakeString(value)); } -inline void NetworkTableEntry::ForceSetRaw(StringRef value) { +inline void NetworkTableEntry::ForceSetRaw(wpi::StringRef value) { SetEntryTypeValue(m_handle, Value::MakeRaw(value)); } -inline void NetworkTableEntry::ForceSetBooleanArray(ArrayRef value) { +inline void NetworkTableEntry::ForceSetBooleanArray(wpi::ArrayRef value) { SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value)); } @@ -262,7 +266,7 @@ inline void NetworkTableEntry::ForceSetBooleanArray( SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value)); } -inline void NetworkTableEntry::ForceSetBooleanArray(ArrayRef value) { +inline void NetworkTableEntry::ForceSetBooleanArray(wpi::ArrayRef value) { SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value)); } @@ -271,7 +275,8 @@ inline void NetworkTableEntry::ForceSetBooleanArray( SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value)); } -inline void NetworkTableEntry::ForceSetDoubleArray(ArrayRef value) { +inline void NetworkTableEntry::ForceSetDoubleArray( + wpi::ArrayRef value) { SetEntryTypeValue(m_handle, Value::MakeDoubleArray(value)); } @@ -281,7 +286,7 @@ inline void NetworkTableEntry::ForceSetDoubleArray( } inline void NetworkTableEntry::ForceSetStringArray( - ArrayRef value) { + wpi::ArrayRef value) { SetEntryTypeValue(m_handle, Value::MakeStringArray(value)); } @@ -316,10 +321,10 @@ inline void NetworkTableEntry::Delete() { inline void NetworkTableEntry::CreateRpc( std::function callback) { - ::nt::CreateRpc(m_handle, StringRef("\0", 1), callback); + ::nt::CreateRpc(m_handle, wpi::StringRef("\0", 1), callback); } -inline RpcCall NetworkTableEntry::CallRpc(StringRef params) { +inline RpcCall NetworkTableEntry::CallRpc(wpi::StringRef params) { return RpcCall{m_handle, ::nt::CallRpc(m_handle, params)}; } diff --git a/ntcore/src/main/native/include/networktables/NetworkTableInstance.h b/ntcore/src/main/native/include/networktables/NetworkTableInstance.h index 7691edad2d..5284091419 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableInstance.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableInstance.h @@ -22,10 +22,6 @@ namespace nt { -using wpi::ArrayRef; -using wpi::StringRef; -using wpi::Twine; - /** * NetworkTables Instance. * @@ -135,7 +131,7 @@ class NetworkTableInstance final { * @param name Key * @return Network table entry. */ - NetworkTableEntry GetEntry(const Twine& name); + NetworkTableEntry GetEntry(const wpi::Twine& name); /** * Get entries starting with the given prefix. @@ -148,7 +144,7 @@ class NetworkTableInstance final { * @param types bitmask of types; 0 is treated as a "don't care" * @return Array of entries. */ - std::vector GetEntries(const Twine& prefix, + std::vector GetEntries(const wpi::Twine& prefix, unsigned int types); /** @@ -162,7 +158,7 @@ class NetworkTableInstance final { * @param types bitmask of types; 0 is treated as a "don't care" * @return Array of entry information. */ - std::vector GetEntryInfo(const Twine& prefix, + std::vector GetEntryInfo(const wpi::Twine& prefix, unsigned int types) const; /** @@ -171,7 +167,7 @@ class NetworkTableInstance final { * @param key the key name * @return The network table */ - std::shared_ptr GetTable(const Twine& key) const; + std::shared_ptr GetTable(const wpi::Twine& key) const; /** * Deletes ALL keys in ALL subtables (except persistent values). @@ -193,7 +189,7 @@ class NetworkTableInstance final { * @return Listener handle */ NT_EntryListener AddEntryListener( - const Twine& prefix, + const wpi::Twine& prefix, std::function callback, unsigned int flags) const; @@ -287,7 +283,7 @@ class NetworkTableInstance final { * * @param name identity to advertise */ - void SetNetworkIdentity(const Twine& name); + void SetNetworkIdentity(const wpi::Twine& name); /** * Get the current network mode. @@ -318,7 +314,7 @@ class NetworkTableInstance final { * address (UTF-8 string, null terminated) * @param port port to communicate over */ - void StartServer(const Twine& persist_filename = "networktables.ini", + void StartServer(const wpi::Twine& persist_filename = "networktables.ini", const char* listen_address = "", unsigned int port = kDefaultPort); @@ -346,7 +342,8 @@ class NetworkTableInstance final { * * @param servers array of server name and port pairs */ - void StartClient(ArrayRef> servers); + void StartClient( + wpi::ArrayRef> servers); /** * Starts a client using the specified servers and port. The @@ -355,7 +352,7 @@ class NetworkTableInstance final { * @param servers array of server names * @param port port to communicate over */ - void StartClient(ArrayRef servers, + void StartClient(wpi::ArrayRef servers, unsigned int port = kDefaultPort); /** @@ -386,7 +383,8 @@ class NetworkTableInstance final { * * @param servers array of server name and port pairs */ - void SetServer(ArrayRef> servers); + void SetServer( + wpi::ArrayRef> servers); /** * Sets server addresses and port for client (without restarting client). @@ -395,7 +393,8 @@ class NetworkTableInstance final { * @param servers array of server names * @param port port to communicate over */ - void SetServer(ArrayRef servers, unsigned int port = kDefaultPort); + void SetServer(wpi::ArrayRef servers, + unsigned int port = kDefaultPort); /** * Sets server addresses and port for client (without restarting client). @@ -466,7 +465,7 @@ class NetworkTableInstance final { * @param filename filename * @return error string, or nullptr if successful */ - const char* SavePersistent(const Twine& filename) const; + const char* SavePersistent(const wpi::Twine& filename) const; /** * Load persistent values from a file. The server automatically does this @@ -478,7 +477,7 @@ class NetworkTableInstance final { * @return error string, or nullptr if successful */ const char* LoadPersistent( - const Twine& filename, + const wpi::Twine& filename, std::function warn); /** @@ -489,7 +488,8 @@ class NetworkTableInstance final { * @param prefix save only keys starting with this prefix * @return error string, or nullptr if successful */ - const char* SaveEntries(const Twine& filename, const Twine& prefix) const; + const char* SaveEntries(const wpi::Twine& filename, + const wpi::Twine& prefix) const; /** * Load table values from a file. The file format used is identical to @@ -501,7 +501,7 @@ class NetworkTableInstance final { * @return error string, or nullptr if successful */ const char* LoadEntries( - const Twine& filename, const Twine& prefix, + const wpi::Twine& filename, const wpi::Twine& prefix, std::function warn); /** @} */ diff --git a/ntcore/src/main/native/include/networktables/NetworkTableInstance.inl b/ntcore/src/main/native/include/networktables/NetworkTableInstance.inl index 9d80f642c0..ef8e9f3f86 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableInstance.inl +++ b/ntcore/src/main/native/include/networktables/NetworkTableInstance.inl @@ -35,12 +35,13 @@ inline NT_Inst NetworkTableInstance::GetHandle() const { return m_handle; } -inline NetworkTableEntry NetworkTableInstance::GetEntry(const Twine& name) { +inline NetworkTableEntry NetworkTableInstance::GetEntry( + const wpi::Twine& name) { return NetworkTableEntry{::nt::GetEntry(m_handle, name)}; } inline std::vector NetworkTableInstance::GetEntries( - const Twine& prefix, unsigned int types) { + const wpi::Twine& prefix, unsigned int types) { std::vector entries; for (auto entry : ::nt::GetEntries(m_handle, prefix, types)) { entries.emplace_back(entry); @@ -49,7 +50,7 @@ inline std::vector NetworkTableInstance::GetEntries( } inline std::vector NetworkTableInstance::GetEntryInfo( - const Twine& prefix, unsigned int types) const { + const wpi::Twine& prefix, unsigned int types) const { return ::nt::GetEntryInfo(m_handle, prefix, types); } @@ -80,7 +81,7 @@ inline bool NetworkTableInstance::WaitForRpcCallQueue(double timeout) { return ::nt::WaitForRpcCallQueue(m_handle, timeout); } -inline void NetworkTableInstance::SetNetworkIdentity(const Twine& name) { +inline void NetworkTableInstance::SetNetworkIdentity(const wpi::Twine& name) { ::nt::SetNetworkIdentity(m_handle, name); } @@ -96,9 +97,9 @@ inline void NetworkTableInstance::StopLocal() { ::nt::StopLocal(m_handle); } -inline void NetworkTableInstance::StartServer(const Twine& persist_filename, - const char* listen_address, - unsigned int port) { +inline void NetworkTableInstance::StartServer( + const wpi::Twine& persist_filename, const char* listen_address, + unsigned int port) { ::nt::StartServer(m_handle, persist_filename, listen_address, port); } @@ -116,7 +117,7 @@ inline void NetworkTableInstance::StartClient(const char* server_name, } inline void NetworkTableInstance::StartClient( - ArrayRef> servers) { + wpi::ArrayRef> servers) { ::nt::StartClient(m_handle, servers); } @@ -135,7 +136,7 @@ inline void NetworkTableInstance::SetServer(const char* server_name, } inline void NetworkTableInstance::SetServer( - ArrayRef> servers) { + wpi::ArrayRef> servers) { ::nt::SetServer(m_handle, servers); } @@ -170,23 +171,23 @@ inline bool NetworkTableInstance::IsConnected() const { } inline const char* NetworkTableInstance::SavePersistent( - const Twine& filename) const { + const wpi::Twine& filename) const { return ::nt::SavePersistent(m_handle, filename); } inline const char* NetworkTableInstance::LoadPersistent( - const Twine& filename, + const wpi::Twine& filename, std::function warn) { return ::nt::LoadPersistent(m_handle, filename, warn); } inline const char* NetworkTableInstance::SaveEntries( - const Twine& filename, const Twine& prefix) const { + const wpi::Twine& filename, const wpi::Twine& prefix) const { return ::nt::SaveEntries(m_handle, filename, prefix); } inline const char* NetworkTableInstance::LoadEntries( - const Twine& filename, const Twine& prefix, + const wpi::Twine& filename, const wpi::Twine& prefix, std::function warn) { return ::nt::LoadEntries(m_handle, filename, prefix, warn); } diff --git a/ntcore/src/main/native/include/networktables/NetworkTableValue.h b/ntcore/src/main/native/include/networktables/NetworkTableValue.h index 40881126d8..014bc326cd 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableValue.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableValue.h @@ -23,10 +23,6 @@ namespace nt { -using wpi::ArrayRef; -using wpi::StringRef; -using wpi::Twine; - /** * A network table entry value. * @ingroup ntcore_cpp_api @@ -167,7 +163,7 @@ class Value final { * * @return The string value. */ - StringRef GetString() const { + wpi::StringRef GetString() const { assert(m_val.type == NT_STRING); return m_string; } @@ -177,7 +173,7 @@ class Value final { * * @return The raw value. */ - StringRef GetRaw() const { + wpi::StringRef GetRaw() const { assert(m_val.type == NT_RAW); return m_string; } @@ -187,7 +183,7 @@ class Value final { * * @return The rpc definition value. */ - StringRef GetRpc() const { + wpi::StringRef GetRpc() const { assert(m_val.type == NT_RPC); return m_string; } @@ -197,10 +193,10 @@ class Value final { * * @return The boolean array value. */ - ArrayRef GetBooleanArray() const { + wpi::ArrayRef GetBooleanArray() const { assert(m_val.type == NT_BOOLEAN_ARRAY); - return ArrayRef(m_val.data.arr_boolean.arr, - m_val.data.arr_boolean.size); + return wpi::ArrayRef(m_val.data.arr_boolean.arr, + m_val.data.arr_boolean.size); } /** @@ -208,10 +204,10 @@ class Value final { * * @return The double array value. */ - ArrayRef GetDoubleArray() const { + wpi::ArrayRef GetDoubleArray() const { assert(m_val.type == NT_DOUBLE_ARRAY); - return ArrayRef(m_val.data.arr_double.arr, - m_val.data.arr_double.size); + return wpi::ArrayRef(m_val.data.arr_double.arr, + m_val.data.arr_double.size); } /** @@ -219,7 +215,7 @@ class Value final { * * @return The string array value. */ - ArrayRef GetStringArray() const { + wpi::ArrayRef GetStringArray() const { assert(m_val.type == NT_STRING_ARRAY); return m_string_array; } @@ -267,7 +263,7 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeString(const Twine& value, + static std::shared_ptr MakeString(const wpi::Twine& value, uint64_t time = 0) { auto val = std::make_shared(NT_STRING, time, private_init()); val->m_string = value.str(); @@ -302,7 +298,8 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeRaw(StringRef value, uint64_t time = 0) { + static std::shared_ptr MakeRaw(wpi::StringRef value, + uint64_t time = 0) { auto val = std::make_shared(NT_RAW, time, private_init()); val->m_string = value; val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); @@ -336,7 +333,8 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeRpc(StringRef value, uint64_t time = 0) { + static std::shared_ptr MakeRpc(wpi::StringRef value, + uint64_t time = 0) { auto val = std::make_shared(NT_RPC, time, private_init()); val->m_string = value; val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); @@ -369,7 +367,7 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeBooleanArray(ArrayRef value, + static std::shared_ptr MakeBooleanArray(wpi::ArrayRef value, uint64_t time = 0); /** @@ -394,7 +392,7 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeBooleanArray(ArrayRef value, + static std::shared_ptr MakeBooleanArray(wpi::ArrayRef value, uint64_t time = 0); /** @@ -419,7 +417,7 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeDoubleArray(ArrayRef value, + static std::shared_ptr MakeDoubleArray(wpi::ArrayRef value, uint64_t time = 0); /** @@ -443,8 +441,8 @@ class Value final { * time) * @return The entry value */ - static std::shared_ptr MakeStringArray(ArrayRef value, - uint64_t time = 0); + static std::shared_ptr MakeStringArray( + wpi::ArrayRef value, uint64_t time = 0); /** * Creates a string array entry value. diff --git a/ntcore/src/main/native/include/networktables/TableEntryListener.h b/ntcore/src/main/native/include/networktables/TableEntryListener.h index cd73697224..4930bf0056 100644 --- a/ntcore/src/main/native/include/networktables/TableEntryListener.h +++ b/ntcore/src/main/native/include/networktables/TableEntryListener.h @@ -16,8 +16,6 @@ class NetworkTable; class NetworkTableEntry; class Value; -using wpi::StringRef; - /** * A listener that listens to changes in values in a NetworkTable. * @@ -32,7 +30,7 @@ using wpi::StringRef; * * @ingroup ntcore_cpp_api */ -typedef std::function value, int flags)> TableEntryListener; diff --git a/ntcore/src/main/native/include/networktables/TableListener.h b/ntcore/src/main/native/include/networktables/TableListener.h index 22b02f8965..3e8f8c70cd 100644 --- a/ntcore/src/main/native/include/networktables/TableListener.h +++ b/ntcore/src/main/native/include/networktables/TableListener.h @@ -14,8 +14,6 @@ namespace nt { class NetworkTable; -using wpi::StringRef; - /** * A listener that listens to new sub-tables in a NetworkTable. * @@ -27,7 +25,7 @@ using wpi::StringRef; * * @ingroup ntcore_cpp_api */ -typedef std::function table)> TableListener; diff --git a/ntcore/src/main/native/include/ntcore_cpp.h b/ntcore/src/main/native/include/ntcore_cpp.h index 3964975797..74bc1e8ac6 100644 --- a/ntcore/src/main/native/include/ntcore_cpp.h +++ b/ntcore/src/main/native/include/ntcore_cpp.h @@ -18,7 +18,6 @@ #include #include #include -#include #include "networktables/NetworkTableValue.h" @@ -33,10 +32,6 @@ namespace nt { * @{ */ -using wpi::ArrayRef; -using wpi::StringRef; -using wpi::Twine; - /** NetworkTables Entry Information */ struct EntryInfo { /** Entry handle */ @@ -103,7 +98,7 @@ struct ConnectionInfo { /** NetworkTables RPC Version 1 Definition Parameter */ struct RpcParamDef { RpcParamDef() = default; - RpcParamDef(StringRef name_, std::shared_ptr def_value_) + RpcParamDef(wpi::StringRef name_, std::shared_ptr def_value_) : name(name_), def_value(std::move(def_value_)) {} std::string name; @@ -113,7 +108,8 @@ struct RpcParamDef { /** NetworkTables RPC Version 1 Definition Result */ struct RpcResultDef { RpcResultDef() = default; - RpcResultDef(StringRef name_, NT_Type type_) : name(name_), type(type_) {} + RpcResultDef(wpi::StringRef name_, NT_Type type_) + : name(name_), type(type_) {} std::string name; NT_Type type; @@ -131,8 +127,8 @@ struct RpcDefinition { class RpcAnswer { public: RpcAnswer() = default; - RpcAnswer(NT_Entry entry_, NT_RpcCall call_, StringRef name_, - StringRef params_, ConnectionInfo conn_) + RpcAnswer(NT_Entry entry_, NT_RpcCall call_, wpi::StringRef name_, + wpi::StringRef params_, ConnectionInfo conn_) : entry(entry_), call(call_), name(name_), @@ -165,7 +161,7 @@ class RpcAnswer { * @param result result raw data that will be provided to remote caller * @return True if posting the response is valid, otherwise false */ - bool PostResponse(StringRef result) const; + bool PostResponse(wpi::StringRef result) const; friend void swap(RpcAnswer& first, RpcAnswer& second) { using std::swap; @@ -182,7 +178,7 @@ class EntryNotification { public: EntryNotification() = default; EntryNotification(NT_EntryListener listener_, NT_Entry entry_, - StringRef name_, std::shared_ptr value_, + wpi::StringRef name_, std::shared_ptr value_, unsigned int flags_) : listener(listener_), entry(entry_), @@ -249,7 +245,7 @@ class LogMessage { public: LogMessage() = default; LogMessage(NT_Logger logger_, unsigned int level_, const char* filename_, - unsigned int line_, StringRef message_) + unsigned int line_, wpi::StringRef message_) : logger(logger_), level(level_), filename(filename_), @@ -331,7 +327,7 @@ NT_Inst GetInstanceFromHandle(NT_Handle handle); * @param name entry name (UTF-8 string) * @return entry handle */ -NT_Entry GetEntry(NT_Inst inst, const Twine& name); +NT_Entry GetEntry(NT_Inst inst, const wpi::Twine& name); /** * Get Entry Handles. @@ -347,7 +343,7 @@ NT_Entry GetEntry(NT_Inst inst, const Twine& name); * as a "don't care" * @return Array of entry handles. */ -std::vector GetEntries(NT_Inst inst, const Twine& prefix, +std::vector GetEntries(NT_Inst inst, const wpi::Twine& prefix, unsigned int types); /** @@ -376,18 +372,6 @@ NT_Type GetEntryType(NT_Entry entry); */ uint64_t GetEntryLastChange(NT_Entry entry); -/** - * Get Entry Value. - * - * Returns copy of current entry value. - * Note that one of the type options is "unassigned". - * - * @param name entry name (UTF-8 string) - * @return entry value - */ -WPI_DEPRECATED("use NT_Entry function instead") -std::shared_ptr GetEntryValue(StringRef name); - /** * Get Entry Value. * @@ -399,20 +383,6 @@ std::shared_ptr GetEntryValue(StringRef name); */ std::shared_ptr GetEntryValue(NT_Entry entry); -/** - * Set Default Entry Value - * - * Returns copy of current entry value if it exists. - * Otherwise, sets passed in value, and returns set value. - * Note that one of the type options is "unassigned". - * - * @param name entry name (UTF-8 string) - * @param value value to be set if name does not exist - * @return False on error (value not set), True on success - */ -WPI_DEPRECATED("use NT_Entry function instead") -bool SetDefaultEntryValue(StringRef name, std::shared_ptr value); - /** * Set Default Entry Value * @@ -426,19 +396,6 @@ bool SetDefaultEntryValue(StringRef name, std::shared_ptr value); */ bool SetDefaultEntryValue(NT_Entry entry, std::shared_ptr value); -/** - * Set Entry Value. - * - * Sets new entry value. If type of new value differs from the type of the - * currently stored entry, returns error and does not update value. - * - * @param name entry name (UTF-8 string) - * @param value new entry value - * @return False on error (type mismatch), True on success - */ -WPI_DEPRECATED("use NT_Entry function instead") -bool SetEntryValue(StringRef name, std::shared_ptr value); - /** * Set Entry Value. * @@ -451,22 +408,6 @@ bool SetEntryValue(StringRef name, std::shared_ptr value); */ bool SetEntryValue(NT_Entry entry, std::shared_ptr value); -/** - * Set Entry Type and Value. - * - * Sets new entry value. If type of new value differs from the type of the - * currently stored entry, the currently stored entry type is overridden - * (generally this will generate an Entry Assignment message). - * - * This is NOT the preferred method to update a value; generally - * SetEntryValue() should be used instead, with appropriate error handling. - * - * @param name entry name (UTF-8 string) - * @param value new entry value - */ -WPI_DEPRECATED("use NT_Entry function instead") -void SetEntryTypeValue(StringRef name, std::shared_ptr value); - /** * Set Entry Type and Value. * @@ -482,15 +423,6 @@ void SetEntryTypeValue(StringRef name, std::shared_ptr value); */ void SetEntryTypeValue(NT_Entry entry, std::shared_ptr value); -/** - * Set Entry Flags. - * - * @param name entry name (UTF-8 string) - * @param flags flags value (bitmask of NT_EntryFlags) - */ -WPI_DEPRECATED("use NT_Entry function instead") -void SetEntryFlags(StringRef name, unsigned int flags); - /** * Set Entry Flags. * @@ -499,15 +431,6 @@ void SetEntryFlags(StringRef name, unsigned int flags); */ void SetEntryFlags(NT_Entry entry, unsigned int flags); -/** - * Get Entry Flags. - * - * @param name entry name (UTF-8 string) - * @return Flags value (bitmask of NT_EntryFlags) - */ -WPI_DEPRECATED("use NT_Entry function instead") -unsigned int GetEntryFlags(StringRef name); - /** * Get Entry Flags. * @@ -516,22 +439,6 @@ unsigned int GetEntryFlags(StringRef name); */ unsigned int GetEntryFlags(NT_Entry entry); -/** - * Delete Entry. - * - * Deletes an entry. This is a new feature in version 3.0 of the protocol, - * so this may not have an effect if any other node in the network is not - * version 3.0 or newer. - * - * Note: GetConnections() can be used to determine the protocol version - * of direct remote connection(s), but this is not sufficient to determine - * if all nodes in the network are version 3.0 or newer. - * - * @param name entry name (UTF-8 string) - */ -WPI_DEPRECATED("use NT_Entry function instead") -void DeleteEntry(StringRef name); - /** * Delete Entry. * @@ -557,12 +464,6 @@ void DeleteEntry(NT_Entry entry); * Note: GetConnections() can be used to determine the protocol version * of direct remote connection(s), but this is not sufficient to determine * if all nodes in the network are version 3.0 or newer. - */ -WPI_DEPRECATED("use NT_Inst function instead") -void DeleteAllEntries(); - -/** - * @copydoc DeleteAllEntries() * * @param inst instance handle */ @@ -576,21 +477,14 @@ void DeleteAllEntries(NT_Inst inst); * filtered by string prefix and entry type to only return a subset of all * entries. * + * @param inst instance handle * @param prefix entry name required prefix; only entries whose name * starts with this string are returned * @param types bitmask of NT_Type values; 0 is treated specially * as a "don't care" * @return Array of entry information. */ -WPI_DEPRECATED("use NT_Inst function instead") -std::vector GetEntryInfo(StringRef prefix, unsigned int types); - -/** - * @copydoc GetEntryInfo(StringRef, unsigned int) - * - * @param inst instance handle - */ -std::vector GetEntryInfo(NT_Inst inst, const Twine& prefix, +std::vector GetEntryInfo(NT_Inst inst, const wpi::Twine& prefix, unsigned int types); /** @@ -622,30 +516,21 @@ EntryInfo GetEntryInfo(NT_Entry entry); * @param flags update flags; for example, NT_NOTIFY_NEW if the key * did not previously exist */ -typedef std::function value, unsigned int flags)> EntryListenerCallback; /** * Add a listener for all entries starting with a certain prefix. * + * @param inst instance handle * @param prefix UTF-8 string prefix * @param callback listener to add * @param flags NotifyKind bitmask * @return Listener handle */ -WPI_DEPRECATED("use NT_Inst function instead") -NT_EntryListener AddEntryListener(StringRef prefix, - EntryListenerCallback callback, - unsigned int flags); - -/** - * @copydoc AddEntryListener(StringRef, EntryListenerCallback, unsigned int) - * - * @param inst instance handle - */ NT_EntryListener AddEntryListener( - NT_Inst inst, const Twine& prefix, + NT_Inst inst, const wpi::Twine& prefix, std::function callback, unsigned int flags); @@ -693,7 +578,7 @@ void DestroyEntryListenerPoller(NT_EntryListenerPoller poller); * @return Listener handle */ NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller, - const Twine& prefix, + const wpi::Twine& prefix, unsigned int flags); /** @@ -787,19 +672,11 @@ using ConnectionListenerCallback = /** * Add a connection listener. * + * @param inst instance handle * @param callback listener to add * @param immediate_notify notify listener of all existing connections * @return Listener handle */ -WPI_DEPRECATED("use NT_Inst function instead") -NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback, - bool immediate_notify); - -/** - * @copydoc AddConnectionListener(ConnectionListenerCallback, bool) - * - * @param inst instance handle - */ NT_ConnectionListener AddConnectionListener( NT_Inst inst, std::function callback, @@ -910,7 +787,7 @@ bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout); * @param callback callback function; note the callback function must call * PostRpcResponse() to provide a response to the call */ -void CreateRpc(NT_Entry entry, StringRef def, +void CreateRpc(NT_Entry entry, wpi::StringRef def, std::function callback); /** @@ -943,7 +820,8 @@ void DestroyRpcCallPoller(NT_RpcCallPoller poller); * @param def RPC definition * @param poller poller handle */ -void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller); +void CreatePolledRpc(NT_Entry entry, wpi::StringRef def, + NT_RpcCallPoller poller); /** * Get the next incoming RPC call. This blocks until the next incoming RPC @@ -1006,7 +884,7 @@ bool WaitForRpcCallQueue(NT_Inst inst, double timeout); * @param result result raw data that will be provided to remote caller * @return true if the response was posted, otherwise false */ -bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result); +bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, wpi::StringRef result); /** * Call a RPC function. May be used on either the client or server. @@ -1019,7 +897,7 @@ bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result); * @return RPC call handle (for use with GetRpcResult() or * CancelRpcResult()). */ -NT_RpcCall CallRpc(NT_Entry entry, StringRef params); +NT_RpcCall CallRpc(NT_Entry entry, wpi::StringRef params); /** * Get the result (return value) of a RPC call. This function blocks until @@ -1070,7 +948,7 @@ std::string PackRpcDefinition(const RpcDefinition& def); * @param def RPC version 1 definition (output) * @return True if successfully unpacked, false otherwise. */ -bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def); +bool UnpackRpcDefinition(wpi::StringRef packed, RpcDefinition* def); /** * Pack RPC values as required for RPC version 1 definition messages. @@ -1078,7 +956,7 @@ bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def); * @param values array of values to pack * @return Raw packed bytes. */ -std::string PackRpcValues(ArrayRef> values); +std::string PackRpcValues(wpi::ArrayRef> values); /** * Unpack RPC values as required for RPC version 1 definition messages. @@ -1087,8 +965,8 @@ std::string PackRpcValues(ArrayRef> values); * @param types array of data types (as provided in the RPC definition) * @return Array of values. */ -std::vector> UnpackRpcValues(StringRef packed, - ArrayRef types); +std::vector> UnpackRpcValues( + wpi::StringRef packed, wpi::ArrayRef types); /** @} */ @@ -1102,25 +980,10 @@ std::vector> UnpackRpcValues(StringRef packed, * This is the name used during the initial connection handshake, and is * visible through ConnectionInfo on the remote node. * + * @param inst instance handle * @param name identity to advertise */ -WPI_DEPRECATED("use NT_Inst function instead") -void SetNetworkIdentity(StringRef name); - -/** - * @copydoc SetNetworkIdentity(StringRef) - * - * @param inst instance handle - */ -void SetNetworkIdentity(NT_Inst inst, const Twine& name); - -/** - * Get the current network mode. - * - * @return Bitmask of NT_NetworkMode. - */ -WPI_DEPRECATED("use NT_Inst function instead") -unsigned int GetNetworkMode(); +void SetNetworkIdentity(NT_Inst inst, const wpi::Twine& name); /** * Get the current network mode. @@ -1146,32 +1009,18 @@ void StopLocal(NT_Inst inst); /** * Starts a server using the specified filename, listening address, and port. * + * @param inst instance handle * @param persist_filename the name of the persist file to use (UTF-8 string, * null terminated) * @param listen_address the address to listen on, or null to listen on any * address. (UTF-8 string, null terminated) * @param port port to communicate over. */ -WPI_DEPRECATED("use NT_Inst function instead") -void StartServer(StringRef persist_filename, const char* listen_address, - unsigned int port); - -/** - * @copydoc StartServer(StringRef, const char*, unsigned int) - * - * @param inst instance handle - */ -void StartServer(NT_Inst inst, const Twine& persist_filename, +void StartServer(NT_Inst inst, const wpi::Twine& persist_filename, const char* listen_address, unsigned int port); /** * Stops the server if it is running. - */ -WPI_DEPRECATED("use NT_Inst function instead") -void StopServer(); - -/** - * @copydoc StopServer() * * @param inst instance handle */ @@ -1179,49 +1028,30 @@ void StopServer(NT_Inst inst); /** * Starts a client. Use SetServer to set the server name and port. - */ -WPI_DEPRECATED("use NT_Inst function instead") -void StartClient(); - -/** - * Starts a client using the specified server and port - * - * @param server_name server name (UTF-8 string, null terminated) - * @param port port to communicate over - */ -WPI_DEPRECATED("use NT_Inst function instead") -void StartClient(const char* server_name, unsigned int port); - -/** - * Starts a client using the specified (server, port) combinations. The - * client will attempt to connect to each server in round robin fashion. - * - * @param servers array of server name and port pairs - */ -WPI_DEPRECATED("use NT_Inst function instead") -void StartClient(ArrayRef> servers); - -/** - * @copydoc StartClient() * * @param inst instance handle */ void StartClient(NT_Inst inst); /** - * @copydoc StartClient(const char*, unsigned int) + * Starts a client using the specified server and port * * @param inst instance handle + * @param server_name server name (UTF-8 string, null terminated) + * @param port port to communicate over */ void StartClient(NT_Inst inst, const char* server_name, unsigned int port); /** - * @copydoc StartClient(ArrayRef>) + * Starts a client using the specified (server, port) combinations. The + * client will attempt to connect to each server in round robin fashion. * * @param inst instance handle + * @param servers array of server name and port pairs */ -void StartClient(NT_Inst inst, - ArrayRef> servers); +void StartClient( + NT_Inst inst, + wpi::ArrayRef> servers); /** * Starts a client using commonly known robot addresses for the specified @@ -1235,12 +1065,7 @@ void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port); /** * Stops the client if it is running. - */ -WPI_DEPRECATED("use NT_Inst function instead") -void StopClient(); - -/** - * @copydoc StopClient() + * * @param inst instance handle */ void StopClient(NT_Inst inst); @@ -1248,35 +1073,21 @@ void StopClient(NT_Inst inst); /** * Sets server address and port for client (without restarting client). * + * @param inst instance handle * @param server_name server name (UTF-8 string, null terminated) * @param port port to communicate over */ -WPI_DEPRECATED("use NT_Inst function instead") -void SetServer(const char* server_name, unsigned int port); +void SetServer(NT_Inst inst, const char* server_name, unsigned int port); /** * Sets server addresses for client (without restarting client). * The client will attempt to connect to each server in round robin fashion. * + * @param inst instance handle * @param servers array of server name and port pairs */ -WPI_DEPRECATED("use NT_Inst function instead") -void SetServer(ArrayRef> servers); - -/** - * @copydoc SetServer(const char*, unsigned int) - * - * @param inst instance handle - */ -void SetServer(NT_Inst inst, const char* server_name, unsigned int port); - -/** - * @copydoc SetServer(ArrayRef>) - * - * @param inst instance handle - */ void SetServer(NT_Inst inst, - ArrayRef> servers); + wpi::ArrayRef> servers); /** * Sets server addresses and port for client (without restarting client). @@ -1293,45 +1104,24 @@ void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port); * This connects to the Driver Station running on localhost to obtain the * server IP address. * - * @param port server port to use in combination with IP from DS - */ -WPI_DEPRECATED("use NT_Inst function instead") -void StartDSClient(unsigned int port); - -/** - * @copydoc StartDSClient(unsigned int) * @param inst instance handle + * @param port server port to use in combination with IP from DS */ void StartDSClient(NT_Inst inst, unsigned int port); -/** Stops requesting server address from Driver Station. */ -WPI_DEPRECATED("use NT_Inst function instead") -void StopDSClient(); - /** - * @copydoc StopDSClient() + * Stops requesting server address from Driver Station. * * @param inst instance handle */ void StopDSClient(NT_Inst inst); -/** Stops the RPC server if it is running. */ -WPI_DEPRECATED("use NT_Inst function instead") -void StopRpcServer(); - /** * Set the periodic update rate. * Sets how frequently updates are sent to other nodes over the network. * - * @param interval update interval in seconds (range 0.01 to 1.0) - */ -WPI_DEPRECATED("use NT_Inst function instead") -void SetUpdateRate(double interval); - -/** - * @copydoc SetUpdateRate(double) - * * @param inst instance handle + * @param interval update interval in seconds (range 0.01 to 1.0) */ void SetUpdateRate(NT_Inst inst, double interval); @@ -1345,12 +1135,6 @@ void SetUpdateRate(NT_Inst inst, double interval); * Note: flushes are rate limited to avoid excessive network traffic. If * the time between calls is too short, the flush will occur after the minimum * time elapses (rather than immediately). - */ -WPI_DEPRECATED("use NT_Inst function instead") -void Flush(); - -/** - * @copydoc Flush() * * @param inst instance handle */ @@ -1360,15 +1144,8 @@ void Flush(NT_Inst inst); * Get information on the currently established network connections. * If operating as a client, this will return either zero or one values. * - * @return array of connection information - */ -WPI_DEPRECATED("use NT_Inst function instead") -std::vector GetConnections(); - -/** - * @copydoc GetConnections() - * * @param inst instance handle + * @return array of connection information */ std::vector GetConnections(NT_Inst inst); @@ -1392,39 +1169,24 @@ bool IsConnected(NT_Inst inst); * but this function provides a way to save persistent values in the same * format to a file on either a client or a server. * + * @param inst instance handle * @param filename filename * @return error string, or nullptr if successful */ -WPI_DEPRECATED("use NT_Inst function instead") -const char* SavePersistent(StringRef filename); - -/** - * @copydoc SavePersistent(StringRef) - * @param inst instance handle - */ -const char* SavePersistent(NT_Inst inst, const Twine& filename); +const char* SavePersistent(NT_Inst inst, const wpi::Twine& filename); /** * Load persistent values from a file. The server automatically does this * at startup, but this function provides a way to restore persistent values * in the same format from a file at any time on either a client or a server. * + * @param inst instance handle * @param filename filename * @param warn callback function for warnings * @return error string, or nullptr if successful */ -WPI_DEPRECATED("use NT_Inst function instead") const char* LoadPersistent( - StringRef filename, std::function warn); - -/** - * @copydoc LoadPersistent(StringRef, std::function) - * - * @param inst instance handle - */ -const char* LoadPersistent( - NT_Inst inst, const Twine& filename, + NT_Inst inst, const wpi::Twine& filename, std::function warn); /** @@ -1436,8 +1198,8 @@ const char* LoadPersistent( * @param prefix save only keys starting with this prefix * @return error string, or nullptr if successful */ -const char* SaveEntries(NT_Inst inst, const Twine& filename, - const Twine& prefix); +const char* SaveEntries(NT_Inst inst, const wpi::Twine& filename, + const wpi::Twine& prefix); /** * Load table values from a file. The file format used is identical to @@ -1449,8 +1211,8 @@ const char* SaveEntries(NT_Inst inst, const Twine& filename, * @param warn callback function for warnings * @return error string, or nullptr if successful */ -const char* LoadEntries(NT_Inst inst, const Twine& filename, - const Twine& prefix, +const char* LoadEntries(NT_Inst inst, const wpi::Twine& filename, + const wpi::Twine& prefix, std::function warn); /** @} */ @@ -1476,30 +1238,6 @@ uint64_t Now(); * @{ */ -/** - * Log function. - * - * @param level log level of the message (see NT_LogLevel) - * @param file origin source filename - * @param line origin source line number - * @param msg message - */ -using LogFunc = - std::function; - -/** - * Set logger callback function. By default, log messages are sent to stderr; - * this function changes the log level and sends log messages to the provided - * callback function instead. The callback function will only be called for - * log messages with level greater than or equal to min_level; messages lower - * than this level will be silently ignored. - * - * @param func log callback function - * @param min_level minimum log level - */ -WPI_DEPRECATED("use NT_Inst function instead") -void SetLogger(LogFunc func, unsigned int min_level); - /** * Add logger callback function. By default, log messages are sent to stderr; * this function sends log messages to the provided callback function instead. @@ -1601,7 +1339,7 @@ bool WaitForLoggerQueue(NT_Inst inst, double timeout); /** @} */ /** @} */ -inline bool RpcAnswer::PostResponse(StringRef result) const { +inline bool RpcAnswer::PostResponse(wpi::StringRef result) const { auto ret = PostRpcResponse(entry, call, result); call = 0; return ret; diff --git a/ntcore/src/main/native/include/tables/ITable.h b/ntcore/src/main/native/include/tables/ITable.h deleted file mode 100644 index 5cd365cb76..0000000000 --- a/ntcore/src/main/native/include/tables/ITable.h +++ /dev/null @@ -1,453 +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. - -#ifndef NTCORE_TABLES_ITABLE_H_ -#define NTCORE_TABLES_ITABLE_H_ - -#include -#include -#include - -#include -#include -#include - -#include "networktables/NetworkTableValue.h" - -namespace nt { -class NetworkTable; -} // namespace nt - -class ITableListener; - -/** - * A table whose values can be read and written to - */ -class WPI_DEPRECATED("Use NetworkTable directly") ITable { - public: - /** - * Determines whether the given key is in this table. - * - * @param key the key to search for - * @return true if the table as a value assigned to the given key - */ - virtual bool ContainsKey(const wpi::Twine& key) const = 0; - - /** - * Determines whether there exists a non-empty subtable for this key - * in this table. - * - * @param key the key to search for - * @return true if there is a subtable with the key which contains at least - * one key/subtable of its own - */ - virtual bool ContainsSubTable(const wpi::Twine& key) const = 0; - - /** - * Gets the subtable in this table for the given name. - * - * @param key the name of the table relative to this one - * @return a sub table relative to this one - */ - virtual std::shared_ptr GetSubTable( - const wpi::Twine& key) const = 0; - - /** - * @param types bitmask of types; 0 is treated as a "don't care". - * @return keys currently in the table - */ - virtual std::vector GetKeys(int types = 0) const = 0; - - /** - * @return subtables currently in the table - */ - virtual std::vector GetSubTables() const = 0; - - /** - * Makes a key's value persistent through program restarts. - * - * @param key the key to make persistent - */ - virtual void SetPersistent(wpi::StringRef key) = 0; - - /** - * Stop making a key's value persistent through program restarts. - * The key cannot be null. - * - * @param key the key name - */ - virtual void ClearPersistent(wpi::StringRef key) = 0; - - /** - * Returns whether the value is persistent through program restarts. - * The key cannot be null. - * - * @param key the key name - */ - virtual bool IsPersistent(wpi::StringRef key) const = 0; - - /** - * Sets flags on the specified key in this table. The key can - * not be null. - * - * @param key the key name - * @param flags the flags to set (bitmask) - */ - virtual void SetFlags(wpi::StringRef key, unsigned int flags) = 0; - - /** - * Clears flags on the specified key in this table. The key can - * not be null. - * - * @param key the key name - * @param flags the flags to clear (bitmask) - */ - virtual void ClearFlags(wpi::StringRef key, unsigned int flags) = 0; - - /** - * Returns the flags for the specified key. - * - * @param key the key name - * @return the flags, or 0 if the key is not defined - */ - virtual unsigned int GetFlags(wpi::StringRef key) const = 0; - - /** - * Deletes the specified key in this table. - * - * @param key the key name - */ - virtual void Delete(const wpi::Twine& key) = 0; - - /** - * Gets the value associated with a key as an object - * - * @param key the key of the value to look up - * @return the value associated with the given key, or nullptr if the key - * does not exist - */ - virtual std::shared_ptr GetValue(const wpi::Twine& key) const = 0; - - /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ - virtual bool SetDefaultValue(const wpi::Twine& key, - std::shared_ptr defaultValue) = 0; - - /** - * Put a value in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - virtual bool PutValue(const wpi::Twine& key, - std::shared_ptr value) = 0; - - /** - * Put a number in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - virtual bool PutNumber(wpi::StringRef key, double value) = 0; - - /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ - virtual bool SetDefaultNumber(wpi::StringRef key, double defaultValue) = 0; - - /** - * Gets the number associated with the given name. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value - * if there is no value associated with the key - */ - virtual double GetNumber(wpi::StringRef key, double defaultValue) const = 0; - - /** - * Put a string in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - virtual bool PutString(wpi::StringRef key, wpi::StringRef value) = 0; - - /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ - virtual bool SetDefaultString(wpi::StringRef key, - wpi::StringRef defaultValue) = 0; - - /** - * Gets the string associated with the given name. If the key does not - * exist or is of different type, it will return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value - * if there is no value associated with the key - * - * @note This makes a copy of the string. If the overhead of this is a - * concern, use GetValue() instead. - */ - virtual std::string GetString(wpi::StringRef key, - wpi::StringRef defaultValue) const = 0; - - /** - * Put a boolean in the table - * - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - virtual bool PutBoolean(wpi::StringRef key, bool value) = 0; - - /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ - virtual bool SetDefaultBoolean(wpi::StringRef key, bool defaultValue) = 0; - - /** - * Gets the boolean associated with the given name. If the key does not - * exist or is of different type, it will return the default value. - * - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value - * if there is no value associated with the key - */ - virtual bool GetBoolean(wpi::StringRef key, bool defaultValue) const = 0; - - /** - * Put a boolean array in the table - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - * - * @note The array must be of int's rather than of bool's because - * std::vector is special-cased in C++. 0 is false, any - * non-zero value is true. - */ - virtual bool PutBooleanArray(wpi::StringRef key, - wpi::ArrayRef value) = 0; - - /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ - virtual bool SetDefaultBooleanArray(wpi::StringRef key, - wpi::ArrayRef defaultValue) = 0; - - /** - * Returns the boolean array the key maps to. If the key does not exist or is - * of different type, it will return the default value. - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value - * if there is no value associated with the key - * - * @note This makes a copy of the array. If the overhead of this is a - * concern, use GetValue() instead. - * - * @note The returned array is std::vector instead of std::vector - * because std::vector is special-cased in C++. 0 is false, any - * non-zero value is true. - */ - virtual std::vector GetBooleanArray( - wpi::StringRef key, wpi::ArrayRef defaultValue) const = 0; - - /** - * Put a number array in the table - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - virtual bool PutNumberArray(wpi::StringRef key, - wpi::ArrayRef value) = 0; - - /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ - virtual bool SetDefaultNumberArray(wpi::StringRef key, - wpi::ArrayRef defaultValue) = 0; - - /** - * Returns the number array the key maps to. If the key does not exist or is - * of different type, it will return the default value. - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value - * if there is no value associated with the key - * - * @note This makes a copy of the array. If the overhead of this is a - * concern, use GetValue() instead. - */ - virtual std::vector GetNumberArray( - wpi::StringRef key, wpi::ArrayRef defaultValue) const = 0; - - /** - * Put a string array in the table - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - virtual bool PutStringArray(wpi::StringRef key, - wpi::ArrayRef value) = 0; - - /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ - virtual bool SetDefaultStringArray( - wpi::StringRef key, wpi::ArrayRef defaultValue) = 0; - - /** - * Returns the string array the key maps to. If the key does not exist or is - * of different type, it will return the default value. - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value - * if there is no value associated with the key - * - * @note This makes a copy of the array. If the overhead of this is a - * concern, use GetValue() instead. - */ - virtual std::vector GetStringArray( - wpi::StringRef key, wpi::ArrayRef defaultValue) const = 0; - - /** - * Put a raw value (byte array) in the table - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - */ - virtual bool PutRaw(wpi::StringRef key, wpi::StringRef value) = 0; - - /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ - virtual bool SetDefaultRaw(wpi::StringRef key, - wpi::StringRef defaultValue) = 0; - - /** - * Returns the raw value (byte array) the key maps to. If the key does not - * exist or is of different type, it will return the default value. - * @param key the key to look up - * @param defaultValue the value to be returned if no value is found - * @return the value associated with the given key or the given default value - * if there is no value associated with the key - * - * @note This makes a copy of the raw contents. If the overhead of this is a - * concern, use GetValue() instead. - */ - virtual std::string GetRaw(wpi::StringRef key, - wpi::StringRef defaultValue) const = 0; - - /** - * Add a listener for changes to the table - * - * @param listener the listener to add - */ - virtual void AddTableListener(ITableListener* listener) = 0; - - /** - * Add a listener for changes to the table - * - * @param listener the listener to add - * @param immediateNotify if true then this listener will be notified of all - * current entries (marked as new) - */ - virtual void AddTableListener(ITableListener* listener, - bool immediateNotify) = 0; - - /** - * Add a listener for changes to the table - * - * @param listener the listener to add - * @param immediateNotify if true then this listener will be notified of all - * current entries (marked as new) - * @param flags bitmask of NT_NotifyKind specifying desired notifications - */ - virtual void AddTableListenerEx(ITableListener* listener, - unsigned int flags) = 0; - - /** - * Add a listener for changes to a specific key the table - * - * @param key the key to listen for - * @param listener the listener to add - * @param immediateNotify if true then this listener will be notified of all - * current entries (marked as new) - */ - virtual void AddTableListener(wpi::StringRef key, ITableListener* listener, - bool immediateNotify) = 0; - - /** - * Add a listener for changes to a specific key the table - * - * @param key the key to listen for - * @param listener the listener to add - * @param immediateNotify if true then this listener will be notified of all - * current entries (marked as new) - * @param flags bitmask of NT_NotifyKind specifying desired notifications - */ - virtual void AddTableListenerEx(wpi::StringRef key, ITableListener* listener, - unsigned int flags) = 0; - - /** - * This will immediately notify the listener of all current sub tables - * @param listener the listener to add - */ - virtual void AddSubTableListener(ITableListener* listener) = 0; - - /** - * This will immediately notify the listener of all current sub tables - * @param listener the listener to add - * @param localNotify if true then this listener will be notified of all - * local changes in addition to all remote changes - */ - virtual void AddSubTableListener(ITableListener* listener, - bool localNotify) = 0; - - /** - * Remove a listener from receiving table events - * - * @param listener the listener to be removed - */ - virtual void RemoveTableListener(ITableListener* listener) = 0; - - /** - * Gets the full path of this table. - */ - virtual wpi::StringRef GetPath() const = 0; -}; - -#endif // NTCORE_TABLES_ITABLE_H_ diff --git a/ntcore/src/main/native/include/tables/ITableListener.h b/ntcore/src/main/native/include/tables/ITableListener.h deleted file mode 100644 index 29a693adf3..0000000000 --- a/ntcore/src/main/native/include/tables/ITableListener.h +++ /dev/null @@ -1,65 +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. - -#ifndef NTCORE_TABLES_ITABLELISTENER_H_ -#define NTCORE_TABLES_ITABLELISTENER_H_ - -#include - -#include -#include - -#include "networktables/NetworkTableValue.h" - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#elif _WIN32 -#pragma warning(push) -#pragma warning(disable : 4996) -#endif - -class ITable; - -/** - * A listener that listens to changes in values in a {@link ITable} - */ -class WPI_DEPRECATED( - "Use EntryListener, TableEntryListener, or TableListener as appropriate") - ITableListener { - public: - virtual ~ITableListener() = default; - /** - * Called when a key-value pair is changed in a {@link ITable} - * @param source the table the key-value pair exists in - * @param key the key associated with the value that changed - * @param value the new value - * @param isNew true if the key did not previously exist in the table, - * otherwise it is false - */ - virtual void ValueChanged(ITable* source, wpi::StringRef key, - std::shared_ptr value, bool isNew) = 0; - - /** - * Extended version of ValueChanged. Called when a key-value pair is - * changed in a {@link ITable}. The default implementation simply calls - * ValueChanged(). If this is overridden, ValueChanged() will not be called. - * @param source the table the key-value pair exists in - * @param key the key associated with the value that changed - * @param value the new value - * @param flags update flags; for example, NT_NOTIFY_NEW if the key did not - * previously exist in the table - */ - virtual void ValueChangedEx(ITable* source, wpi::StringRef key, - std::shared_ptr value, - unsigned int flags); -}; - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#elif _WIN32 -#pragma warning(pop) -#endif - -#endif // NTCORE_TABLES_ITABLELISTENER_H_ diff --git a/ntcore/src/test/native/cpp/EntryNotifierTest.cpp b/ntcore/src/test/native/cpp/EntryNotifierTest.cpp index 3f361fb08d..54285dc873 100644 --- a/ntcore/src/test/native/cpp/EntryNotifierTest.cpp +++ b/ntcore/src/test/native/cpp/EntryNotifierTest.cpp @@ -245,7 +245,7 @@ TEST_F(EntryNotifierTest, PollPrefixBasic) { int g4count = 0; for (const auto& result : results) { SCOPED_TRACE(::testing::PrintToString(result)); - EXPECT_TRUE(StringRef(result.name).startswith("/foo")); + EXPECT_TRUE(wpi::StringRef(result.name).startswith("/foo")); EXPECT_THAT(result.value, ValueEq(Value::MakeDouble(1))); EXPECT_EQ(Handle{result.entry}.GetType(), Handle::kEntry); EXPECT_EQ(Handle{result.entry}.GetInst(), 1); diff --git a/ntcore/src/test/native/cpp/MockEntryNotifier.h b/ntcore/src/test/native/cpp/MockEntryNotifier.h index fb608ae2a2..75e5cc3830 100644 --- a/ntcore/src/test/native/cpp/MockEntryNotifier.h +++ b/ntcore/src/test/native/cpp/MockEntryNotifier.h @@ -30,7 +30,7 @@ class MockEntryNotifier : public IEntryNotifier { unsigned int(unsigned int poller_uid, unsigned int local_id, unsigned int flags)); MOCK_METHOD5(NotifyEntry, - void(unsigned int local_id, StringRef name, + void(unsigned int local_id, wpi::StringRef name, std::shared_ptr value, unsigned int flags, unsigned int only_listener)); }; diff --git a/ntcore/src/test/native/cpp/MockRpcServer.h b/ntcore/src/test/native/cpp/MockRpcServer.h index 10acd3c6c6..4196008381 100644 --- a/ntcore/src/test/native/cpp/MockRpcServer.h +++ b/ntcore/src/test/native/cpp/MockRpcServer.h @@ -16,7 +16,7 @@ class MockRpcServer : public IRpcServer { MOCK_METHOD1(RemoveRpc, void(unsigned int rpc_uid)); MOCK_METHOD7(ProcessRpc, void(unsigned int local_id, unsigned int call_uid, - StringRef name, StringRef params, + wpi::StringRef name, wpi::StringRef params, const ConnectionInfo& conn, SendResponseFunc send_response, unsigned int rpc_uid)); }; diff --git a/ntcore/src/test/native/cpp/NetworkTableTest.cpp b/ntcore/src/test/native/cpp/NetworkTableTest.cpp index ee3dbe7a9b..40c6f81d98 100644 --- a/ntcore/src/test/native/cpp/NetworkTableTest.cpp +++ b/ntcore/src/test/native/cpp/NetworkTableTest.cpp @@ -10,51 +10,51 @@ class NetworkTableTest : public ::testing::Test {}; TEST_F(NetworkTableTest, BasenameKey) { - EXPECT_EQ("simple", NetworkTable::BasenameKey("simple")); - EXPECT_EQ("simple", NetworkTable::BasenameKey("one/two/many/simple")); + EXPECT_EQ("simple", nt::NetworkTable::BasenameKey("simple")); + EXPECT_EQ("simple", nt::NetworkTable::BasenameKey("one/two/many/simple")); EXPECT_EQ("simple", - NetworkTable::BasenameKey("//////an/////awful/key////simple")); + nt::NetworkTable::BasenameKey("//////an/////awful/key////simple")); } TEST_F(NetworkTableTest, NormalizeKeySlash) { - EXPECT_EQ("/", NetworkTable::NormalizeKey("///")); - EXPECT_EQ("/no/normal/req", NetworkTable::NormalizeKey("/no/normal/req")); + EXPECT_EQ("/", nt::NetworkTable::NormalizeKey("///")); + EXPECT_EQ("/no/normal/req", nt::NetworkTable::NormalizeKey("/no/normal/req")); EXPECT_EQ("/no/leading/slash", - NetworkTable::NormalizeKey("no/leading/slash")); - EXPECT_EQ("/what/an/awful/key/", - NetworkTable::NormalizeKey("//////what////an/awful/////key///")); + nt::NetworkTable::NormalizeKey("no/leading/slash")); + EXPECT_EQ("/what/an/awful/key/", nt::NetworkTable::NormalizeKey( + "//////what////an/awful/////key///")); } TEST_F(NetworkTableTest, NormalizeKeyNoSlash) { - EXPECT_EQ("a", NetworkTable::NormalizeKey("a", false)); - EXPECT_EQ("a", NetworkTable::NormalizeKey("///a", false)); + EXPECT_EQ("a", nt::NetworkTable::NormalizeKey("a", false)); + EXPECT_EQ("a", nt::NetworkTable::NormalizeKey("///a", false)); EXPECT_EQ("leading/slash", - NetworkTable::NormalizeKey("/leading/slash", false)); + nt::NetworkTable::NormalizeKey("/leading/slash", false)); EXPECT_EQ("no/leading/slash", - NetworkTable::NormalizeKey("no/leading/slash", false)); - EXPECT_EQ( - "what/an/awful/key/", - NetworkTable::NormalizeKey("//////what////an/awful/////key///", false)); + nt::NetworkTable::NormalizeKey("no/leading/slash", false)); + EXPECT_EQ("what/an/awful/key/", + nt::NetworkTable::NormalizeKey("//////what////an/awful/////key///", + false)); } TEST_F(NetworkTableTest, GetHierarchyEmpty) { std::vector expected{"/"}; - ASSERT_EQ(expected, NetworkTable::GetHierarchy("")); + ASSERT_EQ(expected, nt::NetworkTable::GetHierarchy("")); } TEST_F(NetworkTableTest, GetHierarchyRoot) { std::vector expected{"/"}; - ASSERT_EQ(expected, NetworkTable::GetHierarchy("/")); + ASSERT_EQ(expected, nt::NetworkTable::GetHierarchy("/")); } TEST_F(NetworkTableTest, GetHierarchyNormal) { std::vector expected{"/", "/foo", "/foo/bar", "/foo/bar/baz"}; - ASSERT_EQ(expected, NetworkTable::GetHierarchy("/foo/bar/baz")); + ASSERT_EQ(expected, nt::NetworkTable::GetHierarchy("/foo/bar/baz")); } TEST_F(NetworkTableTest, GetHierarchyTrailingSlash) { std::vector expected{"/", "/foo", "/foo/bar", "/foo/bar/"}; - ASSERT_EQ(expected, NetworkTable::GetHierarchy("/foo/bar/")); + ASSERT_EQ(expected, nt::NetworkTable::GetHierarchy("/foo/bar/")); } TEST_F(NetworkTableTest, ContainsKey) { diff --git a/ntcore/src/test/native/cpp/StorageTest.cpp b/ntcore/src/test/native/cpp/StorageTest.cpp index 2cc9a9c4c4..e8c80539ce 100644 --- a/ntcore/src/test/native/cpp/StorageTest.cpp +++ b/ntcore/src/test/native/cpp/StorageTest.cpp @@ -19,6 +19,7 @@ using ::testing::_; using ::testing::AnyNumber; using ::testing::IsNull; using ::testing::Return; +using wpi::StringRef; namespace nt { diff --git a/ntcore/src/test/native/cpp/StorageTest.h b/ntcore/src/test/native/cpp/StorageTest.h index 20901e1f4e..782a9f1edb 100644 --- a/ntcore/src/test/native/cpp/StorageTest.h +++ b/ntcore/src/test/native/cpp/StorageTest.h @@ -24,7 +24,7 @@ class StorageTest { Storage::EntriesMap& entries() { return storage.m_entries; } Storage::IdMap& idmap() { return storage.m_idmap; } - Storage::Entry* GetEntry(StringRef name) { + Storage::Entry* GetEntry(wpi::StringRef name) { auto i = storage.m_entries.find(name); return i == storage.m_entries.end() ? &tmp_entry : i->getValue(); } diff --git a/outlineviewer/.styleguide b/outlineviewer/.styleguide new file mode 100644 index 0000000000..c8e055a4ca --- /dev/null +++ b/outlineviewer/.styleguide @@ -0,0 +1,27 @@ +cppHeaderFileInclude { + \.h$ + \.inc$ + \.inl$ +} + +cppSrcFileInclude { + \.cpp$ +} + +generatedFileExclude { + src/main/native/resources/ + src/main/native/win/outlineviewer.ico + src/main/native/mac/ov.icns +} + +repoRootNameOverride { + outlineviewer +} + +includeOtherLibs { + ^GLFW + ^imgui + ^ntcore + ^wpi/ + ^wpigui +} diff --git a/outlineviewer/CMakeLists.txt b/outlineviewer/CMakeLists.txt new file mode 100644 index 0000000000..537134d3eb --- /dev/null +++ b/outlineviewer/CMakeLists.txt @@ -0,0 +1,28 @@ +project(outlineviewer) + +include(CompileWarnings) +include(GenResources) +include(LinkMacOSGUI) + +configure_file(src/main/generate/WPILibVersion.cpp.in WPILibVersion.cpp) +GENERATE_RESOURCES(src/main/native/resources generated/main/cpp OV ov outlineviewer_resources_src) + +file(GLOB outlineviewer_src src/main/native/cpp/*.cpp ${CMAKE_CURRENT_BINARY_DIR}/WPILibVersion.cpp) + +if (WIN32) + set(outlineviewer_rc src/main/native/win/outlineviewer.rc) +elseif(APPLE) + set(MACOSX_BUNDLE_ICON_FILE ov.icns) + set(APP_ICON_MACOSX src/main/native/mac/ov.icns) + set_source_files_properties(${APP_ICON_MACOSX} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") +endif() + +add_executable(outlineviewer ${outlineviewer_src} ${outlineviewer_resources_src} ${outlineviewer_rc} ${APP_ICON_MACOSX}) +wpilib_link_macos_gui(outlineviewer) +target_link_libraries(outlineviewer libglassnt libglass) + +if (WIN32) + set_target_properties(outlineviewer PROPERTIES WIN32_EXECUTABLE YES) +elseif(APPLE) + set_target_properties(outlineviewer PROPERTIES MACOSX_BUNDLE YES OUTPUT_NAME "OutlineViewer") +endif() diff --git a/outlineviewer/Info.plist b/outlineviewer/Info.plist new file mode 100644 index 0000000000..a3e8a85d91 --- /dev/null +++ b/outlineviewer/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleName + OutlineViewer + CFBundleExecutable + outlineviewer + CFBundleDisplayName + OutlineViewer + CFBundleIdentifier + edu.wpi.first.tools.OutlineViewer + CFBundleIconFile + ov.icns + CFBundlePackageType + APPL + CFBundleSupportedPlatforms + + MacOSX + + CFBundleInfoDictionaryVersion + 6.0 + CFBundleShortVersionString + 2021 + CFBundleVersion + 2021 + LSMinimumSystemVersion + 10.11 + NSHighResolutionCapable + + + diff --git a/outlineviewer/build.gradle b/outlineviewer/build.gradle new file mode 100644 index 0000000000..5b4ee6ed40 --- /dev/null +++ b/outlineviewer/build.gradle @@ -0,0 +1,119 @@ +import org.gradle.internal.os.OperatingSystem + +if (!project.hasProperty('onlylinuxathena') && !project.hasProperty('onlylinuxraspbian') && !project.hasProperty('onlylinuxaarch64bionic')) { + + description = "NetworkTables Viewer" + + apply plugin: 'cpp' + apply plugin: 'c' + apply plugin: 'google-test-test-suite' + apply plugin: 'visual-studio' + apply plugin: 'edu.wpi.first.NativeUtils' + + if (OperatingSystem.current().isWindows()) { + apply plugin: 'windows-resources' + } + + ext { + nativeName = 'outlineviewer' + } + + apply from: "${rootDir}/shared/resources.gradle" + apply from: "${rootDir}/shared/config.gradle" + + def wpilibVersionFileInput = file("src/main/generate/WPILibVersion.cpp.in") + def wpilibVersionFileOutput = file("$buildDir/generated/main/cpp/WPILibVersion.cpp") + + task generateCppVersion() { + description = 'Generates the wpilib version class' + group = 'WPILib' + + outputs.file wpilibVersionFileOutput + inputs.file wpilibVersionFileInput + + if (wpilibVersioning.releaseMode) { + outputs.upToDateWhen { false } + } + + // We follow a simple set of checks to determine whether we should generate a new version file: + // 1. If the release type is not development, we generate a new version file + // 2. If there is no generated version number, we generate a new version file + // 3. If there is a generated build number, and the release type is development, then we will + // only generate if the publish task is run. + doLast { + def version = wpilibVersioning.version.get() + println "Writing version ${version} to $wpilibVersionFileOutput" + + if (wpilibVersionFileOutput.exists()) { + wpilibVersionFileOutput.delete() + } + def read = wpilibVersionFileInput.text.replace('${wpilib_version}', version) + wpilibVersionFileOutput.write(read) + } + } + + gradle.taskGraph.addTaskExecutionGraphListener { graph -> + def willPublish = graph.hasTask(publish) + if (willPublish) { + generateCppVersion.outputs.upToDateWhen { false } + } + } + + def generateTask = createGenerateResourcesTask('main', 'OV', 'ov', project) + + project(':').libraryBuild.dependsOn build + tasks.withType(CppCompile) { + dependsOn generateTask + dependsOn generateCppVersion + } + + model { + components { + // By default, a development executable will be generated. This is to help the case of + // testing specific functionality of the library. + "${nativeName}"(NativeExecutableSpec) { + baseName = 'outlineviewer' + sources { + cpp { + source { + srcDirs 'src/main/native/cpp', "$buildDir/generated/main/cpp" + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'src/main/native/include' + } + } + if (OperatingSystem.current().isWindows()) { + rc { + source { + srcDirs 'src/main/native/win' + include '*.rc' + } + } + } + } + binaries.all { + if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio || it.targetPlatform.name == nativeUtils.wpi.platforms.raspbian || it.targetPlatform.name == nativeUtils.wpi.platforms.aarch64bionic) { + it.buildable = false + return + } + lib project: ':glass', library: 'glassnt', linkage: 'static' + lib project: ':glass', library: 'glass', linkage: 'static' + lib project: ':ntcore', library: 'ntcore', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' + lib project: ':wpigui', library: 'wpigui', linkage: 'static' + nativeUtils.useRequiredLibrary(it, 'imgui_static') + if (it.targetPlatform.operatingSystem.isWindows()) { + it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' + } else if (it.targetPlatform.operatingSystem.isMacOsX()) { + it.linker.args << '-framework' << 'Metal' << '-framework' << 'MetalKit' << '-framework' << 'Cocoa' << '-framework' << 'IOKit' << '-framework' << 'CoreFoundation' << '-framework' << 'CoreVideo' << '-framework' << 'QuartzCore' + } else { + it.linker.args << '-lX11' + } + } + } + } + } + + apply from: 'publish.gradle' +} diff --git a/outlineviewer/publish.gradle b/outlineviewer/publish.gradle new file mode 100644 index 0000000000..85605c47e3 --- /dev/null +++ b/outlineviewer/publish.gradle @@ -0,0 +1,96 @@ +apply plugin: 'maven-publish' + +def baseArtifactId = 'OutlineViewer' +def artifactGroupId = 'edu.wpi.first.tools' +def zipBaseName = '_GROUP_edu_wpi_first_tools_ID_OutlineViewer_CLS' + +def outputsFolder = file("$project.buildDir/outputs") + +model { + publishing { + def outlineViewerTaskList = [] + $.components.each { component -> + component.binaries.each { binary -> + if (binary in NativeExecutableBinarySpec && binary.component.name.contains("outlineviewer")) { + if (binary.buildable && binary.name.contains("Release")) { + // We are now in the binary that we want. + // This is the default application path for the ZIP task. + def applicationPath = binary.executable.file + def icon = file("$project.projectDir/src/main/native/mac/ov.icns") + + // Create the macOS bundle. + def bundleTask = project.tasks.create("bundleOutlineViewerOsxApp", Copy) { + description("Creates a macOS application bundle for OutlineViewer") + from(file("$project.projectDir/Info.plist")) + into(file("$project.buildDir/outputs/bundles/OutlineViewer.app/Contents")) + into("MacOS") { with copySpec { from binary.executable.file } } + into("Resources") { with copySpec { from icon } } + + doLast { + if (project.hasProperty("developerID")) { + // Get path to binary. + exec { + workingDir rootDir + def args = [ + "sh", + "-c", + "codesign --force --strict --deep " + + "--timestamp --options=runtime " + + "--verbose -s ${project.findProperty("developerID")} " + + "$project.buildDir/outputs/bundles/OutlineViewer.app/" + ] + commandLine args + } + } + } + } + + // Reset the application path if we are creating a bundle. + if (binary.targetPlatform.operatingSystem.isMacOsX()) { + applicationPath = file("$project.buildDir/outputs/bundles") + project.build.dependsOn bundleTask + } + + // Create the ZIP. + def task = project.tasks.create("copyOutlineViewerExecutable", Zip) { + description("Copies the OutlineViewer executable to the outputs directory.") + destinationDirectory = outputsFolder + + archiveBaseName = '_M_' + zipBaseName + duplicatesStrategy = 'exclude' + classifier = nativeUtils.getPublishClassifier(binary) + + from(licenseFile) { + into '/' + } + + from(applicationPath) + into(nativeUtils.getPlatformPath(binary)) + } + + if (binary.targetPlatform.operatingSystem.isMacOsX()) { + bundleTask.dependsOn binary.tasks.link + task.dependsOn(bundleTask) + } + + task.dependsOn binary.tasks.link + outlineViewerTaskList.add(task) + project.build.dependsOn task + project.artifacts { task } + addTaskToCopyAllOutputs(task) + } + } + } + } + + publications { + outlineViewer(MavenPublication) { + outlineViewerTaskList.each { artifact it } + + artifactId = baseArtifactId + groupId = artifactGroupId + version wpilibVersioning.version.get() + } + } + } +} diff --git a/outlineviewer/src/main/generate/WPILibVersion.cpp.in b/outlineviewer/src/main/generate/WPILibVersion.cpp.in new file mode 100644 index 0000000000..b0a4490520 --- /dev/null +++ b/outlineviewer/src/main/generate/WPILibVersion.cpp.in @@ -0,0 +1,7 @@ +/* + * Autogenerated file! Do not manually edit this file. This version is regenerated + * any time the publish task is run, or when this file is deleted. + */ +const char* GetWPILibVersion() { + return "${wpilib_version}"; +} diff --git a/outlineviewer/src/main/native/cpp/main.cpp b/outlineviewer/src/main/native/cpp/main.cpp new file mode 100644 index 0000000000..0bfd91614e --- /dev/null +++ b/outlineviewer/src/main/native/cpp/main.cpp @@ -0,0 +1,229 @@ +// 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 + +#include +#include +#include +#include +#include + +#include "glass/Context.h" +#include "glass/Model.h" +#include "glass/networktables/NetworkTables.h" +#include "glass/networktables/NetworkTablesSettings.h" +#include "glass/other/Log.h" + +namespace gui = wpi::gui; + +const char* GetWPILibVersion(); + +namespace ov { +wpi::StringRef GetResource_ov_16_png(); +wpi::StringRef GetResource_ov_32_png(); +wpi::StringRef GetResource_ov_48_png(); +wpi::StringRef GetResource_ov_64_png(); +wpi::StringRef GetResource_ov_128_png(); +wpi::StringRef GetResource_ov_256_png(); +wpi::StringRef GetResource_ov_512_png(); +} // namespace ov + +static std::unique_ptr gModel; +static std::unique_ptr gSettings; +static glass::LogData gLog; +static glass::NetworkTablesFlagsSettings gFlagsSettings; + +static void NtInitialize() { + // update window title when connection status changes + auto inst = nt::GetDefaultInstance(); + auto poller = nt::CreateConnectionListenerPoller(inst); + nt::AddPolledConnectionListener(poller, true); + gui::AddEarlyExecute([inst, poller] { + auto win = gui::GetSystemWindow(); + if (!win) { + return; + } + bool timedOut; + for (auto&& event : nt::PollConnectionListener(poller, 0, &timedOut)) { + if ((nt::GetNetworkMode(inst) & NT_NET_MODE_SERVER) != 0) { + // for server mode, just print number of clients connected + wpi::SmallString<64> title; + glfwSetWindowTitle(win, ("OutlineViewer - " + + wpi::Twine{nt::GetConnections(inst).size()} + + " Clients Connected") + .toNullTerminatedStringRef(title) + .data()); + } else if (event.connected) { + wpi::SmallString<64> title; + title = "OutlineViewer - Connected ("; + title += event.conn.remote_ip; + title += ')'; + glfwSetWindowTitle(win, title.c_str()); + } else { + glfwSetWindowTitle(win, "OutlineViewer - DISCONNECTED"); + } + } + }); + + // handle NetworkTables log messages + auto logPoller = nt::CreateLoggerPoller(inst); + nt::AddPolledLogger(logPoller, NT_LOG_INFO, 100); + gui::AddEarlyExecute([logPoller] { + bool timedOut; + for (auto&& msg : nt::PollLogger(logPoller, 0, &timedOut)) { + const char* level = ""; + if (msg.level >= NT_LOG_CRITICAL) { + level = "CRITICAL: "; + } else if (msg.level >= NT_LOG_ERROR) { + level = "ERROR: "; + } else if (msg.level >= NT_LOG_WARNING) { + level = "WARNING: "; + } + gLog.Append(wpi::Twine{level} + msg.message + wpi::Twine{" ("} + + msg.filename + wpi::Twine{':'} + wpi::Twine{msg.line} + + wpi::Twine{")\n"}); + } + }); + + // NetworkTables table window + gModel = std::make_unique(); + gui::AddEarlyExecute([] { gModel->Update(); }); + + // NetworkTables settings window + gSettings = std::make_unique(); + gui::AddEarlyExecute([] { gSettings->Update(); }); +} + +static void DisplayGui() { + ImGui::GetStyle().WindowRounding = 0; + + // fill entire OS window with this window + ImGui::SetNextWindowPos(ImVec2(0, 0)); + int width, height; + glfwGetWindowSize(gui::GetSystemWindow(), &width, &height); + ImGui::SetNextWindowSize(ImVec2(width, height)); + + ImGui::Begin("Entries", nullptr, + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_MenuBar | + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoCollapse); + + gFlagsSettings.Update(); + + // can't create popups from within menu, so use flags + bool settings = false; + bool log = false; + bool about = false; + + // main menu + ImGui::BeginMenuBar(); + gui::EmitViewMenu(); + if (ImGui::BeginMenu("View")) { + gFlagsSettings.DisplayMenu(); + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Options")) { + if (ImGui::MenuItem("Settings")) { + settings = true; + } + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Info")) { + if (ImGui::MenuItem("Log")) { + log = true; + } + ImGui::Separator(); + if (ImGui::MenuItem("About")) { + about = true; + } + ImGui::EndMenu(); + } + ImGui::EndMenuBar(); + + // settings popup + if (settings) { + ImGui::OpenPopup("Settings"); + } + if (ImGui::BeginPopupModal("Settings", nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + if (gSettings->Display()) { + ImGui::CloseCurrentPopup(); + } + ImGui::SameLine(); + if (ImGui::Button("Cancel")) { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + + // log popup + if (log) { + ImGui::OpenPopup("Log"); + } + if (ImGui::BeginPopupModal("Log", nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::Button("Close")) { + ImGui::CloseCurrentPopup(); + } + ImGui::BeginChild("Lines", ImVec2(width * 0.75f, height * 0.75f)); + glass::DisplayLog(&gLog, true); + ImGui::EndChild(); + ImGui::EndPopup(); + } + + // about popup + if (about) { + ImGui::OpenPopup("About"); + } + if (ImGui::BeginPopupModal("About", nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::Text("OutlineViewer"); + ImGui::Separator(); + ImGui::Text("v%s", GetWPILibVersion()); + if (ImGui::Button("Close")) { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + + // display table view + glass::DisplayNetworkTables(gModel.get(), gFlagsSettings.GetFlags()); + + ImGui::End(); +} + +#ifdef _WIN32 +int __stdcall WinMain(void* hInstance, void* hPrevInstance, char* pCmdLine, + int nCmdShow) { +#else +int main() { +#endif + gui::CreateContext(); + glass::CreateContext(); + + gui::AddIcon(ov::GetResource_ov_16_png()); + gui::AddIcon(ov::GetResource_ov_32_png()); + gui::AddIcon(ov::GetResource_ov_48_png()); + gui::AddIcon(ov::GetResource_ov_64_png()); + gui::AddIcon(ov::GetResource_ov_128_png()); + gui::AddIcon(ov::GetResource_ov_256_png()); + gui::AddIcon(ov::GetResource_ov_512_png()); + + gui::ConfigurePlatformSaveFile("outlineviewer.ini"); + gui::AddInit(NtInitialize); + + gui::AddLateExecute(DisplayGui); + + gui::Initialize("OutlineViewer - DISCONNECTED", 1024, 768); + gui::Main(); + + gModel.reset(); + gSettings.reset(); + + glass::DestroyContext(); + gui::DestroyContext(); +} diff --git a/outlineviewer/src/main/native/mac/ov.icns b/outlineviewer/src/main/native/mac/ov.icns new file mode 100644 index 0000000000..17f9770a0b Binary files /dev/null and b/outlineviewer/src/main/native/mac/ov.icns differ diff --git a/outlineviewer/src/main/native/resources/ov-128.png b/outlineviewer/src/main/native/resources/ov-128.png new file mode 100644 index 0000000000..950d0ca2db Binary files /dev/null and b/outlineviewer/src/main/native/resources/ov-128.png differ diff --git a/outlineviewer/src/main/native/resources/ov-16.png b/outlineviewer/src/main/native/resources/ov-16.png new file mode 100644 index 0000000000..db84366bd9 Binary files /dev/null and b/outlineviewer/src/main/native/resources/ov-16.png differ diff --git a/outlineviewer/src/main/native/resources/ov-256.png b/outlineviewer/src/main/native/resources/ov-256.png new file mode 100644 index 0000000000..7b3b2b72f6 Binary files /dev/null and b/outlineviewer/src/main/native/resources/ov-256.png differ diff --git a/outlineviewer/src/main/native/resources/ov-32.png b/outlineviewer/src/main/native/resources/ov-32.png new file mode 100644 index 0000000000..4db8e8b589 Binary files /dev/null and b/outlineviewer/src/main/native/resources/ov-32.png differ diff --git a/outlineviewer/src/main/native/resources/ov-48.png b/outlineviewer/src/main/native/resources/ov-48.png new file mode 100644 index 0000000000..026491c286 Binary files /dev/null and b/outlineviewer/src/main/native/resources/ov-48.png differ diff --git a/outlineviewer/src/main/native/resources/ov-512.png b/outlineviewer/src/main/native/resources/ov-512.png new file mode 100644 index 0000000000..d4fd60ce6b Binary files /dev/null and b/outlineviewer/src/main/native/resources/ov-512.png differ diff --git a/outlineviewer/src/main/native/resources/ov-64.png b/outlineviewer/src/main/native/resources/ov-64.png new file mode 100644 index 0000000000..9cd5d968a0 Binary files /dev/null and b/outlineviewer/src/main/native/resources/ov-64.png differ diff --git a/outlineviewer/src/main/native/win/outlineviewer.ico b/outlineviewer/src/main/native/win/outlineviewer.ico new file mode 100644 index 0000000000..7156af8d6a Binary files /dev/null and b/outlineviewer/src/main/native/win/outlineviewer.ico differ diff --git a/outlineviewer/src/main/native/win/outlineviewer.rc b/outlineviewer/src/main/native/win/outlineviewer.rc new file mode 100644 index 0000000000..85bdcae2ef --- /dev/null +++ b/outlineviewer/src/main/native/win/outlineviewer.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON "outlineviewer.ico" diff --git a/settings.gradle b/settings.gradle index 89cba97761..0cd962f700 100644 --- a/settings.gradle +++ b/settings.gradle @@ -29,6 +29,7 @@ include 'wpilibjExamples' include 'wpilibjIntegrationTests' include 'wpilibj' include 'glass' +include 'outlineviewer' include 'simulation:gz_msgs' include 'simulation:frc_gazebo_plugins' include 'simulation:halsim_gazebo' diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java index fa9b26da48..8c1e8b10de 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandBase.java @@ -45,7 +45,6 @@ public abstract class CommandBase implements Sendable, Command { * * @param name name */ - @Override public void setName(String name) { SendableRegistry.setName(this, name); } @@ -66,7 +65,6 @@ public abstract class CommandBase implements Sendable, Command { * * @return Subsystem name */ - @Override public String getSubsystem() { return SendableRegistry.getSubsystem(this); } @@ -76,7 +74,6 @@ public abstract class CommandBase implements Sendable, Command { * * @param subsystem subsystem name */ - @Override public void setSubsystem(String subsystem) { SendableRegistry.setSubsystem(this, subsystem); } diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java index 9f7f399c68..fc1b5fd391 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommand.java @@ -6,18 +6,18 @@ package edu.wpi.first.wpilibj2.command; import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.MecanumDriveKinematics; +import edu.wpi.first.math.kinematics.MecanumDriveMotorVoltages; +import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds; +import edu.wpi.first.math.trajectory.Trajectory; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.controller.HolonomicDriveController; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveMotorVoltages; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveWheelSpeeds; -import edu.wpi.first.wpilibj.trajectory.Trajectory; import java.util.function.Consumer; import java.util.function.Supplier; diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java index b3a747ce79..a3d874f721 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDCommand.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj2.command; -import static edu.wpi.first.wpilibj.trajectory.TrapezoidProfile.State; +import static edu.wpi.first.math.trajectory.TrapezoidProfile.State; import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java index 6139961b64..f960f8b63d 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ProfiledPIDSubsystem.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj2.command; -import static edu.wpi.first.wpilibj.trajectory.TrapezoidProfile.State; +import static edu.wpi.first.math.trajectory.TrapezoidProfile.State; import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; /** * A subsystem that uses a {@link ProfiledPIDController} to control an output. The controller is run diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RamseteCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RamseteCommand.java index 2bba7ea787..2ae3631bfc 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RamseteCommand.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/RamseteCommand.java @@ -6,15 +6,15 @@ package edu.wpi.first.wpilibj2.command; import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; +import edu.wpi.first.math.controller.RamseteController; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.math.trajectory.Trajectory; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.RamseteController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds; -import edu.wpi.first.wpilibj.trajectory.Trajectory; import java.util.function.BiConsumer; import java.util.function.Supplier; diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SubsystemBase.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SubsystemBase.java index d61ed5baba..f0a0fae6d5 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SubsystemBase.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SubsystemBase.java @@ -27,7 +27,6 @@ public abstract class SubsystemBase implements Subsystem, Sendable { * * @return Name */ - @Override public String getName() { return SendableRegistry.getName(this); } @@ -37,7 +36,6 @@ public abstract class SubsystemBase implements Subsystem, Sendable { * * @param name name */ - @Override public void setName(String name) { SendableRegistry.setName(this, name); } @@ -47,7 +45,6 @@ public abstract class SubsystemBase implements Subsystem, Sendable { * * @return Subsystem name */ - @Override public String getSubsystem() { return SendableRegistry.getSubsystem(this); } @@ -57,7 +54,6 @@ public abstract class SubsystemBase implements Subsystem, Sendable { * * @param subsystem subsystem name */ - @Override public void setSubsystem(String subsystem) { SendableRegistry.setSubsystem(this, subsystem); } diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java index 106d2d0097..52cc658925 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommand.java @@ -6,15 +6,15 @@ package edu.wpi.first.wpilibj2.command; import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.kinematics.SwerveModuleState; +import edu.wpi.first.math.trajectory.Trajectory; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.controller.HolonomicDriveController; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.SwerveModuleState; -import edu.wpi.first.wpilibj.trajectory.Trajectory; import java.util.function.Consumer; import java.util.function.Supplier; diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java index 90b2011c5c..674328ea23 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileCommand.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj2.command; -import static edu.wpi.first.wpilibj.trajectory.TrapezoidProfile.State; +import static edu.wpi.first.math.trajectory.TrapezoidProfile.State; import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import java.util.function.Consumer; /** diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java index 330a633ac1..0a6c65877b 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/TrapezoidProfileSubsystem.java @@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj2.command; import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.math.trajectory.TrapezoidProfile; /** * A subsystem that generates and runs trapezoidal motion profiles automatically. The user specifies diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp index 8d2d6d2bd4..9a94d3d026 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp @@ -21,10 +21,9 @@ Command::~Command() { CommandScheduler::GetInstance().Cancel(this); } -Command::Command(const Command& rhs) : ErrorBase(rhs) {} +Command::Command(const Command& rhs) = default; Command& Command::operator=(const Command& rhs) { - ErrorBase::operator=(rhs); m_isGrouped = false; return *this; } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp index c09a7dd113..a59fc0307c 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandGroupBase.cpp @@ -4,19 +4,15 @@ #include "frc2/command/CommandGroupBase.h" -#include - using namespace frc2; bool CommandGroupBase::RequireUngrouped(Command& command) { if (command.IsGrouped()) { - wpi_setGlobalWPIErrorWithContext( - CommandIllegalUse, + throw FRC_MakeError( + frc::err::CommandIllegalUse, "Commands cannot be added to more than one CommandGroup"); - return false; - } else { - return true; } + return true; } bool CommandGroupBase::RequireUngrouped( @@ -26,8 +22,8 @@ bool CommandGroupBase::RequireUngrouped( allUngrouped &= !command.get()->IsGrouped(); } if (!allUngrouped) { - wpi_setGlobalWPIErrorWithContext( - CommandIllegalUse, + throw FRC_MakeError( + frc::err::CommandIllegalUse, "Commands cannot be added to more than one CommandGroup"); } return allUngrouped; @@ -40,8 +36,8 @@ bool CommandGroupBase::RequireUngrouped( allUngrouped &= !command->IsGrouped(); } if (!allUngrouped) { - wpi_setGlobalWPIErrorWithContext( - CommandIllegalUse, + throw FRC_MakeError( + frc::err::CommandIllegalUse, "Commands cannot be added to more than one CommandGroup"); } return allUngrouped; diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp index 3acd9b5fdd..f08c21fd22 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandScheduler.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -71,19 +70,19 @@ CommandScheduler::CommandScheduler() HAL_Report(HALUsageReporting::kResourceType_Command, HALUsageReporting::kCommand2_Scheduler); frc::SendableRegistry::GetInstance().AddLW(this, "Scheduler"); - auto scheduler = frc::LiveWindow::GetInstance(); - scheduler->enabled = [this] { - this->Disable(); - this->CancelAll(); + auto& scheduler = frc::LiveWindow::GetInstance(); + scheduler.enabled = [this] { + Disable(); + CancelAll(); }; - scheduler->disabled = [this] { this->Enable(); }; + scheduler.disabled = [this] { Enable(); }; } CommandScheduler::~CommandScheduler() { frc::SendableRegistry::GetInstance().Remove(this); - auto scheduler = frc::LiveWindow::GetInstance(); - scheduler->enabled = nullptr; - scheduler->disabled = nullptr; + auto& scheduler = frc::LiveWindow::GetInstance(); + scheduler.enabled = nullptr; + scheduler.disabled = nullptr; std::unique_ptr().swap(m_impl); } @@ -112,9 +111,9 @@ void CommandScheduler::Schedule(bool interruptible, Command* command) { } if (command->IsGrouped()) { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "A command that is part of a command group " - "cannot be independently scheduled"); + throw FRC_MakeError(frc::err::CommandIllegalUse, + "A command that is part of a command group " + "cannot be independently scheduled"); return; } if (m_impl->disabled || diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp index c243ed5429..d6169d7574 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp @@ -65,9 +65,9 @@ void ParallelCommandGroup::AddCommands( } if (isRunning) { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "Commands cannot be added to a CommandGroup " - "while the group is running"); + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Commands cannot be added to a CommandGroup " + "while the group is running"); } for (auto&& command : commands) { @@ -77,10 +77,9 @@ void ParallelCommandGroup::AddCommands( m_runWhenDisabled &= command->RunsWhenDisabled(); m_commands.emplace_back(std::move(command), false); } else { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "Multiple commands in a parallel group cannot " - "require the same subsystems"); - return; + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Multiple commands in a parallel group cannot " + "require the same subsystems"); } } } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp index d544a6b905..16104e2513 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp @@ -60,9 +60,9 @@ void ParallelDeadlineGroup::AddCommands( } if (!m_finished) { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "Commands cannot be added to a CommandGroup " - "while the group is running"); + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Commands cannot be added to a CommandGroup " + "while the group is running"); } for (auto&& command : commands) { @@ -72,10 +72,9 @@ void ParallelDeadlineGroup::AddCommands( m_runWhenDisabled &= command->RunsWhenDisabled(); m_commands.emplace_back(std::move(command), false); } else { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "Multiple commands in a parallel group cannot " - "require the same subsystems"); - return; + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Multiple commands in a parallel group cannot " + "require the same subsystems"); } } } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp index 3bee59845c..38e0494b79 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp @@ -50,9 +50,9 @@ void ParallelRaceGroup::AddCommands( } if (isRunning) { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "Commands cannot be added to a CommandGroup " - "while the group is running"); + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Commands cannot be added to a CommandGroup " + "while the group is running"); } for (auto&& command : commands) { @@ -62,10 +62,9 @@ void ParallelRaceGroup::AddCommands( m_runWhenDisabled &= command->RunsWhenDisabled(); m_commands.emplace_back(std::move(command)); } else { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "Multiple commands in a parallel group cannot " - "require the same subsystems"); - return; + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Multiple commands in a parallel group cannot " + "require the same subsystems"); } } } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/SequentialCommandGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/SequentialCommandGroup.cpp index 766d0cefa4..a02870724a 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/SequentialCommandGroup.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/SequentialCommandGroup.cpp @@ -60,9 +60,9 @@ void SequentialCommandGroup::AddCommands( } if (m_currentCommandIndex != invalid_index) { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "Commands cannot be added to a CommandGroup " - "while the group is running"); + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Commands cannot be added to a CommandGroup " + "while the group is running"); } for (auto&& command : commands) { diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h index bc5edb59fe..e1177ad710 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -46,10 +45,10 @@ class ProxyScheduleCommand; * @see CommandScheduler * @see CommandHelper */ -class Command : public frc::ErrorBase { +class Command { public: Command() = default; - ~Command() override; + virtual ~Command(); Command(const Command&); Command& operator=(const Command&); diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h index f9f5f37984..4719524ded 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h @@ -8,8 +8,7 @@ #include #include -#include -#include +#include #include #include #include @@ -29,7 +28,6 @@ class Subsystem; * methods to be called and for their default commands to be scheduled. */ class CommandScheduler final : public frc::Sendable, - public frc::ErrorBase, public frc::SendableHelper { public: /** @@ -182,14 +180,12 @@ class CommandScheduler final : public frc::Sendable, Command, std::remove_reference_t>>> void SetDefaultCommand(Subsystem* subsystem, T&& defaultCommand) { if (!defaultCommand.HasRequirement(subsystem)) { - wpi_setWPIErrorWithContext( - CommandIllegalUse, "Default commands must require their subsystem!"); - return; + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Default commands must require their subsystem!"); } if (defaultCommand.IsFinished()) { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "Default commands should not end!"); - return; + throw FRC_MakeError(frc::err::CommandIllegalUse, + "Default commands should not end!"); } SetDefaultCommandImpl(subsystem, std::make_unique>( diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h b/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h index 843e096cc7..253abb28c1 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/SequentialCommandGroup.h @@ -15,8 +15,6 @@ #include #include -#include -#include #include #include "frc2/command/CommandGroupBase.h" diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java index 8c5489d7ea..16cab4d12d 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MecanumControllerCommandTest.java @@ -8,19 +8,19 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import edu.wpi.first.hal.HAL; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.MecanumDriveKinematics; +import edu.wpi.first.math.kinematics.MecanumDriveOdometry; +import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveWheelSpeeds; import edu.wpi.first.wpilibj.simulation.SimHooks; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import java.util.ArrayList; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java index 8610cde69b..3b48ff60b5 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SwerveControllerCommandTest.java @@ -8,19 +8,19 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import edu.wpi.first.hal.HAL; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.kinematics.SwerveDriveOdometry; +import edu.wpi.first.math.kinematics.SwerveModuleState; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.SwerveModuleState; import edu.wpi.first.wpilibj.simulation.SimHooks; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import java.util.ArrayList; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandRequirementsTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandRequirementsTest.cpp index ad6a09b91e..cf673d8bc6 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandRequirementsTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandRequirementsTest.cpp @@ -2,6 +2,8 @@ // 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 + #include "CommandTestBase.h" #include "frc2/command/CommandScheduler.h" #include "frc2/command/ConditionalCommand.h" @@ -71,11 +73,9 @@ TEST_F(CommandRequirementsTest, RequirementUninterruptibleTest) { TEST_F(CommandRequirementsTest, DefaultCommandRequirementErrorTest) { TestSubsystem requirement1; - ErrorConfirmer confirmer("require"); MockCommand command1; - requirement1.SetDefaultCommand(std::move(command1)); - - EXPECT_TRUE(requirement1.GetDefaultCommand() == nullptr); + ASSERT_THROW(requirement1.SetDefaultCommand(std::move(command1)), + frc::RuntimeError); } diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.h b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.h index 07b1b97b5e..a3890f6ed6 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.h +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandTestBase.h @@ -9,7 +9,6 @@ #include -#include "ErrorConfirmer.h" #include "frc2/command/CommandGroupBase.h" #include "frc2/command/CommandScheduler.h" #include "frc2/command/SetUtilities.h" diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.cpp deleted file mode 100644 index 68f6a42534..0000000000 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.cpp +++ /dev/null @@ -1,19 +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 "ErrorConfirmer.h" - -#include - -ErrorConfirmer* ErrorConfirmer::instance; - -int32_t ErrorConfirmer::HandleError(HAL_Bool isError, int32_t errorCode, - HAL_Bool isLVCode, const char* details, - const char* location, const char* callStack, - HAL_Bool printMsg) { - if (std::regex_search(details, std::regex(instance->m_msg))) { - instance->ConfirmError(); - } - return 1; -} diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.h b/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.h deleted file mode 100644 index e503ab95a9..0000000000 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ErrorConfirmer.h +++ /dev/null @@ -1,38 +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 "gmock/gmock.h" - -class ErrorConfirmer { - public: - explicit ErrorConfirmer(const char* msg) : m_msg(msg) { - if (instance != nullptr) { - return; - } - HALSIM_SetSendError(HandleError); - EXPECT_CALL(*this, ConfirmError()); - instance = this; - } - - ~ErrorConfirmer() { - HALSIM_SetSendError(nullptr); - instance = nullptr; - } - - MOCK_METHOD0(ConfirmError, void()); - - const char* m_msg; - - static int32_t HandleError(HAL_Bool isError, int32_t errorCode, - HAL_Bool isLVCode, const char* details, - const char* location, const char* callStack, - HAL_Bool printMsg); - - private: - static ErrorConfirmer* instance; -}; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDBase.java similarity index 99% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java rename to wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDBase.java index 7116077bc5..cde77003bb 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDBase.java +++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDBase.java @@ -9,6 +9,7 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; import edu.wpi.first.hal.util.BoundaryException; +import edu.wpi.first.math.filter.LinearFilter; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; import java.util.concurrent.locks.ReentrantLock; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDController.java similarity index 100% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDController.java rename to wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDController.java diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDInterface.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDInterface.java similarity index 100% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDInterface.java rename to wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDInterface.java diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java similarity index 100% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java rename to wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDSource.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSource.java similarity index 100% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDSource.java rename to wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSource.java diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDSourceType.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSourceType.java similarity index 100% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PIDSourceType.java rename to wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/PIDSourceType.java diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Command.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Command.java index 5bb49a3800..9b8c41cf4c 100644 --- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Command.java +++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Command.java @@ -36,6 +36,7 @@ import java.util.Enumeration; * @see CommandGroup * @see IllegalUseOfCommandException */ +@SuppressWarnings("PMD.GodClass") public abstract class Command implements Sendable, AutoCloseable { /** The time since this command was initialized. */ private double m_startTime = -1; @@ -561,7 +562,6 @@ public abstract class Command implements Sendable, AutoCloseable { * * @return Name */ - @Override public String getName() { return SendableRegistry.getName(this); } @@ -571,7 +571,6 @@ public abstract class Command implements Sendable, AutoCloseable { * * @param name name */ - @Override public void setName(String name) { SendableRegistry.setName(this, name); } @@ -581,7 +580,6 @@ public abstract class Command implements Sendable, AutoCloseable { * * @return Subsystem name */ - @Override public String getSubsystem() { return SendableRegistry.getSubsystem(this); } @@ -591,7 +589,6 @@ public abstract class Command implements Sendable, AutoCloseable { * * @param subsystem subsystem name */ - @Override public void setSubsystem(String subsystem) { SendableRegistry.setSubsystem(this, subsystem); } diff --git a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java index 8f61663293..f596ed68f4 100644 --- a/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java +++ b/wpilibOldCommands/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java @@ -187,7 +187,6 @@ public abstract class Subsystem implements Sendable, AutoCloseable { * * @return Name */ - @Override public String getName() { return SendableRegistry.getName(this); } @@ -197,7 +196,6 @@ public abstract class Subsystem implements Sendable, AutoCloseable { * * @param name name */ - @Override public void setName(String name) { SendableRegistry.setName(this, name); } @@ -207,7 +205,6 @@ public abstract class Subsystem implements Sendable, AutoCloseable { * * @return Subsystem name */ - @Override public String getSubsystem() { return SendableRegistry.getSubsystem(this); } @@ -217,7 +214,6 @@ public abstract class Subsystem implements Sendable, AutoCloseable { * * @param subsystem subsystem name */ - @Override public void setSubsystem(String subsystem) { SendableRegistry.setSubsystem(this, subsystem); } diff --git a/wpilibc/src/main/native/cpp/PIDBase.cpp b/wpilibOldCommands/src/main/native/cpp/PIDBase.cpp similarity index 100% rename from wpilibc/src/main/native/cpp/PIDBase.cpp rename to wpilibOldCommands/src/main/native/cpp/PIDBase.cpp diff --git a/wpilibc/src/main/native/cpp/PIDController.cpp b/wpilibOldCommands/src/main/native/cpp/PIDController.cpp similarity index 100% rename from wpilibc/src/main/native/cpp/PIDController.cpp rename to wpilibOldCommands/src/main/native/cpp/PIDController.cpp diff --git a/wpilibc/src/main/native/cpp/PIDSource.cpp b/wpilibOldCommands/src/main/native/cpp/PIDSource.cpp similarity index 100% rename from wpilibc/src/main/native/cpp/PIDSource.cpp rename to wpilibOldCommands/src/main/native/cpp/PIDSource.cpp diff --git a/wpilibOldCommands/src/main/native/cpp/commands/Command.cpp b/wpilibOldCommands/src/main/native/cpp/commands/Command.cpp index b1a7554069..c2e9822ce9 100644 --- a/wpilibOldCommands/src/main/native/cpp/commands/Command.cpp +++ b/wpilibOldCommands/src/main/native/cpp/commands/Command.cpp @@ -6,9 +6,9 @@ #include +#include "frc/Errors.h" #include "frc/RobotState.h" #include "frc/Timer.h" -#include "frc/WPIErrors.h" #include "frc/commands/CommandGroup.h" #include "frc/commands/Scheduler.h" #include "frc/livewindow/LiveWindow.h" @@ -32,7 +32,7 @@ Command::Command(Subsystem& subsystem) : Command("", -1.0) { Command::Command(const wpi::Twine& name, double timeout) { // We use -1.0 to indicate no timeout. if (timeout < 0.0 && timeout != -1.0) { - wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); + throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0"); } m_timeout = timeout; @@ -77,15 +77,15 @@ void Command::Requires(Subsystem* subsystem) { if (subsystem != nullptr) { m_requirements.insert(subsystem); } else { - wpi_setWPIErrorWithContext(NullParameter, "subsystem"); + throw FRC_MakeError(err::NullParameter, "subsystem"); } } void Command::Start() { LockChanges(); if (m_parent != nullptr) { - wpi_setWPIErrorWithContext( - CommandIllegalUse, + throw FRC_MakeError( + err::CommandIllegalUse, "Can not start a command that is part of a command group"); } @@ -115,8 +115,8 @@ bool Command::Run() { void Command::Cancel() { if (m_parent != nullptr) { - wpi_setWPIErrorWithContext( - CommandIllegalUse, + throw FRC_MakeError( + err::CommandIllegalUse, "Can not cancel a command that is part of a command group"); } @@ -173,7 +173,7 @@ int Command::GetID() const { void Command::SetTimeout(double timeout) { if (timeout < 0.0) { - wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); + throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0"); } else { m_timeout = timeout; } @@ -185,21 +185,22 @@ bool Command::IsTimedOut() const { bool Command::AssertUnlocked(const std::string& message) { if (m_locked) { - std::string buf = - message + " after being started or being added to a command group"; - wpi_setWPIErrorWithContext(CommandIllegalUse, buf); - return false; + throw FRC_MakeError( + err::CommandIllegalUse, + message + + wpi::Twine{ + " after being started or being added to a command group"}); } return true; } void Command::SetParent(CommandGroup* parent) { if (parent == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "parent"); + throw FRC_MakeError(err::NullParameter, "parent"); } else if (m_parent != nullptr) { - wpi_setWPIErrorWithContext(CommandIllegalUse, - "Can not give command to a command group after " - "already being put in a command group"); + throw FRC_MakeError(err::CommandIllegalUse, + "Can not give command to a command group after " + "already being put in a command group"); } else { LockChanges(); m_parent = parent; diff --git a/wpilibOldCommands/src/main/native/cpp/commands/CommandGroup.cpp b/wpilibOldCommands/src/main/native/cpp/commands/CommandGroup.cpp index ff8ee7c985..f743724889 100644 --- a/wpilibOldCommands/src/main/native/cpp/commands/CommandGroup.cpp +++ b/wpilibOldCommands/src/main/native/cpp/commands/CommandGroup.cpp @@ -4,16 +4,15 @@ #include "frc/commands/CommandGroup.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" using namespace frc; CommandGroup::CommandGroup(const wpi::Twine& name) : Command(name) {} void CommandGroup::AddSequential(Command* command) { - if (command == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "command"); - return; + if (!command) { + throw FRC_MakeError(err::NullParameter, "command"); } if (!AssertUnlocked("Cannot add new command to command group")) { return; @@ -31,16 +30,14 @@ void CommandGroup::AddSequential(Command* command) { } void CommandGroup::AddSequential(Command* command, double timeout) { - if (command == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "command"); - return; + if (!command) { + throw FRC_MakeError(err::NullParameter, "command"); } if (!AssertUnlocked("Cannot add new command to command group")) { return; } if (timeout < 0.0) { - wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); - return; + throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0"); } m_commands.emplace_back(command, CommandGroupEntry::kSequence_InSequence, @@ -56,8 +53,8 @@ void CommandGroup::AddSequential(Command* command, double timeout) { } void CommandGroup::AddParallel(Command* command) { - if (command == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "command"); + if (!command) { + throw FRC_MakeError(err::NullParameter, "command"); return; } if (!AssertUnlocked("Cannot add new command to command group")) { @@ -76,16 +73,14 @@ void CommandGroup::AddParallel(Command* command) { } void CommandGroup::AddParallel(Command* command, double timeout) { - if (command == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "command"); - return; + if (!command) { + throw FRC_MakeError(err::NullParameter, "command"); } if (!AssertUnlocked("Cannot add new command to command group")) { return; } if (timeout < 0.0) { - wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0"); - return; + throw FRC_MakeError(err::ParameterOutOfRange, "timeout < 0.0"); } m_commands.emplace_back(command, CommandGroupEntry::kSequence_BranchChild, diff --git a/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp b/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp index 73569b803d..42bebb821e 100644 --- a/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp +++ b/wpilibOldCommands/src/main/native/cpp/commands/Scheduler.cpp @@ -13,7 +13,7 @@ #include #include -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/buttons/ButtonScheduler.h" #include "frc/commands/Command.h" #include "frc/commands/Subsystem.h" @@ -64,9 +64,8 @@ void Scheduler::AddButton(ButtonScheduler* button) { } void Scheduler::RegisterSubsystem(Subsystem* subsystem) { - if (subsystem == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "subsystem"); - return; + if (!subsystem) { + throw FRC_MakeError(err::NullParameter, "subsystem"); } m_impl->subsystems.insert(subsystem); } @@ -109,8 +108,8 @@ void Scheduler::Run() { for (auto& addition : m_impl->additions) { // Check to make sure no adding during adding if (m_impl->adding) { - wpi_setWPIErrorWithContext(IncompatibleState, - "Can not start command from cancel method"); + FRC_ReportError(warn::IncompatibleState, + "Can not start command from cancel method"); } else { m_impl->ProcessCommandAddition(addition); } @@ -122,8 +121,8 @@ void Scheduler::Run() { for (auto& subsystem : m_impl->subsystems) { if (subsystem->GetCurrentCommand() == nullptr) { if (m_impl->adding) { - wpi_setWPIErrorWithContext(IncompatibleState, - "Can not start command from cancel method"); + FRC_ReportError(warn::IncompatibleState, + "Can not start command from cancel method"); } else { m_impl->ProcessCommandAddition(subsystem->GetDefaultCommand()); } @@ -133,9 +132,8 @@ void Scheduler::Run() { } void Scheduler::Remove(Command* command) { - if (command == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "command"); - return; + if (!command) { + throw FRC_MakeError(err::NullParameter, "command"); } m_impl->Remove(command); @@ -203,19 +201,19 @@ Scheduler::Scheduler() : m_impl(new Impl) { HAL_Report(HALUsageReporting::kResourceType_Command, HALUsageReporting::kCommand_Scheduler); SendableRegistry::GetInstance().AddLW(this, "Scheduler"); - auto scheduler = frc::LiveWindow::GetInstance(); - scheduler->enabled = [this] { - this->SetEnabled(false); - this->RemoveAll(); + auto& scheduler = frc::LiveWindow::GetInstance(); + scheduler.enabled = [this] { + SetEnabled(false); + RemoveAll(); }; - scheduler->disabled = [this] { this->SetEnabled(true); }; + scheduler.disabled = [this] { SetEnabled(true); }; } Scheduler::~Scheduler() { SendableRegistry::GetInstance().Remove(this); - auto scheduler = frc::LiveWindow::GetInstance(); - scheduler->enabled = nullptr; - scheduler->disabled = nullptr; + auto& scheduler = frc::LiveWindow::GetInstance(); + scheduler.enabled = nullptr; + scheduler.disabled = nullptr; } void Scheduler::Impl::Remove(Command* command) { diff --git a/wpilibOldCommands/src/main/native/cpp/commands/Subsystem.cpp b/wpilibOldCommands/src/main/native/cpp/commands/Subsystem.cpp index 3026af85e4..2ef307c610 100644 --- a/wpilibOldCommands/src/main/native/cpp/commands/Subsystem.cpp +++ b/wpilibOldCommands/src/main/native/cpp/commands/Subsystem.cpp @@ -4,7 +4,7 @@ #include "frc/commands/Subsystem.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/commands/Command.h" #include "frc/commands/Scheduler.h" #include "frc/livewindow/LiveWindow.h" @@ -24,9 +24,8 @@ void Subsystem::SetDefaultCommand(Command* command) { } else { const auto& reqs = command->GetRequirements(); if (std::find(reqs.begin(), reqs.end(), this) == reqs.end()) { - wpi_setWPIErrorWithContext( - CommandIllegalUse, "A default command must require the subsystem"); - return; + throw FRC_MakeError(err::CommandIllegalUse, + "A default command must require the subsystem"); } m_defaultCommand = command; diff --git a/wpilibc/src/main/native/include/frc/PIDBase.h b/wpilibOldCommands/src/main/native/include/frc/PIDBase.h similarity index 100% rename from wpilibc/src/main/native/include/frc/PIDBase.h rename to wpilibOldCommands/src/main/native/include/frc/PIDBase.h diff --git a/wpilibc/src/main/native/include/frc/PIDController.h b/wpilibOldCommands/src/main/native/include/frc/PIDController.h similarity index 100% rename from wpilibc/src/main/native/include/frc/PIDController.h rename to wpilibOldCommands/src/main/native/include/frc/PIDController.h diff --git a/wpilibc/src/main/native/include/frc/PIDInterface.h b/wpilibOldCommands/src/main/native/include/frc/PIDInterface.h similarity index 100% rename from wpilibc/src/main/native/include/frc/PIDInterface.h rename to wpilibOldCommands/src/main/native/include/frc/PIDInterface.h diff --git a/wpilibc/src/main/native/include/frc/PIDOutput.h b/wpilibOldCommands/src/main/native/include/frc/PIDOutput.h similarity index 100% rename from wpilibc/src/main/native/include/frc/PIDOutput.h rename to wpilibOldCommands/src/main/native/include/frc/PIDOutput.h diff --git a/wpilibc/src/main/native/include/frc/PIDSource.h b/wpilibOldCommands/src/main/native/include/frc/PIDSource.h similarity index 100% rename from wpilibc/src/main/native/include/frc/PIDSource.h rename to wpilibOldCommands/src/main/native/include/frc/PIDSource.h diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/Command.h b/wpilibOldCommands/src/main/native/include/frc/commands/Command.h index 167d2bf9c4..3863f85836 100644 --- a/wpilibOldCommands/src/main/native/include/frc/commands/Command.h +++ b/wpilibOldCommands/src/main/native/include/frc/commands/Command.h @@ -10,7 +10,6 @@ #include #include -#include "frc/ErrorBase.h" #include "frc/commands/Subsystem.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -43,9 +42,7 @@ class CommandGroup; * @see CommandGroup * @see Subsystem */ -class Command : public ErrorBase, - public Sendable, - public SendableHelper { +class Command : public Sendable, public SendableHelper { friend class CommandGroup; friend class Scheduler; diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/Scheduler.h b/wpilibOldCommands/src/main/native/include/frc/commands/Scheduler.h index 0bdd4b8465..83372dc278 100644 --- a/wpilibOldCommands/src/main/native/include/frc/commands/Scheduler.h +++ b/wpilibOldCommands/src/main/native/include/frc/commands/Scheduler.h @@ -6,7 +6,6 @@ #include -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -16,9 +15,7 @@ class ButtonScheduler; class Command; class Subsystem; -class Scheduler : public ErrorBase, - public Sendable, - public SendableHelper { +class Scheduler : public Sendable, public SendableHelper { public: /** * Returns the Scheduler, creating it if one does not exist. diff --git a/wpilibOldCommands/src/main/native/include/frc/commands/Subsystem.h b/wpilibOldCommands/src/main/native/include/frc/commands/Subsystem.h index a2f9e5f250..fe3a997861 100644 --- a/wpilibOldCommands/src/main/native/include/frc/commands/Subsystem.h +++ b/wpilibOldCommands/src/main/native/include/frc/commands/Subsystem.h @@ -10,7 +10,6 @@ #include #include -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -18,9 +17,7 @@ namespace frc { class Command; -class Subsystem : public ErrorBase, - public Sendable, - public SendableHelper { +class Subsystem : public Sendable, public SendableHelper { friend class Scheduler; public: diff --git a/wpilibc/build.gradle b/wpilibc/build.gradle index f101852109..7af6314ada 100644 --- a/wpilibc/build.gradle +++ b/wpilibc/build.gradle @@ -243,7 +243,7 @@ model { def arch = it.targetPlatform.architecture.name if (arch == 'x86-64' || arch == 'x86') { dependsOn it.tasks.install - + commandLine it.tasks.install.runScriptFile.get().asFile.toString() found = true } } diff --git a/wpilibc/src/main/native/cpp/ADXRS450_Gyro.cpp b/wpilibc/src/main/native/cpp/ADXRS450_Gyro.cpp index 523c1dfd24..2c1c62b14e 100644 --- a/wpilibc/src/main/native/cpp/ADXRS450_Gyro.cpp +++ b/wpilibc/src/main/native/cpp/ADXRS450_Gyro.cpp @@ -8,6 +8,7 @@ #include "frc/DriverStation.h" #include "frc/Timer.h" +#include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" using namespace frc; @@ -134,3 +135,9 @@ void ADXRS450_Gyro::Calibrate() { int ADXRS450_Gyro::GetPort() const { return m_port; } + +void ADXRS450_Gyro::InitSendable(SendableBuilder& builder) { + builder.SetSmartDashboardType("Gyro"); + builder.AddDoubleProperty( + "Value", [=]() { return GetAngle(); }, nullptr); +} diff --git a/wpilibc/src/main/native/cpp/AddressableLED.cpp b/wpilibc/src/main/native/cpp/AddressableLED.cpp index 335982f395..6b8a751c19 100644 --- a/wpilibc/src/main/native/cpp/AddressableLED.cpp +++ b/wpilibc/src/main/native/cpp/AddressableLED.cpp @@ -9,22 +9,25 @@ #include #include #include +#include -#include "frc/WPIErrors.h" +#include "frc/Errors.h" using namespace frc; AddressableLED::AddressableLED(int port) { int32_t status = 0; - m_pwmHandle = HAL_InitializePWMPort(HAL_GetPort(port), &status); - wpi_setHALErrorWithRange(status, 0, HAL_GetNumPWMChannels(), port); + auto stack = wpi::GetStackTrace(1); + m_pwmHandle = + HAL_InitializePWMPort(HAL_GetPort(port), stack.c_str(), &status); + FRC_CheckErrorStatus(status, "Port " + wpi::Twine{port}); if (m_pwmHandle == HAL_kInvalidHandle) { return; } m_handle = HAL_InitializeAddressableLED(m_pwmHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Port " + wpi::Twine{port}); if (m_handle == HAL_kInvalidHandle) { HAL_FreePWMPort(m_pwmHandle, &status); } @@ -36,12 +39,13 @@ AddressableLED::~AddressableLED() { HAL_FreeAddressableLED(m_handle); int32_t status = 0; HAL_FreePWMPort(m_pwmHandle, &status); + FRC_ReportError(status, "FreePWM"); } void AddressableLED::SetLength(int length) { int32_t status = 0; HAL_SetAddressableLEDLength(m_handle, length, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "length " + wpi::Twine{length}); } static_assert(sizeof(AddressableLED::LEDData) == sizeof(HAL_AddressableLEDData), @@ -51,14 +55,14 @@ void AddressableLED::SetData(wpi::ArrayRef ledData) { int32_t status = 0; HAL_WriteAddressableLEDData(m_handle, ledData.begin(), ledData.size(), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetData"); } void AddressableLED::SetData(std::initializer_list ledData) { int32_t status = 0; HAL_WriteAddressableLEDData(m_handle, ledData.begin(), ledData.size(), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetData"); } void AddressableLED::SetBitTiming(units::nanosecond_t lowTime0, @@ -69,25 +73,25 @@ void AddressableLED::SetBitTiming(units::nanosecond_t lowTime0, HAL_SetAddressableLEDBitTiming( m_handle, lowTime0.to(), highTime0.to(), lowTime1.to(), highTime1.to(), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetBitTiming"); } void AddressableLED::SetSyncTime(units::microsecond_t syncTime) { int32_t status = 0; HAL_SetAddressableLEDSyncTime(m_handle, syncTime.to(), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetSyncTime"); } void AddressableLED::Start() { int32_t status = 0; HAL_StartAddressableLEDOutput(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Start"); } void AddressableLED::Stop() { int32_t status = 0; HAL_StopAddressableLEDOutput(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Stop"); } void AddressableLED::LEDData::SetHSV(int h, int s, int v) { diff --git a/wpilibc/src/main/native/cpp/AnalogAccelerometer.cpp b/wpilibc/src/main/native/cpp/AnalogAccelerometer.cpp index fa8654076a..d27048b6f0 100644 --- a/wpilibc/src/main/native/cpp/AnalogAccelerometer.cpp +++ b/wpilibc/src/main/native/cpp/AnalogAccelerometer.cpp @@ -7,7 +7,7 @@ #include #include "frc/Base.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -20,20 +20,18 @@ AnalogAccelerometer::AnalogAccelerometer(int channel) AnalogAccelerometer::AnalogAccelerometer(AnalogInput* channel) : m_analogInput(channel, NullDeleter()) { - if (channel == nullptr) { - wpi_setWPIError(NullParameter); - } else { - InitAccelerometer(); + if (!channel) { + throw FRC_MakeError(err::NullParameter, "channel"); } + InitAccelerometer(); } AnalogAccelerometer::AnalogAccelerometer(std::shared_ptr channel) : m_analogInput(channel) { - if (channel == nullptr) { - wpi_setWPIError(NullParameter); - } else { - InitAccelerometer(); + if (!channel) { + throw FRC_MakeError(err::NullParameter, "channel"); } + InitAccelerometer(); } double AnalogAccelerometer::GetAcceleration() const { @@ -48,10 +46,6 @@ void AnalogAccelerometer::SetZero(double zero) { m_zeroGVoltage = zero; } -double AnalogAccelerometer::PIDGet() { - return GetAcceleration(); -} - void AnalogAccelerometer::InitSendable(SendableBuilder& builder) { builder.SetSmartDashboardType("Accelerometer"); builder.AddDoubleProperty( diff --git a/wpilibc/src/main/native/cpp/AnalogGyro.cpp b/wpilibc/src/main/native/cpp/AnalogGyro.cpp index 867d1c618f..47a9429855 100644 --- a/wpilibc/src/main/native/cpp/AnalogGyro.cpp +++ b/wpilibc/src/main/native/cpp/AnalogGyro.cpp @@ -10,11 +10,13 @@ #include #include #include +#include #include "frc/AnalogInput.h" #include "frc/Base.h" +#include "frc/Errors.h" #include "frc/Timer.h" -#include "frc/WPIErrors.h" +#include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" using namespace frc; @@ -30,12 +32,11 @@ AnalogGyro::AnalogGyro(AnalogInput* channel) AnalogGyro::AnalogGyro(std::shared_ptr channel) : m_analog(channel) { - if (channel == nullptr) { - wpi_setWPIError(NullParameter); - } else { - InitGyro(); - Calibrate(); + if (!channel) { + throw FRC_MakeError(err::NullParameter, "channel"); } + InitGyro(); + Calibrate(); } AnalogGyro::AnalogGyro(int channel, int center, double offset) @@ -46,20 +47,15 @@ AnalogGyro::AnalogGyro(int channel, int center, double offset) AnalogGyro::AnalogGyro(std::shared_ptr channel, int center, double offset) : m_analog(channel) { - if (channel == nullptr) { - wpi_setWPIError(NullParameter); - } else { - InitGyro(); - int32_t status = 0; - HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond, - offset, center, &status); - if (status != 0) { - wpi_setHALError(status); - m_gyroHandle = HAL_kInvalidHandle; - return; - } - Reset(); + if (!channel) { + throw FRC_MakeError(err::NullParameter, "channel"); } + InitGyro(); + int32_t status = 0; + HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond, + offset, center, &status); + FRC_CheckErrorStatus(status, "SetAnalogGyroParameters"); + Reset(); } AnalogGyro::~AnalogGyro() { @@ -67,42 +63,30 @@ AnalogGyro::~AnalogGyro() { } double AnalogGyro::GetAngle() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double value = HAL_GetAnalogGyroAngle(m_gyroHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetAngle"); return value; } double AnalogGyro::GetRate() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double value = HAL_GetAnalogGyroRate(m_gyroHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetRate"); return value; } int AnalogGyro::GetCenter() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetCenter"); return value; } double AnalogGyro::GetOffset() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double value = HAL_GetAnalogGyroOffset(m_gyroHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetOffset"); return value; } @@ -110,57 +94,33 @@ void AnalogGyro::SetSensitivity(double voltsPerDegreePerSecond) { int32_t status = 0; HAL_SetAnalogGyroVoltsPerDegreePerSecond(m_gyroHandle, voltsPerDegreePerSecond, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetSensitivity"); } void AnalogGyro::SetDeadband(double volts) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAnalogGyroDeadband(m_gyroHandle, volts, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetDeadband"); } void AnalogGyro::Reset() { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_ResetAnalogGyro(m_gyroHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Reset"); } void AnalogGyro::InitGyro() { - if (StatusIsFatal()) { - return; - } if (m_gyroHandle == HAL_kInvalidHandle) { int32_t status = 0; - m_gyroHandle = HAL_InitializeAnalogGyro(m_analog->m_port, &status); - if (status == PARAMETER_OUT_OF_RANGE) { - wpi_setWPIErrorWithContext(ParameterOutOfRange, - " channel (must be accumulator channel)"); - m_analog = nullptr; - m_gyroHandle = HAL_kInvalidHandle; - return; - } - if (status != 0) { - wpi_setHALError(status); - m_analog = nullptr; - m_gyroHandle = HAL_kInvalidHandle; - return; - } + std::string stackTrace = wpi::GetStackTrace(1); + m_gyroHandle = + HAL_InitializeAnalogGyro(m_analog->m_port, stackTrace.c_str(), &status); + FRC_CheckErrorStatus(status, "InitializeAnalogGyro"); } int32_t status = 0; HAL_SetupAnalogGyro(m_gyroHandle, &status); - if (status != 0) { - wpi_setHALError(status); - m_analog = nullptr; - m_gyroHandle = HAL_kInvalidHandle; - return; - } + FRC_CheckErrorStatus(status, "SetupAnalogGyro"); HAL_Report(HALUsageReporting::kResourceType_Gyro, m_analog->GetChannel() + 1); @@ -169,14 +129,17 @@ void AnalogGyro::InitGyro() { } void AnalogGyro::Calibrate() { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_CalibrateAnalogGyro(m_gyroHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Calibrate"); } std::shared_ptr AnalogGyro::GetAnalogInput() const { return m_analog; } + +void AnalogGyro::InitSendable(SendableBuilder& builder) { + builder.SetSmartDashboardType("Gyro"); + builder.AddDoubleProperty( + "Value", [=]() { return GetAngle(); }, nullptr); +} diff --git a/wpilibc/src/main/native/cpp/AnalogInput.cpp b/wpilibc/src/main/native/cpp/AnalogInput.cpp index b67120dbf2..dee97343ab 100644 --- a/wpilibc/src/main/native/cpp/AnalogInput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogInput.cpp @@ -9,10 +9,11 @@ #include #include #include +#include +#include "frc/Errors.h" #include "frc/SensorUtil.h" #include "frc/Timer.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -20,22 +21,17 @@ using namespace frc; AnalogInput::AnalogInput(int channel) { if (!SensorUtil::CheckAnalogInputChannel(channel)) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, - "Analog Input " + wpi::Twine(channel)); - return; + throw FRC_MakeError(err::ChannelIndexOutOfRange, + "Analog Input " + wpi::Twine{channel}); } m_channel = channel; HAL_PortHandle port = HAL_GetPort(channel); int32_t status = 0; - m_port = HAL_InitializeAnalogInputPort(port, &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumAnalogInputs(), channel); - m_channel = std::numeric_limits::max(); - m_port = HAL_kInvalidHandle; - return; - } + std::string stackTrace = wpi::GetStackTrace(1); + m_port = HAL_InitializeAnalogInputPort(port, stackTrace.c_str(), &status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{channel}); HAL_Report(HALUsageReporting::kResourceType_AnalogChannel, channel + 1); @@ -47,220 +43,154 @@ AnalogInput::~AnalogInput() { } int AnalogInput::GetValue() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int value = HAL_GetAnalogValue(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return value; } int AnalogInput::GetAverageValue() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int value = HAL_GetAnalogAverageValue(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return value; } double AnalogInput::GetVoltage() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double voltage = HAL_GetAnalogVoltage(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return voltage; } double AnalogInput::GetAverageVoltage() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double voltage = HAL_GetAnalogAverageVoltage(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return voltage; } int AnalogInput::GetChannel() const { - if (StatusIsFatal()) { - return 0; - } return m_channel; } void AnalogInput::SetAverageBits(int bits) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAnalogAverageBits(m_port, bits, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); } int AnalogInput::GetAverageBits() const { int32_t status = 0; int averageBits = HAL_GetAnalogAverageBits(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return averageBits; } void AnalogInput::SetOversampleBits(int bits) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAnalogOversampleBits(m_port, bits, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); } int AnalogInput::GetOversampleBits() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int oversampleBits = HAL_GetAnalogOversampleBits(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return oversampleBits; } int AnalogInput::GetLSBWeight() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return lsbWeight; } int AnalogInput::GetOffset() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int offset = HAL_GetAnalogOffset(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return offset; } bool AnalogInput::IsAccumulatorChannel() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; bool isAccum = HAL_IsAccumulatorChannel(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return isAccum; } void AnalogInput::InitAccumulator() { - if (StatusIsFatal()) { - return; - } m_accumulatorOffset = 0; int32_t status = 0; HAL_InitAccumulator(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); } void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) { - if (StatusIsFatal()) { - return; - } m_accumulatorOffset = initialValue; } void AnalogInput::ResetAccumulator() { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_ResetAccumulator(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); - if (!StatusIsFatal()) { - // Wait until the next sample, so the next call to GetAccumulator*() - // won't have old values. - const double sampleTime = 1.0 / GetSampleRate(); - const double overSamples = 1 << GetOversampleBits(); - const double averageSamples = 1 << GetAverageBits(); - Wait(sampleTime * overSamples * averageSamples); - } + // Wait until the next sample, so the next call to GetAccumulator*() + // won't have old values. + const double sampleTime = 1.0 / GetSampleRate(); + const double overSamples = 1 << GetOversampleBits(); + const double averageSamples = 1 << GetAverageBits(); + Wait(sampleTime * overSamples * averageSamples); } void AnalogInput::SetAccumulatorCenter(int center) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAccumulatorCenter(m_port, center, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); } void AnalogInput::SetAccumulatorDeadband(int deadband) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAccumulatorDeadband(m_port, deadband, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); } int64_t AnalogInput::GetAccumulatorValue() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int64_t value = HAL_GetAccumulatorValue(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return value + m_accumulatorOffset; } int64_t AnalogInput::GetAccumulatorCount() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int64_t count = HAL_GetAccumulatorCount(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); return count; } void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_GetAccumulatorOutput(m_port, &value, &count, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Analog Input " + wpi::Twine{m_channel}); value += m_accumulatorOffset; } void AnalogInput::SetSampleRate(double samplesPerSecond) { int32_t status = 0; HAL_SetAnalogSampleRate(samplesPerSecond, &status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "SetSampleRate"); } double AnalogInput::GetSampleRate() { int32_t status = 0; double sampleRate = HAL_GetAnalogSampleRate(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetSampleRate"); return sampleRate; } -double AnalogInput::PIDGet() { - if (StatusIsFatal()) { - return 0.0; - } - return GetAverageVoltage(); -} - void AnalogInput::SetSimDevice(HAL_SimDeviceHandle device) { HAL_SetAnalogInputSimDevice(m_port, device); } diff --git a/wpilibc/src/main/native/cpp/AnalogOutput.cpp b/wpilibc/src/main/native/cpp/AnalogOutput.cpp index 1c3e2b061a..ce827f5a75 100644 --- a/wpilibc/src/main/native/cpp/AnalogOutput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogOutput.cpp @@ -11,9 +11,10 @@ #include #include #include +#include +#include "frc/Errors.h" #include "frc/SensorUtil.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -21,24 +22,17 @@ using namespace frc; AnalogOutput::AnalogOutput(int channel) { if (!SensorUtil::CheckAnalogOutputChannel(channel)) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, - "analog output " + wpi::Twine(channel)); - m_channel = std::numeric_limits::max(); - m_port = HAL_kInvalidHandle; - return; + throw FRC_MakeError(err::ChannelIndexOutOfRange, + "analog output " + wpi::Twine(channel)); } m_channel = channel; HAL_PortHandle port = HAL_GetPort(m_channel); int32_t status = 0; - m_port = HAL_InitializeAnalogOutputPort(port, &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumAnalogOutputs(), channel); - m_channel = std::numeric_limits::max(); - m_port = HAL_kInvalidHandle; - return; - } + std::string stackTrace = wpi::GetStackTrace(1); + m_port = HAL_InitializeAnalogOutputPort(port, stackTrace.c_str(), &status); + FRC_CheckErrorStatus(status, "analog output " + wpi::Twine(channel)); HAL_Report(HALUsageReporting::kResourceType_AnalogOutput, m_channel + 1); SendableRegistry::GetInstance().AddLW(this, "AnalogOutput", m_channel); @@ -51,16 +45,13 @@ AnalogOutput::~AnalogOutput() { void AnalogOutput::SetVoltage(double voltage) { int32_t status = 0; HAL_SetAnalogOutput(m_port, voltage, &status); - - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetVoltage"); } double AnalogOutput::GetVoltage() const { int32_t status = 0; double voltage = HAL_GetAnalogOutput(m_port, &status); - - wpi_setHALError(status); - + FRC_CheckErrorStatus(status, "GetVoltage"); return voltage; } diff --git a/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp b/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp index b911285bb1..8237658dbc 100644 --- a/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp +++ b/wpilibc/src/main/native/cpp/AnalogPotentiometer.cpp @@ -42,10 +42,6 @@ double AnalogPotentiometer::Get() const { m_offset; } -double AnalogPotentiometer::PIDGet() { - return Get(); -} - void AnalogPotentiometer::InitSendable(SendableBuilder& builder) { builder.SetSmartDashboardType("Analog Input"); builder.AddDoubleProperty( diff --git a/wpilibc/src/main/native/cpp/AnalogTrigger.cpp b/wpilibc/src/main/native/cpp/AnalogTrigger.cpp index 6b547b3e1e..2d19555297 100644 --- a/wpilibc/src/main/native/cpp/AnalogTrigger.cpp +++ b/wpilibc/src/main/native/cpp/AnalogTrigger.cpp @@ -11,7 +11,7 @@ #include "frc/AnalogInput.h" #include "frc/Base.h" #include "frc/DutyCycle.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/smartdashboard/SendableRegistry.h" using namespace frc; @@ -26,11 +26,7 @@ AnalogTrigger::AnalogTrigger(AnalogInput* input) { m_analogInput = input; int32_t status = 0; m_trigger = HAL_InitializeAnalogTrigger(input->m_port, &status); - if (status != 0) { - wpi_setHALError(status); - m_trigger = HAL_kInvalidHandle; - return; - } + FRC_CheckErrorStatus(status, "InitializeAnalogTrigger"); int index = GetIndex(); HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1); @@ -41,11 +37,7 @@ AnalogTrigger::AnalogTrigger(DutyCycle* input) { m_dutyCycle = input; int32_t status = 0; m_trigger = HAL_InitializeAnalogTriggerDutyCycle(input->m_handle, &status); - if (status != 0) { - wpi_setHALError(status); - m_trigger = HAL_kInvalidHandle; - return; - } + FRC_CheckErrorStatus(status, "InitializeAnalogTriggerDutyCycle"); int index = GetIndex(); HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1); @@ -55,6 +47,7 @@ AnalogTrigger::AnalogTrigger(DutyCycle* input) { AnalogTrigger::~AnalogTrigger() { int32_t status = 0; HAL_CleanAnalogTrigger(m_trigger, &status); + FRC_ReportError(status, "CleanAnalogTrigger"); if (m_ownsAnalog) { delete m_analogInput; @@ -62,16 +55,13 @@ AnalogTrigger::~AnalogTrigger() { } AnalogTrigger::AnalogTrigger(AnalogTrigger&& rhs) - : ErrorBase(std::move(rhs)), - SendableHelper(std::move(rhs)), - m_trigger(std::move(rhs.m_trigger)) { + : SendableHelper(std::move(rhs)), m_trigger(std::move(rhs.m_trigger)) { std::swap(m_analogInput, rhs.m_analogInput); std::swap(m_dutyCycle, rhs.m_dutyCycle); std::swap(m_ownsAnalog, rhs.m_ownsAnalog); } AnalogTrigger& AnalogTrigger::operator=(AnalogTrigger&& rhs) { - ErrorBase::operator=(std::move(rhs)); SendableHelper::operator=(std::move(rhs)); m_trigger = std::move(rhs.m_trigger); @@ -83,85 +73,58 @@ AnalogTrigger& AnalogTrigger::operator=(AnalogTrigger&& rhs) { } void AnalogTrigger::SetLimitsVoltage(double lower, double upper) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetLimitsVoltage"); } void AnalogTrigger::SetLimitsDutyCycle(double lower, double upper) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAnalogTriggerLimitsDutyCycle(m_trigger, lower, upper, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetLimitsDutyCycle"); } void AnalogTrigger::SetLimitsRaw(int lower, int upper) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetLimitsRaw"); } void AnalogTrigger::SetAveraged(bool useAveragedValue) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAnalogTriggerAveraged(m_trigger, useAveragedValue, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetAveraged"); } void AnalogTrigger::SetFiltered(bool useFilteredValue) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetAnalogTriggerFiltered(m_trigger, useFilteredValue, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetFiltered"); } int AnalogTrigger::GetIndex() const { - if (StatusIsFatal()) { - return -1; - } int32_t status = 0; auto ret = HAL_GetAnalogTriggerFPGAIndex(m_trigger, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetIndex"); return ret; } bool AnalogTrigger::GetInWindow() { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; bool result = HAL_GetAnalogTriggerInWindow(m_trigger, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetInWindow"); return result; } bool AnalogTrigger::GetTriggerState() { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; bool result = HAL_GetAnalogTriggerTriggerState(m_trigger, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetTriggerState"); return result; } std::shared_ptr AnalogTrigger::CreateOutput( AnalogTriggerType type) const { - if (StatusIsFatal()) { - return nullptr; - } return std::shared_ptr( new AnalogTriggerOutput(*this, type), NullDeleter()); } diff --git a/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp b/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp index a9b8fb4b7f..d9f8ec7942 100644 --- a/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp @@ -7,7 +7,7 @@ #include #include "frc/AnalogTrigger.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" using namespace frc; @@ -16,7 +16,7 @@ bool AnalogTriggerOutput::Get() const { bool result = HAL_GetAnalogTriggerOutput( m_trigger->m_trigger, static_cast(m_outputType), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Get"); return result; } diff --git a/wpilibc/src/main/native/cpp/BuiltInAccelerometer.cpp b/wpilibc/src/main/native/cpp/BuiltInAccelerometer.cpp index a482cf5535..4b8b51d63f 100644 --- a/wpilibc/src/main/native/cpp/BuiltInAccelerometer.cpp +++ b/wpilibc/src/main/native/cpp/BuiltInAccelerometer.cpp @@ -7,7 +7,7 @@ #include #include -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -23,8 +23,8 @@ BuiltInAccelerometer::BuiltInAccelerometer(Range range) { void BuiltInAccelerometer::SetRange(Range range) { if (range == kRange_16G) { - wpi_setWPIErrorWithContext( - ParameterOutOfRange, "16G range not supported (use k2G, k4G, or k8G)"); + throw FRC_MakeError(err::ParameterOutOfRange, + "16G range not supported (use k2G, k4G, or k8G)"); } HAL_SetAccelerometerActive(false); diff --git a/wpilibc/src/main/native/cpp/CAN.cpp b/wpilibc/src/main/native/cpp/CAN.cpp index ee2003bd7a..7c58475afa 100644 --- a/wpilibc/src/main/native/cpp/CAN.cpp +++ b/wpilibc/src/main/native/cpp/CAN.cpp @@ -11,17 +11,15 @@ #include #include +#include "frc/Errors.h" + using namespace frc; CAN::CAN(int deviceId) { int32_t status = 0; m_handle = HAL_InitializeCAN(kTeamManufacturer, deviceId, kTeamDeviceType, &status); - if (status != 0) { - wpi_setHALError(status); - m_handle = HAL_kInvalidHandle; - return; - } + FRC_CheckErrorStatus(status, "device id " + wpi::Twine{deviceId}); HAL_Report(HALUsageReporting::kResourceType_CAN, deviceId + 1); } @@ -31,19 +29,14 @@ CAN::CAN(int deviceId, int deviceManufacturer, int deviceType) { m_handle = HAL_InitializeCAN( static_cast(deviceManufacturer), deviceId, static_cast(deviceType), &status); - if (status != 0) { - wpi_setHALError(status); - m_handle = HAL_kInvalidHandle; - return; - } + FRC_CheckErrorStatus(status, "device id " + wpi::Twine{deviceId} + " mfg " + + wpi::Twine{deviceManufacturer} + " type " + + wpi::Twine{deviceType}); HAL_Report(HALUsageReporting::kResourceType_CAN, deviceId + 1); } CAN::~CAN() { - if (StatusIsFatal()) { - return; - } if (m_handle != HAL_kInvalidHandle) { HAL_CleanCAN(m_handle); m_handle = HAL_kInvalidHandle; @@ -53,20 +46,20 @@ CAN::~CAN() { void CAN::WritePacket(const uint8_t* data, int length, int apiId) { int32_t status = 0; HAL_WriteCANPacket(m_handle, data, length, apiId, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "WritePacket"); } void CAN::WritePacketRepeating(const uint8_t* data, int length, int apiId, int repeatMs) { int32_t status = 0; HAL_WriteCANPacketRepeating(m_handle, data, length, apiId, repeatMs, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "WritePacketRepeating"); } void CAN::WriteRTRFrame(int length, int apiId) { int32_t status = 0; HAL_WriteCANRTRFrame(m_handle, length, apiId, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "WriteRTRFrame"); } int CAN::WritePacketNoError(const uint8_t* data, int length, int apiId) { @@ -91,7 +84,7 @@ int CAN::WriteRTRFrameNoError(int length, int apiId) { void CAN::StopPacketRepeating(int apiId) { int32_t status = 0; HAL_StopCANPacketRepeating(m_handle, apiId, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "StopPacketRepeating"); } bool CAN::ReadPacketNew(int apiId, CANData* data) { @@ -102,7 +95,7 @@ bool CAN::ReadPacketNew(int apiId, CANData* data) { return false; } if (status != 0) { - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ReadPacketNew"); return false; } else { return true; @@ -117,7 +110,7 @@ bool CAN::ReadPacketLatest(int apiId, CANData* data) { return false; } if (status != 0) { - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ReadPacketLatest"); return false; } else { return true; @@ -133,7 +126,7 @@ bool CAN::ReadPacketTimeout(int apiId, int timeoutMs, CANData* data) { return false; } if (status != 0) { - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ReadPacketTimeout"); return false; } else { return true; diff --git a/wpilibc/src/main/native/cpp/Compressor.cpp b/wpilibc/src/main/native/cpp/Compressor.cpp index 8f0582b3a9..52968403ad 100644 --- a/wpilibc/src/main/native/cpp/Compressor.cpp +++ b/wpilibc/src/main/native/cpp/Compressor.cpp @@ -9,7 +9,7 @@ #include #include -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -18,10 +18,7 @@ using namespace frc; Compressor::Compressor(int pcmID) : m_module(pcmID) { int32_t status = 0; m_compressorHandle = HAL_InitializeCompressor(m_module, &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumPCMModules(), pcmID); - return; - } + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); SetClosedLoopControl(true); HAL_Report(HALUsageReporting::kResourceType_Compressor, pcmID + 1); @@ -29,204 +26,96 @@ Compressor::Compressor(int pcmID) : m_module(pcmID) { } void Compressor::Start() { - if (StatusIsFatal()) { - return; - } SetClosedLoopControl(true); } void Compressor::Stop() { - if (StatusIsFatal()) { - return; - } SetClosedLoopControl(false); } bool Compressor::Enabled() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; - bool value; - - value = HAL_GetCompressor(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + bool value = HAL_GetCompressor(m_compressorHandle, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } bool Compressor::GetPressureSwitchValue() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; - bool value; - - value = HAL_GetCompressorPressureSwitch(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + bool value = HAL_GetCompressorPressureSwitch(m_compressorHandle, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } double Compressor::GetCompressorCurrent() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; - double value; - - value = HAL_GetCompressorCurrent(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + double value = HAL_GetCompressorCurrent(m_compressorHandle, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } void Compressor::SetClosedLoopControl(bool on) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; - HAL_SetCompressorClosedLoopControl(m_compressorHandle, on, &status); - - if (status) { - wpi_setWPIError(Timeout); - } + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); } bool Compressor::GetClosedLoopControl() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; - bool value; - - value = HAL_GetCompressorClosedLoopControl(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + bool value = HAL_GetCompressorClosedLoopControl(m_compressorHandle, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } bool Compressor::GetCompressorCurrentTooHighFault() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; - bool value; - - value = HAL_GetCompressorCurrentTooHighFault(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + bool value = + HAL_GetCompressorCurrentTooHighFault(m_compressorHandle, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } bool Compressor::GetCompressorCurrentTooHighStickyFault() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; - bool value; - - value = + bool value = HAL_GetCompressorCurrentTooHighStickyFault(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } bool Compressor::GetCompressorShortedStickyFault() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; - bool value; - - value = HAL_GetCompressorShortedStickyFault(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + bool value = HAL_GetCompressorShortedStickyFault(m_compressorHandle, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } bool Compressor::GetCompressorShortedFault() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; - bool value; - - value = HAL_GetCompressorShortedFault(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + bool value = HAL_GetCompressorShortedFault(m_compressorHandle, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } bool Compressor::GetCompressorNotConnectedStickyFault() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; - bool value; - - value = HAL_GetCompressorNotConnectedStickyFault(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + bool value = + HAL_GetCompressorNotConnectedStickyFault(m_compressorHandle, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } bool Compressor::GetCompressorNotConnectedFault() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; - bool value; - - value = HAL_GetCompressorNotConnectedFault(m_compressorHandle, &status); - - if (status) { - wpi_setWPIError(Timeout); - } - + bool value = HAL_GetCompressorNotConnectedFault(m_compressorHandle, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); return value; } void Compressor::ClearAllPCMStickyFaults() { - if (StatusIsFatal()) { - return; - } int32_t status = 0; - HAL_ClearAllPCMStickyFaults(m_module, &status); - - if (status) { - wpi_setWPIError(Timeout); - } + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{m_module}); } int Compressor::GetModule() const { diff --git a/wpilibc/src/main/native/cpp/Counter.cpp b/wpilibc/src/main/native/cpp/Counter.cpp index e1d9d2920e..02b1df3ba8 100644 --- a/wpilibc/src/main/native/cpp/Counter.cpp +++ b/wpilibc/src/main/native/cpp/Counter.cpp @@ -12,7 +12,7 @@ #include "frc/AnalogTrigger.h" #include "frc/Base.h" #include "frc/DigitalInput.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -22,7 +22,7 @@ Counter::Counter(Mode mode) { int32_t status = 0; m_counter = HAL_InitializeCounter(static_cast(mode), &m_index, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "InitializeCounter"); SetMaxPeriod(0.5); @@ -64,10 +64,8 @@ Counter::Counter(EncodingType encodingType, std::shared_ptr downSource, bool inverted) : Counter(kExternalDirection) { if (encodingType != k1X && encodingType != k2X) { - wpi_setWPIErrorWithContext( - ParameterOutOfRange, - "Counter only supports 1X and 2X quadrature decoding."); - return; + throw FRC_MakeError(err::ParameterOutOfRange, + "Counter only supports 1X and 2X quadrature decoding."); } SetUpSource(upSource); SetDownSource(downSource); @@ -81,22 +79,23 @@ Counter::Counter(EncodingType encodingType, HAL_SetCounterAverageSize(m_counter, 2, &status); } - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Counter constructor"); SetDownSourceEdge(inverted, true); } Counter::~Counter() { - SetUpdateWhenEmpty(true); + try { + SetUpdateWhenEmpty(true); + } catch (const RuntimeError& e) { + e.Report(); + } int32_t status = 0; HAL_FreeCounter(m_counter, &status); - wpi_setHALError(status); + FRC_ReportError(status, "Counter destructor"); } void Counter::SetUpSource(int channel) { - if (StatusIsFatal()) { - return; - } SetUpSource(std::make_shared(channel)); SendableRegistry::GetInstance().AddChild(this, m_upSource.get()); } @@ -110,9 +109,6 @@ void Counter::SetUpSource(AnalogTrigger* analogTrigger, void Counter::SetUpSource(std::shared_ptr analogTrigger, AnalogTriggerType triggerType) { - if (StatusIsFatal()) { - return; - } SetUpSource(analogTrigger->CreateOutput(triggerType)); } @@ -122,20 +118,13 @@ void Counter::SetUpSource(DigitalSource* source) { } void Counter::SetUpSource(std::shared_ptr source) { - if (StatusIsFatal()) { - return; - } m_upSource = source; - if (m_upSource->StatusIsFatal()) { - CloneError(*m_upSource); - } else { - int32_t status = 0; - HAL_SetCounterUpSource(m_counter, source->GetPortHandleForRouting(), - static_cast( - source->GetAnalogTriggerTypeForRouting()), - &status); - wpi_setHALError(status); - } + int32_t status = 0; + HAL_SetCounterUpSource(m_counter, source->GetPortHandleForRouting(), + static_cast( + source->GetAnalogTriggerTypeForRouting()), + &status); + FRC_CheckErrorStatus(status, "SetUpSource"); } void Counter::SetUpSource(DigitalSource& source) { @@ -144,33 +133,24 @@ void Counter::SetUpSource(DigitalSource& source) { } void Counter::SetUpSourceEdge(bool risingEdge, bool fallingEdge) { - if (StatusIsFatal()) { - return; - } if (m_upSource == nullptr) { - wpi_setWPIErrorWithContext( - NullParameter, + throw FRC_MakeError( + err::NullParameter, "Must set non-nullptr UpSource before setting UpSourceEdge"); } int32_t status = 0; HAL_SetCounterUpSourceEdge(m_counter, risingEdge, fallingEdge, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetUpSourceEdge"); } void Counter::ClearUpSource() { - if (StatusIsFatal()) { - return; - } m_upSource.reset(); int32_t status = 0; HAL_ClearCounterUpSource(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ClearUpSource"); } void Counter::SetDownSource(int channel) { - if (StatusIsFatal()) { - return; - } SetDownSource(std::make_shared(channel)); SendableRegistry::GetInstance().AddChild(this, m_downSource.get()); } @@ -184,9 +164,6 @@ void Counter::SetDownSource(AnalogTrigger* analogTrigger, void Counter::SetDownSource(std::shared_ptr analogTrigger, AnalogTriggerType triggerType) { - if (StatusIsFatal()) { - return; - } SetDownSource(analogTrigger->CreateOutput(triggerType)); } @@ -201,106 +178,82 @@ void Counter::SetDownSource(DigitalSource& source) { } void Counter::SetDownSource(std::shared_ptr source) { - if (StatusIsFatal()) { - return; - } m_downSource = source; - if (m_downSource->StatusIsFatal()) { - CloneError(*m_downSource); - } else { - int32_t status = 0; - HAL_SetCounterDownSource(m_counter, source->GetPortHandleForRouting(), - static_cast( - source->GetAnalogTriggerTypeForRouting()), - &status); - wpi_setHALError(status); - } + int32_t status = 0; + HAL_SetCounterDownSource(m_counter, source->GetPortHandleForRouting(), + static_cast( + source->GetAnalogTriggerTypeForRouting()), + &status); + FRC_CheckErrorStatus(status, "SetDownSource"); } void Counter::SetDownSourceEdge(bool risingEdge, bool fallingEdge) { - if (StatusIsFatal()) { - return; - } if (m_downSource == nullptr) { - wpi_setWPIErrorWithContext( - NullParameter, + throw FRC_MakeError( + err::NullParameter, "Must set non-nullptr DownSource before setting DownSourceEdge"); } int32_t status = 0; HAL_SetCounterDownSourceEdge(m_counter, risingEdge, fallingEdge, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetDownSourceEdge"); } void Counter::ClearDownSource() { - if (StatusIsFatal()) { - return; - } m_downSource.reset(); int32_t status = 0; HAL_ClearCounterDownSource(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ClearDownSource"); } void Counter::SetUpDownCounterMode() { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetCounterUpDownMode(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetUpDownCounterMode"); } void Counter::SetExternalDirectionMode() { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetCounterExternalDirectionMode(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetExternalDirectionMode"); } void Counter::SetSemiPeriodMode(bool highSemiPeriod) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetCounterSemiPeriodMode(m_counter, highSemiPeriod, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus( + status, + "SetSemiPeriodMode to " + wpi::Twine{highSemiPeriod ? "true" : "false"}); } void Counter::SetPulseLengthMode(double threshold) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetCounterPulseLengthMode(m_counter, threshold, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetPulseLengthMode"); } void Counter::SetReverseDirection(bool reverseDirection) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetCounterReverseDirection(m_counter, reverseDirection, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, + "SetReverseDirection to " + + wpi::Twine{reverseDirection ? "true" : "false"}); } void Counter::SetSamplesToAverage(int samplesToAverage) { if (samplesToAverage < 1 || samplesToAverage > 127) { - wpi_setWPIErrorWithContext( - ParameterOutOfRange, - "Average counter values must be between 1 and 127"); + throw FRC_MakeError(err::ParameterOutOfRange, + "Average counter values must be between 1 and 127"); } int32_t status = 0; HAL_SetCounterSamplesToAverage(m_counter, samplesToAverage, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus( + status, "SetSamplesToAverage to " + wpi::Twine{samplesToAverage}); } int Counter::GetSamplesToAverage() const { int32_t status = 0; int samples = HAL_GetCounterSamplesToAverage(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetSamplesToAverage"); return samples; } @@ -309,69 +262,48 @@ int Counter::GetFPGAIndex() const { } int Counter::Get() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int value = HAL_GetCounter(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Get"); return value; } void Counter::Reset() { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_ResetCounter(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Reset"); } double Counter::GetPeriod() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double value = HAL_GetCounterPeriod(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetPeriod"); return value; } void Counter::SetMaxPeriod(double maxPeriod) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetCounterMaxPeriod(m_counter, maxPeriod, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetMaxPeriod"); } void Counter::SetUpdateWhenEmpty(bool enabled) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetCounterUpdateWhenEmpty(m_counter, enabled, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetUpdateWhenEmpty"); } bool Counter::GetStopped() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; bool value = HAL_GetCounterStopped(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetStopped"); return value; } bool Counter::GetDirection() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; bool value = HAL_GetCounterDirection(m_counter, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetDirection"); return value; } diff --git a/wpilibc/src/main/native/cpp/DMA.cpp b/wpilibc/src/main/native/cpp/DMA.cpp index 87164f9a94..6c99e14d39 100644 --- a/wpilibc/src/main/native/cpp/DMA.cpp +++ b/wpilibc/src/main/native/cpp/DMA.cpp @@ -4,21 +4,22 @@ #include "frc/DMA.h" -#include -#include -#include -#include -#include - #include #include +#include "frc/AnalogInput.h" +#include "frc/Counter.h" +#include "frc/DigitalSource.h" +#include "frc/DutyCycle.h" +#include "frc/Encoder.h" +#include "frc/Errors.h" + using namespace frc; DMA::DMA() { int32_t status = 0; dmaHandle = HAL_InitializeDMA(&status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "InitializeDMA"); } DMA::~DMA() { @@ -28,68 +29,68 @@ DMA::~DMA() { void DMA::SetPause(bool pause) { int32_t status = 0; HAL_SetDMAPause(dmaHandle, pause, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "SetPause"); } void DMA::SetRate(int cycles) { int32_t status = 0; HAL_SetDMARate(dmaHandle, cycles, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "SetRate"); } void DMA::AddEncoder(const Encoder* encoder) { int32_t status = 0; HAL_AddDMAEncoder(dmaHandle, encoder->m_encoder, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "AddEncoder"); } void DMA::AddEncoderPeriod(const Encoder* encoder) { int32_t status = 0; HAL_AddDMAEncoderPeriod(dmaHandle, encoder->m_encoder, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "AddEncoderPeriod"); } void DMA::AddCounter(const Counter* counter) { int32_t status = 0; HAL_AddDMACounter(dmaHandle, counter->m_counter, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "AddCounter"); } void DMA::AddCounterPeriod(const Counter* counter) { int32_t status = 0; HAL_AddDMACounterPeriod(dmaHandle, counter->m_counter, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "AddCounterPeriod"); } void DMA::AddDigitalSource(const DigitalSource* digitalSource) { int32_t status = 0; HAL_AddDMADigitalSource(dmaHandle, digitalSource->GetPortHandleForRouting(), &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "AddDigitalSource"); } void DMA::AddDutyCycle(const DutyCycle* dutyCycle) { int32_t status = 0; HAL_AddDMADutyCycle(dmaHandle, dutyCycle->m_handle, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "AddDutyCycle"); } void DMA::AddAnalogInput(const AnalogInput* analogInput) { int32_t status = 0; HAL_AddDMAAnalogInput(dmaHandle, analogInput->m_port, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "AddAnalogInput"); } void DMA::AddAveragedAnalogInput(const AnalogInput* analogInput) { int32_t status = 0; HAL_AddDMAAveragedAnalogInput(dmaHandle, analogInput->m_port, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "AddAveragedAnalogInput"); } void DMA::AddAnalogAccumulator(const AnalogInput* analogInput) { int32_t status = 0; HAL_AddDMAAnalogAccumulator(dmaHandle, analogInput->m_port, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "AddAnalogAccumulator"); } void DMA::SetExternalTrigger(DigitalSource* source, bool rising, bool falling) { @@ -98,17 +99,17 @@ void DMA::SetExternalTrigger(DigitalSource* source, bool rising, bool falling) { static_cast( source->GetAnalogTriggerTypeForRouting()), rising, falling, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "SetExternalTrigger"); } void DMA::StartDMA(int queueDepth) { int32_t status = 0; HAL_StartDMA(dmaHandle, queueDepth, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "StartDMA"); } void DMA::StopDMA() { int32_t status = 0; HAL_StopDMA(dmaHandle, &status); - wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); + FRC_CheckErrorStatus(status, "StopDMA"); } diff --git a/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp b/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp index 0ff4ed93aa..9fae85dbd7 100644 --- a/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp +++ b/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp @@ -14,9 +14,9 @@ #include "frc/Counter.h" #include "frc/Encoder.h" +#include "frc/Errors.h" #include "frc/SensorUtil.h" #include "frc/Utility.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableRegistry.h" using namespace frc; @@ -29,7 +29,7 @@ DigitalGlitchFilter::DigitalGlitchFilter() { std::scoped_lock lock(m_mutex); auto index = std::find(m_filterAllocated.begin(), m_filterAllocated.end(), false); - wpi_assert(index != m_filterAllocated.end()); + FRC_Assert(index != m_filterAllocated.end()); m_channelIndex = std::distance(m_filterAllocated.begin(), index); *index = true; @@ -48,12 +48,11 @@ DigitalGlitchFilter::~DigitalGlitchFilter() { } DigitalGlitchFilter::DigitalGlitchFilter(DigitalGlitchFilter&& rhs) - : ErrorBase(std::move(rhs)), SendableHelper(std::move(rhs)) { + : SendableHelper(std::move(rhs)) { std::swap(m_channelIndex, rhs.m_channelIndex); } DigitalGlitchFilter& DigitalGlitchFilter::operator=(DigitalGlitchFilter&& rhs) { - ErrorBase::operator=(std::move(rhs)); SendableHelper::operator=(std::move(rhs)); std::swap(m_channelIndex, rhs.m_channelIndex); @@ -71,35 +70,31 @@ void DigitalGlitchFilter::DoAdd(DigitalSource* input, int requestedIndex) { if (input) { // We don't support GlitchFilters on AnalogTriggers. if (input->IsAnalogTrigger()) { - wpi_setErrorWithContext( + throw FRC_MakeError( -1, "Analog Triggers not supported for DigitalGlitchFilters"); - return; } int32_t status = 0; HAL_SetFilterSelect(input->GetPortHandleForRouting(), requestedIndex, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, + "requested index " + wpi::Twine{requestedIndex}); // Validate that we set it correctly. int actualIndex = HAL_GetFilterSelect(input->GetPortHandleForRouting(), &status); - wpi_assertEqual(actualIndex, requestedIndex); + FRC_CheckErrorStatus(status, + "requested index " + wpi::Twine{requestedIndex}); + FRC_Assert(actualIndex == requestedIndex); } } void DigitalGlitchFilter::Add(Encoder* input) { Add(input->m_aSource.get()); - if (StatusIsFatal()) { - return; - } Add(input->m_bSource.get()); } void DigitalGlitchFilter::Add(Counter* input) { Add(input->m_upSource.get()); - if (StatusIsFatal()) { - return; - } Add(input->m_downSource.get()); } @@ -109,24 +104,18 @@ void DigitalGlitchFilter::Remove(DigitalSource* input) { void DigitalGlitchFilter::Remove(Encoder* input) { Remove(input->m_aSource.get()); - if (StatusIsFatal()) { - return; - } Remove(input->m_bSource.get()); } void DigitalGlitchFilter::Remove(Counter* input) { Remove(input->m_upSource.get()); - if (StatusIsFatal()) { - return; - } Remove(input->m_downSource.get()); } void DigitalGlitchFilter::SetPeriodCycles(int fpgaCycles) { int32_t status = 0; HAL_SetFilterPeriod(m_channelIndex, fpgaCycles, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex}); } void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) { @@ -134,25 +123,20 @@ void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) { int fpgaCycles = nanoseconds * HAL_GetSystemClockTicksPerMicrosecond() / 4 / 1000; HAL_SetFilterPeriod(m_channelIndex, fpgaCycles, &status); - - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex}); } int DigitalGlitchFilter::GetPeriodCycles() { int32_t status = 0; int fpgaCycles = HAL_GetFilterPeriod(m_channelIndex, &status); - - wpi_setHALError(status); - + FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex}); return fpgaCycles; } uint64_t DigitalGlitchFilter::GetPeriodNanoSeconds() { int32_t status = 0; int fpgaCycles = HAL_GetFilterPeriod(m_channelIndex, &status); - - wpi_setHALError(status); - + FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{m_channelIndex}); return static_cast(fpgaCycles) * 1000L / static_cast(HAL_GetSystemClockTicksPerMicrosecond() / 4); } diff --git a/wpilibc/src/main/native/cpp/DigitalInput.cpp b/wpilibc/src/main/native/cpp/DigitalInput.cpp index 1751053950..b97e36cc46 100644 --- a/wpilibc/src/main/native/cpp/DigitalInput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalInput.cpp @@ -4,15 +4,17 @@ #include "frc/DigitalInput.h" +#include #include #include #include #include #include +#include +#include "frc/Errors.h" #include "frc/SensorUtil.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -20,40 +22,29 @@ using namespace frc; DigitalInput::DigitalInput(int channel) { if (!SensorUtil::CheckDigitalChannel(channel)) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, - "Digital Channel " + wpi::Twine(channel)); - m_channel = std::numeric_limits::max(); - return; + throw FRC_MakeError(err::ChannelIndexOutOfRange, + "Digital Channel " + wpi::Twine{channel}); } m_channel = channel; int32_t status = 0; - m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), true, &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumDigitalChannels(), channel); - m_handle = HAL_kInvalidHandle; - m_channel = std::numeric_limits::max(); - return; - } + std::string stackTrace = wpi::GetStackTrace(1); + m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), true, + stackTrace.c_str(), &status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{channel}); HAL_Report(HALUsageReporting::kResourceType_DigitalInput, channel + 1); SendableRegistry::GetInstance().AddLW(this, "DigitalInput", channel); } DigitalInput::~DigitalInput() { - if (StatusIsFatal()) { - return; - } HAL_FreeDIOPort(m_handle); } bool DigitalInput::Get() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; bool value = HAL_GetDIO(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Get"); return value; } diff --git a/wpilibc/src/main/native/cpp/DigitalOutput.cpp b/wpilibc/src/main/native/cpp/DigitalOutput.cpp index c8d3c13a8e..351ac07ed5 100644 --- a/wpilibc/src/main/native/cpp/DigitalOutput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalOutput.cpp @@ -10,9 +10,10 @@ #include #include #include +#include +#include "frc/Errors.h" #include "frc/SensorUtil.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -21,54 +22,42 @@ using namespace frc; DigitalOutput::DigitalOutput(int channel) { m_pwmGenerator = HAL_kInvalidHandle; if (!SensorUtil::CheckDigitalChannel(channel)) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, - "Digital Channel " + wpi::Twine(channel)); - m_channel = std::numeric_limits::max(); - return; + throw FRC_MakeError(err::ChannelIndexOutOfRange, + "Digital Channel " + wpi::Twine{channel}); } m_channel = channel; int32_t status = 0; - m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), false, &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumDigitalChannels(), channel); - m_channel = std::numeric_limits::max(); - m_handle = HAL_kInvalidHandle; - return; - } + std::string stackTrace = wpi::GetStackTrace(1); + m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), false, + stackTrace.c_str(), &status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{channel}); HAL_Report(HALUsageReporting::kResourceType_DigitalOutput, channel + 1); SendableRegistry::GetInstance().AddLW(this, "DigitalOutput", channel); } DigitalOutput::~DigitalOutput() { - if (StatusIsFatal()) { - return; - } // Disable the PWM in case it was running. - DisablePWM(); + try { + DisablePWM(); + } catch (const RuntimeError& e) { + e.Report(); + } HAL_FreeDIOPort(m_handle); } void DigitalOutput::Set(bool value) { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; HAL_SetDIO(m_handle, value, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); } bool DigitalOutput::Get() const { - if (StatusIsFatal()) { - return false; - } - int32_t status = 0; bool val = HAL_GetDIO(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); return val; } @@ -89,34 +78,22 @@ int DigitalOutput::GetChannel() const { } void DigitalOutput::Pulse(double length) { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; HAL_Pulse(m_handle, length, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); } bool DigitalOutput::IsPulsing() const { - if (StatusIsFatal()) { - return false; - } - int32_t status = 0; bool value = HAL_IsPulsing(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); return value; } void DigitalOutput::SetPWMRate(double rate) { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; HAL_SetDigitalPWMRate(rate, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); } void DigitalOutput::EnablePWM(double initialDutyCycle) { @@ -126,29 +103,17 @@ void DigitalOutput::EnablePWM(double initialDutyCycle) { int32_t status = 0; - if (StatusIsFatal()) { - return; - } m_pwmGenerator = HAL_AllocateDigitalPWM(&status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); - if (StatusIsFatal()) { - return; - } HAL_SetDigitalPWMDutyCycle(m_pwmGenerator, initialDutyCycle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); - if (StatusIsFatal()) { - return; - } HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, m_channel, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); } void DigitalOutput::DisablePWM() { - if (StatusIsFatal()) { - return; - } if (m_pwmGenerator == HAL_kInvalidHandle) { return; } @@ -158,22 +123,18 @@ void DigitalOutput::DisablePWM() { // Disable the output by routing to a dead bit. HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, SensorUtil::kDigitalChannels, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); HAL_FreeDigitalPWM(m_pwmGenerator, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); m_pwmGenerator = HAL_kInvalidHandle; } void DigitalOutput::UpdateDutyCycle(double dutyCycle) { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; HAL_SetDigitalPWMDutyCycle(m_pwmGenerator, dutyCycle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Digital Channel " + wpi::Twine{m_channel}); } void DigitalOutput::SetSimDevice(HAL_SimDeviceHandle device) { diff --git a/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp b/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp index 815e3a076e..b0d7cbfd6a 100644 --- a/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp +++ b/wpilibc/src/main/native/cpp/DoubleSolenoid.cpp @@ -11,8 +11,8 @@ #include #include +#include "frc/Errors.h" #include "frc/SensorUtil.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -28,42 +28,31 @@ DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel, m_forwardChannel(forwardChannel), m_reverseChannel(reverseChannel) { if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) { - wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, - "Solenoid Module " + wpi::Twine(m_moduleNumber)); - return; + throw FRC_MakeError(err::ModuleIndexOutOfRange, + "Solenoid Module " + wpi::Twine{m_moduleNumber}); } if (!SensorUtil::CheckSolenoidChannel(m_forwardChannel)) { - wpi_setWPIErrorWithContext( - ChannelIndexOutOfRange, - "Solenoid Channel " + wpi::Twine(m_forwardChannel)); - return; + throw FRC_MakeError(err::ChannelIndexOutOfRange, + "Solenoid Channel " + wpi::Twine{m_forwardChannel}); } if (!SensorUtil::CheckSolenoidChannel(m_reverseChannel)) { - wpi_setWPIErrorWithContext( - ChannelIndexOutOfRange, - "Solenoid Channel " + wpi::Twine(m_reverseChannel)); - return; + throw FRC_MakeError(err::ChannelIndexOutOfRange, + "Solenoid Channel " + wpi::Twine{m_reverseChannel}); } int32_t status = 0; m_forwardHandle = HAL_InitializeSolenoidPort( HAL_GetPortWithModule(moduleNumber, m_forwardChannel), &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumSolenoidChannels(), - forwardChannel); - m_forwardHandle = HAL_kInvalidHandle; - m_reverseHandle = HAL_kInvalidHandle; - return; - } + FRC_CheckErrorStatus(status, "Solenoid Module " + wpi::Twine{m_moduleNumber} + + " Channel " + wpi::Twine{m_forwardChannel}); m_reverseHandle = HAL_InitializeSolenoidPort( HAL_GetPortWithModule(moduleNumber, m_reverseChannel), &status); if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumSolenoidChannels(), - reverseChannel); // free forward solenoid HAL_FreeSolenoidPort(m_forwardHandle); - m_forwardHandle = HAL_kInvalidHandle; - m_reverseHandle = HAL_kInvalidHandle; + FRC_CheckErrorStatus(status, "Solenoid Module " + + wpi::Twine{m_moduleNumber} + " Channel " + + wpi::Twine{m_reverseChannel}); return; } @@ -85,10 +74,6 @@ DoubleSolenoid::~DoubleSolenoid() { } void DoubleSolenoid::Set(Value value) { - if (StatusIsFatal()) { - return; - } - bool forward = false; bool reverse = false; @@ -112,22 +97,26 @@ void DoubleSolenoid::Set(Value value) { int rstatus = 0; HAL_SetSolenoid(m_reverseHandle, reverse, &rstatus); - wpi_setHALError(fstatus); - wpi_setHALError(rstatus); + FRC_CheckErrorStatus(fstatus, "Solenoid Module " + + wpi::Twine{m_moduleNumber} + " Channel " + + wpi::Twine{m_forwardChannel}); + FRC_CheckErrorStatus(rstatus, "Solenoid Module " + + wpi::Twine{m_moduleNumber} + " Channel " + + wpi::Twine{m_reverseChannel}); } DoubleSolenoid::Value DoubleSolenoid::Get() const { - if (StatusIsFatal()) { - return kOff; - } - int fstatus = 0; int rstatus = 0; bool valueForward = HAL_GetSolenoid(m_forwardHandle, &fstatus); bool valueReverse = HAL_GetSolenoid(m_reverseHandle, &rstatus); - wpi_setHALError(fstatus); - wpi_setHALError(rstatus); + FRC_CheckErrorStatus(fstatus, "Solenoid Module " + + wpi::Twine{m_moduleNumber} + " Channel " + + wpi::Twine{m_forwardChannel}); + FRC_CheckErrorStatus(rstatus, "Solenoid Module " + + wpi::Twine{m_moduleNumber} + " Channel " + + wpi::Twine{m_reverseChannel}); if (valueForward) { return kForward; diff --git a/wpilibc/src/main/native/cpp/DriverStation.cpp b/wpilibc/src/main/native/cpp/DriverStation.cpp index 2cce5f6c53..1e1f77397f 100644 --- a/wpilibc/src/main/native/cpp/DriverStation.cpp +++ b/wpilibc/src/main/native/cpp/DriverStation.cpp @@ -17,9 +17,9 @@ #include #include +#include "frc/Errors.h" #include "frc/MotorSafety.h" #include "frc/Timer.h" -#include "frc/WPIErrors.h" namespace frc { // A simple class which caches the previous value written to an NT entry @@ -140,7 +140,8 @@ void DriverStation::ReportError(bool isError, int32_t code, bool DriverStation::GetStickButton(int stick, int button) { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return false; } if (button <= 0) { @@ -163,7 +164,8 @@ bool DriverStation::GetStickButton(int stick, int button) { bool DriverStation::GetStickButtonPressed(int stick, int button) { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return false; } if (button <= 0) { @@ -192,7 +194,8 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) { bool DriverStation::GetStickButtonReleased(int stick, int button) { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return false; } if (button <= 0) { @@ -221,11 +224,13 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) { double DriverStation::GetStickAxis(int stick, int axis) { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return 0.0; } if (axis < 0 || axis >= HAL_kMaxJoystickAxes) { - wpi_setWPIError(BadJoystickAxis); + FRC_ReportError(warn::BadJoystickAxis, + "axis " + wpi::Twine{axis} + " out of range"); return 0.0; } @@ -243,11 +248,13 @@ double DriverStation::GetStickAxis(int stick, int axis) { int DriverStation::GetStickPOV(int stick, int pov) { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return -1; } if (pov < 0 || pov >= HAL_kMaxJoystickPOVs) { - wpi_setWPIError(BadJoystickAxis); + FRC_ReportError(warn::BadJoystickAxis, + "POV " + wpi::Twine{pov} + " out of range"); return -1; } @@ -265,7 +272,8 @@ int DriverStation::GetStickPOV(int stick, int pov) { int DriverStation::GetStickButtons(int stick) const { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return 0; } @@ -277,7 +285,8 @@ int DriverStation::GetStickButtons(int stick) const { int DriverStation::GetStickAxisCount(int stick) const { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return 0; } @@ -289,7 +298,8 @@ int DriverStation::GetStickAxisCount(int stick) const { int DriverStation::GetStickPOVCount(int stick) const { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return 0; } @@ -301,7 +311,8 @@ int DriverStation::GetStickPOVCount(int stick) const { int DriverStation::GetStickButtonCount(int stick) const { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return 0; } @@ -313,7 +324,8 @@ int DriverStation::GetStickButtonCount(int stick) const { bool DriverStation::GetJoystickIsXbox(int stick) const { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return false; } @@ -325,7 +337,8 @@ bool DriverStation::GetJoystickIsXbox(int stick) const { int DriverStation::GetJoystickType(int stick) const { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return -1; } @@ -337,7 +350,8 @@ int DriverStation::GetJoystickType(int stick) const { std::string DriverStation::GetJoystickName(int stick) const { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); } HAL_JoystickDescriptor descriptor; @@ -348,7 +362,8 @@ std::string DriverStation::GetJoystickName(int stick) const { int DriverStation::GetJoystickAxisType(int stick, int axis) const { if (stick < 0 || stick >= kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + FRC_ReportError(warn::BadJoystickIndex, + "stick " + wpi::Twine{stick} + " out of range"); return -1; } @@ -537,7 +552,7 @@ double DriverStation::GetMatchTime() const { double DriverStation::GetBatteryVoltage() const { int32_t status = 0; double voltage = HAL_GetVinVoltage(&status); - wpi_setErrorWithContext(status, "getVinVoltage"); + FRC_CheckErrorStatus(status, "getVinVoltage"); return voltage; } diff --git a/wpilibc/src/main/native/cpp/DutyCycle.cpp b/wpilibc/src/main/native/cpp/DutyCycle.cpp index 6ffcd9713d..f4dbe14085 100644 --- a/wpilibc/src/main/native/cpp/DutyCycle.cpp +++ b/wpilibc/src/main/native/cpp/DutyCycle.cpp @@ -9,18 +9,17 @@ #include "frc/Base.h" #include "frc/DigitalSource.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/smartdashboard/SendableBuilder.h" using namespace frc; DutyCycle::DutyCycle(DigitalSource* source) : m_source{source, NullDeleter()} { - if (m_source == nullptr) { - wpi_setWPIError(NullParameter); - } else { - InitDutyCycle(); + if (!m_source) { + throw FRC_MakeError(err::NullParameter, "source"); } + InitDutyCycle(); } DutyCycle::DutyCycle(DigitalSource& source) @@ -30,11 +29,10 @@ DutyCycle::DutyCycle(DigitalSource& source) DutyCycle::DutyCycle(std::shared_ptr source) : m_source{std::move(source)} { - if (m_source == nullptr) { - wpi_setWPIError(NullParameter); - } else { - InitDutyCycle(); + if (!m_source) { + throw FRC_MakeError(err::NullParameter, "source"); } + InitDutyCycle(); } DutyCycle::~DutyCycle() { @@ -48,7 +46,7 @@ void DutyCycle::InitDutyCycle() { static_cast( m_source->GetAnalogTriggerTypeForRouting()), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "InitDutyCycle"); int index = GetFPGAIndex(); HAL_Report(HALUsageReporting::kResourceType_DutyCycle, index + 1); SendableRegistry::GetInstance().AddLW(this, "Duty Cycle", index); @@ -57,35 +55,35 @@ void DutyCycle::InitDutyCycle() { int DutyCycle::GetFPGAIndex() const { int32_t status = 0; auto retVal = HAL_GetDutyCycleFPGAIndex(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetFPGAIndex"); return retVal; } int DutyCycle::GetFrequency() const { int32_t status = 0; auto retVal = HAL_GetDutyCycleFrequency(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetFrequency"); return retVal; } double DutyCycle::GetOutput() const { int32_t status = 0; auto retVal = HAL_GetDutyCycleOutput(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetOutput"); return retVal; } unsigned int DutyCycle::GetOutputRaw() const { int32_t status = 0; auto retVal = HAL_GetDutyCycleOutputRaw(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetOutputRaw"); return retVal; } unsigned int DutyCycle::GetOutputScaleFactor() const { int32_t status = 0; auto retVal = HAL_GetDutyCycleOutputScaleFactor(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetOutputScaleFactor"); return retVal; } diff --git a/wpilibc/src/main/native/cpp/Encoder.cpp b/wpilibc/src/main/native/cpp/Encoder.cpp index 57e58590af..ce3f5eb47a 100644 --- a/wpilibc/src/main/native/cpp/Encoder.cpp +++ b/wpilibc/src/main/native/cpp/Encoder.cpp @@ -11,7 +11,7 @@ #include "frc/Base.h" #include "frc/DigitalInput.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -31,11 +31,13 @@ Encoder::Encoder(DigitalSource* aSource, DigitalSource* bSource, bool reverseDirection, EncodingType encodingType) : m_aSource(aSource, NullDeleter()), m_bSource(bSource, NullDeleter()) { - if (m_aSource == nullptr || m_bSource == nullptr) { - wpi_setWPIError(NullParameter); - } else { - InitEncoder(reverseDirection, encodingType); + if (!m_aSource) { + throw FRC_MakeError(err::NullParameter, "aSource"); } + if (!m_bSource) { + throw FRC_MakeError(err::NullParameter, "bSource"); + } + InitEncoder(reverseDirection, encodingType); } Encoder::Encoder(DigitalSource& aSource, DigitalSource& bSource, @@ -49,184 +51,133 @@ Encoder::Encoder(std::shared_ptr aSource, std::shared_ptr bSource, bool reverseDirection, EncodingType encodingType) : m_aSource(std::move(aSource)), m_bSource(std::move(bSource)) { - if (m_aSource == nullptr || m_bSource == nullptr) { - wpi_setWPIError(NullParameter); - } else { - InitEncoder(reverseDirection, encodingType); + if (!m_aSource) { + throw FRC_MakeError(err::NullParameter, "aSource"); } + if (!m_bSource) { + throw FRC_MakeError(err::NullParameter, "bSource"); + } + InitEncoder(reverseDirection, encodingType); } Encoder::~Encoder() { int32_t status = 0; HAL_FreeEncoder(m_encoder, &status); - wpi_setHALError(status); + FRC_ReportError(status, "FreeEncoder"); } int Encoder::Get() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int value = HAL_GetEncoder(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Get"); return value; } void Encoder::Reset() { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_ResetEncoder(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Reset"); } double Encoder::GetPeriod() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double value = HAL_GetEncoderPeriod(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetPeriod"); return value; } void Encoder::SetMaxPeriod(double maxPeriod) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetEncoderMaxPeriod(m_encoder, maxPeriod, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetMaxPeriod"); } bool Encoder::GetStopped() const { - if (StatusIsFatal()) { - return true; - } int32_t status = 0; bool value = HAL_GetEncoderStopped(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetStopped"); return value; } bool Encoder::GetDirection() const { - if (StatusIsFatal()) { - return false; - } int32_t status = 0; bool value = HAL_GetEncoderDirection(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetDirection"); return value; } int Encoder::GetRaw() const { - if (StatusIsFatal()) { - return 0; - } int32_t status = 0; int value = HAL_GetEncoderRaw(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetRaw"); return value; } int Encoder::GetEncodingScale() const { int32_t status = 0; int val = HAL_GetEncoderEncodingScale(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetEncodingScale"); return val; } double Encoder::GetDistance() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double value = HAL_GetEncoderDistance(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetDistance"); return value; } double Encoder::GetRate() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double value = HAL_GetEncoderRate(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetRate"); return value; } void Encoder::SetMinRate(double minRate) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetEncoderMinRate(m_encoder, minRate, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetMinRate"); } void Encoder::SetDistancePerPulse(double distancePerPulse) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetEncoderDistancePerPulse(m_encoder, distancePerPulse, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetDistancePerPulse"); } double Encoder::GetDistancePerPulse() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double distancePerPulse = HAL_GetEncoderDistancePerPulse(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetDistancePerPulse"); return distancePerPulse; } void Encoder::SetReverseDirection(bool reverseDirection) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetEncoderReverseDirection(m_encoder, reverseDirection, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetReverseDirection"); } void Encoder::SetSamplesToAverage(int samplesToAverage) { if (samplesToAverage < 1 || samplesToAverage > 127) { - wpi_setWPIErrorWithContext( - ParameterOutOfRange, - "Average counter values must be between 1 and 127"); - return; + throw FRC_MakeError( + err::ParameterOutOfRange, + "Average counter values must be between 1 and 127, got " + + wpi::Twine{samplesToAverage}); } int32_t status = 0; HAL_SetEncoderSamplesToAverage(m_encoder, samplesToAverage, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetSamplesToAverage"); } int Encoder::GetSamplesToAverage() const { int32_t status = 0; int result = HAL_GetEncoderSamplesToAverage(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetSamplesToAverage"); return result; } -double Encoder::PIDGet() { - if (StatusIsFatal()) { - return 0.0; - } - switch (GetPIDSourceType()) { - case PIDSourceType::kDisplacement: - return GetDistance(); - case PIDSourceType::kRate: - return GetRate(); - default: - return 0.0; - } -} - void Encoder::SetIndexSource(int channel, Encoder::IndexingType type) { // Force digital input if just given an index m_indexSource = std::make_shared(channel); @@ -242,7 +193,7 @@ void Encoder::SetIndexSource(const DigitalSource& source, source.GetAnalogTriggerTypeForRouting()), static_cast(type), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetIndexSource"); } void Encoder::SetSimDevice(HAL_SimDeviceHandle device) { @@ -252,14 +203,14 @@ void Encoder::SetSimDevice(HAL_SimDeviceHandle device) { int Encoder::GetFPGAIndex() const { int32_t status = 0; int val = HAL_GetEncoderFPGAIndex(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetFPGAIndex"); return val; } void Encoder::InitSendable(SendableBuilder& builder) { int32_t status = 0; HAL_EncoderEncodingType type = HAL_GetEncoderEncodingType(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetEncodingType"); if (type == HAL_EncoderEncodingType::HAL_Encoder_k4X) { builder.SetSmartDashboardType("Quadrature Encoder"); } else { @@ -285,7 +236,7 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) { m_bSource->GetAnalogTriggerTypeForRouting()), reverseDirection, static_cast(encodingType), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "InitEncoder"); HAL_Report(HALUsageReporting::kResourceType_Encoder, GetFPGAIndex() + 1, encodingType); @@ -294,11 +245,8 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) { } double Encoder::DecodingScaleFactor() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double val = HAL_GetEncoderDecodingScaleFactor(m_encoder, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "DecodingScaleFactor"); return val; } diff --git a/wpilibc/src/main/native/cpp/Error.cpp b/wpilibc/src/main/native/cpp/Error.cpp deleted file mode 100644 index 383bde3830..0000000000 --- a/wpilibc/src/main/native/cpp/Error.cpp +++ /dev/null @@ -1,108 +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 "frc/Error.h" - -#include -#include - -#include "frc/Base.h" -#include "frc/DriverStation.h" -#include "frc/Timer.h" - -using namespace frc; - -Error::Error(Code code, const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, int lineNumber, - const ErrorBase* originatingObject) { - Set(code, contextMessage, filename, function, lineNumber, originatingObject); -} - -bool Error::operator<(const Error& rhs) const { - if (m_code < rhs.m_code) { - return true; - } else if (m_message < rhs.m_message) { - return true; - } else if (m_filename < rhs.m_filename) { - return true; - } else if (m_function < rhs.m_function) { - return true; - } else if (m_lineNumber < rhs.m_lineNumber) { - return true; - } else if (m_originatingObject < rhs.m_originatingObject) { - return true; - } else if (m_timestamp < rhs.m_timestamp) { - return true; - } else { - return false; - } -} - -Error::Code Error::GetCode() const { - return m_code; -} - -std::string Error::GetMessage() const { - return m_message; -} - -std::string Error::GetFilename() const { - return m_filename; -} - -std::string Error::GetFunction() const { - return m_function; -} - -int Error::GetLineNumber() const { - return m_lineNumber; -} - -const ErrorBase* Error::GetOriginatingObject() const { - return m_originatingObject; -} - -double Error::GetTimestamp() const { - return m_timestamp; -} - -void Error::Set(Code code, const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber, const ErrorBase* originatingObject) { - bool report = true; - - if (code == m_code && GetTime() - m_timestamp < 1) { - report = false; - } - - m_code = code; - m_message = contextMessage.str(); - m_filename = filename; - m_function = function; - m_lineNumber = lineNumber; - m_originatingObject = originatingObject; - - if (report) { - m_timestamp = GetTime(); - Report(); - } -} - -void Error::Report() { - DriverStation::ReportError( - true, m_code, m_message, - m_function + wpi::Twine(" [") + wpi::sys::path::filename(m_filename) + - wpi::Twine(':') + wpi::Twine(m_lineNumber) + wpi::Twine(']'), - wpi::GetStackTrace(4)); -} - -void Error::Clear() { - m_code = 0; - m_message = ""; - m_filename = ""; - m_function = ""; - m_lineNumber = 0; - m_originatingObject = nullptr; - m_timestamp = 0.0; -} diff --git a/wpilibc/src/main/native/cpp/ErrorBase.cpp b/wpilibc/src/main/native/cpp/ErrorBase.cpp deleted file mode 100644 index e6c3c9c241..0000000000 --- a/wpilibc/src/main/native/cpp/ErrorBase.cpp +++ /dev/null @@ -1,198 +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 "frc/ErrorBase.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "frc/Base.h" - -using namespace frc; - -namespace { -struct GlobalErrors { - wpi::mutex mutex; - std::set errors; - const Error* lastError{nullptr}; - - static GlobalErrors& GetInstance(); - static void Insert(const Error& error); - static void Insert(Error&& error); -}; -} // namespace - -GlobalErrors& GlobalErrors::GetInstance() { - static GlobalErrors inst; - return inst; -} - -void GlobalErrors::Insert(const Error& error) { - GlobalErrors& inst = GetInstance(); - std::scoped_lock lock(inst.mutex); - inst.lastError = &(*inst.errors.insert(error).first); -} - -void GlobalErrors::Insert(Error&& error) { - GlobalErrors& inst = GetInstance(); - std::scoped_lock lock(inst.mutex); - inst.lastError = &(*inst.errors.insert(std::move(error)).first); -} - -ErrorBase::ErrorBase() { - HAL_Initialize(500, 0); -} - -Error& ErrorBase::GetError() { - return m_error; -} - -const Error& ErrorBase::GetError() const { - return m_error; -} - -void ErrorBase::ClearError() const { - m_error.Clear(); -} - -void ErrorBase::SetErrnoError(const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const { - wpi::SmallString<128> buf; - wpi::raw_svector_ostream err(buf); - int errNo = errno; - if (errNo == 0) { - err << "OK: "; - } else { - err << std::strerror(errNo) << " (" << wpi::format_hex(errNo, 10, true) - << "): "; - } - - // Set the current error information for this object. - m_error.Set(-1, err.str() + contextMessage, filename, function, lineNumber, - this); - - // Update the global error if there is not one already set. - GlobalErrors::Insert(m_error); -} - -void ErrorBase::SetImaqError(int success, const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const { - // If there was an error - if (success <= 0) { - // Set the current error information for this object. - m_error.Set(success, wpi::Twine(success) + ": " + contextMessage, filename, - function, lineNumber, this); - - // Update the global error if there is not one already set. - GlobalErrors::Insert(m_error); - } -} - -void ErrorBase::SetError(Error::Code code, const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const { - // If there was an error - if (code != 0) { - // Set the current error information for this object. - m_error.Set(code, contextMessage, filename, function, lineNumber, this); - - // Update the global error if there is not one already set. - GlobalErrors::Insert(m_error); - } -} - -void ErrorBase::SetErrorRange(Error::Code code, int32_t minRange, - int32_t maxRange, int32_t requestedValue, - const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const { - // If there was an error - if (code != 0) { - // Set the current error information for this object. - m_error.Set(code, - contextMessage + ", Minimum Value: " + wpi::Twine(minRange) + - ", MaximumValue: " + wpi::Twine(maxRange) + - ", Requested Value: " + wpi::Twine(requestedValue), - filename, function, lineNumber, this); - - // Update the global error if there is not one already set. - GlobalErrors::Insert(m_error); - } -} - -void ErrorBase::SetWPIError(const wpi::Twine& errorMessage, Error::Code code, - const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const { - // Set the current error information for this object. - m_error.Set(code, errorMessage + ": " + contextMessage, filename, function, - lineNumber, this); - - // Update the global error if there is not one already set. - GlobalErrors::Insert(m_error); -} - -void ErrorBase::CloneError(const ErrorBase& rhs) const { - m_error = rhs.GetError(); -} - -bool ErrorBase::StatusIsFatal() const { - return m_error.GetCode() < 0; -} - -void ErrorBase::SetGlobalError(Error::Code code, - const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) { - // If there was an error - if (code != 0) { - // Set the current error information for this object. - GlobalErrors::Insert( - Error(code, contextMessage, filename, function, lineNumber, nullptr)); - } -} - -void ErrorBase::SetGlobalWPIError(const wpi::Twine& errorMessage, - const wpi::Twine& contextMessage, - wpi::StringRef filename, - wpi::StringRef function, int lineNumber) { - GlobalErrors::Insert(Error(-1, errorMessage + ": " + contextMessage, filename, - function, lineNumber, nullptr)); -} - -Error ErrorBase::GetGlobalError() { - auto& inst = GlobalErrors::GetInstance(); - std::scoped_lock mutex(inst.mutex); - if (!inst.lastError) { - return {}; - } - return *inst.lastError; -} - -std::vector ErrorBase::GetGlobalErrors() { - auto& inst = GlobalErrors::GetInstance(); - std::scoped_lock mutex(inst.mutex); - std::vector rv; - for (auto&& error : inst.errors) { - rv.push_back(error); - } - return rv; -} - -void ErrorBase::ClearGlobalErrors() { - auto& inst = GlobalErrors::GetInstance(); - std::scoped_lock mutex(inst.mutex); - inst.errors.clear(); - inst.lastError = nullptr; -} diff --git a/wpilibc/src/main/native/cpp/Errors.cpp b/wpilibc/src/main/native/cpp/Errors.cpp new file mode 100644 index 0000000000..b432968845 --- /dev/null +++ b/wpilibc/src/main/native/cpp/Errors.cpp @@ -0,0 +1,78 @@ +// 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 "frc/Errors.h" + +#include + +#include +#include +#include +#include +#include + +using namespace frc; + +RuntimeError::RuntimeError(int32_t code, const wpi::Twine& message, + const wpi::Twine& loc, wpi::StringRef stack) + : runtime_error{message.str()}, m_data{std::make_shared()} { + m_data->code = code; + m_data->loc = loc.str(); + m_data->stack = stack; +} + +RuntimeError::RuntimeError(int32_t code, const wpi::Twine& message, + const char* fileName, int lineNumber, + const char* funcName, wpi::StringRef stack) + : RuntimeError{code, message, + funcName + wpi::Twine{" ["} + + wpi::sys::path::filename(fileName) + ":" + + wpi::Twine{lineNumber} + "]", + stack} {} + +void RuntimeError::Report() const { + HAL_SendError(m_data->code < 0, m_data->code, 0, what(), m_data->loc.c_str(), + m_data->stack.c_str(), 1); +} + +const char* frc::GetErrorMessage(int32_t* code) { + using namespace err; + using namespace warn; + switch (*code) { +#define S(label, offset, message) \ + case label: \ + return message; +#include "frc/WPIErrors.mac" +#include "frc/WPIWarnings.mac" +#undef S + default: + return HAL_GetLastError(code); + } +} + +void frc::ReportError(int32_t status, const wpi::Twine& message, + const char* fileName, int lineNumber, + const char* funcName) { + if (status == 0) { + return; + } + const char* statusMessage = GetErrorMessage(&status); + auto stack = wpi::GetStackTrace(2); + wpi::SmallString<128> buf; + HAL_SendError(status < 0, status, 0, + (statusMessage + wpi::Twine{": "} + message) + .toNullTerminatedStringRef(buf) + .data(), + funcName, stack.c_str(), 1); +} + +RuntimeError frc::MakeError(int32_t status, const wpi::Twine& message, + const char* fileName, int lineNumber, + const char* funcName) { + const char* statusMessage = GetErrorMessage(&status); + auto stack = wpi::GetStackTrace(2); + return RuntimeError{status, statusMessage + wpi::Twine{": "} + message, + fileName, lineNumber, + funcName, stack}; +} diff --git a/wpilibc/src/main/native/cpp/GearTooth.cpp b/wpilibc/src/main/native/cpp/GearTooth.cpp deleted file mode 100644 index 59f5397b0b..0000000000 --- a/wpilibc/src/main/native/cpp/GearTooth.cpp +++ /dev/null @@ -1,43 +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 "frc/GearTooth.h" - -#include "frc/smartdashboard/SendableBuilder.h" -#include "frc/smartdashboard/SendableRegistry.h" - -using namespace frc; - -constexpr double GearTooth::kGearToothThreshold; - -GearTooth::GearTooth(int channel, bool directionSensitive) : Counter(channel) { - EnableDirectionSensing(directionSensitive); - SendableRegistry::GetInstance().SetName(this, "GearTooth", channel); -} - -GearTooth::GearTooth(DigitalSource* source, bool directionSensitive) - : Counter(source) { - EnableDirectionSensing(directionSensitive); - SendableRegistry::GetInstance().SetName(this, "GearTooth", - source->GetChannel()); -} - -GearTooth::GearTooth(std::shared_ptr source, - bool directionSensitive) - : Counter(source) { - EnableDirectionSensing(directionSensitive); - SendableRegistry::GetInstance().SetName(this, "GearTooth", - source->GetChannel()); -} - -void GearTooth::EnableDirectionSensing(bool directionSensitive) { - if (directionSensitive) { - SetPulseLengthMode(kGearToothThreshold); - } -} - -void GearTooth::InitSendable(SendableBuilder& builder) { - Counter::InitSendable(builder); - builder.SetSmartDashboardType("Gear Tooth"); -} diff --git a/wpilibc/src/main/native/cpp/GenericHID.cpp b/wpilibc/src/main/native/cpp/GenericHID.cpp index d606b372f8..423fb351ef 100644 --- a/wpilibc/src/main/native/cpp/GenericHID.cpp +++ b/wpilibc/src/main/native/cpp/GenericHID.cpp @@ -7,13 +7,14 @@ #include #include "frc/DriverStation.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" using namespace frc; GenericHID::GenericHID(int port) : m_ds(&DriverStation::GetInstance()) { - if (port >= DriverStation::kJoystickPorts) { - wpi_setWPIError(BadJoystickIndex); + if (port < 0 || port >= DriverStation::kJoystickPorts) { + throw FRC_MakeError(warn::BadJoystickIndex, + "port " + wpi::Twine{port} + "out of range"); } m_port = port; } diff --git a/wpilibc/src/main/native/cpp/GyroBase.cpp b/wpilibc/src/main/native/cpp/GyroBase.cpp deleted file mode 100644 index 9aeb10cb98..0000000000 --- a/wpilibc/src/main/native/cpp/GyroBase.cpp +++ /dev/null @@ -1,27 +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 "frc/GyroBase.h" - -#include "frc/WPIErrors.h" -#include "frc/smartdashboard/SendableBuilder.h" - -using namespace frc; - -double GyroBase::PIDGet() { - switch (GetPIDSourceType()) { - case PIDSourceType::kRate: - return GetRate(); - case PIDSourceType::kDisplacement: - return GetAngle(); - default: - return 0; - } -} - -void GyroBase::InitSendable(SendableBuilder& builder) { - builder.SetSmartDashboardType("Gyro"); - builder.AddDoubleProperty( - "Value", [=]() { return GetAngle(); }, nullptr); -} diff --git a/wpilibc/src/main/native/cpp/I2C.cpp b/wpilibc/src/main/native/cpp/I2C.cpp index df44730801..439471efd4 100644 --- a/wpilibc/src/main/native/cpp/I2C.cpp +++ b/wpilibc/src/main/native/cpp/I2C.cpp @@ -9,7 +9,7 @@ #include #include -#include "frc/WPIErrors.h" +#include "frc/Errors.h" using namespace frc; @@ -17,7 +17,7 @@ I2C::I2C(Port port, int deviceAddress) : m_port(static_cast(port)), m_deviceAddress(deviceAddress) { int32_t status = 0; HAL_InitializeI2C(m_port, &status); - // wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Port " + wpi::Twine{static_cast(port)}); HAL_Report(HALUsageReporting::kResourceType_I2C, deviceAddress); } @@ -31,7 +31,6 @@ bool I2C::Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived, int32_t status = 0; status = HAL_TransactionI2C(m_port, m_deviceAddress, dataToSend, sendSize, dataReceived, receiveSize); - // wpi_setHALError(status); return status < 0; } @@ -56,12 +55,10 @@ bool I2C::WriteBulk(uint8_t* data, int count) { bool I2C::Read(int registerAddress, int count, uint8_t* buffer) { if (count < 1) { - wpi_setWPIErrorWithContext(ParameterOutOfRange, "count"); - return true; + throw FRC_MakeError(err::ParameterOutOfRange, "count " + wpi::Twine{count}); } - if (buffer == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "buffer"); - return true; + if (!buffer) { + throw FRC_MakeError(err::NullParameter, "buffer"); } uint8_t regAddr = registerAddress; return Transaction(®Addr, sizeof(regAddr), buffer, count); @@ -69,12 +66,10 @@ bool I2C::Read(int registerAddress, int count, uint8_t* buffer) { bool I2C::ReadOnly(int count, uint8_t* buffer) { if (count < 1) { - wpi_setWPIErrorWithContext(ParameterOutOfRange, "count"); - return true; + throw FRC_MakeError(err::ParameterOutOfRange, "count " + wpi::Twine{count}); } - if (buffer == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "buffer"); - return true; + if (!buffer) { + throw FRC_MakeError(err::NullParameter, "buffer"); } return HAL_ReadI2C(m_port, m_deviceAddress, buffer, count) < 0; } diff --git a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp index 1dda99dcc5..334fd3c1d3 100644 --- a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp +++ b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp @@ -4,8 +4,8 @@ #include "frc/InterruptableSensorBase.h" +#include "frc/Errors.h" #include "frc/Utility.h" -#include "frc/WPIErrors.h" using namespace frc; @@ -20,15 +20,8 @@ InterruptableSensorBase::~InterruptableSensorBase() { void InterruptableSensorBase::RequestInterrupts( HAL_InterruptHandlerFunction handler, void* param) { - if (StatusIsFatal()) { - return; - } - - wpi_assert(m_interrupt == HAL_kInvalidHandle); + FRC_Assert(m_interrupt == HAL_kInvalidHandle); AllocateInterrupts(false); - if (StatusIsFatal()) { - return; // if allocate failed, out of interrupts - } int32_t status = 0; HAL_RequestInterrupts( @@ -37,19 +30,12 @@ void InterruptableSensorBase::RequestInterrupts( &status); SetUpSourceEdge(true, false); HAL_AttachInterruptHandler(m_interrupt, handler, param, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "AttachInterruptHandler"); } void InterruptableSensorBase::RequestInterrupts(InterruptEventHandler handler) { - if (StatusIsFatal()) { - return; - } - - wpi_assert(m_interrupt == HAL_kInvalidHandle); + FRC_Assert(m_interrupt == HAL_kInvalidHandle); AllocateInterrupts(false); - if (StatusIsFatal()) { - return; // if allocate failed, out of interrupts - } m_interruptHandler = std::make_unique(std::move(handler)); @@ -74,34 +60,24 @@ void InterruptableSensorBase::RequestInterrupts(InterruptEventHandler handler) { (*self)(res); }, m_interruptHandler.get(), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "AttachInterruptHandler"); } void InterruptableSensorBase::RequestInterrupts() { - if (StatusIsFatal()) { - return; - } - - wpi_assert(m_interrupt == HAL_kInvalidHandle); + FRC_Assert(m_interrupt == HAL_kInvalidHandle); AllocateInterrupts(true); - if (StatusIsFatal()) { - return; // if allocate failed, out of interrupts - } int32_t status = 0; HAL_RequestInterrupts( m_interrupt, GetPortHandleForRouting(), static_cast(GetAnalogTriggerTypeForRouting()), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "RequestInterrupts"); SetUpSourceEdge(true, false); } void InterruptableSensorBase::CancelInterrupts() { - if (StatusIsFatal()) { - return; - } - wpi_assert(m_interrupt != HAL_kInvalidHandle); + FRC_Assert(m_interrupt != HAL_kInvalidHandle); int32_t status = 0; HAL_CleanInterrupts(m_interrupt, &status); // Ignore status, as an invalid handle just needs to be ignored. @@ -111,15 +87,12 @@ void InterruptableSensorBase::CancelInterrupts() { InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt( double timeout, bool ignorePrevious) { - if (StatusIsFatal()) { - return InterruptableSensorBase::kTimeout; - } - wpi_assert(m_interrupt != HAL_kInvalidHandle); + FRC_Assert(m_interrupt != HAL_kInvalidHandle); int32_t status = 0; int result; result = HAL_WaitForInterrupt(m_interrupt, timeout, ignorePrevious, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "WaitForInterrupt"); // Rising edge result is the interrupt bit set in the byte 0xFF // Falling edge result is the interrupt bit set in the byte 0xFF00 @@ -131,69 +104,53 @@ InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt( } void InterruptableSensorBase::EnableInterrupts() { - if (StatusIsFatal()) { - return; - } - wpi_assert(m_interrupt != HAL_kInvalidHandle); + FRC_Assert(m_interrupt != HAL_kInvalidHandle); int32_t status = 0; HAL_EnableInterrupts(m_interrupt, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "EnableInterrupts"); } void InterruptableSensorBase::DisableInterrupts() { - if (StatusIsFatal()) { - return; - } - wpi_assert(m_interrupt != HAL_kInvalidHandle); + FRC_Assert(m_interrupt != HAL_kInvalidHandle); int32_t status = 0; HAL_DisableInterrupts(m_interrupt, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "DisableInterrupts"); } double InterruptableSensorBase::ReadRisingTimestamp() { - if (StatusIsFatal()) { - return 0.0; - } - wpi_assert(m_interrupt != HAL_kInvalidHandle); + FRC_Assert(m_interrupt != HAL_kInvalidHandle); int32_t status = 0; int64_t timestamp = HAL_ReadInterruptRisingTimestamp(m_interrupt, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ReadRisingTimestamp"); return timestamp * 1e-6; } double InterruptableSensorBase::ReadFallingTimestamp() { - if (StatusIsFatal()) { - return 0.0; - } - wpi_assert(m_interrupt != HAL_kInvalidHandle); + FRC_Assert(m_interrupt != HAL_kInvalidHandle); int32_t status = 0; int64_t timestamp = HAL_ReadInterruptFallingTimestamp(m_interrupt, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ReadFallingTimestamp"); return timestamp * 1e-6; } void InterruptableSensorBase::SetUpSourceEdge(bool risingEdge, bool fallingEdge) { - if (StatusIsFatal()) { - return; - } if (m_interrupt == HAL_kInvalidHandle) { - wpi_setWPIErrorWithContext( - NullParameter, + throw FRC_MakeError( + err::NullParameter, "You must call RequestInterrupts before SetUpSourceEdge"); - return; } if (m_interrupt != HAL_kInvalidHandle) { int32_t status = 0; HAL_SetInterruptUpSourceEdge(m_interrupt, risingEdge, fallingEdge, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetUpSourceEdge"); } } void InterruptableSensorBase::AllocateInterrupts(bool watcher) { - wpi_assert(m_interrupt == HAL_kInvalidHandle); + FRC_Assert(m_interrupt == HAL_kInvalidHandle); // Expects the calling leaf class to allocate an interrupt index. int32_t status = 0; m_interrupt = HAL_InitializeInterrupts(watcher, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "AllocateInterrupts"); } diff --git a/wpilibc/src/main/native/cpp/IterativeRobot.cpp b/wpilibc/src/main/native/cpp/IterativeRobot.cpp deleted file mode 100644 index ffc4e8e175..0000000000 --- a/wpilibc/src/main/native/cpp/IterativeRobot.cpp +++ /dev/null @@ -1,46 +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 "frc/IterativeRobot.h" - -#include -#include - -#include "frc/DriverStation.h" - -using namespace frc; - -static constexpr auto kPacketPeriod = 0.02_s; - -IterativeRobot::IterativeRobot() : IterativeRobotBase(kPacketPeriod) { - HAL_Report(HALUsageReporting::kResourceType_Framework, - HALUsageReporting::kFramework_Iterative); -} - -void IterativeRobot::StartCompetition() { - RobotInit(); - - if constexpr (IsSimulation()) { - SimulationInit(); - } - - // Tell the DS that the robot is ready to be enabled - HAL_ObserveUserProgramStarting(); - - // Loop forever, calling the appropriate mode-dependent function - while (true) { - // Wait for driver station data so the loop doesn't hog the CPU - DriverStation::GetInstance().WaitForData(); - if (m_exit) { - break; - } - - LoopFunc(); - } -} - -void IterativeRobot::EndCompetition() { - m_exit = true; - DriverStation::GetInstance().WakeupWaitForData(); -} diff --git a/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp b/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp index 91929037b7..b20409b517 100644 --- a/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp +++ b/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp @@ -100,6 +100,10 @@ void IterativeRobotBase::SetNetworkTablesFlushEnabled(bool enabled) { m_ntFlushEnabled = enabled; } +units::second_t IterativeRobotBase::GetPeriod() const { + return m_period; +} + void IterativeRobotBase::LoopFunc() { m_watchdog.Reset(); @@ -108,7 +112,7 @@ void IterativeRobotBase::LoopFunc() { // Call DisabledInit() if we are now just entering disabled mode from // either a different mode or from power-on. if (m_lastMode != Mode::kDisabled) { - LiveWindow::GetInstance()->SetEnabled(false); + LiveWindow::GetInstance().SetEnabled(false); Shuffleboard::DisableActuatorWidgets(); DisabledInit(); m_watchdog.AddEpoch("DisabledInit()"); @@ -122,7 +126,7 @@ void IterativeRobotBase::LoopFunc() { // Call AutonomousInit() if we are now just entering autonomous mode from // either a different mode or from power-on. if (m_lastMode != Mode::kAutonomous) { - LiveWindow::GetInstance()->SetEnabled(false); + LiveWindow::GetInstance().SetEnabled(false); Shuffleboard::DisableActuatorWidgets(); AutonomousInit(); m_watchdog.AddEpoch("AutonomousInit()"); @@ -136,7 +140,7 @@ void IterativeRobotBase::LoopFunc() { // Call TeleopInit() if we are now just entering teleop mode from // either a different mode or from power-on. if (m_lastMode != Mode::kTeleop) { - LiveWindow::GetInstance()->SetEnabled(false); + LiveWindow::GetInstance().SetEnabled(false); Shuffleboard::DisableActuatorWidgets(); TeleopInit(); m_watchdog.AddEpoch("TeleopInit()"); @@ -150,7 +154,7 @@ void IterativeRobotBase::LoopFunc() { // Call TestInit() if we are now just entering test mode from // either a different mode or from power-on. if (m_lastMode != Mode::kTest) { - LiveWindow::GetInstance()->SetEnabled(true); + LiveWindow::GetInstance().SetEnabled(true); Shuffleboard::EnableActuatorWidgets(); TestInit(); m_watchdog.AddEpoch("TestInit()"); @@ -167,7 +171,7 @@ void IterativeRobotBase::LoopFunc() { SmartDashboard::UpdateValues(); m_watchdog.AddEpoch("SmartDashboard::UpdateValues()"); - LiveWindow::GetInstance()->UpdateValues(); + LiveWindow::GetInstance().UpdateValues(); m_watchdog.AddEpoch("LiveWindow::UpdateValues()"); Shuffleboard::Update(); m_watchdog.AddEpoch("Shuffleboard::Update()"); diff --git a/wpilibc/src/main/native/cpp/MotorSafety.cpp b/wpilibc/src/main/native/cpp/MotorSafety.cpp index 1d0a5d3b21..ed76bf1240 100644 --- a/wpilibc/src/main/native/cpp/MotorSafety.cpp +++ b/wpilibc/src/main/native/cpp/MotorSafety.cpp @@ -12,7 +12,7 @@ #include #include "frc/DriverStation.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" using namespace frc; @@ -30,16 +30,13 @@ MotorSafety::~MotorSafety() { } MotorSafety::MotorSafety(MotorSafety&& rhs) - : ErrorBase(std::move(rhs)), - m_expiration(std::move(rhs.m_expiration)), + : m_expiration(std::move(rhs.m_expiration)), m_enabled(std::move(rhs.m_enabled)), m_stopTime(std::move(rhs.m_stopTime)) {} MotorSafety& MotorSafety::operator=(MotorSafety&& rhs) { std::scoped_lock lock(m_thisMutex, rhs.m_thisMutex); - ErrorBase::operator=(std::move(rhs)); - m_expiration = std::move(rhs.m_expiration); m_enabled = std::move(rhs.m_enabled); m_stopTime = std::move(rhs.m_stopTime); @@ -97,7 +94,7 @@ void MotorSafety::Check() { wpi::raw_svector_ostream desc(buf); GetDescription(desc); desc << "... Output not updated often enough."; - wpi_setWPIErrorWithContext(Timeout, desc.str()); + FRC_ReportError(err::Timeout, desc.str()); StopMotor(); } } diff --git a/wpilibc/src/main/native/cpp/Notifier.cpp b/wpilibc/src/main/native/cpp/Notifier.cpp index 72f8a1d08c..c65a68ce2a 100644 --- a/wpilibc/src/main/native/cpp/Notifier.cpp +++ b/wpilibc/src/main/native/cpp/Notifier.cpp @@ -11,20 +11,20 @@ #include #include +#include "frc/Errors.h" #include "frc/Timer.h" #include "frc/Utility.h" -#include "frc/WPIErrors.h" using namespace frc; Notifier::Notifier(std::function handler) { - if (handler == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr"); + if (!handler) { + throw FRC_MakeError(err::NullParameter, "handler"); } m_handler = handler; int32_t status = 0; m_notifier = HAL_InitializeNotifier(&status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "InitializeNotifier"); m_thread = std::thread([=] { for (;;) { @@ -60,13 +60,13 @@ Notifier::Notifier(std::function handler) { } Notifier::Notifier(int priority, std::function handler) { - if (handler == nullptr) { - wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr"); + if (!handler) { + throw FRC_MakeError(err::NullParameter, "handler"); } m_handler = handler; int32_t status = 0; m_notifier = HAL_InitializeNotifier(&status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "InitializeNotifier"); m_thread = std::thread([=] { int32_t status = 0; @@ -107,7 +107,7 @@ Notifier::~Notifier() { // atomically set handle to 0, then clean HAL_NotifierHandle handle = m_notifier.exchange(0); HAL_StopNotifier(handle, &status); - wpi_setHALError(status); + FRC_ReportError(status, "StopNotifier"); // Join the thread to ensure the handler has exited. if (m_thread.joinable()) { @@ -118,8 +118,7 @@ Notifier::~Notifier() { } Notifier::Notifier(Notifier&& rhs) - : ErrorBase(std::move(rhs)), - m_thread(std::move(rhs.m_thread)), + : m_thread(std::move(rhs.m_thread)), m_notifier(rhs.m_notifier.load()), m_handler(std::move(rhs.m_handler)), m_expirationTime(std::move(rhs.m_expirationTime)), @@ -129,8 +128,6 @@ Notifier::Notifier(Notifier&& rhs) } Notifier& Notifier::operator=(Notifier&& rhs) { - ErrorBase::operator=(std::move(rhs)); - m_thread = std::move(rhs.m_thread); m_notifier = rhs.m_notifier.load(); rhs.m_notifier = HAL_kInvalidHandle; @@ -183,7 +180,7 @@ void Notifier::Stop() { m_periodic = false; int32_t status = 0; HAL_CancelNotifierAlarm(m_notifier, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "CancelNotifierAlarm"); } void Notifier::UpdateAlarm(uint64_t triggerTime) { @@ -194,7 +191,7 @@ void Notifier::UpdateAlarm(uint64_t triggerTime) { return; } HAL_UpdateNotifierAlarm(notifier, triggerTime, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "UpdateNotifierAlarm"); } void Notifier::UpdateAlarm() { diff --git a/wpilibc/src/main/native/cpp/PWM.cpp b/wpilibc/src/main/native/cpp/PWM.cpp index 086553b712..b9aa1d8ffa 100644 --- a/wpilibc/src/main/native/cpp/PWM.cpp +++ b/wpilibc/src/main/native/cpp/PWM.cpp @@ -10,141 +10,100 @@ #include #include #include +#include +#include "frc/Errors.h" #include "frc/SensorUtil.h" #include "frc/Utility.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" using namespace frc; -PWM::PWM(int channel) { +PWM::PWM(int channel, bool registerSendable) { if (!SensorUtil::CheckPWMChannel(channel)) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, - "PWM Channel " + wpi::Twine(channel)); + throw FRC_MakeError(err::ChannelIndexOutOfRange, + "PWM Channel " + wpi::Twine{channel}); return; } + auto stack = wpi::GetStackTrace(1); int32_t status = 0; - m_handle = HAL_InitializePWMPort(HAL_GetPort(channel), &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumPWMChannels(), channel); - m_channel = std::numeric_limits::max(); - m_handle = HAL_kInvalidHandle; - return; - } + m_handle = + HAL_InitializePWMPort(HAL_GetPort(channel), stack.c_str(), &status); + FRC_CheckErrorStatus(status, "PWM Channel " + wpi::Twine{channel}); m_channel = channel; HAL_SetPWMDisabled(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetPWMDisabled"); status = 0; HAL_SetPWMEliminateDeadband(m_handle, false, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetPWMEliminateDeadband"); HAL_Report(HALUsageReporting::kResourceType_PWM, channel + 1); - SendableRegistry::GetInstance().AddLW(this, "PWM", channel); - - SetSafetyEnabled(false); + if (registerSendable) { + SendableRegistry::GetInstance().AddLW(this, "PWM", channel); + } } PWM::~PWM() { int32_t status = 0; HAL_SetPWMDisabled(m_handle, &status); - wpi_setHALError(status); + FRC_ReportError(status, "SetPWMDisabled"); HAL_FreePWMPort(m_handle, &status); - wpi_setHALError(status); -} - -void PWM::StopMotor() { - SetDisabled(); -} - -void PWM::GetDescription(wpi::raw_ostream& desc) const { - desc << "PWM " << GetChannel(); + FRC_ReportError(status, "FreePWM"); } void PWM::SetRaw(uint16_t value) { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; HAL_SetPWMRaw(m_handle, value, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetRaw"); } uint16_t PWM::GetRaw() const { - if (StatusIsFatal()) { - return 0; - } - int32_t status = 0; uint16_t value = HAL_GetPWMRaw(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetRaw"); return value; } void PWM::SetPosition(double pos) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetPWMPosition(m_handle, pos, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetPosition"); } double PWM::GetPosition() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double position = HAL_GetPWMPosition(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetPosition"); return position; } void PWM::SetSpeed(double speed) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetPWMSpeed(m_handle, speed, &status); - wpi_setHALError(status); - - Feed(); + FRC_CheckErrorStatus(status, "SetSpeed"); } double PWM::GetSpeed() const { - if (StatusIsFatal()) { - return 0.0; - } int32_t status = 0; double speed = HAL_GetPWMSpeed(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetSpeed"); return speed; } void PWM::SetDisabled() { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; - HAL_SetPWMDisabled(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetDisabled"); } void PWM::SetPeriodMultiplier(PeriodMultiplier mult) { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; switch (mult) { @@ -163,49 +122,35 @@ void PWM::SetPeriodMultiplier(PeriodMultiplier mult) { wpi_assert(false); } - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetPeriodMultiplier"); } void PWM::SetZeroLatch() { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; - HAL_LatchPWMZero(m_handle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetZeroLatch"); } void PWM::EnableDeadbandElimination(bool eliminateDeadband) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetPWMEliminateDeadband(m_handle, eliminateDeadband, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "EnableDeadbandElimination"); } void PWM::SetBounds(double max, double deadbandMax, double center, double deadbandMin, double min) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetPWMConfig(m_handle, max, deadbandMax, center, deadbandMin, min, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetBounds"); } void PWM::SetRawBounds(int max, int deadbandMax, int center, int deadbandMin, int min) { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetPWMConfigRaw(m_handle, max, deadbandMax, center, deadbandMin, min, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetRawBounds"); } void PWM::GetRawBounds(int* max, int* deadbandMax, int* center, @@ -213,7 +158,7 @@ void PWM::GetRawBounds(int* max, int* deadbandMax, int* center, int32_t status = 0; HAL_GetPWMConfigRaw(m_handle, max, deadbandMax, center, deadbandMin, min, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetRawBounds"); } int PWM::GetChannel() const { @@ -223,8 +168,7 @@ int PWM::GetChannel() const { void PWM::InitSendable(SendableBuilder& builder) { builder.SetSmartDashboardType("PWM"); builder.SetActuator(true); - builder.SetSafeState([=]() { SetDisabled(); }); + builder.SetSafeState([=] { SetDisabled(); }); builder.AddDoubleProperty( - "Value", [=]() { return GetRaw(); }, - [=](double value) { SetRaw(value); }); + "Value", [=] { return GetRaw(); }, [=](double value) { SetRaw(value); }); } diff --git a/wpilibc/src/main/native/cpp/PWMSpeedController.cpp b/wpilibc/src/main/native/cpp/PWMSpeedController.cpp deleted file mode 100644 index 413bf97f7b..0000000000 --- a/wpilibc/src/main/native/cpp/PWMSpeedController.cpp +++ /dev/null @@ -1,48 +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 "frc/PWMSpeedController.h" - -#include "frc/smartdashboard/SendableBuilder.h" - -using namespace frc; - -void PWMSpeedController::Set(double speed) { - SetSpeed(m_isInverted ? -speed : speed); -} - -double PWMSpeedController::Get() const { - return GetSpeed() * (m_isInverted ? -1.0 : 1.0); -} - -void PWMSpeedController::SetInverted(bool isInverted) { - m_isInverted = isInverted; -} - -bool PWMSpeedController::GetInverted() const { - return m_isInverted; -} - -void PWMSpeedController::Disable() { - SetDisabled(); -} - -void PWMSpeedController::StopMotor() { - PWM::StopMotor(); -} - -void PWMSpeedController::PIDWrite(double output) { - Set(output); -} - -PWMSpeedController::PWMSpeedController(int channel) : PWM(channel) {} - -void PWMSpeedController::InitSendable(SendableBuilder& builder) { - builder.SetSmartDashboardType("Speed Controller"); - builder.SetActuator(true); - builder.SetSafeState([=]() { SetDisabled(); }); - builder.AddDoubleProperty( - "Value", [=]() { return GetSpeed(); }, - [=](double value) { SetSpeed(value); }); -} diff --git a/wpilibc/src/main/native/cpp/PWMTalonFX.cpp b/wpilibc/src/main/native/cpp/PWMTalonFX.cpp deleted file mode 100644 index 3ab574da91..0000000000 --- a/wpilibc/src/main/native/cpp/PWMTalonFX.cpp +++ /dev/null @@ -1,21 +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 "frc/PWMTalonFX.h" - -#include - -#include "frc/smartdashboard/SendableRegistry.h" - -using namespace frc; - -PWMTalonFX::PWMTalonFX(int channel) : PWMSpeedController(channel) { - SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); - - HAL_Report(HALUsageReporting::kResourceType_TalonFX, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "PWMTalonFX", GetChannel()); -} diff --git a/wpilibc/src/main/native/cpp/PWMTalonSRX.cpp b/wpilibc/src/main/native/cpp/PWMTalonSRX.cpp deleted file mode 100644 index e305015e39..0000000000 --- a/wpilibc/src/main/native/cpp/PWMTalonSRX.cpp +++ /dev/null @@ -1,21 +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 "frc/PWMTalonSRX.h" - -#include - -#include "frc/smartdashboard/SendableRegistry.h" - -using namespace frc; - -PWMTalonSRX::PWMTalonSRX(int channel) : PWMSpeedController(channel) { - SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); - - HAL_Report(HALUsageReporting::kResourceType_PWMTalonSRX, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "PWMTalonSRX", GetChannel()); -} diff --git a/wpilibc/src/main/native/cpp/PWMVictorSPX.cpp b/wpilibc/src/main/native/cpp/PWMVictorSPX.cpp deleted file mode 100644 index f34a045382..0000000000 --- a/wpilibc/src/main/native/cpp/PWMVictorSPX.cpp +++ /dev/null @@ -1,21 +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 "frc/PWMVictorSPX.h" - -#include - -#include "frc/smartdashboard/SendableRegistry.h" - -using namespace frc; - -PWMVictorSPX::PWMVictorSPX(int channel) : PWMSpeedController(channel) { - SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); - - HAL_Report(HALUsageReporting::kResourceType_PWMVictorSPX, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "PWMVictorSPX", GetChannel()); -} diff --git a/wpilibc/src/main/native/cpp/PowerDistributionPanel.cpp b/wpilibc/src/main/native/cpp/PowerDistributionPanel.cpp index b955f7f2ae..bb95c7bf0c 100644 --- a/wpilibc/src/main/native/cpp/PowerDistributionPanel.cpp +++ b/wpilibc/src/main/native/cpp/PowerDistributionPanel.cpp @@ -7,11 +7,9 @@ #include #include #include -#include -#include +#include "frc/Errors.h" #include "frc/SensorUtil.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -25,10 +23,7 @@ PowerDistributionPanel::PowerDistributionPanel() : PowerDistributionPanel(0) {} PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) { int32_t status = 0; m_handle = HAL_InitializePDP(module, &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumPDPModules(), module); - return; - } + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module}); HAL_Report(HALUsageReporting::kResourceType_PDP, module + 1); SendableRegistry::GetInstance().AddLW(this, "PowerDistributionPanel", module); @@ -36,25 +31,15 @@ PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) { double PowerDistributionPanel::GetVoltage() const { int32_t status = 0; - double voltage = HAL_GetPDPVoltage(m_handle, &status); - - if (status) { - wpi_setWPIErrorWithContext(Timeout, ""); - } - + FRC_CheckErrorStatus(status, "GetVoltage"); return voltage; } double PowerDistributionPanel::GetTemperature() const { int32_t status = 0; - double temperature = HAL_GetPDPTemperature(m_handle, &status); - - if (status) { - wpi_setWPIErrorWithContext(Timeout, ""); - } - + FRC_CheckErrorStatus(status, "GetTemperature"); return temperature; } @@ -62,75 +47,48 @@ double PowerDistributionPanel::GetCurrent(int channel) const { int32_t status = 0; if (!SensorUtil::CheckPDPChannel(channel)) { - wpi::SmallString<32> str; - wpi::raw_svector_ostream buf(str); - buf << "PDP Channel " << channel; - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); + FRC_ReportError(err::ChannelIndexOutOfRange, + "Channel " + wpi::Twine{channel}); + return 0; } double current = HAL_GetPDPChannelCurrent(m_handle, channel, &status); - - if (status) { - wpi_setWPIErrorWithContext(Timeout, ""); - } + FRC_CheckErrorStatus(status, "Channel " + wpi::Twine{channel}); return current; } double PowerDistributionPanel::GetTotalCurrent() const { int32_t status = 0; - double current = HAL_GetPDPTotalCurrent(m_handle, &status); - - if (status) { - wpi_setWPIErrorWithContext(Timeout, ""); - } - + FRC_CheckErrorStatus(status, "GetTotalCurrent"); return current; } double PowerDistributionPanel::GetTotalPower() const { int32_t status = 0; - double power = HAL_GetPDPTotalPower(m_handle, &status); - - if (status) { - wpi_setWPIErrorWithContext(Timeout, ""); - } - + FRC_CheckErrorStatus(status, "GetTotalPower"); return power; } double PowerDistributionPanel::GetTotalEnergy() const { int32_t status = 0; - double energy = HAL_GetPDPTotalEnergy(m_handle, &status); - - if (status) { - wpi_setWPIErrorWithContext(Timeout, ""); - } - + FRC_CheckErrorStatus(status, "GetTotalEnergy"); return energy; } void PowerDistributionPanel::ResetTotalEnergy() { int32_t status = 0; - HAL_ResetPDPTotalEnergy(m_handle, &status); - - if (status) { - wpi_setWPIErrorWithContext(Timeout, ""); - } + FRC_CheckErrorStatus(status, "ResetTotalEnergy"); } void PowerDistributionPanel::ClearStickyFaults() { int32_t status = 0; - HAL_ClearPDPStickyFaults(m_handle, &status); - - if (status) { - wpi_setWPIErrorWithContext(Timeout, ""); - } + FRC_CheckErrorStatus(status, "ClearStickyFaults"); } int PowerDistributionPanel::GetModule() const { diff --git a/wpilibc/src/main/native/cpp/Preferences.cpp b/wpilibc/src/main/native/cpp/Preferences.cpp index b221d5af10..c80e966ca7 100644 --- a/wpilibc/src/main/native/cpp/Preferences.cpp +++ b/wpilibc/src/main/native/cpp/Preferences.cpp @@ -10,16 +10,14 @@ #include #include -#include "frc/WPIErrors.h" - using namespace frc; // The Preferences table name static wpi::StringRef kTableName{"Preferences"}; -Preferences* Preferences::GetInstance() { +Preferences& Preferences::GetInstance() { static Preferences instance; - return &instance; + return instance; } std::vector Preferences::GetKeys() { @@ -51,67 +49,91 @@ int64_t Preferences::GetLong(wpi::StringRef key, int64_t defaultValue) { return static_cast(m_table->GetNumber(key, defaultValue)); } -void Preferences::PutString(wpi::StringRef key, wpi::StringRef value) { +void Preferences::SetString(wpi::StringRef key, wpi::StringRef value) { auto entry = m_table->GetEntry(key); entry.SetString(value); entry.SetPersistent(); } +void Preferences::PutString(wpi::StringRef key, wpi::StringRef value) { + SetString(key, value); +} + void Preferences::InitString(wpi::StringRef key, wpi::StringRef value) { auto entry = m_table->GetEntry(key); entry.SetDefaultString(value); } -void Preferences::PutInt(wpi::StringRef key, int value) { +void Preferences::SetInt(wpi::StringRef key, int value) { auto entry = m_table->GetEntry(key); entry.SetDouble(value); entry.SetPersistent(); } +void Preferences::PutInt(wpi::StringRef key, int value) { + SetInt(key, value); +} + void Preferences::InitInt(wpi::StringRef key, int value) { auto entry = m_table->GetEntry(key); entry.SetDefaultDouble(value); } -void Preferences::PutDouble(wpi::StringRef key, double value) { +void Preferences::SetDouble(wpi::StringRef key, double value) { auto entry = m_table->GetEntry(key); entry.SetDouble(value); entry.SetPersistent(); } +void Preferences::PutDouble(wpi::StringRef key, double value) { + SetDouble(key, value); +} + void Preferences::InitDouble(wpi::StringRef key, double value) { auto entry = m_table->GetEntry(key); entry.SetDefaultDouble(value); } -void Preferences::PutFloat(wpi::StringRef key, float value) { +void Preferences::SetFloat(wpi::StringRef key, float value) { auto entry = m_table->GetEntry(key); entry.SetDouble(value); entry.SetPersistent(); } +void Preferences::PutFloat(wpi::StringRef key, float value) { + SetFloat(key, value); +} + void Preferences::InitFloat(wpi::StringRef key, float value) { auto entry = m_table->GetEntry(key); entry.SetDefaultDouble(value); } -void Preferences::PutBoolean(wpi::StringRef key, bool value) { +void Preferences::SetBoolean(wpi::StringRef key, bool value) { auto entry = m_table->GetEntry(key); entry.SetBoolean(value); entry.SetPersistent(); } +void Preferences::PutBoolean(wpi::StringRef key, bool value) { + SetBoolean(key, value); +} + void Preferences::InitBoolean(wpi::StringRef key, bool value) { auto entry = m_table->GetEntry(key); entry.SetDefaultBoolean(value); } -void Preferences::PutLong(wpi::StringRef key, int64_t value) { +void Preferences::SetLong(wpi::StringRef key, int64_t value) { auto entry = m_table->GetEntry(key); entry.SetDouble(value); entry.SetPersistent(); } +void Preferences::PutLong(wpi::StringRef key, int64_t value) { + SetLong(key, value); +} + void Preferences::InitLong(wpi::StringRef key, int64_t value) { auto entry = m_table->GetEntry(key); entry.SetDefaultDouble(value); @@ -143,3 +165,5 @@ Preferences::Preferences() NT_NOTIFY_NEW | NT_NOTIFY_IMMEDIATE); HAL_Report(HALUsageReporting::kResourceType_Preferences, 0); } + +Preferences::~Preferences() = default; diff --git a/wpilibc/src/main/native/cpp/Relay.cpp b/wpilibc/src/main/native/cpp/Relay.cpp index 9561c6b131..59474c83a8 100644 --- a/wpilibc/src/main/native/cpp/Relay.cpp +++ b/wpilibc/src/main/native/cpp/Relay.cpp @@ -10,10 +10,11 @@ #include #include #include +#include #include +#include "frc/Errors.h" #include "frc/SensorUtil.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -22,8 +23,8 @@ using namespace frc; Relay::Relay(int channel, Relay::Direction direction) : m_channel(channel), m_direction(direction) { if (!SensorUtil::CheckRelayChannel(m_channel)) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, - "Relay Channel " + wpi::Twine(m_channel)); + throw FRC_MakeError(err::ChannelIndexOutOfRange, + "Relay Channel " + wpi::Twine{m_channel}); return; } @@ -31,46 +32,29 @@ Relay::Relay(int channel, Relay::Direction direction) if (m_direction == kBothDirections || m_direction == kForwardOnly) { int32_t status = 0; - m_forwardHandle = HAL_InitializeRelayPort(portHandle, true, &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumRelayChannels(), channel); - m_forwardHandle = HAL_kInvalidHandle; - m_reverseHandle = HAL_kInvalidHandle; - return; - } + std::string stackTrace = wpi::GetStackTrace(1); + m_forwardHandle = + HAL_InitializeRelayPort(portHandle, true, stackTrace.c_str(), &status); + FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel}); HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 1); } if (m_direction == kBothDirections || m_direction == kReverseOnly) { int32_t status = 0; - m_reverseHandle = HAL_InitializeRelayPort(portHandle, false, &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumRelayChannels(), channel); - m_forwardHandle = HAL_kInvalidHandle; - m_reverseHandle = HAL_kInvalidHandle; - return; - } - + std::string stackTrace = wpi::GetStackTrace(1); + m_reverseHandle = + HAL_InitializeRelayPort(portHandle, false, stackTrace.c_str(), &status); + FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel}); HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 128); } int32_t status = 0; if (m_forwardHandle != HAL_kInvalidHandle) { HAL_SetRelay(m_forwardHandle, false, &status); - if (status != 0) { - wpi_setHALError(status); - m_forwardHandle = HAL_kInvalidHandle; - m_reverseHandle = HAL_kInvalidHandle; - return; - } + FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel}); } if (m_reverseHandle != HAL_kInvalidHandle) { HAL_SetRelay(m_reverseHandle, false, &status); - if (status != 0) { - wpi_setHALError(status); - m_forwardHandle = HAL_kInvalidHandle; - m_reverseHandle = HAL_kInvalidHandle; - return; - } + FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel}); } SendableRegistry::GetInstance().AddLW(this, "Relay", m_channel); @@ -90,10 +74,6 @@ Relay::~Relay() { } void Relay::Set(Relay::Value value) { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; switch (value) { @@ -115,7 +95,7 @@ void Relay::Set(Relay::Value value) { break; case kForward: if (m_direction == kReverseOnly) { - wpi_setWPIError(IncompatibleMode); + FRC_ReportError(err::IncompatibleMode, "setting forward"); break; } if (m_direction == kBothDirections || m_direction == kForwardOnly) { @@ -127,7 +107,7 @@ void Relay::Set(Relay::Value value) { break; case kReverse: if (m_direction == kForwardOnly) { - wpi_setWPIError(IncompatibleMode); + FRC_ReportError(err::IncompatibleMode, "setting reverse"); break; } if (m_direction == kBothDirections) { @@ -139,7 +119,7 @@ void Relay::Set(Relay::Value value) { break; } - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Set"); } Relay::Value Relay::Get() const { @@ -174,7 +154,7 @@ Relay::Value Relay::Get() const { } } - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Get"); return value; } diff --git a/wpilibc/src/main/native/cpp/Resource.cpp b/wpilibc/src/main/native/cpp/Resource.cpp index dd16112d98..e41a43c778 100644 --- a/wpilibc/src/main/native/cpp/Resource.cpp +++ b/wpilibc/src/main/native/cpp/Resource.cpp @@ -4,8 +4,7 @@ #include "frc/Resource.h" -#include "frc/ErrorBase.h" -#include "frc/WPIErrors.h" +#include "frc/Errors.h" using namespace frc; @@ -31,19 +30,16 @@ uint32_t Resource::Allocate(const std::string& resourceDesc) { return i; } } - wpi_setWPIErrorWithContext(NoAvailableResources, resourceDesc); - return std::numeric_limits::max(); + throw FRC_MakeError(err::NoAvailableResources, resourceDesc); } uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) { std::scoped_lock lock(m_allocateMutex); if (index >= m_isAllocated.size()) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc); - return std::numeric_limits::max(); + throw FRC_MakeError(err::ChannelIndexOutOfRange, resourceDesc); } if (m_isAllocated[index]) { - wpi_setWPIErrorWithContext(ResourceAlreadyAllocated, resourceDesc); - return std::numeric_limits::max(); + throw FRC_MakeError(err::ResourceAlreadyAllocated, resourceDesc); } m_isAllocated[index] = true; return index; @@ -55,12 +51,10 @@ void Resource::Free(uint32_t index) { return; } if (index >= m_isAllocated.size()) { - wpi_setWPIError(NotAllocated); - return; + throw FRC_MakeError(err::NotAllocated, "index " + wpi::Twine{index}); } if (!m_isAllocated[index]) { - wpi_setWPIError(NotAllocated); - return; + throw FRC_MakeError(err::NotAllocated, "index " + wpi::Twine{index}); } m_isAllocated[index] = false; } diff --git a/wpilibc/src/main/native/cpp/RobotController.cpp b/wpilibc/src/main/native/cpp/RobotController.cpp index ac49cfa225..88da69b7d0 100644 --- a/wpilibc/src/main/native/cpp/RobotController.cpp +++ b/wpilibc/src/main/native/cpp/RobotController.cpp @@ -8,156 +8,154 @@ #include #include -#include "frc/ErrorBase.h" +#include "frc/Errors.h" using namespace frc; int RobotController::GetFPGAVersion() { int32_t status = 0; int version = HAL_GetFPGAVersion(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetFPGAVersion"); return version; } int64_t RobotController::GetFPGARevision() { int32_t status = 0; int64_t revision = HAL_GetFPGARevision(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetFPGARevision"); return revision; } uint64_t RobotController::GetFPGATime() { int32_t status = 0; uint64_t time = HAL_GetFPGATime(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetFPGATime"); return time; } bool RobotController::GetUserButton() { int32_t status = 0; - bool value = HAL_GetFPGAButton(&status); - wpi_setGlobalError(status); - + FRC_CheckErrorStatus(status, "GetUserButton"); return value; } units::volt_t RobotController::GetBatteryVoltage() { int32_t status = 0; double retVal = HAL_GetVinVoltage(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetBatteryVoltage"); return units::volt_t{retVal}; } bool RobotController::IsSysActive() { int32_t status = 0; bool retVal = HAL_GetSystemActive(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "IsSysActive"); return retVal; } bool RobotController::IsBrownedOut() { int32_t status = 0; bool retVal = HAL_GetBrownedOut(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "IsBrownedOut"); return retVal; } double RobotController::GetInputVoltage() { int32_t status = 0; double retVal = HAL_GetVinVoltage(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetInputVoltage"); return retVal; } double RobotController::GetInputCurrent() { int32_t status = 0; double retVal = HAL_GetVinCurrent(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetInputCurrent"); return retVal; } double RobotController::GetVoltage3V3() { int32_t status = 0; double retVal = HAL_GetUserVoltage3V3(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetVoltage3V3"); return retVal; } double RobotController::GetCurrent3V3() { int32_t status = 0; double retVal = HAL_GetUserCurrent3V3(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetCurrent3V3"); return retVal; } bool RobotController::GetEnabled3V3() { int32_t status = 0; bool retVal = HAL_GetUserActive3V3(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetEnabled3V3"); return retVal; } int RobotController::GetFaultCount3V3() { int32_t status = 0; int retVal = HAL_GetUserCurrentFaults3V3(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetFaultCount3V3"); return retVal; } double RobotController::GetVoltage5V() { int32_t status = 0; double retVal = HAL_GetUserVoltage5V(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetVoltage5V"); return retVal; } double RobotController::GetCurrent5V() { int32_t status = 0; double retVal = HAL_GetUserCurrent5V(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetCurrent5V"); return retVal; } bool RobotController::GetEnabled5V() { int32_t status = 0; bool retVal = HAL_GetUserActive5V(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetEnabled5V"); return retVal; } int RobotController::GetFaultCount5V() { int32_t status = 0; int retVal = HAL_GetUserCurrentFaults5V(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetFaultCount5V"); return retVal; } double RobotController::GetVoltage6V() { int32_t status = 0; double retVal = HAL_GetUserVoltage6V(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetVoltage6V"); return retVal; } double RobotController::GetCurrent6V() { int32_t status = 0; double retVal = HAL_GetUserCurrent6V(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetCurrent6V"); return retVal; } bool RobotController::GetEnabled6V() { int32_t status = 0; bool retVal = HAL_GetUserActive6V(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetEnabled6V"); return retVal; } int RobotController::GetFaultCount6V() { int32_t status = 0; int retVal = HAL_GetUserCurrentFaults6V(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetFaultCount6V"); return retVal; } @@ -170,10 +168,7 @@ CANStatus RobotController::GetCANStatus() { uint32_t transmitErrorCount = 0; HAL_CAN_GetCANStatus(&percentBusUtilization, &busOffCount, &txFullCount, &receiveErrorCount, &transmitErrorCount, &status); - if (status != 0) { - wpi_setGlobalHALError(status); - return {}; - } + FRC_CheckErrorStatus(status, "GetCANStatus"); return {percentBusUtilization, static_cast(busOffCount), static_cast(txFullCount), static_cast(receiveErrorCount), static_cast(transmitErrorCount)}; diff --git a/wpilibc/src/main/native/cpp/RobotDrive.cpp b/wpilibc/src/main/native/cpp/RobotDrive.cpp deleted file mode 100644 index 8293282873..0000000000 --- a/wpilibc/src/main/native/cpp/RobotDrive.cpp +++ /dev/null @@ -1,444 +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 "frc/RobotDrive.h" - -#include -#include - -#include - -#include "frc/GenericHID.h" -#include "frc/Joystick.h" -#include "frc/Talon.h" -#include "frc/Utility.h" -#include "frc/WPIErrors.h" - -using namespace frc; - -static std::shared_ptr make_shared_nodelete( - SpeedController* ptr) { - return std::shared_ptr(ptr, NullDeleter()); -} - -RobotDrive::RobotDrive(int leftMotorChannel, int rightMotorChannel) { - InitRobotDrive(); - m_rearLeftMotor = std::make_shared(leftMotorChannel); - m_rearRightMotor = std::make_shared(rightMotorChannel); - SetLeftRightMotorOutputs(0.0, 0.0); -} - -RobotDrive::RobotDrive(int frontLeftMotor, int rearLeftMotor, - int frontRightMotor, int rearRightMotor) { - InitRobotDrive(); - m_rearLeftMotor = std::make_shared(rearLeftMotor); - m_rearRightMotor = std::make_shared(rearRightMotor); - m_frontLeftMotor = std::make_shared(frontLeftMotor); - m_frontRightMotor = std::make_shared(frontRightMotor); - SetLeftRightMotorOutputs(0.0, 0.0); -} - -RobotDrive::RobotDrive(SpeedController* leftMotor, - SpeedController* rightMotor) { - InitRobotDrive(); - if (leftMotor == nullptr || rightMotor == nullptr) { - wpi_setWPIError(NullParameter); - m_rearLeftMotor = m_rearRightMotor = nullptr; - return; - } - m_rearLeftMotor = make_shared_nodelete(leftMotor); - m_rearRightMotor = make_shared_nodelete(rightMotor); -} - -RobotDrive::RobotDrive(SpeedController& leftMotor, - SpeedController& rightMotor) { - InitRobotDrive(); - m_rearLeftMotor = make_shared_nodelete(&leftMotor); - m_rearRightMotor = make_shared_nodelete(&rightMotor); -} - -RobotDrive::RobotDrive(std::shared_ptr leftMotor, - std::shared_ptr rightMotor) { - InitRobotDrive(); - if (leftMotor == nullptr || rightMotor == nullptr) { - wpi_setWPIError(NullParameter); - m_rearLeftMotor = m_rearRightMotor = nullptr; - return; - } - m_rearLeftMotor = leftMotor; - m_rearRightMotor = rightMotor; -} - -RobotDrive::RobotDrive(SpeedController* frontLeftMotor, - SpeedController* rearLeftMotor, - SpeedController* frontRightMotor, - SpeedController* rearRightMotor) { - InitRobotDrive(); - if (frontLeftMotor == nullptr || rearLeftMotor == nullptr || - frontRightMotor == nullptr || rearRightMotor == nullptr) { - wpi_setWPIError(NullParameter); - return; - } - m_frontLeftMotor = make_shared_nodelete(frontLeftMotor); - m_rearLeftMotor = make_shared_nodelete(rearLeftMotor); - m_frontRightMotor = make_shared_nodelete(frontRightMotor); - m_rearRightMotor = make_shared_nodelete(rearRightMotor); -} - -RobotDrive::RobotDrive(SpeedController& frontLeftMotor, - SpeedController& rearLeftMotor, - SpeedController& frontRightMotor, - SpeedController& rearRightMotor) { - InitRobotDrive(); - m_frontLeftMotor = make_shared_nodelete(&frontLeftMotor); - m_rearLeftMotor = make_shared_nodelete(&rearLeftMotor); - m_frontRightMotor = make_shared_nodelete(&frontRightMotor); - m_rearRightMotor = make_shared_nodelete(&rearRightMotor); -} - -RobotDrive::RobotDrive(std::shared_ptr frontLeftMotor, - std::shared_ptr rearLeftMotor, - std::shared_ptr frontRightMotor, - std::shared_ptr rearRightMotor) { - InitRobotDrive(); - if (frontLeftMotor == nullptr || rearLeftMotor == nullptr || - frontRightMotor == nullptr || rearRightMotor == nullptr) { - wpi_setWPIError(NullParameter); - return; - } - m_frontLeftMotor = frontLeftMotor; - m_rearLeftMotor = rearLeftMotor; - m_frontRightMotor = frontRightMotor; - m_rearRightMotor = rearRightMotor; -} - -void RobotDrive::Drive(double outputMagnitude, double curve) { - double leftOutput, rightOutput; - static bool reported = false; - if (!reported) { - HAL_Report(HALUsageReporting::kResourceType_RobotDrive, - HALUsageReporting::kRobotDrive_ArcadeRatioCurve, GetNumMotors()); - reported = true; - } - - if (curve < 0) { - double value = std::log(-curve); - double ratio = (value - m_sensitivity) / (value + m_sensitivity); - if (ratio == 0) { - ratio = 0.0000000001; - } - leftOutput = outputMagnitude / ratio; - rightOutput = outputMagnitude; - } else if (curve > 0) { - double value = std::log(curve); - double ratio = (value - m_sensitivity) / (value + m_sensitivity); - if (ratio == 0) { - ratio = 0.0000000001; - } - leftOutput = outputMagnitude; - rightOutput = outputMagnitude / ratio; - } else { - leftOutput = outputMagnitude; - rightOutput = outputMagnitude; - } - SetLeftRightMotorOutputs(leftOutput, rightOutput); -} - -void RobotDrive::TankDrive(GenericHID* leftStick, GenericHID* rightStick, - bool squaredInputs) { - if (leftStick == nullptr || rightStick == nullptr) { - wpi_setWPIError(NullParameter); - return; - } - TankDrive(leftStick->GetY(), rightStick->GetY(), squaredInputs); -} - -void RobotDrive::TankDrive(GenericHID& leftStick, GenericHID& rightStick, - bool squaredInputs) { - TankDrive(leftStick.GetY(), rightStick.GetY(), squaredInputs); -} - -void RobotDrive::TankDrive(GenericHID* leftStick, int leftAxis, - GenericHID* rightStick, int rightAxis, - bool squaredInputs) { - if (leftStick == nullptr || rightStick == nullptr) { - wpi_setWPIError(NullParameter); - return; - } - TankDrive(leftStick->GetRawAxis(leftAxis), rightStick->GetRawAxis(rightAxis), - squaredInputs); -} - -void RobotDrive::TankDrive(GenericHID& leftStick, int leftAxis, - GenericHID& rightStick, int rightAxis, - bool squaredInputs) { - TankDrive(leftStick.GetRawAxis(leftAxis), rightStick.GetRawAxis(rightAxis), - squaredInputs); -} - -void RobotDrive::TankDrive(double leftValue, double rightValue, - bool squaredInputs) { - static bool reported = false; - if (!reported) { - HAL_Report(HALUsageReporting::kResourceType_RobotDrive, - HALUsageReporting::kRobotDrive_Tank, GetNumMotors()); - reported = true; - } - - leftValue = Limit(leftValue); - rightValue = Limit(rightValue); - - // square the inputs (while preserving the sign) to increase fine control - // while permitting full power - if (squaredInputs) { - leftValue = std::copysign(leftValue * leftValue, leftValue); - rightValue = std::copysign(rightValue * rightValue, rightValue); - } - - SetLeftRightMotorOutputs(leftValue, rightValue); -} - -void RobotDrive::ArcadeDrive(GenericHID* stick, bool squaredInputs) { - // simply call the full-featured ArcadeDrive with the appropriate values - ArcadeDrive(stick->GetY(), stick->GetX(), squaredInputs); -} - -void RobotDrive::ArcadeDrive(GenericHID& stick, bool squaredInputs) { - // simply call the full-featured ArcadeDrive with the appropriate values - ArcadeDrive(stick.GetY(), stick.GetX(), squaredInputs); -} - -void RobotDrive::ArcadeDrive(GenericHID* moveStick, int moveAxis, - GenericHID* rotateStick, int rotateAxis, - bool squaredInputs) { - double moveValue = moveStick->GetRawAxis(moveAxis); - double rotateValue = rotateStick->GetRawAxis(rotateAxis); - - ArcadeDrive(moveValue, rotateValue, squaredInputs); -} - -void RobotDrive::ArcadeDrive(GenericHID& moveStick, int moveAxis, - GenericHID& rotateStick, int rotateAxis, - bool squaredInputs) { - double moveValue = moveStick.GetRawAxis(moveAxis); - double rotateValue = rotateStick.GetRawAxis(rotateAxis); - - ArcadeDrive(moveValue, rotateValue, squaredInputs); -} - -void RobotDrive::ArcadeDrive(double moveValue, double rotateValue, - bool squaredInputs) { - static bool reported = false; - if (!reported) { - HAL_Report(HALUsageReporting::kResourceType_RobotDrive, - HALUsageReporting::kRobotDrive_ArcadeStandard, GetNumMotors()); - reported = true; - } - - // local variables to hold the computed PWM values for the motors - double leftMotorOutput; - double rightMotorOutput; - - moveValue = Limit(moveValue); - rotateValue = Limit(rotateValue); - - // square the inputs (while preserving the sign) to increase fine control - // while permitting full power - if (squaredInputs) { - moveValue = std::copysign(moveValue * moveValue, moveValue); - rotateValue = std::copysign(rotateValue * rotateValue, rotateValue); - } - - if (moveValue > 0.0) { - if (rotateValue > 0.0) { - leftMotorOutput = moveValue - rotateValue; - rightMotorOutput = std::max(moveValue, rotateValue); - } else { - leftMotorOutput = std::max(moveValue, -rotateValue); - rightMotorOutput = moveValue + rotateValue; - } - } else { - if (rotateValue > 0.0) { - leftMotorOutput = -std::max(-moveValue, rotateValue); - rightMotorOutput = moveValue + rotateValue; - } else { - leftMotorOutput = moveValue - rotateValue; - rightMotorOutput = -std::max(-moveValue, -rotateValue); - } - } - SetLeftRightMotorOutputs(leftMotorOutput, rightMotorOutput); -} - -void RobotDrive::MecanumDrive_Cartesian(double x, double y, double rotation, - double gyroAngle) { - static bool reported = false; - if (!reported) { - HAL_Report(HALUsageReporting::kResourceType_RobotDrive, - HALUsageReporting::kRobotDrive_MecanumCartesian, GetNumMotors()); - reported = true; - } - - double xIn = x; - double yIn = y; - // Negate y for the joystick. - yIn = -yIn; - // Compensate for gyro angle. - RotateVector(xIn, yIn, gyroAngle); - - double wheelSpeeds[kMaxNumberOfMotors]; - wheelSpeeds[kFrontLeftMotor] = xIn + yIn + rotation; - wheelSpeeds[kFrontRightMotor] = -xIn + yIn - rotation; - wheelSpeeds[kRearLeftMotor] = -xIn + yIn + rotation; - wheelSpeeds[kRearRightMotor] = xIn + yIn - rotation; - - Normalize(wheelSpeeds); - - m_frontLeftMotor->Set(wheelSpeeds[kFrontLeftMotor] * m_maxOutput); - m_frontRightMotor->Set(wheelSpeeds[kFrontRightMotor] * m_maxOutput); - m_rearLeftMotor->Set(wheelSpeeds[kRearLeftMotor] * m_maxOutput); - m_rearRightMotor->Set(wheelSpeeds[kRearRightMotor] * m_maxOutput); - - Feed(); -} - -void RobotDrive::MecanumDrive_Polar(double magnitude, double direction, - double rotation) { - static bool reported = false; - if (!reported) { - HAL_Report(HALUsageReporting::kResourceType_RobotDrive, - HALUsageReporting::kRobotDrive_MecanumPolar, GetNumMotors()); - reported = true; - } - - // Normalized for full power along the Cartesian axes. - magnitude = Limit(magnitude) * std::sqrt(2.0); - // The rollers are at 45 degree angles. - double dirInRad = (direction + 45.0) * 3.14159 / 180.0; - double cosD = std::cos(dirInRad); - double sinD = std::sin(dirInRad); - - double wheelSpeeds[kMaxNumberOfMotors]; - wheelSpeeds[kFrontLeftMotor] = sinD * magnitude + rotation; - wheelSpeeds[kFrontRightMotor] = cosD * magnitude - rotation; - wheelSpeeds[kRearLeftMotor] = cosD * magnitude + rotation; - wheelSpeeds[kRearRightMotor] = sinD * magnitude - rotation; - - Normalize(wheelSpeeds); - - m_frontLeftMotor->Set(wheelSpeeds[kFrontLeftMotor] * m_maxOutput); - m_frontRightMotor->Set(wheelSpeeds[kFrontRightMotor] * m_maxOutput); - m_rearLeftMotor->Set(wheelSpeeds[kRearLeftMotor] * m_maxOutput); - m_rearRightMotor->Set(wheelSpeeds[kRearRightMotor] * m_maxOutput); - - Feed(); -} - -void RobotDrive::HolonomicDrive(double magnitude, double direction, - double rotation) { - MecanumDrive_Polar(magnitude, direction, rotation); -} - -void RobotDrive::SetLeftRightMotorOutputs(double leftOutput, - double rightOutput) { - wpi_assert(m_rearLeftMotor != nullptr && m_rearRightMotor != nullptr); - - if (m_frontLeftMotor != nullptr) { - m_frontLeftMotor->Set(Limit(leftOutput) * m_maxOutput); - } - m_rearLeftMotor->Set(Limit(leftOutput) * m_maxOutput); - - if (m_frontRightMotor != nullptr) { - m_frontRightMotor->Set(-Limit(rightOutput) * m_maxOutput); - } - m_rearRightMotor->Set(-Limit(rightOutput) * m_maxOutput); - - Feed(); -} - -void RobotDrive::SetInvertedMotor(MotorType motor, bool isInverted) { - if (motor < 0 || motor > 3) { - wpi_setWPIError(InvalidMotorIndex); - return; - } - switch (motor) { - case kFrontLeftMotor: - m_frontLeftMotor->SetInverted(isInverted); - break; - case kFrontRightMotor: - m_frontRightMotor->SetInverted(isInverted); - break; - case kRearLeftMotor: - m_rearLeftMotor->SetInverted(isInverted); - break; - case kRearRightMotor: - m_rearRightMotor->SetInverted(isInverted); - break; - } -} - -void RobotDrive::SetSensitivity(double sensitivity) { - m_sensitivity = sensitivity; -} - -void RobotDrive::SetMaxOutput(double maxOutput) { - m_maxOutput = maxOutput; -} - -void RobotDrive::GetDescription(wpi::raw_ostream& desc) const { - desc << "RobotDrive"; -} - -void RobotDrive::StopMotor() { - if (m_frontLeftMotor != nullptr) { - m_frontLeftMotor->StopMotor(); - } - if (m_frontRightMotor != nullptr) { - m_frontRightMotor->StopMotor(); - } - if (m_rearLeftMotor != nullptr) { - m_rearLeftMotor->StopMotor(); - } - if (m_rearRightMotor != nullptr) { - m_rearRightMotor->StopMotor(); - } - Feed(); -} - -void RobotDrive::InitRobotDrive() { - SetSafetyEnabled(true); -} - -double RobotDrive::Limit(double number) { - if (number > 1.0) { - return 1.0; - } - if (number < -1.0) { - return -1.0; - } - return number; -} - -void RobotDrive::Normalize(double* wheelSpeeds) { - double maxMagnitude = std::fabs(wheelSpeeds[0]); - for (int i = 1; i < kMaxNumberOfMotors; i++) { - double temp = std::fabs(wheelSpeeds[i]); - if (maxMagnitude < temp) { - maxMagnitude = temp; - } - } - if (maxMagnitude > 1.0) { - for (int i = 0; i < kMaxNumberOfMotors; i++) { - wheelSpeeds[i] = wheelSpeeds[i] / maxMagnitude; - } - } -} - -void RobotDrive::RotateVector(double& x, double& y, double angle) { - double cosA = std::cos(angle * (3.14159 / 180.0)); - double sinA = std::sin(angle * (3.14159 / 180.0)); - double xOut = x * cosA - y * sinA; - double yOut = x * sinA + y * cosA; - x = xOut; - y = yOut; -} diff --git a/wpilibc/src/main/native/cpp/SPI.cpp b/wpilibc/src/main/native/cpp/SPI.cpp index 12ebb172d1..9392723b6d 100644 --- a/wpilibc/src/main/native/cpp/SPI.cpp +++ b/wpilibc/src/main/native/cpp/SPI.cpp @@ -14,8 +14,8 @@ #include #include "frc/DigitalSource.h" +#include "frc/Errors.h" #include "frc/Notifier.h" -#include "frc/WPIErrors.h" using namespace frc; @@ -77,9 +77,7 @@ void SPI::Accumulator::Update() { // get amount of data available int32_t numToRead = HAL_ReadSPIAutoReceivedData(m_port, m_buf, 0, 0, &status); - if (status != 0) { - return; // error reading - } + FRC_CheckErrorStatus(status, "ReadSPIAutoReceivedData"); // only get whole responses; +1 is for timestamp numToRead -= numToRead % m_xferSize; @@ -93,9 +91,7 @@ void SPI::Accumulator::Update() { // read buffered data HAL_ReadSPIAutoReceivedData(m_port, m_buf, numToRead, 0, &status); - if (status != 0) { - return; // error reading - } + FRC_CheckErrorStatus(status, "ReadSPIAutoReceivedData"); // loop over all responses for (int32_t off = 0; off < numToRead; off += m_xferSize) { @@ -162,7 +158,7 @@ void SPI::Accumulator::Update() { SPI::SPI(Port port) : m_port(static_cast(port)) { int32_t status = 0; HAL_InitializeSPI(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "InitializeSPI"); HAL_Report(HALUsageReporting::kResourceType_SPI, static_cast(port) + 1); @@ -219,13 +215,13 @@ void SPI::SetClockActiveHigh() { void SPI::SetChipSelectActiveHigh() { int32_t status = 0; HAL_SetSPIChipSelectActiveHigh(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetChipSelectActiveHigh"); } void SPI::SetChipSelectActiveLow() { int32_t status = 0; HAL_SetSPIChipSelectActiveLow(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetChipSelectActiveLow"); } int SPI::Write(uint8_t* data, int size) { @@ -255,26 +251,26 @@ int SPI::Transaction(uint8_t* dataToSend, uint8_t* dataReceived, int size) { void SPI::InitAuto(int bufferSize) { int32_t status = 0; HAL_InitSPIAuto(m_port, bufferSize, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "InitAuto"); } void SPI::FreeAuto() { int32_t status = 0; HAL_FreeSPIAuto(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "FreeAuto"); } void SPI::SetAutoTransmitData(wpi::ArrayRef dataToSend, int zeroSize) { int32_t status = 0; HAL_SetSPIAutoTransmitData(m_port, dataToSend.data(), dataToSend.size(), zeroSize, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetAutoTransmitData"); } void SPI::StartAutoRate(units::second_t period) { int32_t status = 0; HAL_StartSPIAutoRate(m_port, period.to(), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "StartAutoRate"); } void SPI::StartAutoRate(double period) { @@ -287,19 +283,19 @@ void SPI::StartAutoTrigger(DigitalSource& source, bool rising, bool falling) { static_cast( source.GetAnalogTriggerTypeForRouting()), rising, falling, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "StartAutoTrigger"); } void SPI::StopAuto() { int32_t status = 0; HAL_StopSPIAuto(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "StopAuto"); } void SPI::ForceAutoRead() { int32_t status = 0; HAL_ForceSPIAutoRead(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ForceAutoRead"); } int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead, @@ -307,7 +303,7 @@ int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead, int32_t status = 0; int32_t val = HAL_ReadSPIAutoReceivedData(m_port, buffer, numToRead, timeout.to(), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ReadAutoReceivedData"); return val; } @@ -318,7 +314,7 @@ int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead, double timeout) { int SPI::GetAutoDroppedCount() { int32_t status = 0; int32_t val = HAL_GetSPIAutoDroppedCount(m_port, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetAutoDroppedCount"); return val; } @@ -327,7 +323,7 @@ void SPI::ConfigureAutoStall(HAL_SPIPort port, int csToSclkTicks, int32_t status = 0; HAL_ConfigureSPIAutoStall(m_port, csToSclkTicks, stallTicks, pow2BytesPerRead, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "ConfigureAutoStall"); } void SPI::InitAccumulator(units::second_t period, int cmd, int xferSize, diff --git a/wpilibc/src/main/native/cpp/SerialPort.cpp b/wpilibc/src/main/native/cpp/SerialPort.cpp index 70c7fb52d1..6640286477 100644 --- a/wpilibc/src/main/native/cpp/SerialPort.cpp +++ b/wpilibc/src/main/native/cpp/SerialPort.cpp @@ -9,6 +9,8 @@ #include #include +#include "frc/Errors.h" + using namespace frc; SerialPort::SerialPort(int baudRate, Port port, int dataBits, @@ -18,19 +20,17 @@ SerialPort::SerialPort(int baudRate, Port port, int dataBits, m_portHandle = HAL_InitializeSerialPort(static_cast(port), &status); - wpi_setHALError(status); - // Don't continue if initialization failed - if (status < 0) { - return; - } + FRC_CheckErrorStatus(status, "Port " + wpi::Twine{static_cast(port)}); HAL_SetSerialBaudRate(m_portHandle, baudRate, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetSerialBaudRate " + wpi::Twine{baudRate}); HAL_SetSerialDataBits(m_portHandle, dataBits, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetSerialDataBits " + wpi::Twine{dataBits}); HAL_SetSerialParity(m_portHandle, parity, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus( + status, "SetSerialParity " + wpi::Twine{static_cast(parity)}); HAL_SetSerialStopBits(m_portHandle, stopBits, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus( + status, "SetSerialStopBits " + wpi::Twine{static_cast(stopBits)}); // Set the default timeout to 5 seconds. SetTimeout(5.0); @@ -54,19 +54,17 @@ SerialPort::SerialPort(int baudRate, const wpi::Twine& portName, Port port, m_portHandle = HAL_InitializeSerialPortDirect( static_cast(port), portNameC, &status); - wpi_setHALError(status); - // Don't continue if initialization failed - if (status < 0) { - return; - } + FRC_CheckErrorStatus(status, "Port " + wpi::Twine{static_cast(port)}); HAL_SetSerialBaudRate(m_portHandle, baudRate, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetSerialBaudRate " + wpi::Twine{baudRate}); HAL_SetSerialDataBits(m_portHandle, dataBits, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetSerialDataBits " + wpi::Twine{dataBits}); HAL_SetSerialParity(m_portHandle, parity, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus( + status, "SetSerialParity " + wpi::Twine{static_cast(parity)}); HAL_SetSerialStopBits(m_portHandle, stopBits, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus( + status, "SetSerialStopBits " + wpi::Twine{static_cast(stopBits)}); // Set the default timeout to 5 seconds. SetTimeout(5.0); @@ -83,38 +81,40 @@ SerialPort::SerialPort(int baudRate, const wpi::Twine& portName, Port port, SerialPort::~SerialPort() { int32_t status = 0; HAL_CloseSerial(m_portHandle, &status); - wpi_setHALError(status); + FRC_ReportError(status, "CloseSerial"); } void SerialPort::SetFlowControl(SerialPort::FlowControl flowControl) { int32_t status = 0; HAL_SetSerialFlowControl(m_portHandle, flowControl, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus( + status, "SetFlowControl " + wpi::Twine{static_cast(flowControl)}); } void SerialPort::EnableTermination(char terminator) { int32_t status = 0; HAL_EnableSerialTermination(m_portHandle, terminator, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus( + status, "EnableTermination " + wpi::Twine{static_cast(terminator)}); } void SerialPort::DisableTermination() { int32_t status = 0; HAL_DisableSerialTermination(m_portHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "DisableTermination"); } int SerialPort::GetBytesReceived() { int32_t status = 0; int retVal = HAL_GetSerialBytesReceived(m_portHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "GetBytesReceived"); return retVal; } int SerialPort::Read(char* buffer, int count) { int32_t status = 0; int retVal = HAL_ReadSerial(m_portHandle, buffer, count, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Read"); return retVal; } @@ -126,42 +126,43 @@ int SerialPort::Write(wpi::StringRef buffer) { int32_t status = 0; int retVal = HAL_WriteSerial(m_portHandle, buffer.data(), buffer.size(), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Write"); return retVal; } void SerialPort::SetTimeout(double timeout) { int32_t status = 0; HAL_SetSerialTimeout(m_portHandle, timeout, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetTimeout"); } void SerialPort::SetReadBufferSize(int size) { int32_t status = 0; HAL_SetSerialReadBufferSize(m_portHandle, size, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetReadBufferSize " + wpi::Twine{size}); } void SerialPort::SetWriteBufferSize(int size) { int32_t status = 0; HAL_SetSerialWriteBufferSize(m_portHandle, size, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetWriteBufferSize " + wpi::Twine{size}); } void SerialPort::SetWriteBufferMode(SerialPort::WriteBufferMode mode) { int32_t status = 0; HAL_SetSerialWriteMode(m_portHandle, mode, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus( + status, "SetWriteBufferMode " + wpi::Twine{static_cast(mode)}); } void SerialPort::Flush() { int32_t status = 0; HAL_FlushSerial(m_portHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Flush"); } void SerialPort::Reset() { int32_t status = 0; HAL_ClearSerial(m_portHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Reset"); } diff --git a/wpilibc/src/main/native/cpp/Solenoid.cpp b/wpilibc/src/main/native/cpp/Solenoid.cpp index ec54e15df4..1ead9fd130 100644 --- a/wpilibc/src/main/native/cpp/Solenoid.cpp +++ b/wpilibc/src/main/native/cpp/Solenoid.cpp @@ -11,8 +11,8 @@ #include #include +#include "frc/Errors.h" #include "frc/SensorUtil.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -24,24 +24,19 @@ Solenoid::Solenoid(int channel) Solenoid::Solenoid(int moduleNumber, int channel) : SolenoidBase(moduleNumber), m_channel(channel) { if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) { - wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, - "Solenoid Module " + wpi::Twine(m_moduleNumber)); - return; + throw FRC_MakeError(err::ModuleIndexOutOfRange, + "Solenoid Module " + wpi::Twine{m_moduleNumber}); } if (!SensorUtil::CheckSolenoidChannel(m_channel)) { - wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, - "Solenoid Channel " + wpi::Twine(m_channel)); - return; + throw FRC_MakeError(err::ChannelIndexOutOfRange, + "Solenoid Channel " + wpi::Twine{m_channel}); } int32_t status = 0; m_solenoidHandle = HAL_InitializeSolenoidPort( HAL_GetPortWithModule(moduleNumber, channel), &status); - if (status != 0) { - wpi_setHALErrorWithRange(status, 0, HAL_GetNumSolenoidChannels(), channel); - m_solenoidHandle = HAL_kInvalidHandle; - return; - } + FRC_CheckErrorStatus(status, "Solenoid Module " + wpi::Twine{m_moduleNumber} + + " Channel " + wpi::Twine{m_channel}); HAL_Report(HALUsageReporting::kResourceType_Solenoid, m_channel + 1, m_moduleNumber + 1); @@ -54,23 +49,15 @@ Solenoid::~Solenoid() { } void Solenoid::Set(bool on) { - if (StatusIsFatal()) { - return; - } - int32_t status = 0; HAL_SetSolenoid(m_solenoidHandle, on, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Set"); } bool Solenoid::Get() const { - if (StatusIsFatal()) { - return false; - } - int32_t status = 0; bool value = HAL_GetSolenoid(m_solenoidHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "Get"); return value; } @@ -90,21 +77,15 @@ bool Solenoid::IsBlackListed() const { void Solenoid::SetPulseDuration(double durationSeconds) { int32_t durationMS = durationSeconds * 1000; - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_SetOneShotDuration(m_solenoidHandle, durationMS, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "SetPulseDuration"); } void Solenoid::StartPulse() { - if (StatusIsFatal()) { - return; - } int32_t status = 0; HAL_FireOneShot(m_solenoidHandle, &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "StartPulse"); } void Solenoid::InitSendable(SendableBuilder& builder) { diff --git a/wpilibc/src/main/native/cpp/SolenoidBase.cpp b/wpilibc/src/main/native/cpp/SolenoidBase.cpp index c8b64f4b6a..e4598e1ea5 100644 --- a/wpilibc/src/main/native/cpp/SolenoidBase.cpp +++ b/wpilibc/src/main/native/cpp/SolenoidBase.cpp @@ -7,13 +7,15 @@ #include #include +#include "frc/Errors.h" + using namespace frc; int SolenoidBase::GetAll(int module) { int value = 0; int32_t status = 0; value = HAL_GetAllSolenoids(module, &status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module}); return value; } @@ -23,7 +25,9 @@ int SolenoidBase::GetAll() const { int SolenoidBase::GetPCMSolenoidBlackList(int module) { int32_t status = 0; - return HAL_GetPCMSolenoidBlackList(module, &status); + int rv = HAL_GetPCMSolenoidBlackList(module, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module}); + return rv; } int SolenoidBase::GetPCMSolenoidBlackList() const { @@ -32,7 +36,9 @@ int SolenoidBase::GetPCMSolenoidBlackList() const { bool SolenoidBase::GetPCMSolenoidVoltageStickyFault(int module) { int32_t status = 0; - return HAL_GetPCMSolenoidVoltageStickyFault(module, &status); + bool rv = HAL_GetPCMSolenoidVoltageStickyFault(module, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module}); + return rv; } bool SolenoidBase::GetPCMSolenoidVoltageStickyFault() const { @@ -41,7 +47,9 @@ bool SolenoidBase::GetPCMSolenoidVoltageStickyFault() const { bool SolenoidBase::GetPCMSolenoidVoltageFault(int module) { int32_t status = 0; - return HAL_GetPCMSolenoidVoltageFault(module, &status); + bool rv = HAL_GetPCMSolenoidVoltageFault(module, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module}); + return rv; } bool SolenoidBase::GetPCMSolenoidVoltageFault() const { @@ -50,7 +58,8 @@ bool SolenoidBase::GetPCMSolenoidVoltageFault() const { void SolenoidBase::ClearAllPCMStickyFaults(int module) { int32_t status = 0; - return HAL_ClearAllPCMStickyFaults(module, &status); + HAL_ClearAllPCMStickyFaults(module, &status); + FRC_CheckErrorStatus(status, "Module " + wpi::Twine{module}); } void SolenoidBase::ClearAllPCMStickyFaults() { diff --git a/wpilibc/src/main/native/cpp/SpeedControllerGroup.cpp b/wpilibc/src/main/native/cpp/SpeedControllerGroup.cpp index ce9aa32203..a9976d74a3 100644 --- a/wpilibc/src/main/native/cpp/SpeedControllerGroup.cpp +++ b/wpilibc/src/main/native/cpp/SpeedControllerGroup.cpp @@ -60,10 +60,6 @@ void SpeedControllerGroup::StopMotor() { } } -void SpeedControllerGroup::PIDWrite(double output) { - Set(output); -} - void SpeedControllerGroup::InitSendable(SendableBuilder& builder) { builder.SetSmartDashboardType("Speed Controller"); builder.SetActuator(true); diff --git a/wpilibc/src/main/native/cpp/Threads.cpp b/wpilibc/src/main/native/cpp/Threads.cpp index 1b1650aff4..3ecab5569a 100644 --- a/wpilibc/src/main/native/cpp/Threads.cpp +++ b/wpilibc/src/main/native/cpp/Threads.cpp @@ -7,7 +7,7 @@ #include #include -#include "frc/ErrorBase.h" +#include "frc/Errors.h" namespace frc { @@ -16,7 +16,7 @@ int GetThreadPriority(std::thread& thread, bool* isRealTime) { HAL_Bool rt = false; auto native = thread.native_handle(); auto ret = HAL_GetThreadPriority(&native, &rt, &status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetThreadPriority"); *isRealTime = rt; return ret; } @@ -25,7 +25,7 @@ int GetCurrentThreadPriority(bool* isRealTime) { int32_t status = 0; HAL_Bool rt = false; auto ret = HAL_GetCurrentThreadPriority(&rt, &status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "GetCurrentThreadPriority"); *isRealTime = rt; return ret; } @@ -34,14 +34,14 @@ bool SetThreadPriority(std::thread& thread, bool realTime, int priority) { int32_t status = 0; auto native = thread.native_handle(); auto ret = HAL_SetThreadPriority(&native, realTime, priority, &status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "SetThreadPriority"); return ret; } bool SetCurrentThreadPriority(bool realTime, int priority) { int32_t status = 0; auto ret = HAL_SetCurrentThreadPriority(realTime, priority, &status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "SetCurrentThreadPriority"); return ret; } diff --git a/wpilibc/src/main/native/cpp/TimedRobot.cpp b/wpilibc/src/main/native/cpp/TimedRobot.cpp index 2704d51010..d4ddc6c656 100644 --- a/wpilibc/src/main/native/cpp/TimedRobot.cpp +++ b/wpilibc/src/main/native/cpp/TimedRobot.cpp @@ -12,9 +12,9 @@ #include #include +#include "frc/Errors.h" #include "frc/Timer.h" #include "frc/Utility.h" -#include "frc/WPIErrors.h" using namespace frc; @@ -39,7 +39,7 @@ void TimedRobot::StartCompetition() { HAL_UpdateNotifierAlarm( m_notifier, static_cast(callback.expirationTime * 1e6), &status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "UpdateNotifierAlarm"); uint64_t curTime = HAL_WaitForNotifierAlarm(m_notifier, &status); if (curTime == 0 || status != 0) { @@ -69,10 +69,6 @@ void TimedRobot::EndCompetition() { HAL_StopNotifier(m_notifier, &status); } -units::second_t TimedRobot::GetPeriod() const { - return units::second_t(m_period); -} - TimedRobot::TimedRobot(double period) : TimedRobot(units::second_t(period)) {} TimedRobot::TimedRobot(units::second_t period) : IterativeRobotBase(period) { @@ -81,7 +77,7 @@ TimedRobot::TimedRobot(units::second_t period) : IterativeRobotBase(period) { int32_t status = 0; m_notifier = HAL_InitializeNotifier(&status); - wpi_setHALError(status); + FRC_CheckErrorStatus(status, "InitializeNotifier"); HAL_SetNotifierName(m_notifier, "TimedRobot", &status); HAL_Report(HALUsageReporting::kResourceType_Framework, @@ -92,7 +88,7 @@ TimedRobot::~TimedRobot() { int32_t status = 0; HAL_StopNotifier(m_notifier, &status); - wpi_setHALError(status); + FRC_ReportError(status, "StopNotifier"); HAL_CleanNotifier(m_notifier, &status); } diff --git a/wpilibc/src/main/native/cpp/Ultrasonic.cpp b/wpilibc/src/main/native/cpp/Ultrasonic.cpp index dd34fe8553..2389eda1e0 100644 --- a/wpilibc/src/main/native/cpp/Ultrasonic.cpp +++ b/wpilibc/src/main/native/cpp/Ultrasonic.cpp @@ -12,9 +12,9 @@ #include "frc/Counter.h" #include "frc/DigitalInput.h" #include "frc/DigitalOutput.h" +#include "frc/Errors.h" #include "frc/Timer.h" #include "frc/Utility.h" -#include "frc/WPIErrors.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -26,47 +26,41 @@ std::atomic Ultrasonic::m_automaticEnabled{false}; std::vector Ultrasonic::m_sensors; std::thread Ultrasonic::m_thread; -Ultrasonic::Ultrasonic(int pingChannel, int echoChannel, DistanceUnit units) +Ultrasonic::Ultrasonic(int pingChannel, int echoChannel) : m_pingChannel(std::make_shared(pingChannel)), m_echoChannel(std::make_shared(echoChannel)), m_counter(m_echoChannel) { - m_units = units; Initialize(); auto& registry = SendableRegistry::GetInstance(); registry.AddChild(this, m_pingChannel.get()); registry.AddChild(this, m_echoChannel.get()); } -Ultrasonic::Ultrasonic(DigitalOutput* pingChannel, DigitalInput* echoChannel, - DistanceUnit units) +Ultrasonic::Ultrasonic(DigitalOutput* pingChannel, DigitalInput* echoChannel) : m_pingChannel(pingChannel, NullDeleter()), m_echoChannel(echoChannel, NullDeleter()), m_counter(m_echoChannel) { - if (pingChannel == nullptr || echoChannel == nullptr) { - wpi_setWPIError(NullParameter); - m_units = units; - return; + if (!pingChannel) { + throw FRC_MakeError(err::NullParameter, "pingChannel"); + } + if (!echoChannel) { + throw FRC_MakeError(err::NullParameter, "echoChannel"); } - m_units = units; Initialize(); } -Ultrasonic::Ultrasonic(DigitalOutput& pingChannel, DigitalInput& echoChannel, - DistanceUnit units) +Ultrasonic::Ultrasonic(DigitalOutput& pingChannel, DigitalInput& echoChannel) : m_pingChannel(&pingChannel, NullDeleter()), m_echoChannel(&echoChannel, NullDeleter()), m_counter(m_echoChannel) { - m_units = units; Initialize(); } Ultrasonic::Ultrasonic(std::shared_ptr pingChannel, - std::shared_ptr echoChannel, - DistanceUnit units) + std::shared_ptr echoChannel) : m_pingChannel(std::move(pingChannel)), m_echoChannel(std::move(echoChannel)), m_counter(m_echoChannel) { - m_units = units; Initialize(); } @@ -164,31 +158,6 @@ void Ultrasonic::SetEnabled(bool enable) { m_enabled = enable; } -void Ultrasonic::SetDistanceUnits(DistanceUnit units) { - m_units = units; -} - -Ultrasonic::DistanceUnit Ultrasonic::GetDistanceUnits() const { - return m_units; -} - -double Ultrasonic::PIDGet() { - switch (m_units) { - case Ultrasonic::kInches: - return GetRangeInches(); - case Ultrasonic::kMilliMeters: - return GetRangeMM(); - default: - return 0.0; - } -} - -void Ultrasonic::SetPIDSourceType(PIDSourceType pidSource) { - if (wpi_assert(pidSource == PIDSourceType::kDisplacement)) { - m_pidSource = pidSource; - } -} - void Ultrasonic::InitSendable(SendableBuilder& builder) { builder.SetSmartDashboardType("Ultrasonic"); builder.AddDoubleProperty( diff --git a/wpilibc/src/main/native/cpp/VictorSP.cpp b/wpilibc/src/main/native/cpp/VictorSP.cpp deleted file mode 100644 index 10b7fdadcc..0000000000 --- a/wpilibc/src/main/native/cpp/VictorSP.cpp +++ /dev/null @@ -1,21 +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 "frc/VictorSP.h" - -#include - -#include "frc/smartdashboard/SendableRegistry.h" - -using namespace frc; - -VictorSP::VictorSP(int channel) : PWMSpeedController(channel) { - SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); - - HAL_Report(HALUsageReporting::kResourceType_VictorSP, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "VictorSP", GetChannel()); -} diff --git a/wpilibc/src/main/native/cpp/Watchdog.cpp b/wpilibc/src/main/native/cpp/Watchdog.cpp index e93457f33f..5ba4273343 100644 --- a/wpilibc/src/main/native/cpp/Watchdog.cpp +++ b/wpilibc/src/main/native/cpp/Watchdog.cpp @@ -14,6 +14,7 @@ #include #include "frc/DriverStation.h" +#include "frc/Errors.h" #include "frc2/Timer.h" using namespace frc; @@ -47,7 +48,7 @@ class Watchdog::Impl { Watchdog::Impl::Impl() { int32_t status = 0; m_notifier = HAL_InitializeNotifier(&status); - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "starting watchdog notifier"); HAL_SetNotifierName(m_notifier, "Watchdog", &status); m_thread = std::thread([=] { Main(); }); @@ -58,7 +59,7 @@ Watchdog::Impl::~Impl() { // atomically set handle to 0, then clean HAL_NotifierHandle handle = m_notifier.exchange(0); HAL_StopNotifier(handle, &status); - wpi_setGlobalHALError(status); + FRC_ReportError(status, "stopping watchdog notifier"); // Join the thread to ensure the handler has exited. if (m_thread.joinable()) { @@ -84,7 +85,7 @@ void Watchdog::Impl::UpdateAlarm() { 1e6), &status); } - wpi_setGlobalHALError(status); + FRC_CheckErrorStatus(status, "updating watchdog notifier alarm"); } void Watchdog::Impl::Main() { @@ -141,7 +142,11 @@ Watchdog::Watchdog(units::second_t timeout, std::function callback) : m_timeout(timeout), m_callback(std::move(callback)), m_impl(GetImpl()) {} Watchdog::~Watchdog() { - Disable(); + try { + Disable(); + } catch (const RuntimeError& e) { + e.Report(); + } } Watchdog::Watchdog(Watchdog&& rhs) { diff --git a/wpilibc/src/main/native/cpp/drive/DifferentialDrive.cpp b/wpilibc/src/main/native/cpp/drive/DifferentialDrive.cpp index 7a7a93b475..59e3622dbe 100644 --- a/wpilibc/src/main/native/cpp/drive/DifferentialDrive.cpp +++ b/wpilibc/src/main/native/cpp/drive/DifferentialDrive.cpp @@ -15,6 +15,14 @@ using namespace frc; +#if defined(_MSC_VER) +#pragma warning(disable : 4996) // was declared deprecated +#elif defined(__clang__) +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + DifferentialDrive::DifferentialDrive(SpeedController& leftMotor, SpeedController& rightMotor) : m_leftMotor(&leftMotor), m_rightMotor(&rightMotor) { diff --git a/wpilibc/src/main/native/cpp/drive/KilloughDrive.cpp b/wpilibc/src/main/native/cpp/drive/KilloughDrive.cpp index 6c2247b9b6..7cdf145d8f 100644 --- a/wpilibc/src/main/native/cpp/drive/KilloughDrive.cpp +++ b/wpilibc/src/main/native/cpp/drive/KilloughDrive.cpp @@ -16,6 +16,14 @@ using namespace frc; +#if defined(_MSC_VER) +#pragma warning(disable : 4996) // was declared deprecated +#elif defined(__clang__) +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + KilloughDrive::KilloughDrive(SpeedController& leftMotor, SpeedController& rightMotor, SpeedController& backMotor) diff --git a/wpilibc/src/main/native/cpp/drive/MecanumDrive.cpp b/wpilibc/src/main/native/cpp/drive/MecanumDrive.cpp index 2a9eac01f9..d9886b66f5 100644 --- a/wpilibc/src/main/native/cpp/drive/MecanumDrive.cpp +++ b/wpilibc/src/main/native/cpp/drive/MecanumDrive.cpp @@ -17,6 +17,14 @@ using namespace frc; +#if defined(_MSC_VER) +#pragma warning(disable : 4996) // was declared deprecated +#elif defined(__clang__) +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + MecanumDrive::MecanumDrive(SpeedController& frontLeftMotor, SpeedController& rearLeftMotor, SpeedController& frontRightMotor, diff --git a/wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp b/wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp index 594cfbcf0c..3b03c3a75a 100644 --- a/wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp +++ b/wpilibc/src/main/native/cpp/drive/RobotDriveBase.cpp @@ -11,7 +11,7 @@ #include #include "frc/Base.h" -#include "frc/SpeedController.h" +#include "frc/motorcontrol/MotorController.h" using namespace frc; diff --git a/wpilibc/src/main/native/cpp/filters/Filter.cpp b/wpilibc/src/main/native/cpp/filters/Filter.cpp deleted file mode 100644 index 1676c94894..0000000000 --- a/wpilibc/src/main/native/cpp/filters/Filter.cpp +++ /dev/null @@ -1,27 +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 "frc/filters/Filter.h" - -#include "frc/Base.h" - -using namespace frc; - -Filter::Filter(PIDSource& source) - : m_source(std::shared_ptr(&source, NullDeleter())) {} - -Filter::Filter(std::shared_ptr source) - : m_source(std::move(source)) {} - -void Filter::SetPIDSourceType(PIDSourceType pidSource) { - m_source->SetPIDSourceType(pidSource); -} - -PIDSourceType Filter::GetPIDSourceType() const { - return m_source->GetPIDSourceType(); -} - -double Filter::PIDGetSource() { - return m_source->PIDGet(); -} diff --git a/wpilibc/src/main/native/cpp/filters/LinearDigitalFilter.cpp b/wpilibc/src/main/native/cpp/filters/LinearDigitalFilter.cpp deleted file mode 100644 index c4b48f6783..0000000000 --- a/wpilibc/src/main/native/cpp/filters/LinearDigitalFilter.cpp +++ /dev/null @@ -1,133 +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 "frc/filters/LinearDigitalFilter.h" - -#include -#include - -#include - -using namespace frc; - -LinearDigitalFilter::LinearDigitalFilter(PIDSource& source, - wpi::ArrayRef ffGains, - wpi::ArrayRef fbGains) - : Filter(source), - m_inputs(ffGains.size()), - m_outputs(fbGains.size()), - m_inputGains(ffGains), - m_outputGains(fbGains) { - static int instances = 0; - instances++; - HAL_Report(HALUsageReporting::kResourceType_LinearFilter, instances); -} - -LinearDigitalFilter::LinearDigitalFilter(PIDSource& source, - std::initializer_list ffGains, - std::initializer_list fbGains) - : LinearDigitalFilter(source, - wpi::makeArrayRef(ffGains.begin(), ffGains.end()), - wpi::makeArrayRef(fbGains.begin(), fbGains.end())) {} - -LinearDigitalFilter::LinearDigitalFilter(std::shared_ptr source, - wpi::ArrayRef ffGains, - wpi::ArrayRef fbGains) - : Filter(source), - m_inputs(ffGains.size()), - m_outputs(fbGains.size()), - m_inputGains(ffGains), - m_outputGains(fbGains) { - static int instances = 0; - instances++; - HAL_Report(HALUsageReporting::kResourceType_LinearFilter, instances); -} - -LinearDigitalFilter::LinearDigitalFilter(std::shared_ptr source, - std::initializer_list ffGains, - std::initializer_list fbGains) - : LinearDigitalFilter(source, - wpi::makeArrayRef(ffGains.begin(), ffGains.end()), - wpi::makeArrayRef(fbGains.begin(), fbGains.end())) {} - -LinearDigitalFilter LinearDigitalFilter::SinglePoleIIR(PIDSource& source, - double timeConstant, - double period) { - double gain = std::exp(-period / timeConstant); - return LinearDigitalFilter(source, {1.0 - gain}, {-gain}); -} - -LinearDigitalFilter LinearDigitalFilter::HighPass(PIDSource& source, - double timeConstant, - double period) { - double gain = std::exp(-period / timeConstant); - return LinearDigitalFilter(source, {gain, -gain}, {-gain}); -} - -LinearDigitalFilter LinearDigitalFilter::MovingAverage(PIDSource& source, - int taps) { - assert(taps > 0); - - std::vector gains(taps, 1.0 / taps); - return LinearDigitalFilter(source, gains, {}); -} - -LinearDigitalFilter LinearDigitalFilter::SinglePoleIIR( - std::shared_ptr source, double timeConstant, double period) { - double gain = std::exp(-period / timeConstant); - return LinearDigitalFilter(std::move(source), {1.0 - gain}, {-gain}); -} - -LinearDigitalFilter LinearDigitalFilter::HighPass( - std::shared_ptr source, double timeConstant, double period) { - double gain = std::exp(-period / timeConstant); - return LinearDigitalFilter(std::move(source), {gain, -gain}, {-gain}); -} - -LinearDigitalFilter LinearDigitalFilter::MovingAverage( - std::shared_ptr source, int taps) { - assert(taps > 0); - - std::vector gains(taps, 1.0 / taps); - return LinearDigitalFilter(std::move(source), gains, {}); -} - -double LinearDigitalFilter::Get() const { - double retVal = 0.0; - - // Calculate the new value - for (size_t i = 0; i < m_inputGains.size(); i++) { - retVal += m_inputs[i] * m_inputGains[i]; - } - for (size_t i = 0; i < m_outputGains.size(); i++) { - retVal -= m_outputs[i] * m_outputGains[i]; - } - - return retVal; -} - -void LinearDigitalFilter::Reset() { - m_inputs.reset(); - m_outputs.reset(); -} - -double LinearDigitalFilter::PIDGet() { - double retVal = 0.0; - - // Rotate the inputs - m_inputs.push_front(PIDGetSource()); - - // Calculate the new value - for (size_t i = 0; i < m_inputGains.size(); i++) { - retVal += m_inputs[i] * m_inputGains[i]; - } - for (size_t i = 0; i < m_outputGains.size(); i++) { - retVal -= m_outputs[i] * m_outputGains[i]; - } - - // Rotate the outputs - m_outputs.push_front(retVal); - - return retVal; -} diff --git a/wpilibc/src/main/native/cpp/interfaces/Potentiometer.cpp b/wpilibc/src/main/native/cpp/interfaces/Potentiometer.cpp deleted file mode 100644 index 9b412213b5..0000000000 --- a/wpilibc/src/main/native/cpp/interfaces/Potentiometer.cpp +++ /dev/null @@ -1,15 +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 "frc/interfaces/Potentiometer.h" - -#include "frc/Utility.h" - -using namespace frc; - -void Potentiometer::SetPIDSourceType(PIDSourceType pidSource) { - if (wpi_assert(pidSource == PIDSourceType::kDisplacement)) { - m_pidSource = pidSource; - } -} diff --git a/wpilibc/src/main/native/cpp/livewindow/LiveWindow.cpp b/wpilibc/src/main/native/cpp/livewindow/LiveWindow.cpp index 0c13b4da72..1b749b6141 100644 --- a/wpilibc/src/main/native/cpp/livewindow/LiveWindow.cpp +++ b/wpilibc/src/main/native/cpp/livewindow/LiveWindow.cpp @@ -61,9 +61,9 @@ std::shared_ptr LiveWindow::Impl::GetOrAdd( return data; } -LiveWindow* LiveWindow::GetInstance() { +LiveWindow& LiveWindow::GetInstance() { static LiveWindow instance; - return &instance; + return instance; } void LiveWindow::EnableTelemetry(Sendable* sendable) { @@ -154,7 +154,7 @@ void LiveWindow::UpdateValuesUnsafe() { return; } auto ssTable = m_impl->liveWindowTable->GetSubTable(cbdata.subsystem); - std::shared_ptr table; + std::shared_ptr table; // Treat name==subsystem as top level of subsystem if (cbdata.name == cbdata.subsystem) { table = ssTable; diff --git a/wpilibc/src/main/native/cpp/DMC60.cpp b/wpilibc/src/main/native/cpp/motorcontrol/DMC60.cpp similarity index 51% rename from wpilibc/src/main/native/cpp/DMC60.cpp rename to wpilibc/src/main/native/cpp/motorcontrol/DMC60.cpp index f84d839e62..81fa868f84 100644 --- a/wpilibc/src/main/native/cpp/DMC60.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/DMC60.cpp @@ -2,20 +2,17 @@ // 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 "frc/DMC60.h" +#include "frc/motorcontrol/DMC60.h" #include -#include "frc/smartdashboard/SendableRegistry.h" - using namespace frc; -DMC60::DMC60(int channel) : PWMSpeedController(channel) { - SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); +DMC60::DMC60(int channel) : PWMMotorController("DMC60", channel) { + m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); HAL_Report(HALUsageReporting::kResourceType_DigilentDMC60, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "DMC60", GetChannel()); } diff --git a/wpilibc/src/main/native/cpp/Jaguar.cpp b/wpilibc/src/main/native/cpp/motorcontrol/Jaguar.cpp similarity index 50% rename from wpilibc/src/main/native/cpp/Jaguar.cpp rename to wpilibc/src/main/native/cpp/motorcontrol/Jaguar.cpp index eded12f082..c68ae0c8f2 100644 --- a/wpilibc/src/main/native/cpp/Jaguar.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/Jaguar.cpp @@ -2,20 +2,17 @@ // 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 "frc/Jaguar.h" +#include "frc/motorcontrol/Jaguar.h" #include -#include "frc/smartdashboard/SendableRegistry.h" - using namespace frc; -Jaguar::Jaguar(int channel) : PWMSpeedController(channel) { - SetBounds(2.31, 1.55, 1.507, 1.454, 0.697); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); +Jaguar::Jaguar(int channel) : PWMMotorController("Jaguar", channel) { + m_pwm.SetBounds(2.31, 1.55, 1.507, 1.454, 0.697); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); HAL_Report(HALUsageReporting::kResourceType_Jaguar, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "Jaguar", GetChannel()); } diff --git a/wpilibc/src/main/native/cpp/motorcontrol/MotorControllerGroup.cpp b/wpilibc/src/main/native/cpp/motorcontrol/MotorControllerGroup.cpp new file mode 100644 index 0000000000..54ec4d8a94 --- /dev/null +++ b/wpilibc/src/main/native/cpp/motorcontrol/MotorControllerGroup.cpp @@ -0,0 +1,69 @@ +// 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 "frc/motorcontrol/MotorControllerGroup.h" + +#include "frc/smartdashboard/SendableBuilder.h" +#include "frc/smartdashboard/SendableRegistry.h" + +using namespace frc; + +// Can't use a delegated constructor here because of an MSVC bug. +// https://developercommunity.visualstudio.com/content/problem/583/compiler-bug-with-delegating-a-constructor.html + +MotorControllerGroup::MotorControllerGroup( + std::vector>&& motorControllers) + : m_motorControllers(std::move(motorControllers)) { + Initialize(); +} + +void MotorControllerGroup::Initialize() { + for (auto& motorController : m_motorControllers) { + SendableRegistry::GetInstance().AddChild(this, &motorController.get()); + } + static int instances = 0; + ++instances; + SendableRegistry::GetInstance().Add(this, "MotorControllerGroup", instances); +} + +void MotorControllerGroup::Set(double speed) { + for (auto motorController : m_motorControllers) { + motorController.get().Set(m_isInverted ? -speed : speed); + } +} + +double MotorControllerGroup::Get() const { + if (!m_motorControllers.empty()) { + return m_motorControllers.front().get().Get() * (m_isInverted ? -1 : 1); + } + return 0.0; +} + +void MotorControllerGroup::SetInverted(bool isInverted) { + m_isInverted = isInverted; +} + +bool MotorControllerGroup::GetInverted() const { + return m_isInverted; +} + +void MotorControllerGroup::Disable() { + for (auto motorController : m_motorControllers) { + motorController.get().Disable(); + } +} + +void MotorControllerGroup::StopMotor() { + for (auto motorController : m_motorControllers) { + motorController.get().StopMotor(); + } +} + +void MotorControllerGroup::InitSendable(SendableBuilder& builder) { + builder.SetSmartDashboardType("Motor Controller"); + builder.SetActuator(true); + builder.SetSafeState([=]() { StopMotor(); }); + builder.AddDoubleProperty( + "Value", [=]() { return Get(); }, [=](double value) { Set(value); }); +} diff --git a/wpilibc/src/main/native/cpp/NidecBrushless.cpp b/wpilibc/src/main/native/cpp/motorcontrol/NidecBrushless.cpp similarity index 95% rename from wpilibc/src/main/native/cpp/NidecBrushless.cpp rename to wpilibc/src/main/native/cpp/motorcontrol/NidecBrushless.cpp index 1ea2b95f9b..fdca9b9341 100644 --- a/wpilibc/src/main/native/cpp/NidecBrushless.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/NidecBrushless.cpp @@ -2,9 +2,10 @@ // 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 "frc/NidecBrushless.h" +#include "frc/motorcontrol/NidecBrushless.h" #include +#include #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -58,10 +59,6 @@ void NidecBrushless::Enable() { m_disabled = false; } -void NidecBrushless::PIDWrite(double output) { - Set(output); -} - void NidecBrushless::StopMotor() { m_dio.UpdateDutyCycle(0.5); m_pwm.SetDisabled(); diff --git a/wpilibc/src/main/native/cpp/motorcontrol/PWMMotorController.cpp b/wpilibc/src/main/native/cpp/motorcontrol/PWMMotorController.cpp new file mode 100644 index 0000000000..9f0394639a --- /dev/null +++ b/wpilibc/src/main/native/cpp/motorcontrol/PWMMotorController.cpp @@ -0,0 +1,56 @@ +// 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 "frc/motorcontrol/PWMMotorController.h" + +#include + +#include "frc/smartdashboard/SendableBuilder.h" + +using namespace frc; + +void PWMMotorController::Set(double speed) { + m_pwm.SetSpeed(m_isInverted ? -speed : speed); +} + +double PWMMotorController::Get() const { + return m_pwm.GetSpeed() * (m_isInverted ? -1.0 : 1.0); +} + +void PWMMotorController::SetInverted(bool isInverted) { + m_isInverted = isInverted; +} + +bool PWMMotorController::GetInverted() const { + return m_isInverted; +} + +void PWMMotorController::Disable() { + m_pwm.SetDisabled(); +} + +void PWMMotorController::StopMotor() { + Disable(); +} + +void PWMMotorController::GetDescription(wpi::raw_ostream& desc) const { + desc << "PWM " << GetChannel(); +} + +int PWMMotorController::GetChannel() const { + return m_pwm.GetChannel(); +} + +PWMMotorController::PWMMotorController(const wpi::Twine& name, int channel) + : m_pwm(channel, false) { + SendableRegistry::GetInstance().AddLW(this, name, channel); +} + +void PWMMotorController::InitSendable(SendableBuilder& builder) { + builder.SetSmartDashboardType("Motor Controller"); + builder.SetActuator(true); + builder.SetSafeState([=] { Disable(); }); + builder.AddDoubleProperty( + "Value", [=] { return Get(); }, [=](double value) { Set(value); }); +} diff --git a/wpilibc/src/main/native/cpp/PWMSparkMax.cpp b/wpilibc/src/main/native/cpp/motorcontrol/PWMSparkMax.cpp similarity index 56% rename from wpilibc/src/main/native/cpp/PWMSparkMax.cpp rename to wpilibc/src/main/native/cpp/motorcontrol/PWMSparkMax.cpp index 1b7915cb64..666f1e928c 100644 --- a/wpilibc/src/main/native/cpp/PWMSparkMax.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/PWMSparkMax.cpp @@ -2,7 +2,7 @@ // 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 "frc/PWMSparkMax.h" +#include "frc/motorcontrol/PWMSparkMax.h" #include @@ -10,12 +10,12 @@ using namespace frc; -PWMSparkMax::PWMSparkMax(int channel) : PWMSpeedController(channel) { - SetBounds(2.003, 1.55, 1.50, 1.46, 0.999); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); +PWMSparkMax::PWMSparkMax(int channel) + : PWMMotorController("PWMSparkMax", channel) { + m_pwm.SetBounds(2.003, 1.55, 1.50, 1.46, 0.999); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); HAL_Report(HALUsageReporting::kResourceType_RevSparkMaxPWM, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "PWMSparkMax", GetChannel()); } diff --git a/wpilibc/src/main/native/cpp/motorcontrol/PWMTalonFX.cpp b/wpilibc/src/main/native/cpp/motorcontrol/PWMTalonFX.cpp new file mode 100644 index 0000000000..2c6982b132 --- /dev/null +++ b/wpilibc/src/main/native/cpp/motorcontrol/PWMTalonFX.cpp @@ -0,0 +1,19 @@ +// 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 "frc/motorcontrol/PWMTalonFX.h" + +#include + +using namespace frc; + +PWMTalonFX::PWMTalonFX(int channel) + : PWMMotorController("PWMTalonFX", channel) { + m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); + + HAL_Report(HALUsageReporting::kResourceType_TalonFX, GetChannel() + 1); +} diff --git a/wpilibc/src/main/native/cpp/motorcontrol/PWMTalonSRX.cpp b/wpilibc/src/main/native/cpp/motorcontrol/PWMTalonSRX.cpp new file mode 100644 index 0000000000..b253412766 --- /dev/null +++ b/wpilibc/src/main/native/cpp/motorcontrol/PWMTalonSRX.cpp @@ -0,0 +1,19 @@ +// 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 "frc/motorcontrol/PWMTalonSRX.h" + +#include + +using namespace frc; + +PWMTalonSRX::PWMTalonSRX(int channel) + : PWMMotorController("PWMTalonSRX", channel) { + m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); + + HAL_Report(HALUsageReporting::kResourceType_PWMTalonSRX, GetChannel() + 1); +} diff --git a/wpilibc/src/main/native/cpp/PWMVenom.cpp b/wpilibc/src/main/native/cpp/motorcontrol/PWMVenom.cpp similarity index 50% rename from wpilibc/src/main/native/cpp/PWMVenom.cpp rename to wpilibc/src/main/native/cpp/motorcontrol/PWMVenom.cpp index ec1c09bfac..e55802837a 100644 --- a/wpilibc/src/main/native/cpp/PWMVenom.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/PWMVenom.cpp @@ -2,20 +2,17 @@ // 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 "frc/PWMVenom.h" +#include "frc/motorcontrol/PWMVenom.h" #include -#include "frc/smartdashboard/SendableRegistry.h" - using namespace frc; -PWMVenom::PWMVenom(int channel) : PWMSpeedController(channel) { - SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); +PWMVenom::PWMVenom(int channel) : PWMMotorController("PWMVenom", channel) { + m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); HAL_Report(HALUsageReporting::kResourceType_FusionVenom, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "PWMVenom", GetChannel()); } diff --git a/wpilibc/src/main/native/cpp/motorcontrol/PWMVictorSPX.cpp b/wpilibc/src/main/native/cpp/motorcontrol/PWMVictorSPX.cpp new file mode 100644 index 0000000000..10ce992114 --- /dev/null +++ b/wpilibc/src/main/native/cpp/motorcontrol/PWMVictorSPX.cpp @@ -0,0 +1,19 @@ +// 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 "frc/motorcontrol/PWMVictorSPX.h" + +#include + +using namespace frc; + +PWMVictorSPX::PWMVictorSPX(int channel) + : PWMMotorController("PWMVictorSPX", channel) { + m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); + + HAL_Report(HALUsageReporting::kResourceType_PWMVictorSPX, GetChannel() + 1); +} diff --git a/wpilibc/src/main/native/cpp/SD540.cpp b/wpilibc/src/main/native/cpp/motorcontrol/SD540.cpp similarity index 52% rename from wpilibc/src/main/native/cpp/SD540.cpp rename to wpilibc/src/main/native/cpp/motorcontrol/SD540.cpp index 03e37df5b4..3d5738f3bc 100644 --- a/wpilibc/src/main/native/cpp/SD540.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/SD540.cpp @@ -2,21 +2,18 @@ // 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 "frc/SD540.h" +#include "frc/motorcontrol/SD540.h" #include -#include "frc/smartdashboard/SendableRegistry.h" - using namespace frc; -SD540::SD540(int channel) : PWMSpeedController(channel) { - SetBounds(2.05, 1.55, 1.50, 1.44, 0.94); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); +SD540::SD540(int channel) : PWMMotorController("SD540", channel) { + m_pwm.SetBounds(2.05, 1.55, 1.50, 1.44, 0.94); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); HAL_Report(HALUsageReporting::kResourceType_MindsensorsSD540, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "SD540", GetChannel()); } diff --git a/wpilibc/src/main/native/cpp/Spark.cpp b/wpilibc/src/main/native/cpp/motorcontrol/Spark.cpp similarity index 50% rename from wpilibc/src/main/native/cpp/Spark.cpp rename to wpilibc/src/main/native/cpp/motorcontrol/Spark.cpp index 2e0bcaa758..45394df33d 100644 --- a/wpilibc/src/main/native/cpp/Spark.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/Spark.cpp @@ -2,20 +2,17 @@ // 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 "frc/Spark.h" +#include "frc/motorcontrol/Spark.h" #include -#include "frc/smartdashboard/SendableRegistry.h" - using namespace frc; -Spark::Spark(int channel) : PWMSpeedController(channel) { - SetBounds(2.003, 1.55, 1.50, 1.46, 0.999); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); +Spark::Spark(int channel) : PWMMotorController("Spark", channel) { + m_pwm.SetBounds(2.003, 1.55, 1.50, 1.46, 0.999); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); HAL_Report(HALUsageReporting::kResourceType_RevSPARK, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "Spark", GetChannel()); } diff --git a/wpilibc/src/main/native/cpp/Talon.cpp b/wpilibc/src/main/native/cpp/motorcontrol/Talon.cpp similarity index 50% rename from wpilibc/src/main/native/cpp/Talon.cpp rename to wpilibc/src/main/native/cpp/motorcontrol/Talon.cpp index 2f9a51e8af..f4b3b69740 100644 --- a/wpilibc/src/main/native/cpp/Talon.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/Talon.cpp @@ -2,20 +2,17 @@ // 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 "frc/Talon.h" +#include "frc/motorcontrol/Talon.h" #include -#include "frc/smartdashboard/SendableRegistry.h" - using namespace frc; -Talon::Talon(int channel) : PWMSpeedController(channel) { - SetBounds(2.037, 1.539, 1.513, 1.487, 0.989); - SetPeriodMultiplier(kPeriodMultiplier_1X); - SetSpeed(0.0); - SetZeroLatch(); +Talon::Talon(int channel) : PWMMotorController("Talon", channel) { + m_pwm.SetBounds(2.037, 1.539, 1.513, 1.487, 0.989); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); HAL_Report(HALUsageReporting::kResourceType_Talon, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "Talon", GetChannel()); } diff --git a/wpilibc/src/main/native/cpp/Victor.cpp b/wpilibc/src/main/native/cpp/motorcontrol/Victor.cpp similarity index 50% rename from wpilibc/src/main/native/cpp/Victor.cpp rename to wpilibc/src/main/native/cpp/motorcontrol/Victor.cpp index a466add795..3ad29f73ee 100644 --- a/wpilibc/src/main/native/cpp/Victor.cpp +++ b/wpilibc/src/main/native/cpp/motorcontrol/Victor.cpp @@ -2,20 +2,17 @@ // 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 "frc/Victor.h" +#include "frc/motorcontrol/Victor.h" #include -#include "frc/smartdashboard/SendableRegistry.h" - using namespace frc; -Victor::Victor(int channel) : PWMSpeedController(channel) { - SetBounds(2.027, 1.525, 1.507, 1.49, 1.026); - SetPeriodMultiplier(kPeriodMultiplier_2X); - SetSpeed(0.0); - SetZeroLatch(); +Victor::Victor(int channel) : PWMMotorController("Victor", channel) { + m_pwm.SetBounds(2.027, 1.525, 1.507, 1.49, 1.026); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_2X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); HAL_Report(HALUsageReporting::kResourceType_Victor, GetChannel() + 1); - SendableRegistry::GetInstance().SetName(this, "Victor", GetChannel()); } diff --git a/wpilibc/src/main/native/cpp/motorcontrol/VictorSP.cpp b/wpilibc/src/main/native/cpp/motorcontrol/VictorSP.cpp new file mode 100644 index 0000000000..6dc888ef1a --- /dev/null +++ b/wpilibc/src/main/native/cpp/motorcontrol/VictorSP.cpp @@ -0,0 +1,18 @@ +// 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 "frc/motorcontrol/VictorSP.h" + +#include + +using namespace frc; + +VictorSP::VictorSP(int channel) : PWMMotorController("VictorSP", channel) { + m_pwm.SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.SetPeriodMultiplier(PWM::kPeriodMultiplier_1X); + m_pwm.SetSpeed(0.0); + m_pwm.SetZeroLatch(); + + HAL_Report(HALUsageReporting::kResourceType_VictorSP, GetChannel() + 1); +} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp index 84738bcde4..dc01b9f44a 100644 --- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp +++ b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp @@ -7,6 +7,7 @@ #include #include +#include "frc/Errors.h" #include "frc/shuffleboard/ComplexWidget.h" #include "frc/shuffleboard/ShuffleboardComponent.h" #include "frc/shuffleboard/ShuffleboardLayout.h" @@ -56,8 +57,8 @@ ShuffleboardLayout& ShuffleboardContainer::GetLayout(const wpi::Twine& title) { wpi::SmallVector storage; auto titleRef = title.toStringRef(storage); if (m_layouts.count(titleRef) == 0) { - wpi_setWPIErrorWithContext( - InvalidParameter, "No layout with the given title has been defined"); + throw FRC_MakeError(err::InvalidParameter, + "No layout with the given title has been defined"); } return *m_layouts[titleRef]; } diff --git a/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp index 7d42b99c21..ef8dfc6bec 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/MechanismLigament2d.cpp @@ -19,7 +19,8 @@ MechanismLigament2d::MechanismLigament2d(const wpi::Twine& name, double length, SetColor(color); } -void MechanismLigament2d::UpdateEntries(std::shared_ptr table) { +void MechanismLigament2d::UpdateEntries( + std::shared_ptr table) { table->GetEntry(".type").SetString("line"); m_colorEntry = table->GetEntry("color"); diff --git a/wpilibc/src/main/native/cpp/smartdashboard/MechanismObject2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/MechanismObject2d.cpp index 72192c32d4..f1a1cce864 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/MechanismObject2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/MechanismObject2d.cpp @@ -13,7 +13,7 @@ const std::string& MechanismObject2d::GetName() const { return m_name; } -void MechanismObject2d::Update(std::shared_ptr table) { +void MechanismObject2d::Update(std::shared_ptr table) { std::scoped_lock lock(m_mutex); m_table = table; UpdateEntries(m_table); diff --git a/wpilibc/src/main/native/cpp/smartdashboard/MechanismRoot2d.cpp b/wpilibc/src/main/native/cpp/smartdashboard/MechanismRoot2d.cpp index 48cc9a78ef..f91c34696a 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/MechanismRoot2d.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/MechanismRoot2d.cpp @@ -23,7 +23,7 @@ void MechanismRoot2d::SetPosition(double x, double y) { Flush(); } -void MechanismRoot2d::UpdateEntries(std::shared_ptr table) { +void MechanismRoot2d::UpdateEntries(std::shared_ptr table) { m_posEntry = table->GetEntry(kPosition); Flush(); } diff --git a/wpilibc/src/main/native/cpp/smartdashboard/SendableBase.cpp b/wpilibc/src/main/native/cpp/smartdashboard/SendableBase.cpp deleted file mode 100644 index 2b92c0f531..0000000000 --- a/wpilibc/src/main/native/cpp/smartdashboard/SendableBase.cpp +++ /dev/null @@ -1,17 +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 "frc/smartdashboard/SendableBase.h" - -#include "frc/smartdashboard/SendableRegistry.h" - -using namespace frc; - -SendableBase::SendableBase(bool addLiveWindow) { - if (addLiveWindow) { - SendableRegistry::GetInstance().AddLW(this, ""); - } else { - SendableRegistry::GetInstance().Add(this, ""); - } -} diff --git a/wpilibc/src/main/native/cpp/smartdashboard/SendableRegistry.cpp b/wpilibc/src/main/native/cpp/smartdashboard/SendableRegistry.cpp index de40d0565a..15cc985bf5 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/SendableRegistry.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/SendableRegistry.cpp @@ -352,7 +352,7 @@ Sendable* SendableRegistry::GetSendable(UID uid) { } void SendableRegistry::Publish(UID sendableUid, - std::shared_ptr table) { + std::shared_ptr table) { std::scoped_lock lock(m_impl->mutex); if (sendableUid == 0 || (sendableUid - 1) >= m_impl->components.size() || !m_impl->components[sendableUid - 1]) { diff --git a/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp b/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp index 35feb9de11..3cbd29ffd7 100644 --- a/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp +++ b/wpilibc/src/main/native/cpp/smartdashboard/SmartDashboard.cpp @@ -10,7 +10,7 @@ #include #include -#include "frc/WPIErrors.h" +#include "frc/Errors.h" #include "frc/smartdashboard/SendableRegistry.h" using namespace frc; @@ -85,9 +85,8 @@ nt::NetworkTableEntry SmartDashboard::GetEntry(wpi::StringRef key) { } void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) { - if (data == nullptr) { - wpi_setGlobalWPIErrorWithContext(NullParameter, "value"); - return; + if (!data) { + throw FRC_MakeError(err::NullParameter, "value"); } auto& inst = Singleton::GetInstance(); std::scoped_lock lock(inst.tablesToDataMutex); @@ -103,9 +102,8 @@ void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) { } void SmartDashboard::PutData(Sendable* value) { - if (value == nullptr) { - wpi_setGlobalWPIErrorWithContext(NullParameter, "value"); - return; + if (!value) { + throw FRC_MakeError(err::NullParameter, "value"); } auto name = SendableRegistry::GetInstance().GetName(value); if (!name.empty()) { @@ -118,8 +116,7 @@ Sendable* SmartDashboard::GetData(wpi::StringRef key) { std::scoped_lock lock(inst.tablesToDataMutex); auto it = inst.tablesToData.find(key); if (it == inst.tablesToData.end()) { - wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key); - return nullptr; + throw FRC_MakeError(err::SmartDashboardMissingKey, key); } return SendableRegistry::GetInstance().GetSendable(it->getValue()); } diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index d0b23faa9e..7a1ef244bd 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -18,9 +18,9 @@ #include "WPILibVersion.h" #include "frc/DriverStation.h" +#include "frc/Errors.h" #include "frc/RobotState.h" #include "frc/Utility.h" -#include "frc/WPIErrors.h" #include "frc/livewindow/LiveWindow.h" #include "frc/smartdashboard/SmartDashboard.h" @@ -54,10 +54,10 @@ class WPILibCameraServerShared : public frc::CameraServerShared { HAL_Report(HALUsageReporting::kResourceType_PCVideoServer, id); } void SetCameraServerError(const wpi::Twine& error) override { - wpi_setGlobalWPIErrorWithContext(CameraServerError, error); + FRC_ReportError(err::CameraServerError, error); } void SetVisionRunnerError(const wpi::Twine& error) override { - wpi_setGlobalErrorWithContext(-1, error); + FRC_ReportError(-1, error); } void ReportDriverStationError(const wpi::Twine& error) override { DriverStation::ReportError(error); @@ -214,7 +214,7 @@ RobotBase::RobotBase() : m_ds(DriverStation::GetInstance()) { ->GetEntry("LW Enabled") .SetBoolean(false); - LiveWindow::GetInstance()->SetEnabled(false); + LiveWindow::GetInstance().SetEnabled(false); } RobotBase::RobotBase(RobotBase&&) noexcept diff --git a/wpilibc/src/main/native/include/frc/ADXL345_I2C.h b/wpilibc/src/main/native/include/frc/ADXL345_I2C.h index 7820751442..feedd4c67d 100644 --- a/wpilibc/src/main/native/include/frc/ADXL345_I2C.h +++ b/wpilibc/src/main/native/include/frc/ADXL345_I2C.h @@ -6,7 +6,6 @@ #include -#include "frc/ErrorBase.h" #include "frc/I2C.h" #include "frc/interfaces/Accelerometer.h" #include "frc/smartdashboard/Sendable.h" @@ -23,8 +22,7 @@ class SendableBuilder; * an I2C bus. This class assumes the default (not alternate) sensor address of * 0x1D (7-bit address). */ -class ADXL345_I2C : public ErrorBase, - public Accelerometer, +class ADXL345_I2C : public Accelerometer, public Sendable, public SendableHelper { public: diff --git a/wpilibc/src/main/native/include/frc/ADXL345_SPI.h b/wpilibc/src/main/native/include/frc/ADXL345_SPI.h index ee16518760..bc6122343d 100644 --- a/wpilibc/src/main/native/include/frc/ADXL345_SPI.h +++ b/wpilibc/src/main/native/include/frc/ADXL345_SPI.h @@ -6,7 +6,6 @@ #include -#include "frc/ErrorBase.h" #include "frc/SPI.h" #include "frc/interfaces/Accelerometer.h" #include "frc/smartdashboard/Sendable.h" @@ -20,8 +19,7 @@ namespace frc { * This class allows access to an Analog Devices ADXL345 3-axis accelerometer * via SPI. This class assumes the sensor is wired in 4-wire SPI mode. */ -class ADXL345_SPI : public ErrorBase, - public Accelerometer, +class ADXL345_SPI : public Accelerometer, public Sendable, public SendableHelper { public: diff --git a/wpilibc/src/main/native/include/frc/ADXL362.h b/wpilibc/src/main/native/include/frc/ADXL362.h index 39734e1d57..ca9bc9129c 100644 --- a/wpilibc/src/main/native/include/frc/ADXL362.h +++ b/wpilibc/src/main/native/include/frc/ADXL362.h @@ -6,7 +6,6 @@ #include -#include "frc/ErrorBase.h" #include "frc/SPI.h" #include "frc/interfaces/Accelerometer.h" #include "frc/smartdashboard/Sendable.h" @@ -21,8 +20,7 @@ class SendableBuilder; * * This class allows access to an Analog Devices ADXL362 3-axis accelerometer. */ -class ADXL362 : public ErrorBase, - public Accelerometer, +class ADXL362 : public Accelerometer, public Sendable, public SendableHelper { public: diff --git a/wpilibc/src/main/native/include/frc/ADXRS450_Gyro.h b/wpilibc/src/main/native/include/frc/ADXRS450_Gyro.h index 3c49c05622..69b6492f72 100644 --- a/wpilibc/src/main/native/include/frc/ADXRS450_Gyro.h +++ b/wpilibc/src/main/native/include/frc/ADXRS450_Gyro.h @@ -8,8 +8,10 @@ #include -#include "frc/GyroBase.h" #include "frc/SPI.h" +#include "frc/interfaces/Gyro.h" +#include "frc/smartdashboard/Sendable.h" +#include "frc/smartdashboard/SendableHelper.h" namespace frc { @@ -26,7 +28,9 @@ namespace frc { * This class is for the digital ADXRS450 gyro sensor that connects via SPI. * Only one instance of an ADXRS Gyro is supported. */ -class ADXRS450_Gyro : public GyroBase { +class ADXRS450_Gyro : public Gyro, + public Sendable, + public SendableHelper { public: /** * Gyro constructor on onboard CS0. @@ -96,6 +100,8 @@ class ADXRS450_Gyro : public GyroBase { */ int GetPort() const; + void InitSendable(SendableBuilder& builder) override; + private: SPI m_spi; SPI::Port m_port; diff --git a/wpilibc/src/main/native/include/frc/AddressableLED.h b/wpilibc/src/main/native/include/frc/AddressableLED.h index d0b5428055..2cdff76bf2 100644 --- a/wpilibc/src/main/native/include/frc/AddressableLED.h +++ b/wpilibc/src/main/native/include/frc/AddressableLED.h @@ -11,7 +11,6 @@ #include #include -#include "frc/ErrorBase.h" #include "util/Color.h" #include "util/Color8Bit.h" @@ -22,7 +21,7 @@ namespace frc { * *

Only 1 LED driver is currently supported by the roboRIO. */ -class AddressableLED : public ErrorBase { +class AddressableLED { public: class LEDData : public HAL_AddressableLEDData { public: @@ -86,7 +85,7 @@ class AddressableLED : public ErrorBase { */ explicit AddressableLED(int port); - ~AddressableLED() override; + ~AddressableLED(); /** * Sets the length of the LED strip. diff --git a/wpilibc/src/main/native/include/frc/AnalogAccelerometer.h b/wpilibc/src/main/native/include/frc/AnalogAccelerometer.h index 96b9598c74..acc5c5f8d1 100644 --- a/wpilibc/src/main/native/include/frc/AnalogAccelerometer.h +++ b/wpilibc/src/main/native/include/frc/AnalogAccelerometer.h @@ -7,8 +7,6 @@ #include #include "frc/AnalogInput.h" -#include "frc/ErrorBase.h" -#include "frc/PIDSource.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -23,9 +21,7 @@ class SendableBuilder; * sensors have multiple axis and can be treated as multiple devices. Each is * calibrated by finding the center value over a period of time. */ -class AnalogAccelerometer : public ErrorBase, - public PIDSource, - public Sendable, +class AnalogAccelerometer : public Sendable, public SendableHelper { public: /** @@ -97,13 +93,6 @@ class AnalogAccelerometer : public ErrorBase, */ void SetZero(double zero); - /** - * Get the Acceleration for the PID Source parent. - * - * @return The current acceleration in Gs. - */ - double PIDGet() override; - void InitSendable(SendableBuilder& builder) override; private: diff --git a/wpilibc/src/main/native/include/frc/AnalogEncoder.h b/wpilibc/src/main/native/include/frc/AnalogEncoder.h index 61959f89ab..44b3f02339 100644 --- a/wpilibc/src/main/native/include/frc/AnalogEncoder.h +++ b/wpilibc/src/main/native/include/frc/AnalogEncoder.h @@ -12,7 +12,6 @@ #include "frc/AnalogTrigger.h" #include "frc/Counter.h" -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -22,9 +21,7 @@ class AnalogInput; /** * Class for supporting continuous analog encoders, such as the US Digital MA3. */ -class AnalogEncoder : public ErrorBase, - public Sendable, - public SendableHelper { +class AnalogEncoder : public Sendable, public SendableHelper { public: /** * Construct a new AnalogEncoder attached to a specific AnalogIn channel. diff --git a/wpilibc/src/main/native/include/frc/AnalogGyro.h b/wpilibc/src/main/native/include/frc/AnalogGyro.h index 42b6317def..ef36ab0126 100644 --- a/wpilibc/src/main/native/include/frc/AnalogGyro.h +++ b/wpilibc/src/main/native/include/frc/AnalogGyro.h @@ -8,7 +8,7 @@ #include -#include "frc/GyroBase.h" +#include "frc/interfaces/Gyro.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -29,7 +29,9 @@ class AnalogInput; * * This class is for gyro sensors that connect to an analog input. */ -class AnalogGyro : public GyroBase { +class AnalogGyro : public Gyro, + public Sendable, + public SendableHelper { public: static constexpr int kOversampleBits = 10; static constexpr int kAverageBits = 0; @@ -190,6 +192,8 @@ class AnalogGyro : public GyroBase { */ std::shared_ptr GetAnalogInput() const; + void InitSendable(SendableBuilder& builder) override; + protected: std::shared_ptr m_analog; diff --git a/wpilibc/src/main/native/include/frc/AnalogInput.h b/wpilibc/src/main/native/include/frc/AnalogInput.h index e9cb320ccc..6b1828225e 100644 --- a/wpilibc/src/main/native/include/frc/AnalogInput.h +++ b/wpilibc/src/main/native/include/frc/AnalogInput.h @@ -8,8 +8,6 @@ #include -#include "frc/ErrorBase.h" -#include "frc/PIDSource.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -31,10 +29,7 @@ class DMASample; * are divided by the number of samples to retain the resolution, but get more * stable values. */ -class AnalogInput : public ErrorBase, - public PIDSource, - public Sendable, - public SendableHelper { +class AnalogInput : public Sendable, public SendableHelper { friend class AnalogTrigger; friend class AnalogGyro; friend class DMA; @@ -280,13 +275,6 @@ class AnalogInput : public ErrorBase, */ static double GetSampleRate(); - /** - * Get the Average value for the PID Source base object. - * - * @return The average voltage. - */ - double PIDGet() override; - /** * Indicates this input is used by a simulated device. * diff --git a/wpilibc/src/main/native/include/frc/AnalogOutput.h b/wpilibc/src/main/native/include/frc/AnalogOutput.h index 6120059e2b..f93511a903 100644 --- a/wpilibc/src/main/native/include/frc/AnalogOutput.h +++ b/wpilibc/src/main/native/include/frc/AnalogOutput.h @@ -6,7 +6,6 @@ #include -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -17,9 +16,7 @@ class SendableBuilder; /** * MXP analog output class. */ -class AnalogOutput : public ErrorBase, - public Sendable, - public SendableHelper { +class AnalogOutput : public Sendable, public SendableHelper { public: /** * Construct an analog output on the given channel. diff --git a/wpilibc/src/main/native/include/frc/AnalogPotentiometer.h b/wpilibc/src/main/native/include/frc/AnalogPotentiometer.h index f34e34f385..8c470bbf45 100644 --- a/wpilibc/src/main/native/include/frc/AnalogPotentiometer.h +++ b/wpilibc/src/main/native/include/frc/AnalogPotentiometer.h @@ -7,8 +7,6 @@ #include #include "frc/AnalogInput.h" -#include "frc/ErrorBase.h" -#include "frc/interfaces/Potentiometer.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -22,9 +20,7 @@ class SendableBuilder; * units you choose, by way of the scaling and offset constants passed to the * constructor. */ -class AnalogPotentiometer : public ErrorBase, - public Potentiometer, - public Sendable, +class AnalogPotentiometer : public Sendable, public SendableHelper { public: /** @@ -105,14 +101,7 @@ class AnalogPotentiometer : public ErrorBase, * @return The current position of the potentiometer (in the units used for * fullRange and offset). */ - double Get() const override; - - /** - * Implement the PIDSource interface. - * - * @return The current reading. - */ - double PIDGet() override; + double Get() const; void InitSendable(SendableBuilder& builder) override; diff --git a/wpilibc/src/main/native/include/frc/AnalogTrigger.h b/wpilibc/src/main/native/include/frc/AnalogTrigger.h index 6cb6ec0959..6fb41cf0c2 100644 --- a/wpilibc/src/main/native/include/frc/AnalogTrigger.h +++ b/wpilibc/src/main/native/include/frc/AnalogTrigger.h @@ -9,7 +9,6 @@ #include #include "frc/AnalogTriggerOutput.h" -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -19,9 +18,7 @@ class AnalogInput; class DutyCycle; class SendableBuilder; -class AnalogTrigger : public ErrorBase, - public Sendable, - public SendableHelper { +class AnalogTrigger : public Sendable, public SendableHelper { friend class AnalogTriggerOutput; public: diff --git a/wpilibc/src/main/native/include/frc/BuiltInAccelerometer.h b/wpilibc/src/main/native/include/frc/BuiltInAccelerometer.h index 8a55a978f1..517b7ae483 100644 --- a/wpilibc/src/main/native/include/frc/BuiltInAccelerometer.h +++ b/wpilibc/src/main/native/include/frc/BuiltInAccelerometer.h @@ -4,7 +4,6 @@ #pragma once -#include "frc/ErrorBase.h" #include "frc/interfaces/Accelerometer.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -18,8 +17,7 @@ class SendableBuilder; * * This class allows access to the roboRIO's internal accelerometer. */ -class BuiltInAccelerometer : public ErrorBase, - public Accelerometer, +class BuiltInAccelerometer : public Accelerometer, public Sendable, public SendableHelper { public: diff --git a/wpilibc/src/main/native/include/frc/CAN.h b/wpilibc/src/main/native/include/frc/CAN.h index 495e782992..4c9b9bd917 100644 --- a/wpilibc/src/main/native/include/frc/CAN.h +++ b/wpilibc/src/main/native/include/frc/CAN.h @@ -8,8 +8,6 @@ #include -#include "frc/ErrorBase.h" - namespace frc { struct CANData { uint8_t data[8]; @@ -27,7 +25,7 @@ struct CANData { * All methods are thread save, however the buffer objects passed in * by the user need to not be modified for the duration of their calls. */ -class CAN : public ErrorBase { +class CAN { public: /** * Create a new CAN communication interface with the specific device ID. @@ -52,7 +50,7 @@ class CAN : public ErrorBase { /** * Closes the CAN communication. */ - ~CAN() override; + ~CAN(); CAN(CAN&&) = default; CAN& operator=(CAN&&) = default; diff --git a/wpilibc/src/main/native/include/frc/Compressor.h b/wpilibc/src/main/native/include/frc/Compressor.h index 96b1be5738..e83ba0f611 100644 --- a/wpilibc/src/main/native/include/frc/Compressor.h +++ b/wpilibc/src/main/native/include/frc/Compressor.h @@ -6,7 +6,6 @@ #include -#include "frc/ErrorBase.h" #include "frc/SensorUtil.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -30,9 +29,7 @@ class SendableBuilder; * loop control. You can only turn off closed loop control, thereby stopping * the compressor from operating. */ -class Compressor : public ErrorBase, - public Sendable, - public SendableHelper { +class Compressor : public Sendable, public SendableHelper { public: /** * Constructor. The default PCM ID is 0. diff --git a/wpilibc/src/main/native/include/frc/Counter.h b/wpilibc/src/main/native/include/frc/Counter.h index dc0f4179e0..c15814e293 100644 --- a/wpilibc/src/main/native/include/frc/Counter.h +++ b/wpilibc/src/main/native/include/frc/Counter.h @@ -10,7 +10,6 @@ #include "frc/AnalogTrigger.h" #include "frc/CounterBase.h" -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -31,8 +30,7 @@ class DMASample; * All counters will immediately start counting - Reset() them if you need them * to be zeroed before use. */ -class Counter : public ErrorBase, - public CounterBase, +class Counter : public CounterBase, public Sendable, public SendableHelper { friend class DMA; diff --git a/wpilibc/src/main/native/include/frc/DMA.h b/wpilibc/src/main/native/include/frc/DMA.h index 7646fa8b81..72c3829215 100644 --- a/wpilibc/src/main/native/include/frc/DMA.h +++ b/wpilibc/src/main/native/include/frc/DMA.h @@ -6,8 +6,6 @@ #include -#include "frc/ErrorBase.h" - namespace frc { class Encoder; class Counter; @@ -16,12 +14,12 @@ class DutyCycle; class AnalogInput; class DMASample; -class DMA : public ErrorBase { +class DMA { friend class DMASample; public: DMA(); - ~DMA() override; + ~DMA(); DMA& operator=(DMA&& other) = default; DMA(DMA&& other) = default; diff --git a/wpilibc/src/main/native/include/frc/DigitalGlitchFilter.h b/wpilibc/src/main/native/include/frc/DigitalGlitchFilter.h index 3fce2d083f..e75ea3923b 100644 --- a/wpilibc/src/main/native/include/frc/DigitalGlitchFilter.h +++ b/wpilibc/src/main/native/include/frc/DigitalGlitchFilter.h @@ -11,7 +11,6 @@ #include #include "frc/DigitalSource.h" -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -27,8 +26,7 @@ class Counter; * filter. The filter lets the user configure the time that an input must remain * high or low before it is classified as high or low. */ -class DigitalGlitchFilter : public ErrorBase, - public Sendable, +class DigitalGlitchFilter : public Sendable, public SendableHelper { public: DigitalGlitchFilter(); diff --git a/wpilibc/src/main/native/include/frc/DriverStation.h b/wpilibc/src/main/native/include/frc/DriverStation.h index ba521c7be0..91e36a6503 100644 --- a/wpilibc/src/main/native/include/frc/DriverStation.h +++ b/wpilibc/src/main/native/include/frc/DriverStation.h @@ -15,8 +15,6 @@ #include #include -#include "frc/ErrorBase.h" - namespace frc { class MatchDataSender; @@ -25,12 +23,12 @@ class MatchDataSender; * Provide access to the network communication data to / from the Driver * Station. */ -class DriverStation : public ErrorBase { +class DriverStation { public: enum Alliance { kRed, kBlue, kInvalid }; enum MatchType { kNone, kPractice, kQualification, kElimination }; - ~DriverStation() override; + ~DriverStation(); DriverStation(const DriverStation&) = delete; DriverStation& operator=(const DriverStation&) = delete; diff --git a/wpilibc/src/main/native/include/frc/DutyCycle.h b/wpilibc/src/main/native/include/frc/DutyCycle.h index 8b02e875bf..0cdf8c3019 100644 --- a/wpilibc/src/main/native/include/frc/DutyCycle.h +++ b/wpilibc/src/main/native/include/frc/DutyCycle.h @@ -8,7 +8,6 @@ #include -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -29,9 +28,7 @@ class DMASample; * order to implement rollover checking. * */ -class DutyCycle : public ErrorBase, - public Sendable, - public SendableHelper { +class DutyCycle : public Sendable, public SendableHelper { friend class AnalogTrigger; friend class DMA; friend class DMASample; diff --git a/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h b/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h index 87789f2fc2..fc1d0108ea 100644 --- a/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h +++ b/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h @@ -12,7 +12,6 @@ #include "frc/AnalogTrigger.h" #include "frc/Counter.h" -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -25,8 +24,7 @@ class DigitalSource; * PWM Output, the CTRE Mag Encoder, the Rev Hex Encoder, and the AM Mag * Encoder. */ -class DutyCycleEncoder : public ErrorBase, - public Sendable, +class DutyCycleEncoder : public Sendable, public SendableHelper { public: /** diff --git a/wpilibc/src/main/native/include/frc/Encoder.h b/wpilibc/src/main/native/include/frc/Encoder.h index 973e995434..50f8cbf152 100644 --- a/wpilibc/src/main/native/include/frc/Encoder.h +++ b/wpilibc/src/main/native/include/frc/Encoder.h @@ -10,8 +10,6 @@ #include "frc/Counter.h" #include "frc/CounterBase.h" -#include "frc/ErrorBase.h" -#include "frc/PIDSource.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -38,9 +36,7 @@ class DMASample; * All encoders will immediately start counting - Reset() them if you need them * to be zeroed before use. */ -class Encoder : public ErrorBase, - public CounterBase, - public PIDSource, +class Encoder : public CounterBase, public Sendable, public SendableHelper { friend class DMA; @@ -314,8 +310,6 @@ class Encoder : public ErrorBase, */ int GetSamplesToAverage() const; - double PIDGet() override; - /** * Set the index source for the encoder. * diff --git a/wpilibc/src/main/native/include/frc/Error.h b/wpilibc/src/main/native/include/frc/Error.h deleted file mode 100644 index 812d1491bb..0000000000 --- a/wpilibc/src/main/native/include/frc/Error.h +++ /dev/null @@ -1,63 +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 - -#ifdef _WIN32 -#pragma push_macro("GetMessage") -#undef GetMessage -#endif - -namespace frc { - -class ErrorBase; - -/** - * Error object represents a library error. - */ -class Error { - public: - using Code = int; - - Error() = default; - Error(Code code, const wpi::Twine& contextMessage, wpi::StringRef filename, - wpi::StringRef function, int lineNumber, - const ErrorBase* originatingObject); - - bool operator<(const Error& rhs) const; - - Code GetCode() const; - std::string GetMessage() const; - std::string GetFilename() const; - std::string GetFunction() const; - int GetLineNumber() const; - const ErrorBase* GetOriginatingObject() const; - double GetTimestamp() const; - void Clear(); - void Set(Code code, const wpi::Twine& contextMessage, wpi::StringRef filename, - wpi::StringRef function, int lineNumber, - const ErrorBase* originatingObject); - - private: - void Report(); - - Code m_code = 0; - std::string m_message; - std::string m_filename; - std::string m_function; - int m_lineNumber = 0; - const ErrorBase* m_originatingObject = nullptr; - double m_timestamp = 0.0; -}; - -} // namespace frc - -#ifdef _WIN32 -#pragma pop_macro("GetMessage") -#endif diff --git a/wpilibc/src/main/native/include/frc/ErrorBase.h b/wpilibc/src/main/native/include/frc/ErrorBase.h deleted file mode 100644 index f9e8b00bf4..0000000000 --- a/wpilibc/src/main/native/include/frc/ErrorBase.h +++ /dev/null @@ -1,239 +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 - -#include "frc/Error.h" - -// Forward declared manually to avoid needing to pull in entire HAL header. -extern "C" const char* HAL_GetErrorMessage(int32_t code); - -#define wpi_setErrnoErrorWithContext(context) \ - this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__) -#define wpi_setErrnoError() wpi_setErrnoErrorWithContext("") -#define wpi_setImaqErrorWithContext(code, context) \ - do { \ - if ((code) != 0) \ - this->SetImaqError((code), (context), __FILE__, __FUNCTION__, __LINE__); \ - } while (0) -#define wpi_setErrorWithContext(code, context) \ - do { \ - if ((code) != 0) \ - this->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__); \ - } while (0) -#define wpi_setErrorWithContextRange(code, min, max, req, context) \ - do { \ - if ((code) != 0) \ - this->SetErrorRange((code), (min), (max), (req), (context), __FILE__, \ - __FUNCTION__, __LINE__); \ - } while (0) - -#define wpi_setHALError(code) \ - do { \ - if ((code) != 0) \ - this->SetError((code), HAL_GetErrorMessage(code), __FILE__, \ - __FUNCTION__, __LINE__); \ - } while (0) - -#define wpi_setHALErrorWithRange(code, min, max, req) \ - do { \ - if ((code) != 0) \ - this->SetErrorRange((code), (min), (max), (req), \ - HAL_GetErrorMessage(code), __FILE__, __FUNCTION__, \ - __LINE__); \ - } while (0) - -#define wpi_setError(code) wpi_setErrorWithContext(code, "") -#define wpi_setStaticErrorWithContext(object, code, context) \ - do { \ - if ((code) != 0) \ - object->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__); \ - } while (0) -#define wpi_setStaticError(object, code) \ - wpi_setStaticErrorWithContext(object, code, "") - -#define wpi_setGlobalErrorWithContext(code, context) \ - do { \ - if ((code) != 0) \ - ::frc::ErrorBase::SetGlobalError((code), (context), __FILE__, \ - __FUNCTION__, __LINE__); \ - } while (0) - -#define wpi_setGlobalHALError(code) \ - do { \ - if ((code) != 0) \ - ::frc::ErrorBase::SetGlobalError((code), HAL_GetErrorMessage(code), \ - __FILE__, __FUNCTION__, __LINE__); \ - } while (0) - -#define wpi_setGlobalError(code) wpi_setGlobalErrorWithContext(code, "") -#define wpi_setWPIErrorWithContext(error, context) \ - this->SetWPIError(wpi_error_s_##error(), wpi_error_value_##error(), \ - (context), __FILE__, __FUNCTION__, __LINE__) -#define wpi_setWPIError(error) (wpi_setWPIErrorWithContext(error, "")) -#define wpi_setStaticWPIErrorWithContext(object, error, context) \ - object->SetWPIError(wpi_error_s_##error(), (context), __FILE__, \ - __FUNCTION__, __LINE__) -#define wpi_setStaticWPIError(object, error) \ - wpi_setStaticWPIErrorWithContext(object, error, "") -#define wpi_setGlobalWPIErrorWithContext(error, context) \ - ::frc::ErrorBase::SetGlobalWPIError(wpi_error_s_##error(), (context), \ - __FILE__, __FUNCTION__, __LINE__) -#define wpi_setGlobalWPIError(error) wpi_setGlobalWPIErrorWithContext(error, "") - -namespace frc { - -/** - * Base class for most objects. - * - * ErrorBase is the base class for most objects since it holds the generated - * error for that object. In addition, there is a single instance of a global - * error object. - */ -class ErrorBase { - // TODO: Consider initializing instance variables and cleanup in destructor - public: - ErrorBase(); - virtual ~ErrorBase() = default; - - ErrorBase(const ErrorBase&) = default; - ErrorBase& operator=(const ErrorBase&) = default; - ErrorBase(ErrorBase&&) = default; - ErrorBase& operator=(ErrorBase&&) = default; - - /** - * @brief Retrieve the current error. - * - * Get the current error information associated with this sensor. - */ - virtual Error& GetError(); - - /** - * @brief Retrieve the current error. - * - * Get the current error information associated with this sensor. - */ - virtual const Error& GetError() const; - - /** - * @brief Clear the current error information associated with this sensor. - */ - virtual void ClearError() const; - - /** - * @brief Set error information associated with a C library call that set an - * error to the "errno" global variable. - * - * @param contextMessage A custom message from the code that set the error. - * @param filename Filename of the error source - * @param function Function of the error source - * @param lineNumber Line number of the error source - */ - virtual void SetErrnoError(const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const; - - /** - * @brief Set the current error information associated from the nivision Imaq - * API. - * - * @param success The return from the function - * @param contextMessage A custom message from the code that set the error. - * @param filename Filename of the error source - * @param function Function of the error source - * @param lineNumber Line number of the error source - */ - virtual void SetImaqError(int success, const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const; - - /** - * @brief Set the current error information associated with this sensor. - * - * @param code The error code - * @param contextMessage A custom message from the code that set the error. - * @param filename Filename of the error source - * @param function Function of the error source - * @param lineNumber Line number of the error source - */ - virtual void SetError(Error::Code code, const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const; - - /** - * @brief Set the current error information associated with this sensor. - * Range versions use for initialization code. - * - * @param code The error code - * @param minRange The minimum allowed allocation range - * @param maxRange The maximum allowed allocation range - * @param requestedValue The requested value to allocate - * @param contextMessage A custom message from the code that set the error. - * @param filename Filename of the error source - * @param function Function of the error source - * @param lineNumber Line number of the error source - */ - virtual void SetErrorRange(Error::Code code, int32_t minRange, - int32_t maxRange, int32_t requestedValue, - const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const; - - /** - * @brief Set the current error information associated with this sensor. - * - * @param errorMessage The error message from WPIErrors.h - * @param contextMessage A custom message from the code that set the error. - * @param filename Filename of the error source - * @param function Function of the error source - * @param lineNumber Line number of the error source - */ - virtual void SetWPIError(const wpi::Twine& errorMessage, Error::Code code, - const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber) const; - - virtual void CloneError(const ErrorBase& rhs) const; - - /** - * @brief Check if the current error code represents a fatal error. - * - * @return true if the current error is fatal. - */ - virtual bool StatusIsFatal() const; - - static void SetGlobalError(Error::Code code, const wpi::Twine& contextMessage, - wpi::StringRef filename, wpi::StringRef function, - int lineNumber); - - static void SetGlobalWPIError(const wpi::Twine& errorMessage, - const wpi::Twine& contextMessage, - wpi::StringRef filename, - wpi::StringRef function, int lineNumber); - - /** - * Retrieve the last global error. - */ - static Error GetGlobalError(); - - /** - * Retrieve all global errors. - */ - static std::vector GetGlobalErrors(); - - /** - * Clear global errors. - */ - void ClearGlobalErrors(); - - protected: - mutable Error m_error; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/Errors.h b/wpilibc/src/main/native/include/frc/Errors.h new file mode 100644 index 0000000000..64b965f3c0 --- /dev/null +++ b/wpilibc/src/main/native/include/frc/Errors.h @@ -0,0 +1,139 @@ +// 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 +#include + +#include + +namespace frc { + +/** + * Runtime error exception. + */ +class RuntimeError : public std::runtime_error { + public: + RuntimeError(int32_t code, const wpi::Twine& message, const wpi::Twine& loc, + wpi::StringRef stack); + RuntimeError(int32_t code, const wpi::Twine& message, const char* fileName, + int lineNumber, const char* funcName, wpi::StringRef stack); + + int32_t code() const noexcept { return m_data->code; } + const char* loc() const noexcept { return m_data->loc.c_str(); } + const char* stack() const noexcept { return m_data->stack.c_str(); } + + /** + * Reports error to Driver Station (using HAL_SendError). + */ + void Report() const; + + private: + struct Data { + int32_t code; + std::string loc; + std::string stack; + }; + std::shared_ptr m_data; +}; + +/** + * Gets error message string for an error code. + */ +const char* GetErrorMessage(int32_t* code); + +/** + * Reports an error to the driver station (using HAL_SendError). + * Generally the FRC_ReportError wrapper macro should be used instead. + * + * @param status error code + * @param message error message details + * @param fileName source file name + * @param lineNumber source line number + * @param funcName source function name + */ +void ReportError(int32_t status, const wpi::Twine& message, + const char* fileName, int lineNumber, const char* funcName); + +/** + * Makes a runtime error exception object. This object should be thrown + * by the caller. Generally the FRC_MakeError wrapper macro should be used + * instead. + * + * @param status error code + * @param message error message details + * @param fileName source file name + * @param lineNumber source line number + * @param funcName source function name + * @return runtime error object + */ +[[nodiscard]] RuntimeError MakeError(int32_t status, const wpi::Twine& message, + const char* fileName, int lineNumber, + const char* funcName); + +namespace err { +#define S(label, offset, message) inline constexpr int label = offset; +#include "frc/WPIErrors.mac" +#undef S +} // namespace err + +namespace warn { +#define S(label, offset, message) inline constexpr int label = offset; +#include "frc/WPIWarnings.mac" +#undef S +} // namespace warn +} // namespace frc + +/** + * Reports an error to the driver station (using HAL_SendError). + * + * @param status error code + * @param message error message details + */ +#define FRC_ReportError(status, message) \ + do { \ + if ((status) != 0) { \ + ::frc::ReportError(status, message, __FILE__, __LINE__, __FUNCTION__); \ + } \ + } while (0) + +/** + * Makes a runtime error exception object. This object should be thrown + * by the caller. + * + * @param status error code + * @param message error message details + * @return runtime error object + */ +#define FRC_MakeError(status, message) \ + ::frc::MakeError(status, message, __FILE__, __LINE__, __FUNCTION__) + +/** + * Checks a status code and depending on its value, either throws a + * RuntimeError exception, calls ReportError, or does nothing (if no error). + * + * @param status error code + * @param message error message details + */ +#define FRC_CheckErrorStatus(status, message) \ + do { \ + if ((status) < 0) { \ + throw FRC_MakeError(status, message); \ + } else if ((status) > 0) { \ + FRC_ReportError(status, message); \ + } \ + } while (0) + +#define FRC_AssertMessage(condition, message) \ + do { \ + if (!(condition)) { \ + throw FRC_MakeError(err::AssertionFailure, message); \ + } \ + } while (0) + +#define FRC_Assert(condition) FRC_AssertMessage(condition, #condition) diff --git a/wpilibc/src/main/native/include/frc/GearTooth.h b/wpilibc/src/main/native/include/frc/GearTooth.h deleted file mode 100644 index 1df5699c6a..0000000000 --- a/wpilibc/src/main/native/include/frc/GearTooth.h +++ /dev/null @@ -1,85 +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 - -#include "frc/Counter.h" - -namespace frc { - -/** - * Alias for counter class. - * - * Implements the gear tooth sensor supplied by FIRST. Currently there is no - * reverse sensing on the gear tooth sensor, but in future versions we might - * implement the necessary timing in the FPGA to sense direction. - * - * @deprecated No longer used per FMS usage reporting - */ -class GearTooth : public Counter { - public: - // 55 uSec for threshold - static constexpr double kGearToothThreshold = 55e-6; - - /** - * Construct a GearTooth sensor given a channel. - * - * @param channel The DIO channel that the sensor is connected to. - * 0-9 are on-board, 10-25 are on the MXP. - * @param directionSensitive True to enable the pulse length decoding in - * hardware to specify count direction. - */ - WPI_DEPRECATED( - "The only sensor this works with is no longer available and no teams use " - "it according to FMS usage reporting.") - explicit GearTooth(int channel, bool directionSensitive = false); - - /** - * Construct a GearTooth sensor given a digital input. - * - * This should be used when sharing digital inputs. - * - * @param source A pointer to the existing DigitalSource object - * (such as a DigitalInput) - * @param directionSensitive True to enable the pulse length decoding in - * hardware to specify count direction. - */ - WPI_DEPRECATED( - "The only sensor this works with is no longer available and no teams use " - "it according to FMS usage reporting.") - explicit GearTooth(DigitalSource* source, bool directionSensitive = false); - - /** - * Construct a GearTooth sensor given a digital input. - * - * This should be used when sharing digital inputs. - * - * @param source A reference to the existing DigitalSource object - * (such as a DigitalInput) - * @param directionSensitive True to enable the pulse length decoding in - * hardware to specify count direction. - */ - WPI_DEPRECATED( - "The only sensor this works with is no longer available and no teams use " - "it according to FMS usage reporting.") - explicit GearTooth(std::shared_ptr source, - bool directionSensitive = false); - - GearTooth(GearTooth&&) = default; - GearTooth& operator=(GearTooth&&) = default; - - /** - * Common code called by the constructors. - */ - void EnableDirectionSensing(bool directionSensitive); - - void InitSendable(SendableBuilder& builder) override; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/GenericHID.h b/wpilibc/src/main/native/include/frc/GenericHID.h index e441204034..880782b1d9 100644 --- a/wpilibc/src/main/native/include/frc/GenericHID.h +++ b/wpilibc/src/main/native/include/frc/GenericHID.h @@ -8,8 +8,6 @@ #include -#include "frc/ErrorBase.h" - namespace frc { class DriverStation; @@ -17,7 +15,7 @@ class DriverStation; /** * GenericHID Interface. */ -class GenericHID : public ErrorBase { +class GenericHID { public: enum RumbleType { kLeftRumble, kRightRumble }; @@ -44,7 +42,7 @@ class GenericHID : public ErrorBase { enum JoystickHand { kLeftHand = 0, kRightHand = 1 }; explicit GenericHID(int port); - ~GenericHID() override = default; + virtual ~GenericHID() = default; GenericHID(GenericHID&&) = default; GenericHID& operator=(GenericHID&&) = default; diff --git a/wpilibc/src/main/native/include/frc/GyroBase.h b/wpilibc/src/main/native/include/frc/GyroBase.h deleted file mode 100644 index cec8a6f4a8..0000000000 --- a/wpilibc/src/main/native/include/frc/GyroBase.h +++ /dev/null @@ -1,41 +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 "frc/ErrorBase.h" -#include "frc/PIDSource.h" -#include "frc/interfaces/Gyro.h" -#include "frc/smartdashboard/Sendable.h" -#include "frc/smartdashboard/SendableHelper.h" - -namespace frc { - -/** - * GyroBase is the common base class for Gyro implementations such as - * AnalogGyro. - */ -class GyroBase : public Gyro, - public ErrorBase, - public PIDSource, - public Sendable, - public SendableHelper { - public: - GyroBase() = default; - GyroBase(GyroBase&&) = default; - GyroBase& operator=(GyroBase&&) = default; - - // PIDSource interface - /** - * Get the PIDOutput for the PIDSource base object. Can be set to return - * angle or rate using SetPIDSourceType(). Defaults to angle. - * - * @return The PIDOutput (angle or rate, defaults to angle) - */ - double PIDGet() override; - - void InitSendable(SendableBuilder& builder) override; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/I2C.h b/wpilibc/src/main/native/include/frc/I2C.h index f62aaf0731..5031673160 100644 --- a/wpilibc/src/main/native/include/frc/I2C.h +++ b/wpilibc/src/main/native/include/frc/I2C.h @@ -8,8 +8,6 @@ #include -#include "frc/ErrorBase.h" - namespace frc { /** @@ -18,7 +16,7 @@ namespace frc { * This class is intended to be used by sensor (and other I2C device) drivers. * It probably should not be used directly. */ -class I2C : public ErrorBase { +class I2C { public: enum Port { kOnboard = 0, kMXP }; @@ -30,7 +28,7 @@ class I2C : public ErrorBase { */ I2C(Port port, int deviceAddress); - ~I2C() override; + ~I2C(); I2C(I2C&&) = default; I2C& operator=(I2C&&) = default; diff --git a/wpilibc/src/main/native/include/frc/InterruptableSensorBase.h b/wpilibc/src/main/native/include/frc/InterruptableSensorBase.h index 6e361ab26d..cefc2d2d0c 100644 --- a/wpilibc/src/main/native/include/frc/InterruptableSensorBase.h +++ b/wpilibc/src/main/native/include/frc/InterruptableSensorBase.h @@ -10,11 +10,10 @@ #include #include "frc/AnalogTriggerType.h" -#include "frc/ErrorBase.h" namespace frc { -class InterruptableSensorBase : public ErrorBase { +class InterruptableSensorBase { public: enum WaitResult { kTimeout = 0x0, @@ -35,7 +34,7 @@ class InterruptableSensorBase : public ErrorBase { /** * Free the resources for an interrupt event. */ - ~InterruptableSensorBase() override; + virtual ~InterruptableSensorBase(); InterruptableSensorBase(InterruptableSensorBase&&) = default; InterruptableSensorBase& operator=(InterruptableSensorBase&&) = default; diff --git a/wpilibc/src/main/native/include/frc/IterativeRobot.h b/wpilibc/src/main/native/include/frc/IterativeRobot.h deleted file mode 100644 index f6c1532917..0000000000 --- a/wpilibc/src/main/native/include/frc/IterativeRobot.h +++ /dev/null @@ -1,50 +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 "frc/IterativeRobotBase.h" - -namespace frc { - -/** - * IterativeRobot implements the IterativeRobotBase robot program framework. - * - * The IterativeRobot class is intended to be subclassed by a user creating a - * robot program. - * - * Periodic() functions from the base class are called each time a new packet is - * received from the driver station. - * - * @deprecated Use TimedRobot instead. It's a drop-in replacement that provides - * more regular execution periods. - */ -class IterativeRobot : public IterativeRobotBase { - public: - WPI_DEPRECATED( - "Use TimedRobot instead. It's a drop-in replacement that provides more " - "regular execution periods.") - IterativeRobot(); - ~IterativeRobot() override = default; - - /** - * Provide an alternate "main loop" via StartCompetition(). - * - * This specific StartCompetition() implements "main loop" behavior synced - * with the DS packets. - */ - void StartCompetition() override; - - /** - * Ends the main loop in StartCompetition(). - */ - void EndCompetition() override; - - private: - std::atomic m_exit{false}; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/IterativeRobotBase.h b/wpilibc/src/main/native/include/frc/IterativeRobotBase.h index 7d04868da7..beb7f4cbe1 100644 --- a/wpilibc/src/main/native/include/frc/IterativeRobotBase.h +++ b/wpilibc/src/main/native/include/frc/IterativeRobotBase.h @@ -160,6 +160,11 @@ class IterativeRobotBase : public RobotBase { */ void SetNetworkTablesFlushEnabled(bool enabled); + /** + * Gets time period between calls to Periodic() functions. + */ + units::second_t GetPeriod() const; + /** * Constructor for IterativeRobotBase. * @@ -186,12 +191,11 @@ class IterativeRobotBase : public RobotBase { void LoopFunc(); - units::second_t m_period; - private: enum class Mode { kNone, kDisabled, kAutonomous, kTeleop, kTest }; Mode m_lastMode = Mode::kNone; + units::second_t m_period; Watchdog m_watchdog; bool m_ntFlushEnabled = false; diff --git a/wpilibc/src/main/native/include/frc/MotorSafety.h b/wpilibc/src/main/native/include/frc/MotorSafety.h index ee191b8459..0f56b42f40 100644 --- a/wpilibc/src/main/native/include/frc/MotorSafety.h +++ b/wpilibc/src/main/native/include/frc/MotorSafety.h @@ -5,11 +5,13 @@ #pragma once #include -#include -#include "frc/ErrorBase.h" #include "frc/Timer.h" +namespace wpi { +class raw_ostream; +} // namespace wpi + namespace frc { /** @@ -18,10 +20,10 @@ namespace frc { * * The subclass should call Feed() whenever the motor value is updated. */ -class MotorSafety : public ErrorBase { +class MotorSafety { public: MotorSafety(); - ~MotorSafety() override; + virtual ~MotorSafety(); MotorSafety(MotorSafety&& rhs); MotorSafety& operator=(MotorSafety&& rhs); diff --git a/wpilibc/src/main/native/include/frc/Notifier.h b/wpilibc/src/main/native/include/frc/Notifier.h index df8c37ca53..fee783b937 100644 --- a/wpilibc/src/main/native/include/frc/Notifier.h +++ b/wpilibc/src/main/native/include/frc/Notifier.h @@ -18,11 +18,9 @@ #include #include -#include "frc/ErrorBase.h" - namespace frc { -class Notifier : public ErrorBase { +class Notifier { public: /** * Create a Notifier for timer event notification. @@ -63,7 +61,7 @@ class Notifier : public ErrorBase { /** * Free the resources for a timer event. */ - ~Notifier() override; + ~Notifier(); Notifier(Notifier&& rhs); Notifier& operator=(Notifier&& rhs); diff --git a/wpilibc/src/main/native/include/frc/PWM.h b/wpilibc/src/main/native/include/frc/PWM.h index 7f7cd912ae..65de64ba55 100644 --- a/wpilibc/src/main/native/include/frc/PWM.h +++ b/wpilibc/src/main/native/include/frc/PWM.h @@ -7,9 +7,7 @@ #include #include -#include -#include "frc/MotorSafety.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -34,7 +32,7 @@ class SendableBuilder; * - 1 = minimum pulse width (currently 0.5ms) * - 0 = disabled (i.e. PWM output is held low) */ -class PWM : public MotorSafety, public Sendable, public SendableHelper { +class PWM : public Sendable, public SendableHelper { public: friend class AddressableLED; /** @@ -64,8 +62,10 @@ class PWM : public MotorSafety, public Sendable, public SendableHelper { * * @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the * MXP port + * @param registerSendable If true, adds this instance to SendableRegistry + * and LiveWindow */ - explicit PWM(int channel); + explicit PWM(int channel, bool registerSendable = true); /** * Free the PWM channel. @@ -77,10 +77,6 @@ class PWM : public MotorSafety, public Sendable, public SendableHelper { PWM(PWM&&) = default; PWM& operator=(PWM&&) = default; - // MotorSafety interface - void StopMotor() override; - void GetDescription(wpi::raw_ostream& desc) const override; - /** * Set the PWM value directly to the hardware. * diff --git a/wpilibc/src/main/native/include/frc/PowerDistributionPanel.h b/wpilibc/src/main/native/include/frc/PowerDistributionPanel.h index d40b988989..ba285bc08f 100644 --- a/wpilibc/src/main/native/include/frc/PowerDistributionPanel.h +++ b/wpilibc/src/main/native/include/frc/PowerDistributionPanel.h @@ -6,7 +6,6 @@ #include -#include "frc/ErrorBase.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -18,8 +17,7 @@ class SendableBuilder; * Class for getting voltage, current, temperature, power and energy from the * CAN PDP. */ -class PowerDistributionPanel : public ErrorBase, - public Sendable, +class PowerDistributionPanel : public Sendable, public SendableHelper { public: PowerDistributionPanel(); diff --git a/wpilibc/src/main/native/include/frc/Preferences.h b/wpilibc/src/main/native/include/frc/Preferences.h index 368ff2cac8..c22c9af97e 100644 --- a/wpilibc/src/main/native/include/frc/Preferences.h +++ b/wpilibc/src/main/native/include/frc/Preferences.h @@ -11,8 +11,7 @@ #include #include - -#include "frc/ErrorBase.h" +#include namespace frc { @@ -30,14 +29,14 @@ namespace frc { * This will also interact with {@link NetworkTable} by creating a table called * "Preferences" with all the key-value pairs. */ -class Preferences : public ErrorBase { +class Preferences { public: /** * Get the one and only {@link Preferences} object. * - * @return pointer to the {@link Preferences} + * @return reference to the {@link Preferences} */ - static Preferences* GetInstance(); + static Preferences& GetInstance(); /** * Returns a vector of all the keys. @@ -116,6 +115,18 @@ class Preferences : public ErrorBase { * @param key the key * @param value the value */ + void SetString(wpi::StringRef key, wpi::StringRef value); + + /** + * Puts the given string into the preferences table. + * + * The value may not have quotation marks, nor may the key have any whitespace + * nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetString instead.") void PutString(wpi::StringRef key, wpi::StringRef value); /** @@ -132,6 +143,17 @@ class Preferences : public ErrorBase { * @param key the key * @param value the value */ + void SetInt(wpi::StringRef key, int value); + + /** + * Puts the given int into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetInt instead.") void PutInt(wpi::StringRef key, int value); /** @@ -148,6 +170,17 @@ class Preferences : public ErrorBase { * @param key the key * @param value the value */ + void SetDouble(wpi::StringRef key, double value); + + /** + * Puts the given double into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetDouble instead.") void PutDouble(wpi::StringRef key, double value); /** @@ -164,6 +197,17 @@ class Preferences : public ErrorBase { * @param key the key * @param value the value */ + void SetFloat(wpi::StringRef key, float value); + + /** + * Puts the given float into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetFloat instead.") void PutFloat(wpi::StringRef key, float value); /** @@ -180,6 +224,17 @@ class Preferences : public ErrorBase { * @param key the key * @param value the value */ + void SetBoolean(wpi::StringRef key, bool value); + + /** + * Puts the given boolean into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetBoolean instead.") void PutBoolean(wpi::StringRef key, bool value); /** @@ -196,6 +251,17 @@ class Preferences : public ErrorBase { * @param key the key * @param value the value */ + void SetLong(wpi::StringRef key, int64_t value); + + /** + * Puts the given long (int64_t) into the preferences table. + * + * The key may not have any whitespace nor an equals sign. + * + * @param key the key + * @param value the value + */ + WPI_DEPRECATED("Use SetLong instead.") void PutLong(wpi::StringRef key, int64_t value); /** @@ -226,7 +292,7 @@ class Preferences : public ErrorBase { protected: Preferences(); - ~Preferences() override = default; + ~Preferences(); Preferences(Preferences&&) = default; Preferences& operator=(Preferences&&) = default; diff --git a/wpilibc/src/main/native/include/frc/Relay.h b/wpilibc/src/main/native/include/frc/Relay.h index 14a59a8012..b623701649 100644 --- a/wpilibc/src/main/native/include/frc/Relay.h +++ b/wpilibc/src/main/native/include/frc/Relay.h @@ -9,7 +9,6 @@ #include #include -#include "frc/ErrorBase.h" #include "frc/MotorSafety.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" diff --git a/wpilibc/src/main/native/include/frc/Resource.h b/wpilibc/src/main/native/include/frc/Resource.h index 6880d65265..4109cc461c 100644 --- a/wpilibc/src/main/native/include/frc/Resource.h +++ b/wpilibc/src/main/native/include/frc/Resource.h @@ -12,8 +12,6 @@ #include -#include "frc/ErrorBase.h" - namespace frc { /** @@ -26,9 +24,9 @@ namespace frc { * resources; it just tracks which indices were marked in use by Allocate and * not yet freed by Free. */ -class Resource : public ErrorBase { +class Resource { public: - ~Resource() override = default; + virtual ~Resource() = default; /** * Factory method to create a Resource allocation-tracker *if* needed. diff --git a/wpilibc/src/main/native/include/frc/RobotBase.h b/wpilibc/src/main/native/include/frc/RobotBase.h index ffc59eec50..c477438639 100644 --- a/wpilibc/src/main/native/include/frc/RobotBase.h +++ b/wpilibc/src/main/native/include/frc/RobotBase.h @@ -14,6 +14,7 @@ #include #include "frc/Base.h" +#include "frc/Errors.h" namespace frc { @@ -25,12 +26,17 @@ namespace impl { template void RunRobot(wpi::mutex& m, Robot** robot) { - static Robot theRobot; - { - std::scoped_lock lock{m}; - *robot = &theRobot; + try { + static Robot theRobot; + { + std::scoped_lock lock{m}; + *robot = &theRobot; + } + theRobot.StartCompetition(); + } catch (const frc::RuntimeError& e) { + e.Report(); + throw; } - theRobot.StartCompetition(); } } // namespace impl diff --git a/wpilibc/src/main/native/include/frc/RobotDrive.h b/wpilibc/src/main/native/include/frc/RobotDrive.h deleted file mode 100644 index fa22e0e8cc..0000000000 --- a/wpilibc/src/main/native/include/frc/RobotDrive.h +++ /dev/null @@ -1,461 +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 - -#include "frc/ErrorBase.h" -#include "frc/MotorSafety.h" - -namespace frc { - -class SpeedController; -class GenericHID; - -/** - * Utility class for handling Robot drive based on a definition of the motor - * configuration. - * - * The robot drive class handles basic driving for a robot. Currently, 2 and 4 - * motor tank and mecanum drive trains are supported. In the future other drive - * types like swerve might be implemented. Motor channel numbers are passed - * supplied on creation of the class. Those are used for either the Drive - * function (intended for hand created drive code, such as autonomous) or with - * the Tank/Arcade functions intended to be used for Operator Control driving. - * - * @deprecated Use DifferentialDrive or MecanumDrive classes instead. - * - */ -class RobotDrive : public MotorSafety { - public: - enum MotorType { - kFrontLeftMotor = 0, - kFrontRightMotor = 1, - kRearLeftMotor = 2, - kRearRightMotor = 3 - }; - - /** - * Constructor for RobotDrive with 2 motors specified with channel numbers. - * - * Set up parameters for a two wheel drive system where the - * left and right motor pwm channels are specified in the call. - * This call assumes Talons for controlling the motors. - * - * @param leftMotorChannel The PWM channel number that drives the left motor. - * 0-9 are on-board, 10-19 are on the MXP port - * @param rightMotorChannel The PWM channel number that drives the right - * motor. 0-9 are on-board, 10-19 are on the MXP port - */ - WPI_DEPRECATED("Use DifferentialDrive or MecanumDrive classes instead.") - RobotDrive(int leftMotorChannel, int rightMotorChannel); - - /** - * Constructor for RobotDrive with 4 motors specified with channel numbers. - * - * Set up parameters for a four wheel drive system where all four motor - * pwm channels are specified in the call. - * This call assumes Talons for controlling the motors. - * - * @param frontLeftMotor Front left motor channel number. 0-9 are on-board, - * 10-19 are on the MXP port - * @param rearLeftMotor Rear Left motor channel number. 0-9 are on-board, - * 10-19 are on the MXP port - * @param frontRightMotor Front right motor channel number. 0-9 are on-board, - * 10-19 are on the MXP port - * @param rearRightMotor Rear Right motor channel number. 0-9 are on-board, - * 10-19 are on the MXP port - */ - WPI_DEPRECATED("Use DifferentialDrive or MecanumDrive classes instead.") - RobotDrive(int frontLeftMotorChannel, int rearLeftMotorChannel, - int frontRightMotorChannel, int rearRightMotorChannel); - - /** - * Constructor for RobotDrive with 2 motors specified as SpeedController - * objects. - * - * The SpeedController version of the constructor enables programs to use the - * RobotDrive classes with subclasses of the SpeedController objects, for - * example, versions with ramping or reshaping of the curve to suit motor bias - * or deadband elimination. - * - * @param leftMotor The left SpeedController object used to drive the robot. - * @param rightMotor The right SpeedController object used to drive the robot. - */ - WPI_DEPRECATED("Use DifferentialDrive or MecanumDrive classes instead.") - RobotDrive(SpeedController* leftMotor, SpeedController* rightMotor); - - WPI_DEPRECATED("Use DifferentialDrive or MecanumDrive classes instead.") - RobotDrive(SpeedController& leftMotor, SpeedController& rightMotor); - - WPI_DEPRECATED("Use DifferentialDrive or MecanumDrive classes instead.") - RobotDrive(std::shared_ptr leftMotor, - std::shared_ptr rightMotor); - - /** - * Constructor for RobotDrive with 4 motors specified as SpeedController - * objects. - * - * Speed controller input version of RobotDrive (see previous comments). - * - * @param frontLeftMotor The front left SpeedController object used to drive - * the robot. - * @param rearLeftMotor The back left SpeedController object used to drive - * the robot. - * @param frontRightMotor The front right SpeedController object used to drive - * the robot. - * @param rearRightMotor The back right SpeedController object used to drive - * the robot. - */ - WPI_DEPRECATED("Use DifferentialDrive or MecanumDrive classes instead.") - RobotDrive(SpeedController* frontLeftMotor, SpeedController* rearLeftMotor, - SpeedController* frontRightMotor, SpeedController* rearRightMotor); - - WPI_DEPRECATED("Use DifferentialDrive or MecanumDrive classes instead.") - RobotDrive(SpeedController& frontLeftMotor, SpeedController& rearLeftMotor, - SpeedController& frontRightMotor, SpeedController& rearRightMotor); - - WPI_DEPRECATED("Use DifferentialDrive or MecanumDrive classes instead.") - RobotDrive(std::shared_ptr frontLeftMotor, - std::shared_ptr rearLeftMotor, - std::shared_ptr frontRightMotor, - std::shared_ptr rearRightMotor); - - ~RobotDrive() override = default; - - RobotDrive(RobotDrive&&) = default; - RobotDrive& operator=(RobotDrive&&) = default; - - /** - * Drive the motors at "outputMagnitude" and "curve". - * - * Both outputMagnitude and curve are -1.0 to +1.0 values, where 0.0 - * represents stopped and not turning. curve < 0 will turn left and curve > 0 - * will turn right. - * - * The algorithm for steering provides a constant turn radius for any normal - * speed range, both forward and backward. Increasing m_sensitivity causes - * sharper turns for fixed values of curve. - * - * This function will most likely be used in an autonomous routine. - * - * @param outputMagnitude The speed setting for the outside wheel in a turn, - * forward or backwards, +1 to -1. - * @param curve The rate of turn, constant for different forward - * speeds. Set curve < 0 for left turn or curve > 0 for - * right turn. - * - * Set curve = e^(-r/w) to get a turn radius r for wheelbase w of your robot. - * Conversely, turn radius r = -ln(curve)*w for a given value of curve and - * wheelbase w. - */ - void Drive(double outputMagnitude, double curve); - - /** - * Provide tank steering using the stored robot configuration. - * - * Drive the robot using two joystick inputs. The Y-axis will be selected from - * each Joystick object. - * - * @param leftStick The joystick to control the left side of the robot. - * @param rightStick The joystick to control the right side of the robot. - * @param squaredInputs If true, the sensitivity will be decreased for small - * values - */ - void TankDrive(GenericHID* leftStick, GenericHID* rightStick, - bool squaredInputs = true); - - /** - * Provide tank steering using the stored robot configuration. - * - * Drive the robot using two joystick inputs. The Y-axis will be selected from - * each Joystick object. - * - * @param leftStick The joystick to control the left side of the robot. - * @param rightStick The joystick to control the right side of the robot. - * @param squaredInputs If true, the sensitivity will be decreased for small - * values - */ - void TankDrive(GenericHID& leftStick, GenericHID& rightStick, - bool squaredInputs = true); - - /** - * Provide tank steering using the stored robot configuration. - * - * This function lets you pick the axis to be used on each Joystick object for - * the left and right sides of the robot. - * - * @param leftStick The Joystick object to use for the left side of the - * robot. - * @param leftAxis The axis to select on the left side Joystick object. - * @param rightStick The Joystick object to use for the right side of the - * robot. - * @param rightAxis The axis to select on the right side Joystick object. - * @param squaredInputs If true, the sensitivity will be decreased for small - * values - */ - void TankDrive(GenericHID* leftStick, int leftAxis, GenericHID* rightStick, - int rightAxis, bool squaredInputs = true); - - void TankDrive(GenericHID& leftStick, int leftAxis, GenericHID& rightStick, - int rightAxis, bool squaredInputs = true); - - /** - * Provide tank steering using the stored robot configuration. - * - * This function lets you directly provide joystick values from any source. - * - * @param leftValue The value of the left stick. - * @param rightValue The value of the right stick. - * @param squaredInputs If true, the sensitivity will be decreased for small - * values - */ - void TankDrive(double leftValue, double rightValue, - bool squaredInputs = true); - - /** - * Arcade drive implements single stick driving. - * - * Given a single Joystick, the class assumes the Y axis for the move value - * and the X axis for the rotate value. (Should add more information here - * regarding the way that arcade drive works.) - * - * @param stick The joystick to use for Arcade single-stick driving. - * The Y-axis will be selected for forwards/backwards and - * the X-axis will be selected for rotation rate. - * @param squaredInputs If true, the sensitivity will be decreased for small - * values - */ - void ArcadeDrive(GenericHID* stick, bool squaredInputs = true); - - /** - * Arcade drive implements single stick driving. - * - * Given a single Joystick, the class assumes the Y axis for the move value - * and the X axis for the rotate value. (Should add more information here - * regarding the way that arcade drive works.) - * - * @param stick The joystick to use for Arcade single-stick driving. - * The Y-axis will be selected for forwards/backwards and - * the X-axis will be selected for rotation rate. - * @param squaredInputs If true, the sensitivity will be decreased for small - * values - */ - void ArcadeDrive(GenericHID& stick, bool squaredInputs = true); - - /** - * Arcade drive implements single stick driving. - * - * Given two joystick instances and two axis, compute the values to send to - * either two or four motors. - * - * @param moveStick The Joystick object that represents the - * forward/backward direction - * @param moveAxis The axis on the moveStick object to use for - * forwards/backwards (typically Y_AXIS) - * @param rotateStick The Joystick object that represents the rotation value - * @param rotateAxis The axis on the rotation object to use for the rotate - * right/left (typically X_AXIS) - * @param squaredInputs Setting this parameter to true increases the - * sensitivity at lower speeds - */ - void ArcadeDrive(GenericHID* moveStick, int moveChannel, - GenericHID* rotateStick, int rotateChannel, - bool squaredInputs = true); - - /** - * Arcade drive implements single stick driving. - * - * Given two joystick instances and two axis, compute the values to send to - * either two or four motors. - * - * @param moveStick The Joystick object that represents the - * forward/backward direction - * @param moveAxis The axis on the moveStick object to use for - * forwards/backwards (typically Y_AXIS) - * @param rotateStick The Joystick object that represents the rotation value - * @param rotateAxis The axis on the rotation object to use for the rotate - * right/left (typically X_AXIS) - * @param squaredInputs Setting this parameter to true increases the - * sensitivity at lower speeds - */ - void ArcadeDrive(GenericHID& moveStick, int moveChannel, - GenericHID& rotateStick, int rotateChannel, - bool squaredInputs = true); - - /** - * Arcade drive implements single stick driving. - * - * This function lets you directly provide joystick values from any source. - * - * @param moveValue The value to use for fowards/backwards - * @param rotateValue The value to use for the rotate right/left - * @param squaredInputs If set, increases the sensitivity at low speeds - */ - void ArcadeDrive(double moveValue, double rotateValue, - bool squaredInputs = true); - - /** - * Drive method for Mecanum wheeled robots. - * - * A method for driving with Mecanum wheeled robots. There are 4 wheels - * on the robot, arranged so that the front and back wheels are toed in 45 - * degrees. - * When looking at the wheels from the top, the roller axles should form an X - * across the robot. - * - * This is designed to be directly driven by joystick axes. - * - * @param x The speed that the robot should drive in the X direction. - * [-1.0..1.0] - * @param y The speed that the robot should drive in the Y direction. - * This input is inverted to match the forward == -1.0 that - * joysticks produce. [-1.0..1.0] - * @param rotation The rate of rotation for the robot that is completely - * independent of the translation. [-1.0..1.0] - * @param gyroAngle The current angle reading from the gyro. Use this to - * implement field-oriented controls. - */ - void MecanumDrive_Cartesian(double x, double y, double rotation, - double gyroAngle = 0.0); - - /** - * Drive method for Mecanum wheeled robots. - * - * A method for driving with Mecanum wheeled robots. There are 4 wheels - * on the robot, arranged so that the front and back wheels are toed in 45 - * degrees. - * When looking at the wheels from the top, the roller axles should form an X - * across the robot. - * - * @param magnitude The speed that the robot should drive in a given - * direction. [-1.0..1.0] - * @param direction The direction the robot should drive in degrees. The - * direction and maginitute are independent of the rotation - * rate. - * @param rotation The rate of rotation for the robot that is completely - * independent of the magnitute or direction. [-1.0..1.0] - */ - void MecanumDrive_Polar(double magnitude, double direction, double rotation); - - /** - * Holonomic Drive method for Mecanum wheeled robots. - * - * This is an alias to MecanumDrive_Polar() for backward compatibility - * - * @param magnitude The speed that the robot should drive in a given - * direction. [-1.0..1.0] - * @param direction The direction the robot should drive. The direction and - * magnitude are independent of the rotation rate. - * @param rotation The rate of rotation for the robot that is completely - * independent of the magnitude or direction. [-1.0..1.0] - */ - void HolonomicDrive(double magnitude, double direction, double rotation); - - /** - * Set the speed of the right and left motors. - * - * This is used once an appropriate drive setup function is called such as - * TwoWheelDrive(). The motors are set to "leftOutput" and "rightOutput" - * and includes flipping the direction of one side for opposing motors. - * - * @param leftOutput The speed to send to the left side of the robot. - * @param rightOutput The speed to send to the right side of the robot. - */ - virtual void SetLeftRightMotorOutputs(double leftOutput, double rightOutput); - - /* - * Invert a motor direction. - * - * This is used when a motor should run in the opposite direction as the drive - * code would normally run it. Motors that are direct drive would be inverted, - * the Drive code assumes that the motors are geared with one reversal. - * - * @param motor The motor index to invert. - * @param isInverted True if the motor should be inverted when operated. - */ - void SetInvertedMotor(MotorType motor, bool isInverted); - - /** - * Set the turning sensitivity. - * - * This only impacts the Drive() entry-point. - * - * @param sensitivity Effectively sets the turning sensitivity (or turn radius - * for a given value) - */ - void SetSensitivity(double sensitivity); - - /** - * Configure the scaling factor for using RobotDrive with motor controllers in - * a mode other than PercentVbus. - * - * @param maxOutput Multiplied with the output percentage computed by the - * drive functions. - */ - void SetMaxOutput(double maxOutput); - - void StopMotor() override; - void GetDescription(wpi::raw_ostream& desc) const override; - - protected: - /** - * Common function to initialize all the robot drive constructors. - * - * Create a motor safety object (the real reason for the common code) and - * initialize all the motor assignments. The default timeout is set for the - * robot drive. - */ - void InitRobotDrive(); - - /** - * Limit motor values to the -1.0 to +1.0 range. - */ - double Limit(double number); - - /** - * Normalize all wheel speeds if the magnitude of any wheel is greater than - * 1.0. - */ - void Normalize(double* wheelSpeeds); - - /** - * Rotate a vector in Cartesian space. - */ - void RotateVector(double& x, double& y, double angle); - - static constexpr int kMaxNumberOfMotors = 4; - - double m_sensitivity = 0.5; - double m_maxOutput = 1.0; - - std::shared_ptr m_frontLeftMotor; - std::shared_ptr m_frontRightMotor; - std::shared_ptr m_rearLeftMotor; - std::shared_ptr m_rearRightMotor; - - private: - int GetNumMotors() { - int motors = 0; - if (m_frontLeftMotor) { - motors++; - } - if (m_frontRightMotor) { - motors++; - } - if (m_rearLeftMotor) { - motors++; - } - if (m_rearRightMotor) { - motors++; - } - return motors; - } -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/SPI.h b/wpilibc/src/main/native/include/frc/SPI.h index 59fe0db418..be9d6ef8f3 100644 --- a/wpilibc/src/main/native/include/frc/SPI.h +++ b/wpilibc/src/main/native/include/frc/SPI.h @@ -13,8 +13,6 @@ #include #include -#include "frc/ErrorBase.h" - namespace frc { class DigitalSource; @@ -26,7 +24,7 @@ class DigitalSource; * It probably should not be used directly. * */ -class SPI : public ErrorBase { +class SPI { public: enum Port { kOnboardCS0 = 0, kOnboardCS1, kOnboardCS2, kOnboardCS3, kMXP }; @@ -37,7 +35,7 @@ class SPI : public ErrorBase { */ explicit SPI(Port port); - ~SPI() override; + ~SPI(); SPI(SPI&&) = default; SPI& operator=(SPI&&) = default; diff --git a/wpilibc/src/main/native/include/frc/SerialPort.h b/wpilibc/src/main/native/include/frc/SerialPort.h index 9bbd9961ca..b11cb64dd7 100644 --- a/wpilibc/src/main/native/include/frc/SerialPort.h +++ b/wpilibc/src/main/native/include/frc/SerialPort.h @@ -11,8 +11,6 @@ #include #include -#include "frc/ErrorBase.h" - namespace frc { /** @@ -27,7 +25,7 @@ namespace frc { * and the NI-VISA Programmer's Reference Manual here: * http://www.ni.com/pdf/manuals/370132c.pdf */ -class SerialPort : public ErrorBase { +class SerialPort { public: enum Parity { kParity_None = 0, @@ -88,7 +86,7 @@ class SerialPort : public ErrorBase { int dataBits = 8, Parity parity = kParity_None, StopBits stopBits = kStopBits_One); - ~SerialPort() override; + ~SerialPort(); SerialPort(SerialPort&& rhs) = default; SerialPort& operator=(SerialPort&& rhs) = default; diff --git a/wpilibc/src/main/native/include/frc/Servo.h b/wpilibc/src/main/native/include/frc/Servo.h index aa14185aba..feaaf0f557 100644 --- a/wpilibc/src/main/native/include/frc/Servo.h +++ b/wpilibc/src/main/native/include/frc/Servo.h @@ -5,7 +5,6 @@ #pragma once #include "frc/PWM.h" -#include "frc/SpeedController.h" namespace frc { diff --git a/wpilibc/src/main/native/include/frc/SolenoidBase.h b/wpilibc/src/main/native/include/frc/SolenoidBase.h index c0acc4334f..82121fbe1b 100644 --- a/wpilibc/src/main/native/include/frc/SolenoidBase.h +++ b/wpilibc/src/main/native/include/frc/SolenoidBase.h @@ -4,16 +4,16 @@ #pragma once -#include "frc/ErrorBase.h" - namespace frc { /** * SolenoidBase class is the common base class for the Solenoid and * DoubleSolenoid classes. */ -class SolenoidBase : public ErrorBase { +class SolenoidBase { public: + virtual ~SolenoidBase() = default; + /** * Get the CAN ID of the module this solenoid is connected to. * diff --git a/wpilibc/src/main/native/include/frc/SpeedController.h b/wpilibc/src/main/native/include/frc/SpeedController.h index 23e0d7b0ab..a1827b4c3a 100644 --- a/wpilibc/src/main/native/include/frc/SpeedController.h +++ b/wpilibc/src/main/native/include/frc/SpeedController.h @@ -5,15 +5,14 @@ #pragma once #include - -#include "frc/PIDOutput.h" +#include namespace frc { /** * Interface for speed controlling devices. */ -class SpeedController : public PIDOutput { +class WPI_DEPRECATED("use MotorController") SpeedController { public: virtual ~SpeedController() = default; diff --git a/wpilibc/src/main/native/include/frc/SpeedControllerGroup.h b/wpilibc/src/main/native/include/frc/SpeedControllerGroup.h index f7153c64fe..5552c80ebe 100644 --- a/wpilibc/src/main/native/include/frc/SpeedControllerGroup.h +++ b/wpilibc/src/main/native/include/frc/SpeedControllerGroup.h @@ -7,15 +7,18 @@ #include #include -#include "frc/SpeedController.h" +#include + +#include "frc/motorcontrol/MotorController.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" namespace frc { -class SpeedControllerGroup : public Sendable, - public SpeedController, - public SendableHelper { +class WPI_DEPRECATED("use MotorControllerGroup") SpeedControllerGroup + : public Sendable, + public MotorController, + public SendableHelper { public: template explicit SpeedControllerGroup(SpeedController& speedController, @@ -32,7 +35,6 @@ class SpeedControllerGroup : public Sendable, bool GetInverted() const override; void Disable() override; void StopMotor() override; - void PIDWrite(double output) override; void InitSendable(SendableBuilder& builder) override; diff --git a/wpilibc/src/main/native/include/frc/TimedRobot.h b/wpilibc/src/main/native/include/frc/TimedRobot.h index 817e6317b3..18038eaa79 100644 --- a/wpilibc/src/main/native/include/frc/TimedRobot.h +++ b/wpilibc/src/main/native/include/frc/TimedRobot.h @@ -14,7 +14,6 @@ #include #include -#include "frc/ErrorBase.h" #include "frc/IterativeRobotBase.h" #include "frc2/Timer.h" @@ -29,7 +28,7 @@ namespace frc { * Periodic() functions from the base class are called on an interval by a * Notifier instance. */ -class TimedRobot : public IterativeRobotBase, public ErrorBase { +class TimedRobot : public IterativeRobotBase { public: static constexpr units::second_t kDefaultPeriod = 20_ms; @@ -43,11 +42,6 @@ class TimedRobot : public IterativeRobotBase, public ErrorBase { */ void EndCompetition() override; - /** - * Get the time period between calls to Periodic() functions. - */ - units::second_t GetPeriod() const; - /** * Constructor for TimedRobot. * diff --git a/wpilibc/src/main/native/include/frc/Ultrasonic.h b/wpilibc/src/main/native/include/frc/Ultrasonic.h index 71afd73659..adb86b54bc 100644 --- a/wpilibc/src/main/native/include/frc/Ultrasonic.h +++ b/wpilibc/src/main/native/include/frc/Ultrasonic.h @@ -12,8 +12,6 @@ #include #include "frc/Counter.h" -#include "frc/ErrorBase.h" -#include "frc/PIDSource.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -34,13 +32,8 @@ class DigitalOutput; * received. The time that the line is high determines the round trip distance * (time of flight). */ -class Ultrasonic : public ErrorBase, - public Sendable, - public PIDSource, - public SendableHelper { +class Ultrasonic : public Sendable, public SendableHelper { public: - enum DistanceUnit { kInches = 0, kMilliMeters = 1 }; - /** * Create an instance of the Ultrasonic Sensor. * @@ -51,9 +44,8 @@ class Ultrasonic : public ErrorBase, * @param echoChannel The digital input channel that receives the echo. The * length of time that the echo is high represents the * round trip time of the ping, and the distance. - * @param units The units returned in either kInches or kMilliMeters */ - Ultrasonic(int pingChannel, int echoChannel, DistanceUnit units = kInches); + Ultrasonic(int pingChannel, int echoChannel); /** * Create an instance of an Ultrasonic Sensor from a DigitalInput for the echo @@ -63,10 +55,8 @@ class Ultrasonic : public ErrorBase, * ping. Requires a 10uS pulse to start. * @param echoChannel The digital input object that times the return pulse to * determine the range. - * @param units The units returned in either kInches or kMilliMeters */ - Ultrasonic(DigitalOutput* pingChannel, DigitalInput* echoChannel, - DistanceUnit units = kInches); + Ultrasonic(DigitalOutput* pingChannel, DigitalInput* echoChannel); /** * Create an instance of an Ultrasonic Sensor from a DigitalInput for the echo @@ -76,10 +66,8 @@ class Ultrasonic : public ErrorBase, * ping. Requires a 10uS pulse to start. * @param echoChannel The digital input object that times the return pulse to * determine the range. - * @param units The units returned in either kInches or kMilliMeters */ - Ultrasonic(DigitalOutput& pingChannel, DigitalInput& echoChannel, - DistanceUnit units = kInches); + Ultrasonic(DigitalOutput& pingChannel, DigitalInput& echoChannel); /** * Create an instance of an Ultrasonic Sensor from a DigitalInput for the echo @@ -89,11 +77,9 @@ class Ultrasonic : public ErrorBase, * ping. Requires a 10uS pulse to start. * @param echoChannel The digital input object that times the return pulse to * determine the range. - * @param units The units returned in either kInches or kMilliMeters */ Ultrasonic(std::shared_ptr pingChannel, - std::shared_ptr echoChannel, - DistanceUnit units = kInches); + std::shared_ptr echoChannel); ~Ultrasonic() override; @@ -156,30 +142,6 @@ class Ultrasonic : public ErrorBase, void SetEnabled(bool enable); - /** - * Set the current DistanceUnit that should be used for the PIDSource base - * object. - * - * @param units The DistanceUnit that should be used. - */ - void SetDistanceUnits(DistanceUnit units); - - /** - * Get the current DistanceUnit that is used for the PIDSource base object. - * - * @return The type of DistanceUnit that is being used. - */ - DistanceUnit GetDistanceUnits() const; - - /** - * Get the range in the current DistanceUnit for the PIDSource base object. - * - * @return The range in DistanceUnit - */ - double PIDGet() override; - - void SetPIDSourceType(PIDSourceType pidSource) override; - void InitSendable(SendableBuilder& builder) override; private: @@ -228,7 +190,6 @@ class Ultrasonic : public ErrorBase, std::shared_ptr m_echoChannel; bool m_enabled = false; Counter m_counter; - DistanceUnit m_units; hal::SimDevice m_simDevice; hal::SimBoolean m_simRangeValid; diff --git a/wpilibc/src/main/native/include/frc/WPIErrors.h b/wpilibc/src/main/native/include/frc/WPIErrors.mac similarity index 55% rename from wpilibc/src/main/native/include/frc/WPIErrors.h rename to wpilibc/src/main/native/include/frc/WPIErrors.mac index 3ff8dd23d4..f159ccd848 100644 --- a/wpilibc/src/main/native/include/frc/WPIErrors.h +++ b/wpilibc/src/main/native/include/frc/WPIErrors.mac @@ -2,18 +2,9 @@ // 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 - -#define S(label, offset, message) \ - constexpr inline const char* wpi_error_s_##label() { return message; } \ - constexpr inline int wpi_error_value_##label() { return offset; } - -// Fatal errors S(ModuleIndexOutOfRange, -1, "Allocating module that is out of range or not found") -S(ChannelIndexOutOfRange, -1, "Allocating channel that is out of range") +S(ChannelIndexOutOfRange, -45, "Allocating channel that is out of range") S(NotAllocated, -2, "Attempting to free unallocated resource") S(ResourceAlreadyAllocated, -3, "Attempted to reuse an allocated resource") S(NoAvailableResources, -4, "No available resources to allocate") @@ -26,13 +17,13 @@ S(IncompatibleMode, -9, "The object is in an incompatible mode") S(AnalogTriggerLimitOrderError, -10, "AnalogTrigger limits error. Lower limit > Upper Limit") S(AnalogTriggerPulseOutputError, -11, - "Attempted to read AnalogTrigger pulse output.") + "Attempted to read AnalogTrigger pulse output") S(TaskError, -12, "Task can't be started") -S(TaskIDError, -13, "Task error: Invalid ID.") -S(TaskDeletedError, -14, "Task error: Task already deleted.") -S(TaskOptionsError, -15, "Task error: Invalid options.") -S(TaskMemoryError, -16, "Task can't be started due to insufficient memory.") -S(TaskPriorityError, -17, "Task error: Invalid priority [1-255].") +S(TaskIDError, -13, "Task error: Invalid ID") +S(TaskDeletedError, -14, "Task error: Task already deleted") +S(TaskOptionsError, -15, "Task error: Invalid options") +S(TaskMemoryError, -16, "Task can't be started due to insufficient memory") +S(TaskPriorityError, -17, "Task error: Invalid priority [1-255]") S(DriveUninitialized, -18, "RobotDrive not initialized for the C interface") S(CompressorNonMatching, -19, "Compressor slot/channel doesn't match previous instance") @@ -41,19 +32,19 @@ S(CompressorUndefined, -21, "Using compressor functions without defining compressor") S(InconsistentArrayValueAdded, -22, "When packing data into an array to the dashboard, not all values added were " - "of the same type.") + "of the same type") S(MismatchedComplexTypeClose, -23, "When packing data to the dashboard, a Close for a complex type was called " - "without a matching Open.") + "without a matching Open") S(DashboardDataOverflow, -24, "When packing data to the dashboard, too much data was packed and the buffer " - "overflowed.") + "overflowed") S(DashboardDataCollision, -25, - "The same buffer was used for packing data and for printing.") -S(EnhancedIOMissing, -26, "IO is not attached or Enhanced IO is not enabled.") + "The same buffer was used for packing data and for printing") +S(EnhancedIOMissing, -26, "IO is not attached or Enhanced IO is not enabled") S(LineNotOutput, -27, - "Cannot SetDigitalOutput for a line not configured for output.") -S(ParameterOutOfRange, -28, "A parameter is out of range.") + "Cannot SetDigitalOutput for a line not configured for output") +S(ParameterOutOfRange, -28, "A parameter is out of range") S(SPIClockRateTooLow, -29, "SPI clock rate was below the minimum supported") S(JaguarVersionError, -30, "Jaguar firmware version error") S(JaguarMessageNotFound, -31, "Jaguar message not found") @@ -62,31 +53,9 @@ S(NetworkTablesBufferFull, -41, "Buffer full writing to NetworkTables socket") S(NetworkTablesWrongType, -42, "The wrong type was read from the NetworkTables entry") S(NetworkTablesCorrupt, -43, "NetworkTables data stream is corrupt") -S(SmartDashboardMissingKey, -43, "SmartDashboard data does not exist") +S(SmartDashboardMissingKey, -44, "SmartDashboard data does not exist") S(CommandIllegalUse, -50, "Illegal use of Command") S(UnsupportedInSimulation, -80, "Unsupported in simulation") S(CameraServerError, -90, "CameraServer error") S(InvalidParameter, -100, "Invalid parameter value") - -// Warnings -S(SampleRateTooHigh, 1, "Analog module sample rate is too high") -S(VoltageOutOfRange, 2, - "Voltage to convert to raw value is out of range [-10; 10]") -S(CompressorTaskError, 3, "Compressor task won't start") -S(LoopTimingError, 4, "Digital module loop timing is not the expected value") -S(NonBinaryDigitalValue, 5, "Digital output value is not 0 or 1") -S(IncorrectBatteryChannel, 6, - "Battery measurement channel is not correct value") -S(BadJoystickIndex, 7, "Joystick index is out of range, should be 0-3") -S(BadJoystickAxis, 8, "Joystick axis or POV is out of range") -S(InvalidMotorIndex, 9, "Motor index is out of range, should be 0-3") -S(DriverStationTaskError, 10, "Driver Station task won't start") -S(EnhancedIOPWMPeriodOutOfRange, 11, - "Driver Station Enhanced IO PWM Output period out of range.") -S(SPIWriteNoMOSI, 12, "Cannot write to SPI port with no MOSI output") -S(SPIReadNoMISO, 13, "Cannot read from SPI port with no MISO input") -S(SPIReadNoData, 14, "No data available to read from SPI") -S(IncompatibleState, 15, - "Incompatible State: The operation cannot be completed") - -#undef S +S(AssertionFailure, -110, "Assertion failed") diff --git a/wpilibc/src/main/native/include/frc/WPILib.h b/wpilibc/src/main/native/include/frc/WPILib.h deleted file mode 100644 index 25cd0143af..0000000000 --- a/wpilibc/src/main/native/include/frc/WPILib.h +++ /dev/null @@ -1,107 +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 - -// clang-format off -#ifdef _MSC_VER -#pragma message("warning: Including this header drastically increases compilation times and is bad style. Include only what you use instead.") -#else -#warning "Including this header drastically increases compilation times and is bad style. Include only what you use instead." -#endif - -// clang-format on - -#if __has_include() -#include -#include -#endif - -#include "frc/ADXL345_I2C.h" -#include "frc/ADXL345_SPI.h" -#include "frc/ADXL362.h" -#include "frc/ADXRS450_Gyro.h" -#include "frc/AnalogAccelerometer.h" -#include "frc/AnalogGyro.h" -#include "frc/AnalogInput.h" -#include "frc/AnalogOutput.h" -#include "frc/AnalogPotentiometer.h" -#include "frc/AnalogTrigger.h" -#include "frc/AnalogTriggerOutput.h" -#include "frc/BuiltInAccelerometer.h" -#include "frc/Compressor.h" -#include "frc/Counter.h" -#include "frc/DMC60.h" -#include "frc/DigitalInput.h" -#include "frc/DigitalOutput.h" -#include "frc/DigitalSource.h" -#include "frc/DoubleSolenoid.h" -#include "frc/DriverStation.h" -#include "frc/Encoder.h" -#include "frc/ErrorBase.h" -#include "frc/GearTooth.h" -#include "frc/GenericHID.h" -#include "frc/I2C.h" -#include "frc/InterruptableSensorBase.h" -#include "frc/IterativeRobot.h" -#include "frc/Jaguar.h" -#include "frc/Joystick.h" -#include "frc/NidecBrushless.h" -#include "frc/Notifier.h" -#include "frc/PIDController.h" -#include "frc/PIDOutput.h" -#include "frc/PIDSource.h" -#include "frc/PWM.h" -#include "frc/PWMSpeedController.h" -#include "frc/PWMTalonSRX.h" -#include "frc/PWMVictorSPX.h" -#include "frc/PowerDistributionPanel.h" -#include "frc/Preferences.h" -#include "frc/Relay.h" -#include "frc/RobotBase.h" -#include "frc/RobotController.h" -#include "frc/RobotDrive.h" -#include "frc/SD540.h" -#include "frc/SPI.h" -#include "frc/SensorUtil.h" -#include "frc/SerialPort.h" -#include "frc/Servo.h" -#include "frc/Solenoid.h" -#include "frc/Spark.h" -#include "frc/SpeedController.h" -#include "frc/SpeedControllerGroup.h" -#include "frc/Talon.h" -#include "frc/Threads.h" -#include "frc/TimedRobot.h" -#include "frc/Timer.h" -#include "frc/Ultrasonic.h" -#include "frc/Utility.h" -#include "frc/Victor.h" -#include "frc/VictorSP.h" -#include "frc/WPIErrors.h" -#include "frc/XboxController.h" -#if __has_include("frc/buttons/InternalButton.h") -#include "frc/buttons/InternalButton.h" -#include "frc/buttons/JoystickButton.h" -#include "frc/buttons/NetworkButton.h" -#include "frc/commands/Command.h" -#include "frc/commands/CommandGroup.h" -#include "frc/commands/PIDCommand.h" -#include "frc/commands/PIDSubsystem.h" -#include "frc/commands/PrintCommand.h" -#include "frc/commands/StartCommand.h" -#include "frc/commands/Subsystem.h" -#include "frc/commands/WaitCommand.h" -#include "frc/commands/WaitForChildren.h" -#include "frc/commands/WaitUntilCommand.h" -#endif -#include "frc/drive/DifferentialDrive.h" -#include "frc/drive/KilloughDrive.h" -#include "frc/drive/MecanumDrive.h" -#include "frc/filters/LinearDigitalFilter.h" -#include "frc/interfaces/Accelerometer.h" -#include "frc/interfaces/Gyro.h" -#include "frc/interfaces/Potentiometer.h" -#include "frc/smartdashboard/SendableChooser.h" -#include "frc/smartdashboard/SmartDashboard.h" diff --git a/wpilibc/src/main/native/include/frc/WPIWarnings.mac b/wpilibc/src/main/native/include/frc/WPIWarnings.mac new file mode 100644 index 0000000000..8e39ac1d6c --- /dev/null +++ b/wpilibc/src/main/native/include/frc/WPIWarnings.mac @@ -0,0 +1,23 @@ +// 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. + +S(SampleRateTooHigh, 1, "Analog module sample rate is too high") +S(VoltageOutOfRange, 2, + "Voltage to convert to raw value is out of range [-10; 10]") +S(CompressorTaskError, 3, "Compressor task won't start") +S(LoopTimingError, 4, "Digital module loop timing is not the expected value") +S(NonBinaryDigitalValue, 5, "Digital output value is not 0 or 1") +S(IncorrectBatteryChannel, 6, + "Battery measurement channel is not correct value") +S(BadJoystickIndex, 7, "Joystick index is out of range, should be 0-3") +S(BadJoystickAxis, 8, "Joystick axis or POV is out of range") +S(InvalidMotorIndex, 9, "Motor index is out of range, should be 0-3") +S(DriverStationTaskError, 10, "Driver Station task won't start") +S(EnhancedIOPWMPeriodOutOfRange, 11, + "Driver Station Enhanced IO PWM Output period out of range") +S(SPIWriteNoMOSI, 12, "Cannot write to SPI port with no MOSI output") +S(SPIReadNoMISO, 13, "Cannot read from SPI port with no MISO input") +S(SPIReadNoData, 14, "No data available to read from SPI") +S(IncompatibleState, 15, + "Incompatible State: The operation cannot be completed") diff --git a/wpilibc/src/main/native/include/frc/controller/PIDController.h b/wpilibc/src/main/native/include/frc/controller/PIDController.h index ba6aa4080b..29d9ad4f06 100644 --- a/wpilibc/src/main/native/include/frc/controller/PIDController.h +++ b/wpilibc/src/main/native/include/frc/controller/PIDController.h @@ -239,3 +239,9 @@ class PIDController : public frc::Sendable, }; } // namespace frc2 + +namespace frc { + +using frc2::PIDController; + +} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/drive/DifferentialDrive.h b/wpilibc/src/main/native/include/frc/drive/DifferentialDrive.h index 4e0ff1e79e..57a125e558 100644 --- a/wpilibc/src/main/native/include/frc/drive/DifferentialDrive.h +++ b/wpilibc/src/main/native/include/frc/drive/DifferentialDrive.h @@ -12,6 +12,17 @@ namespace frc { +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4996) // was declared deprecated +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + class SpeedController; /** @@ -19,9 +30,9 @@ class SpeedController; * the Kit of Parts drive base, "tank drive", or West Coast Drive. * * These drive bases typically have drop-center / skid-steer with two or more - * wheels per side (e.g., 6WD or 8WD). This class takes a SpeedController per + * wheels per side (e.g., 6WD or 8WD). This class takes a MotorController per * side. For four and six motor drivetrains, construct and pass in - * SpeedControllerGroup instances as follows. + * MotorControllerGroup instances as follows. * * Four motor drivetrain: * @code{.cpp} @@ -29,11 +40,11 @@ class SpeedController; * public: * frc::PWMVictorSPX m_frontLeft{1}; * frc::PWMVictorSPX m_rearLeft{2}; - * frc::SpeedControllerGroup m_left{m_frontLeft, m_rearLeft}; + * frc::MotorControllerGroup m_left{m_frontLeft, m_rearLeft}; * * frc::PWMVictorSPX m_frontRight{3}; * frc::PWMVictorSPX m_rearRight{4}; - * frc::SpeedControllerGroup m_right{m_frontRight, m_rearRight}; + * frc::MotorControllerGroup m_right{m_frontRight, m_rearRight}; * * frc::DifferentialDrive m_drive{m_left, m_right}; * }; @@ -46,12 +57,12 @@ class SpeedController; * frc::PWMVictorSPX m_frontLeft{1}; * frc::PWMVictorSPX m_midLeft{2}; * frc::PWMVictorSPX m_rearLeft{3}; - * frc::SpeedControllerGroup m_left{m_frontLeft, m_midLeft, m_rearLeft}; + * frc::MotorControllerGroup m_left{m_frontLeft, m_midLeft, m_rearLeft}; * * frc::PWMVictorSPX m_frontRight{4}; * frc::PWMVictorSPX m_midRight{5}; * frc::PWMVictorSPX m_rearRight{6}; - * frc::SpeedControllerGroup m_right{m_frontRight, m_midRight, m_rearRight}; + * frc::MotorControllerGroup m_right{m_frontRight, m_midRight, m_rearRight}; * * frc::DifferentialDrive m_drive{m_left, m_right}; * }; @@ -87,12 +98,12 @@ class SpeedController; * *

RobotDrive porting guide: *
TankDrive(double, double, bool) is equivalent to - * RobotDrive#TankDrive(double, double, bool) if a deadband of 0 is used. + * RobotDrive's TankDrive(double, double, bool) if a deadband of 0 is used. *
ArcadeDrive(double, double, bool) is equivalent to - * RobotDrive#ArcadeDrive(double, double, bool) if a deadband of 0 is used + * RobotDrive's ArcadeDrive(double, double, bool) if a deadband of 0 is used * and the the rotation input is inverted eg ArcadeDrive(y, -rotation, false) *
CurvatureDrive(double, double, bool) is similar in concept to - * RobotDrive#Drive(double, double) with the addition of a quick turn + * RobotDrive's Drive(double, double) with the addition of a quick turn * mode. However, it is not designed to give exactly the same response. */ class DifferentialDrive : public RobotDriveBase, @@ -105,7 +116,7 @@ class DifferentialDrive : public RobotDriveBase, /** * Construct a DifferentialDrive. * - * To pass multiple motors per side, use a SpeedControllerGroup. If a motor + * To pass multiple motors per side, use a MotorControllerGroup. If a motor * needs to be inverted, do so before passing it in. */ DifferentialDrive(SpeedController& leftMotor, SpeedController& rightMotor); @@ -219,4 +230,12 @@ class DifferentialDrive : public RobotDriveBase, double m_rightSideInvertMultiplier = -1.0; }; +#if defined(_MSC_VER) +#pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/drive/KilloughDrive.h b/wpilibc/src/main/native/include/frc/drive/KilloughDrive.h index d2ebd83d8d..25f370a77a 100644 --- a/wpilibc/src/main/native/include/frc/drive/KilloughDrive.h +++ b/wpilibc/src/main/native/include/frc/drive/KilloughDrive.h @@ -15,6 +15,17 @@ namespace frc { +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4996) // was declared deprecated +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + class SpeedController; /** @@ -140,4 +151,12 @@ class KilloughDrive : public RobotDriveBase, bool reported = false; }; +#if defined(_MSC_VER) +#pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/drive/MecanumDrive.h b/wpilibc/src/main/native/include/frc/drive/MecanumDrive.h index e478e3b11b..7c7c161f01 100644 --- a/wpilibc/src/main/native/include/frc/drive/MecanumDrive.h +++ b/wpilibc/src/main/native/include/frc/drive/MecanumDrive.h @@ -14,6 +14,17 @@ namespace frc { +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4996) // was declared deprecated +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + class SpeedController; /** @@ -53,12 +64,12 @@ class SpeedController; * inverted, while in RobotDrive, no speed controllers are automatically * inverted. *
DriveCartesian(double, double, double, double) is equivalent to - * RobotDrive#MecanumDrive_Cartesian(double, double, double, double) + * RobotDrive's MecanumDrive_Cartesian(double, double, double, double) * if a deadband of 0 is used, and the ySpeed and gyroAngle values are inverted * compared to RobotDrive (eg DriveCartesian(xSpeed, -ySpeed, zRotation, * -gyroAngle). *
DrivePolar(double, double, double) is equivalent to - * RobotDrive#MecanumDrive_Polar(double, double, double) if a + * RobotDrive's MecanumDrive_Polar(double, double, double) if a * deadband of 0 is used. */ class MecanumDrive : public RobotDriveBase, @@ -145,4 +156,12 @@ class MecanumDrive : public RobotDriveBase, bool reported = false; }; +#if defined(_MSC_VER) +#pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/drive/RobotDriveBase.h b/wpilibc/src/main/native/include/frc/drive/RobotDriveBase.h index 830ed326b4..60c0ac38ac 100644 --- a/wpilibc/src/main/native/include/frc/drive/RobotDriveBase.h +++ b/wpilibc/src/main/native/include/frc/drive/RobotDriveBase.h @@ -13,8 +13,6 @@ namespace frc { -class SpeedController; - /** * Common base class for drive platforms. */ diff --git a/wpilibc/src/main/native/include/frc/filters/Filter.h b/wpilibc/src/main/native/include/frc/filters/Filter.h deleted file mode 100644 index 9ec3efb3dd..0000000000 --- a/wpilibc/src/main/native/include/frc/filters/Filter.h +++ /dev/null @@ -1,61 +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 "frc/PIDSource.h" - -namespace frc { - -/** - * Interface for filters - * - * @deprecated only used by the deprecated LinearDigitalFilter - */ -class Filter : public PIDSource { - public: - WPI_DEPRECATED("This class is no longer used.") - explicit Filter(PIDSource& source); - WPI_DEPRECATED("This class is no longer used.") - explicit Filter(std::shared_ptr source); - ~Filter() override = default; - - Filter(Filter&&) = default; - Filter& operator=(Filter&&) = default; - - // PIDSource interface - void SetPIDSourceType(PIDSourceType pidSource) override; - PIDSourceType GetPIDSourceType() const override; - double PIDGet() override = 0; - - /** - * Returns the current filter estimate without also inserting new data as - * PIDGet() would do. - * - * @return The current filter estimate - */ - virtual double Get() const = 0; - - /** - * Reset the filter state - */ - virtual void Reset() = 0; - - protected: - /** - * Calls PIDGet() of source - * - * @return Current value of source - */ - double PIDGetSource(); - - private: - std::shared_ptr m_source; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/filters/LinearDigitalFilter.h b/wpilibc/src/main/native/include/frc/filters/LinearDigitalFilter.h deleted file mode 100644 index e26a79bc23..0000000000 --- a/wpilibc/src/main/native/include/frc/filters/LinearDigitalFilter.h +++ /dev/null @@ -1,223 +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 - -#include -#include -#include - -#include "frc/filters/Filter.h" - -namespace frc { - -/** - * This class implements a linear, digital filter. All types of FIR and IIR - * filters are supported. Static factory methods are provided to create commonly - * used types of filters. - * - * Filters are of the form:
- * y[n] = (b0 * x[n] + b1 * x[n-1] + ... + bP * x[n-P]) - - * (a0 * y[n-1] + a2 * y[n-2] + ... + aQ * y[n-Q]) - * - * Where:
- * y[n] is the output at time "n"
- * x[n] is the input at time "n"
- * y[n-1] is the output from the LAST time step ("n-1")
- * x[n-1] is the input from the LAST time step ("n-1")
- * b0...bP are the "feedforward" (FIR) gains
- * a0...aQ are the "feedback" (IIR) gains
- * IMPORTANT! Note the "-" sign in front of the feedback term! This is a common - * convention in signal processing. - * - * What can linear filters do? Basically, they can filter, or diminish, the - * effects of undesirable input frequencies. High frequencies, or rapid changes, - * can be indicative of sensor noise or be otherwise undesirable. A "low pass" - * filter smooths out the signal, reducing the impact of these high frequency - * components. Likewise, a "high pass" filter gets rid of slow-moving signal - * components, letting you detect large changes more easily. - * - * Example FRC applications of filters: - * - Getting rid of noise from an analog sensor input (note: the roboRIO's FPGA - * can do this faster in hardware) - * - Smoothing out joystick input to prevent the wheels from slipping or the - * robot from tipping - * - Smoothing motor commands so that unnecessary strain isn't put on - * electrical or mechanical components - * - If you use clever gains, you can make a PID controller out of this class! - * - * For more on filters, I highly recommend the following articles:
- * http://en.wikipedia.org/wiki/Linear_filter
- * http://en.wikipedia.org/wiki/Iir_filter
- * http://en.wikipedia.org/wiki/Fir_filter
- * - * Note 1: PIDGet() should be called by the user on a known, regular period. - * You can set up a Notifier to do this (look at the WPILib PIDController - * class), or do it "inline" with code in a periodic function. - * - * Note 2: For ALL filters, gains are necessarily a function of frequency. If - * you make a filter that works well for you at, say, 100Hz, you will most - * definitely need to adjust the gains if you then want to run it at 200Hz! - * Combining this with Note 1 - the impetus is on YOU as a developer to make - * sure PIDGet() gets called at the desired, constant frequency! - * - * @deprecated Use LinearFilter class instead - */ -class LinearDigitalFilter : public Filter { - public: - /** - * Create a linear FIR or IIR filter. - * - * @param source The PIDSource object that is used to get values - * @param ffGains The "feed forward" or FIR gains - * @param fbGains The "feed back" or IIR gains - */ - WPI_DEPRECATED("Use LinearFilter class instead.") - LinearDigitalFilter(PIDSource& source, wpi::ArrayRef ffGains, - wpi::ArrayRef fbGains); - - /** - * Create a linear FIR or IIR filter. - * - * @param source The PIDSource object that is used to get values - * @param ffGains The "feed forward" or FIR gains - * @param fbGains The "feed back" or IIR gains - */ - WPI_DEPRECATED("Use LinearFilter class instead.") - LinearDigitalFilter(PIDSource& source, std::initializer_list ffGains, - std::initializer_list fbGains); - - /** - * Create a linear FIR or IIR filter. - * - * @param source The PIDSource object that is used to get values - * @param ffGains The "feed forward" or FIR gains - * @param fbGains The "feed back" or IIR gains - */ - WPI_DEPRECATED("Use LinearFilter class instead.") - LinearDigitalFilter(std::shared_ptr source, - wpi::ArrayRef ffGains, - wpi::ArrayRef fbGains); - - /** - * Create a linear FIR or IIR filter. - * - * @param source The PIDSource object that is used to get values - * @param ffGains The "feed forward" or FIR gains - * @param fbGains The "feed back" or IIR gains - */ - WPI_DEPRECATED("Use LinearFilter class instead.") - LinearDigitalFilter(std::shared_ptr source, - std::initializer_list ffGains, - std::initializer_list fbGains); - - LinearDigitalFilter(LinearDigitalFilter&&) = default; - LinearDigitalFilter& operator=(LinearDigitalFilter&&) = default; - - // Static methods to create commonly used filters - /** - * Creates a one-pole IIR low-pass filter of the form:
- * y[n] = (1 - gain) * x[n] + gain * y[n-1]
- * where gain = e-dt / T, T is the time constant in seconds - * - * This filter is stable for time constants greater than zero. - * - * @param source The PIDSource object that is used to get values - * @param timeConstant The discrete-time time constant in seconds - * @param period The period in seconds between samples taken by the user - */ - static LinearDigitalFilter SinglePoleIIR(PIDSource& source, - double timeConstant, double period); - - /** - * Creates a first-order high-pass filter of the form:
- * y[n] = gain * x[n] + (-gain) * x[n-1] + gain * y[n-1]
- * where gain = e-dt / T, T is the time constant in seconds - * - * This filter is stable for time constants greater than zero. - * - * @param source The PIDSource object that is used to get values - * @param timeConstant The discrete-time time constant in seconds - * @param period The period in seconds between samples taken by the user - */ - static LinearDigitalFilter HighPass(PIDSource& source, double timeConstant, - double period); - - /** - * Creates a K-tap FIR moving average filter of the form:
- * y[n] = 1/k * (x[k] + x[k-1] + … + x[0]) - * - * This filter is always stable. - * - * @param source The PIDSource object that is used to get values - * @param taps The number of samples to average over. Higher = smoother but - * slower - */ - static LinearDigitalFilter MovingAverage(PIDSource& source, int taps); - - /** - * Creates a one-pole IIR low-pass filter of the form:
- * y[n] = (1 - gain) * x[n] + gain * y[n-1]
- * where gain = e-dt / T, T is the time constant in seconds - * - * This filter is stable for time constants greater than zero. - * - * @param source The PIDSource object that is used to get values - * @param timeConstant The discrete-time time constant in seconds - * @param period The period in seconds between samples taken by the user - */ - static LinearDigitalFilter SinglePoleIIR(std::shared_ptr source, - double timeConstant, double period); - - /** - * Creates a first-order high-pass filter of the form:
- * y[n] = gain * x[n] + (-gain) * x[n-1] + gain * y[n-1]
- * where gain = e-dt / T, T is the time constant in seconds - * - * This filter is stable for time constants greater than zero. - * - * @param source The PIDSource object that is used to get values - * @param timeConstant The discrete-time time constant in seconds - * @param period The period in seconds between samples taken by the user - */ - static LinearDigitalFilter HighPass(std::shared_ptr source, - double timeConstant, double period); - - /** - * Creates a K-tap FIR moving average filter of the form:
- * y[n] = 1/k * (x[k] + x[k-1] + … + x[0]) - * - * This filter is always stable. - * - * @param source The PIDSource object that is used to get values - * @param taps The number of samples to average over. Higher = smoother but - * slower - */ - static LinearDigitalFilter MovingAverage(std::shared_ptr source, - int taps); - - // Filter interface - double Get() const override; - void Reset() override; - - // PIDSource interface - /** - * Calculates the next value of the filter - * - * @return The filtered value at this step - */ - double PIDGet() override; - - private: - wpi::circular_buffer m_inputs; - wpi::circular_buffer m_outputs; - std::vector m_inputGains; - std::vector m_outputGains; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/interfaces/Potentiometer.h b/wpilibc/src/main/native/include/frc/interfaces/Potentiometer.h deleted file mode 100644 index f3392c9b03..0000000000 --- a/wpilibc/src/main/native/include/frc/interfaces/Potentiometer.h +++ /dev/null @@ -1,32 +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 "frc/PIDSource.h" - -namespace frc { - -/** - * Interface for potentiometers. - */ -class Potentiometer : public PIDSource { - public: - Potentiometer() = default; - ~Potentiometer() override = default; - - Potentiometer(Potentiometer&&) = default; - Potentiometer& operator=(Potentiometer&&) = default; - - /** - * Common interface for getting the current value of a potentiometer. - * - * @return The current set speed. Value is between -1.0 and 1.0. - */ - virtual double Get() const = 0; - - void SetPIDSourceType(PIDSourceType pidSource) override; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/livewindow/LiveWindow.h b/wpilibc/src/main/native/include/frc/livewindow/LiveWindow.h index f3b6092b52..4f8ce59725 100644 --- a/wpilibc/src/main/native/include/frc/livewindow/LiveWindow.h +++ b/wpilibc/src/main/native/include/frc/livewindow/LiveWindow.h @@ -29,7 +29,7 @@ class LiveWindow { * This is a singleton to guarantee that there is only a single instance * regardless of how many times GetInstance is called. */ - static LiveWindow* GetInstance(); + static LiveWindow& GetInstance(); /** * Enable telemetry for a single component. @@ -69,6 +69,7 @@ class LiveWindow { private: LiveWindow(); + ~LiveWindow() = default; struct Impl; std::unique_ptr m_impl; diff --git a/wpilibc/src/main/native/include/frc/DMC60.h b/wpilibc/src/main/native/include/frc/motorcontrol/DMC60.h similarity index 90% rename from wpilibc/src/main/native/include/frc/DMC60.h rename to wpilibc/src/main/native/include/frc/motorcontrol/DMC60.h index 492059ca86..928cceda07 100644 --- a/wpilibc/src/main/native/include/frc/DMC60.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/DMC60.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * Digilent DMC 60 Speed Controller. + * Digilent DMC 60 Motor Controller. * * Note that the DMC 60 uses the following bounds for PWM values. These * values should work reasonably well for most controllers, but if users @@ -24,7 +24,7 @@ namespace frc { * \li 1.480ms = the "low end" of the deadband range * \li 0.997ms = full "reverse" */ -class DMC60 : public PWMSpeedController { +class DMC60 : public PWMMotorController { public: /** * Constructor for a Digilent DMC 60. diff --git a/wpilibc/src/main/native/include/frc/Jaguar.h b/wpilibc/src/main/native/include/frc/motorcontrol/Jaguar.h similarity index 88% rename from wpilibc/src/main/native/include/frc/Jaguar.h rename to wpilibc/src/main/native/include/frc/motorcontrol/Jaguar.h index 15cbf7b3c7..461bf91947 100644 --- a/wpilibc/src/main/native/include/frc/Jaguar.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/Jaguar.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * Luminary Micro / Vex Robotics Jaguar Speed Controller with PWM control. + * Luminary Micro / Vex Robotics Jaguar Motor Controller with PWM control. * * Note that the Jaguar uses the following bounds for PWM values. These values * should work reasonably well for most controllers, but if users experience @@ -24,7 +24,7 @@ namespace frc { * \li 1.454ms = the "low end" of the deadband range * \li 0.697ms = full "reverse" */ -class Jaguar : public PWMSpeedController { +class Jaguar : public PWMMotorController { public: /** * Constructor for a Jaguar connected via PWM. diff --git a/wpilibc/src/main/native/include/frc/motorcontrol/MotorController.h b/wpilibc/src/main/native/include/frc/motorcontrol/MotorController.h new file mode 100644 index 0000000000..8ed19bcba5 --- /dev/null +++ b/wpilibc/src/main/native/include/frc/motorcontrol/MotorController.h @@ -0,0 +1,37 @@ +// 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 "frc/SpeedController.h" + +namespace frc { + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4996) // was declared deprecated +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +/** + * Interface for motor controlling devices. + */ +class MotorController : public SpeedController {}; + +#if defined(_MSC_VER) +#pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + +} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/motorcontrol/MotorControllerGroup.h b/wpilibc/src/main/native/include/frc/motorcontrol/MotorControllerGroup.h new file mode 100644 index 0000000000..584eb02da9 --- /dev/null +++ b/wpilibc/src/main/native/include/frc/motorcontrol/MotorControllerGroup.h @@ -0,0 +1,47 @@ +// 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 "frc/motorcontrol/MotorController.h" +#include "frc/smartdashboard/Sendable.h" +#include "frc/smartdashboard/SendableHelper.h" + +namespace frc { + +class MotorControllerGroup : public Sendable, + public MotorController, + public SendableHelper { + public: + template + explicit MotorControllerGroup(MotorController& motorController, + MotorControllers&... motorControllers); + explicit MotorControllerGroup( + std::vector>&& motorControllers); + + MotorControllerGroup(MotorControllerGroup&&) = default; + MotorControllerGroup& operator=(MotorControllerGroup&&) = default; + + void Set(double speed) override; + double Get() const override; + void SetInverted(bool isInverted) override; + bool GetInverted() const override; + void Disable() override; + void StopMotor() override; + + void InitSendable(SendableBuilder& builder) override; + + private: + bool m_isInverted = false; + std::vector> m_motorControllers; + + void Initialize(); +}; + +} // namespace frc + +#include "frc/motorcontrol/MotorControllerGroup.inc" diff --git a/wpilibc/src/main/native/include/frc/motorcontrol/MotorControllerGroup.inc b/wpilibc/src/main/native/include/frc/motorcontrol/MotorControllerGroup.inc new file mode 100644 index 0000000000..8f876354a1 --- /dev/null +++ b/wpilibc/src/main/native/include/frc/motorcontrol/MotorControllerGroup.inc @@ -0,0 +1,22 @@ +// 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 "frc/motorcontrol/MotorControllerGroup.h" + +namespace frc { + +template +MotorControllerGroup::MotorControllerGroup( + MotorController& motorController, MotorControllers&... motorControllers) + : m_motorControllers(std::vector>{ + motorController, motorControllers...}) { + Initialize(); +} + +} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/NidecBrushless.h b/wpilibc/src/main/native/include/frc/motorcontrol/NidecBrushless.h similarity index 86% rename from wpilibc/src/main/native/include/frc/NidecBrushless.h rename to wpilibc/src/main/native/include/frc/motorcontrol/NidecBrushless.h index 3f12d6235d..112cbd13b4 100644 --- a/wpilibc/src/main/native/include/frc/NidecBrushless.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/NidecBrushless.h @@ -5,10 +5,9 @@ #pragma once #include "frc/DigitalOutput.h" -#include "frc/ErrorBase.h" #include "frc/MotorSafety.h" #include "frc/PWM.h" -#include "frc/SpeedController.h" +#include "frc/motorcontrol/MotorController.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" @@ -19,7 +18,7 @@ class SendableBuilder; /** * Nidec Brushless Motor. */ -class NidecBrushless : public SpeedController, +class NidecBrushless : public MotorController, public MotorSafety, public Sendable, public SendableHelper { @@ -39,7 +38,7 @@ class NidecBrushless : public SpeedController, NidecBrushless(NidecBrushless&&) = default; NidecBrushless& operator=(NidecBrushless&&) = default; - // SpeedController interface + // MotorController interface /** * Set the PWM value. * @@ -73,14 +72,6 @@ class NidecBrushless : public SpeedController, */ void Enable(); - // PIDOutput interface - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - void PIDWrite(double output) override; - // MotorSafety interface void StopMotor() override; void GetDescription(wpi::raw_ostream& desc) const override; diff --git a/wpilibc/src/main/native/include/frc/PWMSpeedController.h b/wpilibc/src/main/native/include/frc/motorcontrol/PWMMotorController.h similarity index 55% rename from wpilibc/src/main/native/include/frc/PWMSpeedController.h rename to wpilibc/src/main/native/include/frc/motorcontrol/PWMMotorController.h index 3d12fb70c6..eb85b0a992 100644 --- a/wpilibc/src/main/native/include/frc/PWMSpeedController.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/PWMMotorController.h @@ -4,18 +4,30 @@ #pragma once +#include + +#include "frc/MotorSafety.h" #include "frc/PWM.h" -#include "frc/SpeedController.h" +#include "frc/motorcontrol/MotorController.h" +#include "frc/smartdashboard/Sendable.h" +#include "frc/smartdashboard/SendableHelper.h" + +namespace wpi { +class raw_ostream; +} // namespace wpi namespace frc { /** - * Common base class for all PWM Speed Controllers. + * Common base class for all PWM Motor Controllers. */ -class PWMSpeedController : public PWM, public SpeedController { +class PWMMotorController : public MotorController, + public MotorSafety, + public Sendable, + public SendableHelper { public: - PWMSpeedController(PWMSpeedController&&) = default; - PWMSpeedController& operator=(PWMSpeedController&&) = default; + PWMMotorController(PWMMotorController&&) = default; + PWMMotorController& operator=(PWMMotorController&&) = default; /** * Set the PWM value. @@ -30,7 +42,7 @@ class PWMSpeedController : public PWM, public SpeedController { /** * Get the recently set value of the PWM. This value is affected by the * inversion property. If you want the value that is sent directly to the - * SpeedController, use {@link PWM#getSpeed()} instead. + * MotorController, use {@link PWM#getSpeed()} instead. * * @return The most recently set value for the PWM between -1.0 and 1.0. */ @@ -42,26 +54,26 @@ class PWMSpeedController : public PWM, public SpeedController { void Disable() override; + // MotorSafety interface void StopMotor() override; + void GetDescription(wpi::raw_ostream& desc) const override; - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - void PIDWrite(double output) override; + int GetChannel() const; protected: /** - * Constructor for a PWM Speed Controller connected via PWM. + * Constructor for a PWM Motor Controller connected via PWM. * + * @param name Name to use for SendableRegistry * @param channel The PWM channel that the controller is attached to. 0-9 are * on-board, 10-19 are on the MXP port */ - explicit PWMSpeedController(int channel); + PWMMotorController(const wpi::Twine& name, int channel); void InitSendable(SendableBuilder& builder) override; + PWM m_pwm; + private: bool m_isInverted = false; }; diff --git a/wpilibc/src/main/native/include/frc/PWMSparkMax.h b/wpilibc/src/main/native/include/frc/motorcontrol/PWMSparkMax.h similarity index 89% rename from wpilibc/src/main/native/include/frc/PWMSparkMax.h rename to wpilibc/src/main/native/include/frc/motorcontrol/PWMSparkMax.h index 2a32d996a2..9b6b65aba4 100644 --- a/wpilibc/src/main/native/include/frc/PWMSparkMax.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/PWMSparkMax.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * REV Robotics SPARK MAX Speed Controller. + * REV Robotics SPARK MAX Motor Controller. * * Note that the SPARK MAX uses the following bounds for PWM values. These * values should work reasonably well for most controllers, but if users @@ -24,7 +24,7 @@ namespace frc { * \li 1.460ms = the "low end" of the deadband range * \li 0.999ms = full "reverse" */ -class PWMSparkMax : public PWMSpeedController { +class PWMSparkMax : public PWMMotorController { public: /** * Constructor for a SPARK MAX. diff --git a/wpilibc/src/main/native/include/frc/PWMTalonFX.h b/wpilibc/src/main/native/include/frc/motorcontrol/PWMTalonFX.h similarity index 88% rename from wpilibc/src/main/native/include/frc/PWMTalonFX.h rename to wpilibc/src/main/native/include/frc/motorcontrol/PWMTalonFX.h index 406d8afd0a..38d24248ee 100644 --- a/wpilibc/src/main/native/include/frc/PWMTalonFX.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/PWMTalonFX.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * Cross the Road Electronics (CTRE) Talon FX Speed Controller with PWM + * Cross the Road Electronics (CTRE) Talon FX Motor Controller with PWM * control. * * Note that the Talon FX uses the following bounds for PWM values. These @@ -25,7 +25,7 @@ namespace frc { * \li 1.480ms = the "low end" of the deadband range * \li 0.997ms = full "reverse" */ -class PWMTalonFX : public PWMSpeedController { +class PWMTalonFX : public PWMMotorController { public: /** * Construct a Talon FX connected via PWM. diff --git a/wpilibc/src/main/native/include/frc/PWMTalonSRX.h b/wpilibc/src/main/native/include/frc/motorcontrol/PWMTalonSRX.h similarity index 88% rename from wpilibc/src/main/native/include/frc/PWMTalonSRX.h rename to wpilibc/src/main/native/include/frc/motorcontrol/PWMTalonSRX.h index c7e01e690d..6b0e1c2871 100644 --- a/wpilibc/src/main/native/include/frc/PWMTalonSRX.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/PWMTalonSRX.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * Cross the Road Electronics (CTRE) Talon SRX Speed Controller with PWM + * Cross the Road Electronics (CTRE) Talon SRX Motor Controller with PWM * control. * * Note that the Talon SRX uses the following bounds for PWM values. These @@ -25,7 +25,7 @@ namespace frc { * \li 1.480ms = the "low end" of the deadband range * \li 0.997ms = full "reverse" */ -class PWMTalonSRX : public PWMSpeedController { +class PWMTalonSRX : public PWMMotorController { public: /** * Construct a Talon SRX connected via PWM. diff --git a/wpilibc/src/main/native/include/frc/PWMVenom.h b/wpilibc/src/main/native/include/frc/motorcontrol/PWMVenom.h similarity index 92% rename from wpilibc/src/main/native/include/frc/PWMVenom.h rename to wpilibc/src/main/native/include/frc/motorcontrol/PWMVenom.h index 60526b31fb..1047e8e7fc 100644 --- a/wpilibc/src/main/native/include/frc/PWMVenom.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/PWMVenom.h @@ -4,7 +4,7 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { @@ -23,7 +23,7 @@ namespace frc { * \li 1.480ms = the "low end" of the deadband range * \li 0.997ms = full "reverse" */ -class PWMVenom : public PWMSpeedController { +class PWMVenom : public PWMMotorController { public: /** * Construct a Venom connected via PWM. diff --git a/wpilibc/src/main/native/include/frc/PWMVictorSPX.h b/wpilibc/src/main/native/include/frc/motorcontrol/PWMVictorSPX.h similarity index 88% rename from wpilibc/src/main/native/include/frc/PWMVictorSPX.h rename to wpilibc/src/main/native/include/frc/motorcontrol/PWMVictorSPX.h index ecba52a974..b0369966e1 100644 --- a/wpilibc/src/main/native/include/frc/PWMVictorSPX.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/PWMVictorSPX.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * Cross the Road Electronics (CTRE) Victor SPX Speed Controller with PWM + * Cross the Road Electronics (CTRE) Victor SPX Motor Controller with PWM * control. * * Note that the Victor SPX uses the following bounds for PWM values. These @@ -25,7 +25,7 @@ namespace frc { * \li 1.480ms = the "low end" of the deadband range * \li 0.997ms = full "reverse" */ -class PWMVictorSPX : public PWMSpeedController { +class PWMVictorSPX : public PWMMotorController { public: /** * Construct a Victor SPX connected via PWM. diff --git a/wpilibc/src/main/native/include/frc/SD540.h b/wpilibc/src/main/native/include/frc/motorcontrol/SD540.h similarity index 90% rename from wpilibc/src/main/native/include/frc/SD540.h rename to wpilibc/src/main/native/include/frc/motorcontrol/SD540.h index 101a677dac..b292c34886 100644 --- a/wpilibc/src/main/native/include/frc/SD540.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/SD540.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * Mindsensors SD540 Speed Controller. + * Mindsensors SD540 Motor Controller. * * Note that the SD540 uses the following bounds for PWM values. These values * should work reasonably well for most controllers, but if users experience @@ -24,7 +24,7 @@ namespace frc { * \li 1.44ms = the "low end" of the deadband range * \li 0.94ms = full "reverse" */ -class SD540 : public PWMSpeedController { +class SD540 : public PWMMotorController { public: /** * Constructor for a SD540. diff --git a/wpilibc/src/main/native/include/frc/Spark.h b/wpilibc/src/main/native/include/frc/motorcontrol/Spark.h similarity index 90% rename from wpilibc/src/main/native/include/frc/Spark.h rename to wpilibc/src/main/native/include/frc/motorcontrol/Spark.h index 7ec2b82c1d..9391d25251 100644 --- a/wpilibc/src/main/native/include/frc/Spark.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/Spark.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * REV Robotics SPARK Speed Controller. + * REV Robotics SPARK Motor Controller. * * Note that the SPARK uses the following bounds for PWM values. These values * should work reasonably well for most controllers, but if users experience @@ -24,7 +24,7 @@ namespace frc { * \li 1.460ms = the "low end" of the deadband range * \li 0.999ms = full "reverse" */ -class Spark : public PWMSpeedController { +class Spark : public PWMMotorController { public: /** * Constructor for a SPARK. diff --git a/wpilibc/src/main/native/include/frc/Talon.h b/wpilibc/src/main/native/include/frc/motorcontrol/Talon.h similarity index 88% rename from wpilibc/src/main/native/include/frc/Talon.h rename to wpilibc/src/main/native/include/frc/motorcontrol/Talon.h index 510eba512a..dbeb836ea8 100644 --- a/wpilibc/src/main/native/include/frc/Talon.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/Talon.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * Cross the Road Electronics (CTRE) Talon and Talon SR Speed Controller. + * Cross the Road Electronics (CTRE) Talon and Talon SR Motor Controller. * * Note that the Talon uses the following bounds for PWM values. These values * should work reasonably well for most controllers, but if users experience @@ -24,7 +24,7 @@ namespace frc { * \li 1.487ms = the "low end" of the deadband range * \li 0.989ms = full "reverse" */ -class Talon : public PWMSpeedController { +class Talon : public PWMMotorController { public: /** * Constructor for a Talon (original or Talon SR). diff --git a/wpilibc/src/main/native/include/frc/Victor.h b/wpilibc/src/main/native/include/frc/motorcontrol/Victor.h similarity index 87% rename from wpilibc/src/main/native/include/frc/Victor.h rename to wpilibc/src/main/native/include/frc/motorcontrol/Victor.h index 600e9a17aa..670eb3dbf2 100644 --- a/wpilibc/src/main/native/include/frc/Victor.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/Victor.h @@ -4,14 +4,14 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * Vex Robotics Victor 888 Speed Controller. + * Vex Robotics Victor 888 Motor Controller. * - * The Vex Robotics Victor 884 Speed Controller can also be used with this + * The Vex Robotics Victor 884 Motor Controller can also be used with this * class but may need to be calibrated per the Victor 884 user manual. * * Note that the Victor uses the following bounds for PWM values. These @@ -28,7 +28,7 @@ namespace frc { * \li 1.490ms = the "low end" of the deadband range * \li 1.026ms = full "reverse" */ -class Victor : public PWMSpeedController { +class Victor : public PWMMotorController { public: /** * Constructor for a Victor. diff --git a/wpilibc/src/main/native/include/frc/VictorSP.h b/wpilibc/src/main/native/include/frc/motorcontrol/VictorSP.h similarity index 89% rename from wpilibc/src/main/native/include/frc/VictorSP.h rename to wpilibc/src/main/native/include/frc/motorcontrol/VictorSP.h index 941a3ec6ee..534e83afd7 100644 --- a/wpilibc/src/main/native/include/frc/VictorSP.h +++ b/wpilibc/src/main/native/include/frc/motorcontrol/VictorSP.h @@ -4,12 +4,12 @@ #pragma once -#include "frc/PWMSpeedController.h" +#include "frc/motorcontrol/PWMMotorController.h" namespace frc { /** - * Vex Robotics Victor SP Speed Controller. + * Vex Robotics Victor SP Motor Controller. * * Note that the Victor SP uses the following bounds for PWM values. These * values should work reasonably well for most controllers, but if users @@ -24,7 +24,7 @@ namespace frc { * \li 1.480ms = the "low end" of the deadband range * \li 0.997ms = full "reverse" */ -class VictorSP : public PWMSpeedController { +class VictorSP : public PWMMotorController { public: /** * Constructor for a Victor SP. diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInWidgets.h b/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInWidgets.h index b2f5991b91..1b959ff4bf 100644 --- a/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInWidgets.h +++ b/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInWidgets.h @@ -200,10 +200,10 @@ enum class BuiltInWidgets { */ kEncoder, /** - * Displays a SpeedController. + * Displays a MotorController. * The speed controller will be controllable from the dashboard when test mode * is enabled, but will otherwise be view-only.
Supported types:

    - *
  • PWMSpeedController
  • + *
  • PWMMotorController
  • *
  • DMC60
  • *
  • Jaguar
  • *
  • PWMTalonSRX
  • @@ -213,7 +213,7 @@ enum class BuiltInWidgets { *
  • Talon
  • *
  • Victor
  • *
  • VictorSP
  • - *
  • SpeedControllerGroup
  • + *
  • MotorControllerGroup
  • *
  • Any custom subclass of {@code SpeedContorller}
  • *
*
Custom properties: @@ -223,7 +223,7 @@ enum class BuiltInWidgets { * One of {@code ["HORIZONTAL", "VERTICAL"]} * */ - kSpeedController, + kMotorController, /** * Displays a command with a toggle button. Pressing the button will start the * command, and the button will automatically release when the command diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h index a25c81fe89..33b9fe713f 100644 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h +++ b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h @@ -16,8 +16,6 @@ #include #include -#include "frc/ErrorBase.h" -#include "frc/WPIErrors.h" #include "frc/shuffleboard/BuiltInLayouts.h" #include "frc/shuffleboard/LayoutType.h" #include "frc/shuffleboard/ShuffleboardComponentBase.h" @@ -38,8 +36,7 @@ class SimpleWidget; /** * Common interface for objects that can contain shuffleboard components. */ -class ShuffleboardContainer : public virtual ShuffleboardValue, - public ErrorBase { +class ShuffleboardContainer : public virtual ShuffleboardValue { public: explicit ShuffleboardContainer(const wpi::Twine& title); diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/MechanismLigament2d.h b/wpilibc/src/main/native/include/frc/smartdashboard/MechanismLigament2d.h index dd47fd0937..e2a89d6510 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/MechanismLigament2d.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/MechanismLigament2d.h @@ -68,7 +68,7 @@ class MechanismLigament2d : public MechanismObject2d { void SetLineWeight(double lineWidth); protected: - void UpdateEntries(std::shared_ptr table) override; + void UpdateEntries(std::shared_ptr table) override; private: void Flush(); diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/MechanismObject2d.h b/wpilibc/src/main/native/include/frc/smartdashboard/MechanismObject2d.h index ad0d9860ea..e71e7697e6 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/MechanismObject2d.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/MechanismObject2d.h @@ -37,7 +37,7 @@ class MechanismObject2d { * * @param table the new table. */ - virtual void UpdateEntries(std::shared_ptr table) = 0; + virtual void UpdateEntries(std::shared_ptr table) = 0; mutable wpi::mutex m_mutex; @@ -82,7 +82,7 @@ class MechanismObject2d { private: std::string m_name; wpi::StringMap> m_objects; - std::shared_ptr m_table; - void Update(std::shared_ptr table); + std::shared_ptr m_table; + void Update(std::shared_ptr table); }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/MechanismRoot2d.h b/wpilibc/src/main/native/include/frc/smartdashboard/MechanismRoot2d.h index 12b27a5781..0d97a60792 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/MechanismRoot2d.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/MechanismRoot2d.h @@ -40,7 +40,7 @@ class MechanismRoot2d : private MechanismObject2d { using MechanismObject2d::Append; private: - void UpdateEntries(std::shared_ptr table) override; + void UpdateEntries(std::shared_ptr table) override; inline void Flush(); double m_x; double m_y; diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SendableBase.h b/wpilibc/src/main/native/include/frc/smartdashboard/SendableBase.h deleted file mode 100644 index 7f50d0ad07..0000000000 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SendableBase.h +++ /dev/null @@ -1,27 +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 "frc/smartdashboard/Sendable.h" -#include "frc/smartdashboard/SendableHelper.h" - -namespace frc { - -class SendableBase : public Sendable, public SendableHelper { - public: - /** - * Creates an instance of the sensor base - * - * @deprecated use Sendable and SendableHelper - * - * @param addLiveWindow if true, add this Sendable to LiveWindow - */ - WPI_DEPRECATED("use Sendable and SendableHelper") - explicit SendableBase(bool addLiveWindow = true); -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SendableRegistry.h b/wpilibc/src/main/native/include/frc/smartdashboard/SendableRegistry.h index e3fd0de9ef..e24c1934d2 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SendableRegistry.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/SendableRegistry.h @@ -285,7 +285,7 @@ class SendableRegistry { * @param sendableUid sendable unique id * @param table network table */ - void Publish(UID sendableUid, std::shared_ptr table); + void Publish(UID sendableUid, std::shared_ptr table); /** * Updates network table information from an object. diff --git a/wpilibc/src/main/native/include/frc/smartdashboard/SmartDashboard.h b/wpilibc/src/main/native/include/frc/smartdashboard/SmartDashboard.h index 1dd0a1efbf..6a6ee299cf 100644 --- a/wpilibc/src/main/native/include/frc/smartdashboard/SmartDashboard.h +++ b/wpilibc/src/main/native/include/frc/smartdashboard/SmartDashboard.h @@ -11,16 +11,13 @@ #include #include -#include "frc/ErrorBase.h" #include "frc/smartdashboard/ListenerExecutor.h" #include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableHelper.h" namespace frc { -class SmartDashboard : public ErrorBase, - public Sendable, - public SendableHelper { +class SmartDashboard : public Sendable, public SendableHelper { public: static void init(); diff --git a/wpilibc/src/test/native/cpp/MockSpeedController.cpp b/wpilibc/src/test/native/cpp/MockMotorController.cpp similarity index 50% rename from wpilibc/src/test/native/cpp/MockSpeedController.cpp rename to wpilibc/src/test/native/cpp/MockMotorController.cpp index f4d3459f8b..62fd54a31c 100644 --- a/wpilibc/src/test/native/cpp/MockSpeedController.cpp +++ b/wpilibc/src/test/native/cpp/MockMotorController.cpp @@ -2,34 +2,30 @@ // 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 "MockSpeedController.h" +#include "MockMotorController.h" using namespace frc; -void MockSpeedController::Set(double speed) { +void MockMotorController::Set(double speed) { m_speed = m_isInverted ? -speed : speed; } -double MockSpeedController::Get() const { +double MockMotorController::Get() const { return m_speed; } -void MockSpeedController::SetInverted(bool isInverted) { +void MockMotorController::SetInverted(bool isInverted) { m_isInverted = isInverted; } -bool MockSpeedController::GetInverted() const { +bool MockMotorController::GetInverted() const { return m_isInverted; } -void MockSpeedController::Disable() { +void MockMotorController::Disable() { m_speed = 0; } -void MockSpeedController::StopMotor() { +void MockMotorController::StopMotor() { Disable(); } - -void MockSpeedController::PIDWrite(double output) { - Set(output); -} diff --git a/wpilibc/src/test/native/cpp/SpeedControllerGroupTest.cpp b/wpilibc/src/test/native/cpp/SpeedControllerGroupTest.cpp index 597d228644..2b344afcfb 100644 --- a/wpilibc/src/test/native/cpp/SpeedControllerGroupTest.cpp +++ b/wpilibc/src/test/native/cpp/SpeedControllerGroupTest.cpp @@ -2,29 +2,29 @@ // 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 "frc/SpeedControllerGroup.h" // NOLINT(build/include_order) +#include "frc/motorcontrol/MotorControllerGroup.h" // NOLINT(build/include_order) #include #include -#include "MockSpeedController.h" +#include "MockMotorController.h" #include "gtest/gtest.h" using namespace frc; -enum SpeedControllerGroupTestType { TEST_ONE, TEST_TWO, TEST_THREE }; +enum MotorControllerGroupTestType { TEST_ONE, TEST_TWO, TEST_THREE }; std::ostream& operator<<(std::ostream& os, - const SpeedControllerGroupTestType& type) { + const MotorControllerGroupTestType& type) { switch (type) { case TEST_ONE: - os << "SpeedControllerGroup with one speed controller"; + os << "MotorControllerGroup with one speed controller"; break; case TEST_TWO: - os << "SpeedControllerGroup with two speed controllers"; + os << "MotorControllerGroup with two speed controllers"; break; case TEST_THREE: - os << "SpeedControllerGroup with three speed controllers"; + os << "MotorControllerGroup with three speed controllers"; break; } @@ -32,26 +32,26 @@ std::ostream& operator<<(std::ostream& os, } /** - * A fixture used for SpeedControllerGroup testing. + * A fixture used for MotorControllerGroup testing. */ -class SpeedControllerGroupTest - : public testing::TestWithParam { +class MotorControllerGroupTest + : public testing::TestWithParam { protected: - std::vector m_speedControllers; - std::unique_ptr m_group; + std::vector m_speedControllers; + std::unique_ptr m_group; void SetUp() override { switch (GetParam()) { case TEST_ONE: { m_speedControllers.emplace_back(); - m_group = std::make_unique(m_speedControllers[0]); + m_group = std::make_unique(m_speedControllers[0]); break; } case TEST_TWO: { m_speedControllers.emplace_back(); m_speedControllers.emplace_back(); - m_group = std::make_unique(m_speedControllers[0], + m_group = std::make_unique(m_speedControllers[0], m_speedControllers[1]); break; } @@ -60,7 +60,7 @@ class SpeedControllerGroupTest m_speedControllers.emplace_back(); m_speedControllers.emplace_back(); m_speedControllers.emplace_back(); - m_group = std::make_unique(m_speedControllers[0], + m_group = std::make_unique(m_speedControllers[0], m_speedControllers[1], m_speedControllers[2]); break; @@ -69,7 +69,7 @@ class SpeedControllerGroupTest } }; -TEST_P(SpeedControllerGroupTest, Set) { +TEST_P(MotorControllerGroupTest, Set) { m_group->Set(1.0); for (auto& speedController : m_speedControllers) { @@ -77,13 +77,13 @@ TEST_P(SpeedControllerGroupTest, Set) { } } -TEST_P(SpeedControllerGroupTest, GetInverted) { +TEST_P(MotorControllerGroupTest, GetInverted) { m_group->SetInverted(true); EXPECT_TRUE(m_group->GetInverted()); } -TEST_P(SpeedControllerGroupTest, SetInvertedDoesNotModifySpeedControllers) { +TEST_P(MotorControllerGroupTest, SetInvertedDoesNotModifyMotorControllers) { for (auto& speedController : m_speedControllers) { speedController.SetInverted(false); } @@ -94,7 +94,7 @@ TEST_P(SpeedControllerGroupTest, SetInvertedDoesNotModifySpeedControllers) { } } -TEST_P(SpeedControllerGroupTest, SetInvertedDoesInvert) { +TEST_P(MotorControllerGroupTest, SetInvertedDoesInvert) { m_group->SetInverted(true); m_group->Set(1.0); @@ -103,7 +103,7 @@ TEST_P(SpeedControllerGroupTest, SetInvertedDoesInvert) { } } -TEST_P(SpeedControllerGroupTest, Disable) { +TEST_P(MotorControllerGroupTest, Disable) { m_group->Set(1.0); m_group->Disable(); @@ -112,7 +112,7 @@ TEST_P(SpeedControllerGroupTest, Disable) { } } -TEST_P(SpeedControllerGroupTest, StopMotor) { +TEST_P(MotorControllerGroupTest, StopMotor) { m_group->Set(1.0); m_group->StopMotor(); @@ -121,13 +121,5 @@ TEST_P(SpeedControllerGroupTest, StopMotor) { } } -TEST_P(SpeedControllerGroupTest, PIDWrite) { - m_group->PIDWrite(1.0); - - for (auto& speedController : m_speedControllers) { - EXPECT_FLOAT_EQ(speedController.Get(), 1.0); - } -} - -INSTANTIATE_TEST_SUITE_P(Test, SpeedControllerGroupTest, +INSTANTIATE_TEST_SUITE_P(Test, MotorControllerGroupTest, testing::Values(TEST_ONE, TEST_TWO, TEST_THREE)); diff --git a/wpilibc/src/test/native/cpp/drive/DriveTest.cpp b/wpilibc/src/test/native/cpp/drive/DriveTest.cpp deleted file mode 100644 index 643aac3f13..0000000000 --- a/wpilibc/src/test/native/cpp/drive/DriveTest.cpp +++ /dev/null @@ -1,187 +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 "MockSpeedController.h" -#include "frc/RobotDrive.h" -#include "frc/drive/DifferentialDrive.h" -#include "frc/drive/MecanumDrive.h" -#include "gtest/gtest.h" - -using namespace frc; - -class DriveTest : public testing::Test { - protected: - MockSpeedController m_rdFrontLeft; - MockSpeedController m_rdRearLeft; - MockSpeedController m_rdFrontRight; - MockSpeedController m_rdRearRight; - MockSpeedController m_frontLeft; - MockSpeedController m_rearLeft; - MockSpeedController m_frontRight; - MockSpeedController m_rearRight; - frc::RobotDrive m_robotDrive{m_rdFrontLeft, m_rdRearLeft, m_rdFrontRight, - m_rdRearRight}; - frc::DifferentialDrive m_differentialDrive{m_frontLeft, m_frontRight}; - frc::MecanumDrive m_mecanumDrive{m_frontLeft, m_rearLeft, m_frontRight, - m_rearRight}; - - double m_testJoystickValues[9] = {-1.0, -0.9, -0.5, -0.01, 0.0, - 0.01, 0.5, 0.9, 1.0}; - double m_testGyroValues[19] = {0, 45, 90, 135, 180, 225, 270, - 305, 360, 540, -45, -90, -135, -180, - -225, -270, -305, -360, -540}; -}; - -TEST_F(DriveTest, TankDrive) { - int joystickSize = sizeof(m_testJoystickValues) / sizeof(double); - double leftJoystick, rightJoystick; - m_differentialDrive.SetDeadband(0.0); - m_differentialDrive.SetSafetyEnabled(false); - m_mecanumDrive.SetSafetyEnabled(false); - m_robotDrive.SetSafetyEnabled(false); - for (int i = 0; i < joystickSize; i++) { - for (int j = 0; j < joystickSize; j++) { - leftJoystick = m_testJoystickValues[i]; - rightJoystick = m_testJoystickValues[j]; - m_robotDrive.TankDrive(leftJoystick, rightJoystick, false); - m_differentialDrive.TankDrive(leftJoystick, rightJoystick, false); - ASSERT_NEAR(m_rdFrontLeft.Get(), m_frontLeft.Get(), 0.01); - ASSERT_NEAR(m_rdFrontRight.Get(), m_frontRight.Get(), 0.01); - } - } -} - -TEST_F(DriveTest, TankDriveSquared) { - int joystickSize = sizeof(m_testJoystickValues) / sizeof(double); - double leftJoystick, rightJoystick; - m_differentialDrive.SetDeadband(0.0); - m_differentialDrive.SetSafetyEnabled(false); - m_mecanumDrive.SetSafetyEnabled(false); - m_robotDrive.SetSafetyEnabled(false); - for (int i = 0; i < joystickSize; i++) { - for (int j = 0; j < joystickSize; j++) { - leftJoystick = m_testJoystickValues[i]; - rightJoystick = m_testJoystickValues[j]; - m_robotDrive.TankDrive(leftJoystick, rightJoystick, true); - m_differentialDrive.TankDrive(leftJoystick, rightJoystick, true); - ASSERT_NEAR(m_rdFrontLeft.Get(), m_frontLeft.Get(), 0.01); - ASSERT_NEAR(m_rdFrontRight.Get(), m_frontRight.Get(), 0.01); - } - } -} - -TEST_F(DriveTest, ArcadeDriveSquared) { - int joystickSize = sizeof(m_testJoystickValues) / sizeof(double); - double moveJoystick, rotateJoystick; - m_differentialDrive.SetDeadband(0.0); - m_differentialDrive.SetSafetyEnabled(false); - m_mecanumDrive.SetSafetyEnabled(false); - m_robotDrive.SetSafetyEnabled(false); - for (int i = 0; i < joystickSize; i++) { - for (int j = 0; j < joystickSize; j++) { - moveJoystick = m_testJoystickValues[i]; - rotateJoystick = m_testJoystickValues[j]; - m_robotDrive.ArcadeDrive(moveJoystick, rotateJoystick, true); - m_differentialDrive.ArcadeDrive(moveJoystick, -rotateJoystick, true); - ASSERT_NEAR(m_rdFrontLeft.Get(), m_frontLeft.Get(), 0.01); - ASSERT_NEAR(m_rdFrontRight.Get(), m_frontRight.Get(), 0.01); - } - } -} - -TEST_F(DriveTest, ArcadeDrive) { - int joystickSize = sizeof(m_testJoystickValues) / sizeof(double); - double moveJoystick, rotateJoystick; - m_differentialDrive.SetDeadband(0.0); - m_differentialDrive.SetSafetyEnabled(false); - m_mecanumDrive.SetSafetyEnabled(false); - m_robotDrive.SetSafetyEnabled(false); - for (int i = 0; i < joystickSize; i++) { - for (int j = 0; j < joystickSize; j++) { - moveJoystick = m_testJoystickValues[i]; - rotateJoystick = m_testJoystickValues[j]; - m_robotDrive.ArcadeDrive(moveJoystick, rotateJoystick, false); - m_differentialDrive.ArcadeDrive(moveJoystick, -rotateJoystick, false); - ASSERT_NEAR(m_rdFrontLeft.Get(), m_frontLeft.Get(), 0.01); - ASSERT_NEAR(m_rdFrontRight.Get(), m_frontRight.Get(), 0.01); - } - } -} - -TEST_F(DriveTest, MecanumCartesian) { - int joystickSize = sizeof(m_testJoystickValues) / sizeof(double); - int gyroSize = sizeof(m_testGyroValues) / sizeof(double); - double xJoystick, yJoystick, rotateJoystick, gyroValue; - m_mecanumDrive.SetDeadband(0.0); - m_mecanumDrive.SetSafetyEnabled(false); - m_differentialDrive.SetSafetyEnabled(false); - m_robotDrive.SetSafetyEnabled(false); - for (int i = 0; i < joystickSize; i++) { - for (int j = 0; j < joystickSize; j++) { - for (int k = 0; k < joystickSize; k++) { - for (int l = 0; l < gyroSize; l++) { - xJoystick = m_testJoystickValues[i]; - yJoystick = m_testJoystickValues[j]; - rotateJoystick = m_testJoystickValues[k]; - gyroValue = m_testGyroValues[l]; - m_robotDrive.MecanumDrive_Cartesian(xJoystick, yJoystick, - rotateJoystick, gyroValue); - m_mecanumDrive.DriveCartesian(xJoystick, -yJoystick, rotateJoystick, - -gyroValue); - ASSERT_NEAR(m_rdFrontLeft.Get(), m_frontLeft.Get(), 0.01) - << "X: " << xJoystick << " Y: " << yJoystick - << " Rotate: " << rotateJoystick << " Gyro: " << gyroValue; - ASSERT_NEAR(m_rdFrontRight.Get(), -m_frontRight.Get(), 0.01) - << "X: " << xJoystick << " Y: " << yJoystick - << " Rotate: " << rotateJoystick << " Gyro: " << gyroValue; - ASSERT_NEAR(m_rdRearLeft.Get(), m_rearLeft.Get(), 0.01) - << "X: " << xJoystick << " Y: " << yJoystick - << " Rotate: " << rotateJoystick << " Gyro: " << gyroValue; - ASSERT_NEAR(m_rdRearRight.Get(), -m_rearRight.Get(), 0.01) - << "X: " << xJoystick << " Y: " << yJoystick - << " Rotate: " << rotateJoystick << " Gyro: " << gyroValue; - } - } - } - } -} - -TEST_F(DriveTest, MecanumPolar) { - int joystickSize = sizeof(m_testJoystickValues) / sizeof(double); - int gyroSize = sizeof(m_testGyroValues) / sizeof(double); - double magnitudeJoystick, directionJoystick, rotateJoystick; - m_mecanumDrive.SetDeadband(0.0); - m_mecanumDrive.SetSafetyEnabled(false); - m_differentialDrive.SetSafetyEnabled(false); - m_robotDrive.SetSafetyEnabled(false); - for (int i = 0; i < joystickSize; i++) { - for (int j = 0; j < gyroSize; j++) { - for (int k = 0; k < joystickSize; k++) { - magnitudeJoystick = m_testJoystickValues[i]; - directionJoystick = m_testGyroValues[j]; - rotateJoystick = m_testJoystickValues[k]; - m_robotDrive.MecanumDrive_Polar(magnitudeJoystick, directionJoystick, - rotateJoystick); - m_mecanumDrive.DrivePolar(magnitudeJoystick, directionJoystick, - rotateJoystick); - ASSERT_NEAR(m_rdFrontLeft.Get(), m_frontLeft.Get(), 0.01) - << "Magnitude: " << magnitudeJoystick - << " Direction: " << directionJoystick - << " Rotate: " << rotateJoystick; - ASSERT_NEAR(m_rdFrontRight.Get(), -m_frontRight.Get(), 0.01) - << "Magnitude: " << magnitudeJoystick - << " Direction: " << directionJoystick - << " Rotate: " << rotateJoystick; - ASSERT_NEAR(m_rdRearLeft.Get(), m_rearLeft.Get(), 0.01) - << "Magnitude: " << magnitudeJoystick - << " Direction: " << directionJoystick - << " Rotate: " << rotateJoystick; - ASSERT_NEAR(m_rdRearRight.Get(), -m_rearRight.Get(), 0.01) - << "Magnitude: " << magnitudeJoystick - << " Direction: " << directionJoystick - << " Rotate: " << rotateJoystick; - } - } - } -} diff --git a/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp index 1083ad51a6..6e9bfbd93a 100644 --- a/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp @@ -7,10 +7,10 @@ #include #include "frc/Encoder.h" -#include "frc/PWMVictorSPX.h" #include "frc/RobotController.h" #include "frc/StateSpaceUtil.h" #include "frc/controller/PIDController.h" +#include "frc/motorcontrol/PWMVictorSPX.h" #include "frc/simulation/ElevatorSim.h" #include "frc/simulation/EncoderSim.h" #include "frc/system/NumericalIntegration.h" diff --git a/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp index c53605e224..ba089d54c1 100644 --- a/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/StateSpaceSimTest.cpp @@ -8,10 +8,10 @@ #include #include "frc/Encoder.h" -#include "frc/PWMVictorSPX.h" #include "frc/RobotController.h" #include "frc/controller/PIDController.h" #include "frc/controller/SimpleMotorFeedforward.h" +#include "frc/motorcontrol/PWMVictorSPX.h" #include "frc/simulation/BatterySim.h" #include "frc/simulation/DifferentialDrivetrainSim.h" #include "frc/simulation/ElevatorSim.h" diff --git a/wpilibc/src/test/native/include/MockSpeedController.h b/wpilibc/src/test/native/include/MockMotorController.h similarity index 80% rename from wpilibc/src/test/native/include/MockSpeedController.h rename to wpilibc/src/test/native/include/MockMotorController.h index ff0cea8e58..e17931fbb6 100644 --- a/wpilibc/src/test/native/include/MockSpeedController.h +++ b/wpilibc/src/test/native/include/MockMotorController.h @@ -4,11 +4,11 @@ #pragma once -#include "frc/SpeedController.h" +#include "frc/motorcontrol/MotorController.h" namespace frc { -class MockSpeedController : public SpeedController { +class MockMotorController : public MotorController { public: void Set(double speed) override; double Get() const override; @@ -17,8 +17,6 @@ class MockSpeedController : public SpeedController { void Disable() override; void StopMotor() override; - void PIDWrite(double output) override; - private: double m_speed = 0.0; bool m_isInverted = false; diff --git a/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp index 379520e4ca..abe79f48a8 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ArcadeDrive/cpp/Robot.cpp @@ -3,9 +3,9 @@ // the WPILib BSD license file in the root directory of this project. #include -#include #include #include +#include /** * This is a demo program showing the use of the DifferentialDrive class. diff --git a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp index 7f34b09cae..5b48f0adb4 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveXboxController/cpp/Robot.cpp @@ -3,10 +3,10 @@ // the WPILib BSD license file in the root directory of this project. #include -#include #include #include #include +#include /** * This is a demo program showing the use of the DifferentialDrive class. diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/ArmSubsystem.h b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/ArmSubsystem.h index 1b1c1ee109..45cd582117 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/ArmSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/ArmSubsystem.h @@ -5,8 +5,8 @@ #pragma once #include -#include #include +#include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/DriveSubsystem.h index 7aaac36654..47bf28e4d9 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/ArmBot/include/subsystems/DriveSubsystem.h @@ -5,9 +5,9 @@ #pragma once #include -#include -#include #include +#include +#include #include #include "Constants.h" @@ -76,10 +76,10 @@ class DriveSubsystem : public frc2::SubsystemBase { frc::PWMSparkMax m_right2; // The motors on the left side of the drive - frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2}; + frc::MotorControllerGroup m_leftMotors{m_left1, m_left2}; // The motors on the right side of the drive - frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2}; + frc::MotorControllerGroup m_rightMotors{m_right1, m_right2}; // The robot's drive frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors}; diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/ExampleSmartMotorController.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/ExampleSmartMotorController.h index cb2c748550..5d55839892 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/ExampleSmartMotorController.h +++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/ExampleSmartMotorController.h @@ -4,7 +4,7 @@ #pragma once -#include +#include /** * A simplified stub class that simulates the API of a common "smart" motor @@ -12,7 +12,7 @@ * *

Has no actual functionality. */ -class ExampleSmartMotorController : public frc::SpeedController { +class ExampleSmartMotorController : public frc::MotorController { public: enum PIDMode { kPosition, kVelocity, kMovementWitchcraft }; @@ -79,6 +79,4 @@ class ExampleSmartMotorController : public frc::SpeedController { void Disable() override {} void StopMotor() override {} - - void PIDWrite(double output) override {} }; diff --git a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h index 7aaac36654..47bf28e4d9 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/ArmBotOffboard/include/subsystems/DriveSubsystem.h @@ -5,9 +5,9 @@ #pragma once #include -#include -#include #include +#include +#include #include #include "Constants.h" @@ -76,10 +76,10 @@ class DriveSubsystem : public frc2::SubsystemBase { frc::PWMSparkMax m_right2; // The motors on the left side of the drive - frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2}; + frc::MotorControllerGroup m_leftMotors{m_left1, m_left2}; // The motors on the right side of the drive - frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2}; + frc::MotorControllerGroup m_rightMotors{m_right1, m_right2}; // The robot's drive frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors}; diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp index 94ef9c25f7..b777af3e2e 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp @@ -5,11 +5,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/AxisCameraSample/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/AxisCameraSample/cpp/Robot.cpp index 5051fb71ed..ce9f4580c0 100644 --- a/wpilibcExamples/src/main/cpp/examples/AxisCameraSample/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/AxisCameraSample/cpp/Robot.cpp @@ -19,15 +19,15 @@ class Robot : public frc::TimedRobot { static void VisionThread() { // Get the Axis camera from CameraServer cs::AxisCamera camera = - frc::CameraServer::GetInstance()->AddAxisCamera("axis-camera.local"); + frc::CameraServer::GetInstance().AddAxisCamera("axis-camera.local"); // Set the resolution camera.SetResolution(640, 480); // Get a CvSink. This will capture Mats from the Camera - cs::CvSink cvSink = frc::CameraServer::GetInstance()->GetVideo(); + cs::CvSink cvSink = frc::CameraServer::GetInstance().GetVideo(); // Setup a CvSource. This will send images back to the Dashboard cs::CvSource outputStream = - frc::CameraServer::GetInstance()->PutVideo("Rectangle", 640, 480); + frc::CameraServer::GetInstance().PutVideo("Rectangle", 640, 480); // Mats are very memory expensive. Lets reuse this Mat. cv::Mat mat; diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h index 57532e9b14..d7e9e078b6 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.h @@ -6,12 +6,12 @@ #include #include -#include -#include #include #include #include #include +#include +#include #include #include #include @@ -57,8 +57,8 @@ class Drivetrain { frc::PWMSparkMax m_rightLeader{3}; frc::PWMSparkMax m_rightFollower{4}; - frc::SpeedControllerGroup m_leftGroup{m_leftLeader, m_leftFollower}; - frc::SpeedControllerGroup m_rightGroup{m_rightLeader, m_rightFollower}; + frc::MotorControllerGroup m_leftGroup{m_leftLeader, m_leftFollower}; + frc::MotorControllerGroup m_rightGroup{m_rightLeader, m_rightFollower}; frc::Encoder m_leftEncoder{0, 1}; frc::Encoder m_rightEncoder{2, 3}; diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h index 37f05e40ca..e9b657be8a 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h @@ -6,12 +6,12 @@ #include #include -#include -#include #include #include #include #include +#include +#include #include #include #include @@ -57,8 +57,8 @@ class Drivetrain { frc::PWMSparkMax m_rightLeader{3}; frc::PWMSparkMax m_rightFollower{4}; - frc::SpeedControllerGroup m_leftGroup{m_leftLeader, m_leftFollower}; - frc::SpeedControllerGroup m_rightGroup{m_rightLeader, m_rightFollower}; + frc::MotorControllerGroup m_leftGroup{m_leftLeader, m_leftFollower}; + frc::MotorControllerGroup m_rightGroup{m_rightLeader, m_rightFollower}; frc::Encoder m_leftEncoder{0, 1}; frc::Encoder m_rightEncoder{2, 3}; diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.h b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.h index 46720e1f81..71dc4d4864 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.h +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.h @@ -4,7 +4,7 @@ #pragma once -#include +#include /** * A simplified stub class that simulates the API of a common "smart" motor @@ -12,7 +12,7 @@ * *

Has no actual functionality. */ -class ExampleSmartMotorController : public frc::SpeedController { +class ExampleSmartMotorController : public frc::MotorController { public: enum PIDMode { kPosition, kVelocity, kMovementWitchcraft }; @@ -80,8 +80,6 @@ class ExampleSmartMotorController : public frc::SpeedController { void StopMotor() override {} - void PIDWrite(double output) override {} - private: double m_value = 0.0; }; diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp index 6472fa581b..14f34d729f 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp @@ -4,9 +4,9 @@ #include #include -#include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp index 77de329929..0aa766fb15 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp @@ -5,11 +5,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/include/ExampleSmartMotorController.h b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/include/ExampleSmartMotorController.h index cb2c748550..5d55839892 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/include/ExampleSmartMotorController.h +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/include/ExampleSmartMotorController.h @@ -4,7 +4,7 @@ #pragma once -#include +#include /** * A simplified stub class that simulates the API of a common "smart" motor @@ -12,7 +12,7 @@ * *

Has no actual functionality. */ -class ExampleSmartMotorController : public frc::SpeedController { +class ExampleSmartMotorController : public frc::MotorController { public: enum PIDMode { kPosition, kVelocity, kMovementWitchcraft }; @@ -79,6 +79,4 @@ class ExampleSmartMotorController : public frc::SpeedController { void Disable() override {} void StopMotor() override {} - - void PIDWrite(double output) override {} }; diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/DriveSubsystem.h index 7aaac36654..47bf28e4d9 100644 --- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/DriveSubsystem.h @@ -5,9 +5,9 @@ #pragma once #include -#include -#include #include +#include +#include #include #include "Constants.h" @@ -76,10 +76,10 @@ class DriveSubsystem : public frc2::SubsystemBase { frc::PWMSparkMax m_right2; // The motors on the left side of the drive - frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2}; + frc::MotorControllerGroup m_leftMotors{m_left1, m_left2}; // The motors on the right side of the drive - frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2}; + frc::MotorControllerGroup m_rightMotors{m_right1, m_right2}; // The robot's drive frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors}; diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/ShooterSubsystem.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/ShooterSubsystem.h index c3ccdc8325..e53b32ddae 100644 --- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/ShooterSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/subsystems/ShooterSubsystem.h @@ -5,8 +5,8 @@ #pragma once #include -#include #include +#include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h index 4870705aba..3b65382c5c 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include /** diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h index 52a7153e23..f704df80ae 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h @@ -7,9 +7,9 @@ #include #include #include -#include -#include #include +#include +#include #include namespace frc { @@ -66,11 +66,11 @@ class DriveTrain : public frc2::SubsystemBase { private: frc::PWMSparkMax m_frontLeft{1}; frc::PWMSparkMax m_rearLeft{2}; - frc::SpeedControllerGroup m_left{m_frontLeft, m_rearLeft}; + frc::MotorControllerGroup m_left{m_frontLeft, m_rearLeft}; frc::PWMSparkMax m_frontRight{3}; frc::PWMSparkMax m_rearRight{4}; - frc::SpeedControllerGroup m_right{m_frontRight, m_rearRight}; + frc::MotorControllerGroup m_right{m_frontRight, m_rearRight}; frc::DifferentialDrive m_robotDrive{m_left, m_right}; diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h index 875a5f1a97..80008c5d0e 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include /** diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h index ef660a2a39..e873c2cccc 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include /** diff --git a/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp index 3f2d0c77fe..a46581379c 100644 --- a/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp @@ -3,11 +3,11 @@ // the WPILib BSD license file in the root directory of this project. #include -#include #include #include #include #include +#include class Robot : public frc::TimedRobot { public: @@ -50,7 +50,7 @@ class Robot : public frc::TimedRobot { frc::DifferentialDrive m_robotDrive{m_left, m_right}; frc::Joystick m_stick{0}; - frc::LiveWindow& m_lw = *frc::LiveWindow::GetInstance(); + frc::LiveWindow& m_lw = frc::LiveWindow::GetInstance(); frc::Timer m_timer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp index 4bfc3c1154..1dda356ff5 100644 --- a/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp @@ -6,9 +6,9 @@ #include #include -#include #include #include +#include /** * This is a sample program to demonstrate how to use a gyro sensor to make a diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/subsystems/DriveSubsystem.h index dc546db0cf..96174dd4f7 100644 --- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/subsystems/DriveSubsystem.h @@ -6,9 +6,9 @@ #include #include -#include -#include #include +#include +#include #include #include @@ -92,10 +92,10 @@ class DriveSubsystem : public frc2::SubsystemBase { frc::PWMSparkMax m_right2; // The motors on the left side of the drive - frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2}; + frc::MotorControllerGroup m_leftMotors{m_left1, m_left2}; // The motors on the right side of the drive - frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2}; + frc::MotorControllerGroup m_rightMotors{m_right1, m_right2}; // The robot's drive frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors}; diff --git a/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp index 0922ae4923..58858733f4 100644 --- a/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GyroMecanum/cpp/Robot.cpp @@ -4,9 +4,9 @@ #include #include -#include #include #include +#include /** * This is a sample program that uses mecanum drive with a gyro sensor to diff --git a/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c b/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c index 29de08fb7b..0db402bf76 100644 --- a/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c +++ b/wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c @@ -62,10 +62,11 @@ int main(void) { // Create a Motor Controller status = 0; - HAL_DigitalHandle pwmPort = HAL_InitializePWMPort(HAL_GetPort(2), &status); + HAL_DigitalHandle pwmPort = + HAL_InitializePWMPort(HAL_GetPort(2), NULL, &status); if (status != 0) { - const char* message = HAL_GetErrorMessage(status); + const char* message = HAL_GetLastError(&status); printf("%s\n", message); return 1; } @@ -75,10 +76,11 @@ int main(void) { // Create an Input status = 0; - HAL_DigitalHandle dio = HAL_InitializeDIOPort(HAL_GetPort(2), 1, &status); + HAL_DigitalHandle dio = + HAL_InitializeDIOPort(HAL_GetPort(2), 1, NULL, &status); if (status != 0) { - const char* message = HAL_GetErrorMessage(status); + const char* message = HAL_GetLastError(&status); printf("%s\n", message); status = 0; HAL_FreePWMPort(pwmPort, &status); diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.h index 7aaac36654..47bf28e4d9 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.h @@ -5,9 +5,9 @@ #pragma once #include -#include -#include #include +#include +#include #include #include "Constants.h" @@ -76,10 +76,10 @@ class DriveSubsystem : public frc2::SubsystemBase { frc::PWMSparkMax m_right2; // The motors on the left side of the drive - frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2}; + frc::MotorControllerGroup m_leftMotors{m_left1, m_left2}; // The motors on the right side of the drive - frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2}; + frc::MotorControllerGroup m_rightMotors{m_right1, m_right2}; // The robot's drive frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors}; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.h index 7aaac36654..47bf28e4d9 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.h @@ -5,9 +5,9 @@ #pragma once #include -#include -#include #include +#include +#include #include #include "Constants.h" @@ -76,10 +76,10 @@ class DriveSubsystem : public frc2::SubsystemBase { frc::PWMSparkMax m_right2; // The motors on the left side of the drive - frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2}; + frc::MotorControllerGroup m_leftMotors{m_left1, m_left2}; // The motors on the right side of the drive - frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2}; + frc::MotorControllerGroup m_rightMotors{m_right1, m_right2}; // The robot's drive frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors}; diff --git a/wpilibcExamples/src/main/cpp/examples/IntermediateVision/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/IntermediateVision/cpp/Robot.cpp index 923b4253cc..51778a304b 100644 --- a/wpilibcExamples/src/main/cpp/examples/IntermediateVision/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/IntermediateVision/cpp/Robot.cpp @@ -24,15 +24,15 @@ class Robot : public frc::TimedRobot { static void VisionThread() { // Get the USB camera from CameraServer cs::UsbCamera camera = - frc::CameraServer::GetInstance()->StartAutomaticCapture(); + frc::CameraServer::GetInstance().StartAutomaticCapture(); // Set the resolution camera.SetResolution(640, 480); // Get a CvSink. This will capture Mats from the Camera - cs::CvSink cvSink = frc::CameraServer::GetInstance()->GetVideo(); + cs::CvSink cvSink = frc::CameraServer::GetInstance().GetVideo(); // Setup a CvSource. This will send images back to the Dashboard cs::CvSource outputStream = - frc::CameraServer::GetInstance()->PutVideo("Rectangle", 640, 480); + frc::CameraServer::GetInstance().PutVideo("Rectangle", 640, 480); // Mats are very memory expensive. Lets reuse this Mat. cv::Mat mat; diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h index 62a14a0b12..1b097fe489 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.h @@ -6,13 +6,13 @@ #include #include -#include #include #include #include #include #include #include +#include #include /** diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp index 863034e0b1..e7822238f1 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp @@ -96,7 +96,7 @@ frc2::Command* RobotContainer::GetAutonomousCommand() { [this](units::volt_t frontLeft, units::volt_t rearLeft, units::volt_t frontRight, units::volt_t rearRight) { - m_drive.SetSpeedControllersVolts(frontLeft, rearLeft, frontRight, + m_drive.SetMotorControllersVolts(frontLeft, rearLeft, frontRight, rearRight); }, diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp index 8d357f429f..4cc4e47a1c 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/subsystems/DriveSubsystem.cpp @@ -56,7 +56,7 @@ void DriveSubsystem::Drive(double xSpeed, double ySpeed, double rot, } } -void DriveSubsystem::SetSpeedControllersVolts(units::volt_t frontLeftPower, +void DriveSubsystem::SetMotorControllersVolts(units::volt_t frontLeftPower, units::volt_t rearLeftPower, units::volt_t frontRightPower, units::volt_t rearRightPower) { diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h index a521219f4a..95b08b6937 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/include/subsystems/DriveSubsystem.h @@ -6,13 +6,13 @@ #include #include -#include #include #include #include #include #include #include +#include #include #include "Constants.h" @@ -82,9 +82,9 @@ class DriveSubsystem : public frc2::SubsystemBase { frc::MecanumDriveWheelSpeeds getCurrentWheelSpeeds(); /** - * Sets the drive SpeedControllers to a desired voltage. + * Sets the drive MotorControllers to a desired voltage. */ - void SetSpeedControllersVolts(units::volt_t frontLeftPower, + void SetMotorControllersVolts(units::volt_t frontLeftPower, units::volt_t rearLeftPower, units::volt_t frontRightPower, units::volt_t rearRightPower); diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp index f7c1be3517..822e9ee675 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp @@ -3,9 +3,9 @@ // the WPILib BSD license file in the root directory of this project. #include -#include #include #include +#include /** * This is a demo program showing how to use Mecanum control with the diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h index 5dca8277c9..ba796d5a0d 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.h @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #include /** diff --git a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp index 407d3e0799..7df57472e7 100644 --- a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp @@ -5,8 +5,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp index 0b8351b6da..0092ec3240 100644 --- a/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MotorControl/cpp/Robot.cpp @@ -3,8 +3,8 @@ // the WPILib BSD license file in the root directory of this project. #include -#include #include +#include /** * This sample program shows how to control a motor using a joystick. In the diff --git a/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp index 76ba76d655..5b76a62f80 100644 --- a/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MotorControlEncoder/cpp/Robot.cpp @@ -4,8 +4,8 @@ #include #include -#include #include +#include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/DriveTrain.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/DriveTrain.cpp index e39972384d..e9c878a3e6 100644 --- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/DriveTrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/DriveTrain.cpp @@ -24,10 +24,6 @@ DriveTrain::DriveTrain() : frc::Subsystem("DriveTrain") { m_leftCIMs.SetInverted(true); m_rightCIMs.SetInverted(true); - // Configure encoders - m_rightEncoder.SetPIDSourceType(frc::PIDSourceType::kDisplacement); - m_leftEncoder.SetPIDSourceType(frc::PIDSourceType::kDisplacement); - #ifndef SIMULATION // Converts to feet m_rightEncoder.SetDistancePerPulse(0.0785398); diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pivot.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pivot.cpp index c8cf025619..ba6f1a6d01 100644 --- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pivot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/subsystems/Pivot.cpp @@ -27,7 +27,7 @@ double Pivot::ReturnPIDInput() { } void Pivot::UsePIDOutput(double output) { - m_motor.PIDWrite(output); + m_motor.Set(output); } bool Pivot::IsAtUpperLimit() { diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Collector.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Collector.h index 77b0bb4695..9994a35bf7 100644 --- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Collector.h +++ b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Collector.h @@ -5,9 +5,9 @@ #pragma once #include -#include #include #include +#include /** * The Collector subsystem has one motor for the rollers, a limit switch for diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/DriveTrain.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/DriveTrain.h index 739f662136..65d29cd933 100644 --- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/DriveTrain.h +++ b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/DriveTrain.h @@ -6,10 +6,10 @@ #include #include -#include -#include #include #include +#include +#include namespace frc { class Joystick; @@ -62,11 +62,11 @@ class DriveTrain : public frc::Subsystem { // Subsystem devices frc::PWMSparkMax m_frontLeftCIM{1}; frc::PWMSparkMax m_rearLeftCIM{2}; - frc::SpeedControllerGroup m_leftCIMs{m_frontLeftCIM, m_rearLeftCIM}; + frc::MotorControllerGroup m_leftCIMs{m_frontLeftCIM, m_rearLeftCIM}; frc::PWMSparkMax m_frontRightCIM{3}; frc::PWMSparkMax m_rearRightCIM{4}; - frc::SpeedControllerGroup m_rightCIMs{m_frontRightCIM, m_rearRightCIM}; + frc::MotorControllerGroup m_rightCIMs{m_frontRightCIM, m_rearRightCIM}; frc::DifferentialDrive m_robotDrive{m_leftCIMs, m_rightCIMs}; diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pivot.h b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pivot.h index 23d342f1cf..95b3be9eca 100644 --- a/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pivot.h +++ b/wpilibcExamples/src/main/cpp/examples/PacGoat/include/subsystems/Pivot.h @@ -6,8 +6,8 @@ #include #include -#include #include +#include /** * The Pivot subsystem contains the Van-door motor and the pot for PID control diff --git a/wpilibcExamples/src/main/cpp/examples/PotentiometerPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/PotentiometerPID/cpp/Robot.cpp index 6149d40721..5b6b024ec1 100644 --- a/wpilibcExamples/src/main/cpp/examples/PotentiometerPID/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/PotentiometerPID/cpp/Robot.cpp @@ -6,9 +6,9 @@ #include #include -#include #include #include +#include /** * This is a sample program to demonstrate how to use a soft potentiometer and a diff --git a/wpilibcExamples/src/main/cpp/examples/QuickVision/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/QuickVision/cpp/Robot.cpp index b754deb277..d9f5071efc 100644 --- a/wpilibcExamples/src/main/cpp/examples/QuickVision/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/QuickVision/cpp/Robot.cpp @@ -16,7 +16,7 @@ class Robot : public frc::TimedRobot { public: void RobotInit() override { #if defined(__linux__) - frc::CameraServer::GetInstance()->StartAutomaticCapture(); + frc::CameraServer::GetInstance().StartAutomaticCapture(); #else wpi::errs() << "Vision only available on Linux.\n"; wpi::errs().flush(); diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/subsystems/DriveSubsystem.h index 28707ea61f..8ea14dad39 100644 --- a/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/RamseteCommand/include/subsystems/DriveSubsystem.h @@ -6,11 +6,11 @@ #include #include -#include -#include #include #include #include +#include +#include #include #include @@ -123,10 +123,10 @@ class DriveSubsystem : public frc2::SubsystemBase { frc::PWMSparkMax m_right2; // The motors on the left side of the drive - frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2}; + frc::MotorControllerGroup m_leftMotors{m_left1, m_left2}; // The motors on the right side of the drive - frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2}; + frc::MotorControllerGroup m_rightMotors{m_right1, m_right2}; // The robot's drive frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors}; diff --git a/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h index baa5a090ab..3cdbd1e4d2 100644 --- a/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/RamseteController/include/Drivetrain.h @@ -6,12 +6,12 @@ #include #include -#include -#include #include #include #include #include +#include +#include #include #include #include @@ -57,8 +57,8 @@ class Drivetrain { frc::PWMSparkMax m_rightLeader{3}; frc::PWMSparkMax m_rightFollower{4}; - frc::SpeedControllerGroup m_leftGroup{m_leftLeader, m_leftFollower}; - frc::SpeedControllerGroup m_rightGroup{m_rightLeader, m_rightFollower}; + frc::MotorControllerGroup m_leftGroup{m_leftLeader, m_leftFollower}; + frc::MotorControllerGroup m_rightGroup{m_rightLeader, m_rightFollower}; frc::Encoder m_leftEncoder{0, 1}; frc::Encoder m_rightEncoder{2, 3}; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h index 7bedcdee4b..98ae9574b0 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.h @@ -6,8 +6,8 @@ #include #include -#include #include +#include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp index ceb3470a1b..a114b927ae 100644 --- a/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp @@ -5,9 +5,9 @@ #include #include #include -#include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h index 48d758a7af..f60deefc3e 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h @@ -6,12 +6,12 @@ #include #include -#include -#include #include #include #include #include +#include +#include #include #include #include @@ -73,8 +73,8 @@ class Drivetrain { frc::PWMSparkMax m_rightLeader{3}; frc::PWMSparkMax m_rightFollower{4}; - frc::SpeedControllerGroup m_leftGroup{m_leftLeader, m_leftFollower}; - frc::SpeedControllerGroup m_rightGroup{m_rightLeader, m_rightFollower}; + frc::MotorControllerGroup m_leftGroup{m_leftLeader, m_leftFollower}; + frc::MotorControllerGroup m_rightGroup{m_rightLeader, m_rightFollower}; frc::Encoder m_leftEncoder{0, 1}; frc::Encoder m_rightEncoder{2, 3}; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp index 63fc0a6f37..5841f5fb15 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -12,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h index 9b7dadba41..395133c88c 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceDifferentialDriveSimulation/include/subsystems/DriveSubsystem.h @@ -6,11 +6,11 @@ #include #include -#include -#include #include #include #include +#include +#include #include #include #include @@ -134,10 +134,10 @@ class DriveSubsystem : public frc2::SubsystemBase { frc::PWMSparkMax m_right2{DriveConstants::kRightMotor2Port}; // The motors on the left side of the drive - frc::SpeedControllerGroup m_leftMotors{m_left1, m_left2}; + frc::MotorControllerGroup m_leftMotors{m_left1, m_left2}; // The motors on the right side of the drive - frc::SpeedControllerGroup m_rightMotors{m_right1, m_right2}; + frc::MotorControllerGroup m_rightMotors{m_right1, m_right2}; // The robot's drive frc::DifferentialDrive m_drive{m_leftMotors, m_rightMotors}; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp index 4d94321e7f..a0d9eaf717 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp @@ -4,13 +4,13 @@ #include #include -#include #include #include #include #include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp index bab52d939f..b52fc7ca7d 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp @@ -5,13 +5,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp index 1b7d9b76d5..26cebd646b 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -13,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h index 119137d5ef..3c3afa697a 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.h @@ -5,11 +5,11 @@ #pragma once #include -#include #include #include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h index c11f8e2b64..351aeb3ac7 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/DriveSubsystem.h @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #include #include "Constants.h" @@ -51,7 +51,7 @@ class DriveSubsystem : public frc2::SubsystemBase { void ResetEncoders(); /** - * Sets the drive SpeedControllers to a power from -1 to 1. + * Sets the drive MotorControllers to a power from -1 to 1. */ void SetModuleStates(wpi::array desiredStates); diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h index 7f3dba843b..304d8736c6 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/include/subsystems/SwerveModule.h @@ -5,11 +5,11 @@ #pragma once #include -#include #include #include #include #include +#include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h index 84182c09b1..0a33cb9dd4 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.h @@ -5,11 +5,11 @@ #pragma once #include -#include #include #include #include #include +#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp index 3fa97cf654..fffc78dd4b 100644 --- a/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/TankDriveXboxController/cpp/Robot.cpp @@ -3,10 +3,10 @@ // the WPILib BSD license file in the root directory of this project. #include -#include #include #include #include +#include /** * This is a demo program showing the use of the DifferentialDrive class. diff --git a/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp index 1cd070712e..482e5ffb10 100644 --- a/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp @@ -4,9 +4,9 @@ #include #include -#include #include #include +#include /** * This is a sample program demonstrating how to use an ultrasonic sensor and diff --git a/wpilibcExamples/src/main/cpp/examples/UltrasonicPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/UltrasonicPID/cpp/Robot.cpp index 08743128a0..4673975e71 100644 --- a/wpilibcExamples/src/main/cpp/examples/UltrasonicPID/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/UltrasonicPID/cpp/Robot.cpp @@ -4,10 +4,10 @@ #include #include -#include #include #include #include +#include /** * This is a sample program demonstrating how to use an ultrasonic sensor and diff --git a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp index 4650f7f039..f457e69a55 100644 --- a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp @@ -21,7 +21,7 @@ void Robot::Teleop() {} void Robot::Test() {} void Robot::StartCompetition() { - auto& lw = *frc::LiveWindow::GetInstance(); + auto& lw = frc::LiveWindow::GetInstance(); RobotInit(); diff --git a/wpilibcIntegrationTests/src/main/native/cpp/CounterTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/CounterTest.cpp index 6090a0bf27..23e9b2f90d 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/CounterTest.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/CounterTest.cpp @@ -5,10 +5,10 @@ #include "frc/Counter.h" // NOLINT(build/include_order) #include "TestBench.h" -#include "frc/Jaguar.h" -#include "frc/Talon.h" #include "frc/Timer.h" -#include "frc/Victor.h" +#include "frc/motorcontrol/Jaguar.h" +#include "frc/motorcontrol/Talon.h" +#include "frc/motorcontrol/Victor.h" #include "gtest/gtest.h" using namespace frc; diff --git a/wpilibcIntegrationTests/src/main/native/cpp/MotorEncoderTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/MotorEncoderTest.cpp index 1f84faad06..9737d78355 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/MotorEncoderTest.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/MotorEncoderTest.cpp @@ -6,13 +6,13 @@ #include "TestBench.h" #include "frc/Encoder.h" -#include "frc/Jaguar.h" #include "frc/LinearFilter.h" #include "frc/Notifier.h" -#include "frc/Talon.h" #include "frc/Timer.h" -#include "frc/Victor.h" #include "frc/controller/PIDController.h" +#include "frc/motorcontrol/Jaguar.h" +#include "frc/motorcontrol/Talon.h" +#include "frc/motorcontrol/Victor.h" #include "gtest/gtest.h" using namespace frc; @@ -38,31 +38,31 @@ std::ostream& operator<<(std::ostream& os, MotorEncoderTestType const& type) { static constexpr double kMotorTime = 0.5; /** - * A fixture that includes a PWM speed controller and an encoder connected to + * A fixture that includes a PWM motor controller and an encoder connected to * the same motor. */ class MotorEncoderTest : public testing::TestWithParam { protected: - SpeedController* m_speedController; + MotorController* m_motorController; Encoder* m_encoder; LinearFilter* m_filter; void SetUp() override { switch (GetParam()) { case TEST_VICTOR: - m_speedController = new Victor(TestBench::kVictorChannel); + m_motorController = new Victor(TestBench::kVictorChannel); m_encoder = new Encoder(TestBench::kVictorEncoderChannelA, TestBench::kVictorEncoderChannelB); break; case TEST_JAGUAR: - m_speedController = new Jaguar(TestBench::kJaguarChannel); + m_motorController = new Jaguar(TestBench::kJaguarChannel); m_encoder = new Encoder(TestBench::kJaguarEncoderChannelA, TestBench::kJaguarEncoderChannelB); break; case TEST_TALON: - m_speedController = new Talon(TestBench::kTalonChannel); + m_motorController = new Talon(TestBench::kTalonChannel); m_encoder = new Encoder(TestBench::kTalonEncoderChannelA, TestBench::kTalonEncoderChannelB); break; @@ -72,13 +72,13 @@ class MotorEncoderTest : public testing::TestWithParam { } void TearDown() override { - delete m_speedController; + delete m_motorController; delete m_encoder; delete m_filter; } void Reset() { - m_speedController->Set(0.0); + m_motorController->Set(0.0); m_encoder->Reset(); m_filter->Reset(); } @@ -90,10 +90,10 @@ class MotorEncoderTest : public testing::TestWithParam { TEST_P(MotorEncoderTest, Increment) { Reset(); - /* Drive the speed controller briefly to move the encoder */ - m_speedController->Set(0.2f); + /* Drive the motor controller briefly to move the encoder */ + m_motorController->Set(0.2f); Wait(kMotorTime); - m_speedController->Set(0.0); + m_motorController->Set(0.0); /* The encoder should be positive now */ EXPECT_GT(m_encoder->Get(), 0) @@ -106,10 +106,10 @@ TEST_P(MotorEncoderTest, Increment) { TEST_P(MotorEncoderTest, Decrement) { Reset(); - /* Drive the speed controller briefly to move the encoder */ - m_speedController->Set(-0.2); + /* Drive the motor controller briefly to move the encoder */ + m_motorController->Set(-0.2); Wait(kMotorTime); - m_speedController->Set(0.0); + m_motorController->Set(0.0); /* The encoder should be positive now */ EXPECT_LT(m_encoder->Get(), 0.0) @@ -122,15 +122,15 @@ TEST_P(MotorEncoderTest, Decrement) { TEST_P(MotorEncoderTest, ClampSpeed) { Reset(); - m_speedController->Set(2.0); + m_motorController->Set(2.0); Wait(kMotorTime); - EXPECT_FLOAT_EQ(1.0, m_speedController->Get()); + EXPECT_FLOAT_EQ(1.0, m_motorController->Get()); - m_speedController->Set(-2.0); + m_motorController->Set(-2.0); Wait(kMotorTime); - EXPECT_FLOAT_EQ(-1.0, m_speedController->Get()); + EXPECT_FLOAT_EQ(-1.0, m_motorController->Get()); } /** @@ -147,7 +147,7 @@ TEST_P(MotorEncoderTest, PositionPIDController) { /* 10 seconds should be plenty time to get to the reference */ frc::Notifier pidRunner{[this, &pidController] { auto speed = pidController.Calculate(m_encoder->GetDistance()); - m_speedController->Set(std::clamp(speed, -0.2, 0.2)); + m_motorController->Set(std::clamp(speed, -0.2, 0.2)); }}; pidRunner.StartPeriodic(pidController.GetPeriod()); Wait(10.0); @@ -174,7 +174,7 @@ TEST_P(MotorEncoderTest, VelocityPIDController) { frc::Notifier pidRunner{[this, &pidController] { auto speed = pidController.Calculate(m_filter->Calculate(m_encoder->GetRate())); - m_speedController->Set(std::clamp(speed, -0.3, 0.3)); + m_motorController->Set(std::clamp(speed, -0.3, 0.3)); }}; pidRunner.StartPeriodic(pidController.GetPeriod()); Wait(10.0); diff --git a/wpilibcIntegrationTests/src/main/native/cpp/MotorInvertingTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/MotorInvertingTest.cpp index c9abdb9bc7..72f658a440 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/MotorInvertingTest.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/MotorInvertingTest.cpp @@ -4,10 +4,10 @@ #include "TestBench.h" #include "frc/Encoder.h" -#include "frc/Jaguar.h" -#include "frc/Talon.h" #include "frc/Timer.h" -#include "frc/Victor.h" +#include "frc/motorcontrol/Jaguar.h" +#include "frc/motorcontrol/Talon.h" +#include "frc/motorcontrol/Victor.h" #include "gtest/gtest.h" using namespace frc; @@ -33,25 +33,25 @@ std::ostream& operator<<(std::ostream& os, MotorInvertingTestType const& type) { class MotorInvertingTest : public testing::TestWithParam { protected: - SpeedController* m_speedController; + MotorController* m_motorController; Encoder* m_encoder; void SetUp() override { switch (GetParam()) { case TEST_VICTOR: - m_speedController = new Victor(TestBench::kVictorChannel); + m_motorController = new Victor(TestBench::kVictorChannel); m_encoder = new Encoder(TestBench::kVictorEncoderChannelA, TestBench::kVictorEncoderChannelB); break; case TEST_JAGUAR: - m_speedController = new Jaguar(TestBench::kJaguarChannel); + m_motorController = new Jaguar(TestBench::kJaguarChannel); m_encoder = new Encoder(TestBench::kJaguarEncoderChannelA, TestBench::kJaguarEncoderChannelB); break; case TEST_TALON: - m_speedController = new Talon(TestBench::kTalonChannel); + m_motorController = new Talon(TestBench::kTalonChannel); m_encoder = new Encoder(TestBench::kTalonEncoderChannelA, TestBench::kTalonEncoderChannelB); break; @@ -59,13 +59,13 @@ class MotorInvertingTest } void TearDown() override { - delete m_speedController; + delete m_motorController; delete m_encoder; } void Reset() { - m_speedController->SetInverted(false); - m_speedController->Set(0.0); + m_motorController->SetInverted(false); + m_motorController->Set(0.0); m_encoder->Reset(); } }; @@ -73,13 +73,13 @@ class MotorInvertingTest TEST_P(MotorInvertingTest, InvertingPositive) { Reset(); - m_speedController->Set(motorSpeed); + m_motorController->Set(motorSpeed); Wait(delayTime); bool initDirection = m_encoder->GetDirection(); - m_speedController->SetInverted(true); - m_speedController->Set(motorSpeed); + m_motorController->SetInverted(true); + m_motorController->Set(motorSpeed); Wait(delayTime); @@ -92,14 +92,14 @@ TEST_P(MotorInvertingTest, InvertingPositive) { TEST_P(MotorInvertingTest, InvertingNegative) { Reset(); - m_speedController->SetInverted(false); - m_speedController->Set(-motorSpeed); + m_motorController->SetInverted(false); + m_motorController->Set(-motorSpeed); Wait(delayTime); bool initDirection = m_encoder->GetDirection(); - m_speedController->SetInverted(true); - m_speedController->Set(-motorSpeed); + m_motorController->SetInverted(true); + m_motorController->Set(-motorSpeed); Wait(delayTime); @@ -112,14 +112,14 @@ TEST_P(MotorInvertingTest, InvertingNegative) { TEST_P(MotorInvertingTest, InvertingSwitchingPosToNeg) { Reset(); - m_speedController->SetInverted(false); - m_speedController->Set(motorSpeed); + m_motorController->SetInverted(false); + m_motorController->Set(motorSpeed); Wait(delayTime); bool initDirection = m_encoder->GetDirection(); - m_speedController->SetInverted(true); - m_speedController->Set(-motorSpeed); + m_motorController->SetInverted(true); + m_motorController->Set(-motorSpeed); Wait(delayTime); @@ -132,14 +132,14 @@ TEST_P(MotorInvertingTest, InvertingSwitchingPosToNeg) { TEST_P(MotorInvertingTest, InvertingSwitchingNegToPos) { Reset(); - m_speedController->SetInverted(false); - m_speedController->Set(-motorSpeed); + m_motorController->SetInverted(false); + m_motorController->Set(-motorSpeed); Wait(delayTime); bool initDirection = m_encoder->GetDirection(); - m_speedController->SetInverted(true); - m_speedController->Set(motorSpeed); + m_motorController->SetInverted(true); + m_motorController->Set(motorSpeed); Wait(delayTime); diff --git a/wpilibcIntegrationTests/src/main/native/cpp/PowerDistributionPanelTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/PowerDistributionPanelTest.cpp index 349f0f5a16..f213d56d9c 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/PowerDistributionPanelTest.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/PowerDistributionPanelTest.cpp @@ -9,10 +9,10 @@ #include #include "TestBench.h" -#include "frc/Jaguar.h" -#include "frc/Talon.h" #include "frc/Timer.h" -#include "frc/Victor.h" +#include "frc/motorcontrol/Jaguar.h" +#include "frc/motorcontrol/Talon.h" +#include "frc/motorcontrol/Victor.h" #include "gtest/gtest.h" using namespace frc; @@ -47,10 +47,8 @@ TEST_F(PowerDistributionPanelTest, CheckRepeatedCalls) { for (int i = 0; i < 50; i++) { for (int j = 0; j < numChannels; j++) { m_pdp->GetCurrent(j); - ASSERT_TRUE(m_pdp->GetError().GetCode() == 0); } m_pdp->GetVoltage(); - ASSERT_TRUE(m_pdp->GetError().GetCode() == 0); } std::this_thread::sleep_for(std::chrono::milliseconds(20)); } diff --git a/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp b/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp index 4b5ab1ca65..ba134efe87 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/PreferencesTest.cpp @@ -44,14 +44,14 @@ TEST(PreferencesTest, ReadPreferencesFromFile) { preferencesFile.close(); inst.StartServer(); - Preferences* preferences = Preferences::GetInstance(); + Preferences& preferences = Preferences::GetInstance(); EXPECT_EQ("Hello, preferences file", - preferences->GetString("testFileGetString")); - EXPECT_EQ(1, preferences->GetInt("testFileGetInt")); - EXPECT_FLOAT_EQ(0.5, preferences->GetDouble("testFileGetDouble")); - EXPECT_FLOAT_EQ(0.25f, preferences->GetFloat("testFileGetFloat")); - EXPECT_TRUE(preferences->GetBoolean("testFileGetBoolean")); - EXPECT_EQ(1000000000000000000ll, preferences->GetLong("testFileGetLong")); + preferences.GetString("testFileGetString")); + EXPECT_EQ(1, preferences.GetInt("testFileGetInt")); + EXPECT_FLOAT_EQ(0.5, preferences.GetDouble("testFileGetDouble")); + EXPECT_FLOAT_EQ(0.25f, preferences.GetFloat("testFileGetFloat")); + EXPECT_TRUE(preferences.GetBoolean("testFileGetBoolean")); + EXPECT_EQ(1000000000000000000ll, preferences.GetLong("testFileGetLong")); } /** @@ -61,22 +61,22 @@ TEST(PreferencesTest, ReadPreferencesFromFile) { TEST(PreferencesTest, WritePreferencesToFile) { auto inst = nt::NetworkTableInstance::GetDefault(); inst.StartServer(); - Preferences* preferences = Preferences::GetInstance(); - preferences->Remove("testFileGetString"); - preferences->Remove("testFileGetInt"); - preferences->Remove("testFileGetDouble"); - preferences->Remove("testFileGetFloat"); - preferences->Remove("testFileGetBoolean"); - preferences->Remove("testFileGetLong"); + Preferences& preferences = Preferences::GetInstance(); + preferences.Remove("testFileGetString"); + preferences.Remove("testFileGetInt"); + preferences.Remove("testFileGetDouble"); + preferences.Remove("testFileGetFloat"); + preferences.Remove("testFileGetBoolean"); + preferences.Remove("testFileGetLong"); Wait(kSaveTime); - preferences->PutString("testFilePutString", "Hello, preferences file"); - preferences->PutInt("testFilePutInt", 1); - preferences->PutDouble("testFilePutDouble", 0.5); - preferences->PutFloat("testFilePutFloat", 0.25f); - preferences->PutBoolean("testFilePutBoolean", true); - preferences->PutLong("testFilePutLong", 1000000000000000000ll); + preferences.PutString("testFilePutString", "Hello, preferences file"); + preferences.PutInt("testFilePutInt", 1); + preferences.PutDouble("testFilePutDouble", 0.5); + preferences.PutFloat("testFilePutFloat", 0.25f); + preferences.PutBoolean("testFilePutBoolean", true); + preferences.PutLong("testFilePutLong", 1000000000000000000ll); Wait(kSaveTime); diff --git a/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp b/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp index 27d785ec1c..f848024d64 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp @@ -40,7 +40,7 @@ class TestEnvironment : public testing::Environment { station returns that the robot is enabled, to ensure that tests will be able to run on the hardware. */ HAL_ObserveUserProgramStarting(); - LiveWindow::GetInstance()->SetEnabled(false); + LiveWindow::GetInstance().SetEnabled(false); wpi::outs() << "Started coms\n"; diff --git a/wpilibcIntegrationTests/src/main/native/include/shuffleboard/MockActuatorSendable.h b/wpilibcIntegrationTests/src/main/native/include/shuffleboard/MockActuatorSendable.h index 76f7c7cf40..f59cc956bd 100644 --- a/wpilibcIntegrationTests/src/main/native/include/shuffleboard/MockActuatorSendable.h +++ b/wpilibcIntegrationTests/src/main/native/include/shuffleboard/MockActuatorSendable.h @@ -6,7 +6,7 @@ #include -#include "frc/smartdashboard/SendableBase.h" +#include "frc/smartdashboard/Sendable.h" #include "frc/smartdashboard/SendableBuilder.h" namespace frc { @@ -14,7 +14,7 @@ namespace frc { /** * A mock sendable that marks itself as an actuator. */ -class MockActuatorSendable : public SendableBase { +class MockActuatorSendable : public Sendable { public: explicit MockActuatorSendable(wpi::StringRef name); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java index a179f1f870..183960a60d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java @@ -9,6 +9,8 @@ import edu.wpi.first.hal.HAL; import edu.wpi.first.hal.SimBoolean; import edu.wpi.first.hal.SimDevice; import edu.wpi.first.hal.SimDouble; +import edu.wpi.first.wpilibj.interfaces.Gyro; +import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -24,7 +26,7 @@ import java.nio.ByteOrder; * an ADXRS Gyro is supported. */ @SuppressWarnings({"TypeName", "AbbreviationAsWordInName", "PMD.UnusedPrivateField"}) -public class ADXRS450_Gyro extends GyroBase { +public class ADXRS450_Gyro implements Gyro, Sendable { private static final double kSamplePeriod = 0.0005; private static final double kCalibrationSampleTime = 5.0; private static final double kDegreePerSecondPerLSB = 0.0125; @@ -206,4 +208,10 @@ public class ADXRS450_Gyro extends GyroBase { } return m_spi.getAccumulatorLastValue() * kDegreePerSecondPerLSB; } + + @Override + public void initSendable(SendableBuilder builder) { + builder.setSmartDashboardType("Gyro"); + builder.addDoubleProperty("Value", this::getAngle, null); + } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java index 960518cb63..b0395b859a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java @@ -16,12 +16,11 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; * through the sensor. Many sensors have multiple axis and can be treated as multiple devices. Each * is calibrated by finding the center value over a period of time. */ -public class AnalogAccelerometer implements PIDSource, Sendable, AutoCloseable { +public class AnalogAccelerometer implements Sendable, AutoCloseable { private AnalogInput m_analogChannel; private double m_voltsPerG = 1.0; private double m_zeroGVoltage = 2.5; private final boolean m_allocatedChannel; - protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement; /** Common initialization. */ private void initAccelerometer() { @@ -108,26 +107,6 @@ public class AnalogAccelerometer implements PIDSource, Sendable, AutoCloseable { m_zeroGVoltage = zero; } - @Override - public void setPIDSourceType(PIDSourceType pidSource) { - m_pidSource = pidSource; - } - - @Override - public PIDSourceType getPIDSourceType() { - return m_pidSource; - } - - /** - * Get the Acceleration for the PID Source parent. - * - * @return The current acceleration in Gs. - */ - @Override - public double pidGet() { - return getAcceleration(); - } - @Override public void initSendable(SendableBuilder builder) { builder.setSmartDashboardType("Accelerometer"); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java index 11958cbd2d..2b250d3bbc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java @@ -9,6 +9,8 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; import edu.wpi.first.hal.AnalogGyroJNI; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; +import edu.wpi.first.wpilibj.interfaces.Gyro; +import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; /** @@ -20,7 +22,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; * *

This class is for gyro sensors that connect to an analog input. */ -public class AnalogGyro extends GyroBase { +public class AnalogGyro implements Gyro, Sendable { private static final double kDefaultVoltsPerDegreePerSecond = 0.007; protected AnalogInput m_analog; private boolean m_channelAllocated; @@ -188,4 +190,10 @@ public class AnalogGyro extends GyroBase { public AnalogInput getAnalogInput() { return m_analog; } + + @Override + public void initSendable(SendableBuilder builder) { + builder.setSmartDashboardType("Gyro"); + builder.addDoubleProperty("Value", this::getAngle, null); + } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java index ccec9604c0..428801ead6 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java @@ -25,13 +25,12 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; * accumulated effectively increasing the resolution, while the averaged samples are divided by the * number of samples to retain the resolution, but get more stable values. */ -public class AnalogInput implements PIDSource, Sendable, AutoCloseable { +public class AnalogInput implements Sendable, AutoCloseable { private static final int kAccumulatorSlot = 1; int m_port; // explicit no modifier, private and package accessible. private int m_channel; private static final int[] kAccumulatorChannels = {0, 1}; private long m_accumulatorOffset; - protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement; /** * Construct an analog channel. @@ -322,26 +321,6 @@ public class AnalogInput implements PIDSource, Sendable, AutoCloseable { return AnalogJNI.getAnalogSampleRate(); } - @Override - public void setPIDSourceType(PIDSourceType pidSource) { - m_pidSource = pidSource; - } - - @Override - public PIDSourceType getPIDSourceType() { - return m_pidSource; - } - - /** - * Get the average voltage for use with PIDController. - * - * @return the average voltage - */ - @Override - public double pidGet() { - return getAverageVoltage(); - } - /** * Indicates this input is used by a simulated device. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java index 34ea6d1ac9..b752ddba05 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java @@ -4,7 +4,6 @@ package edu.wpi.first.wpilibj; -import edu.wpi.first.wpilibj.interfaces.Potentiometer; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; @@ -13,12 +12,11 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; * corresponds to a position. The position is in whichever units you choose, by way of the scaling * and offset constants passed to the constructor. */ -public class AnalogPotentiometer implements Potentiometer, Sendable, AutoCloseable { +public class AnalogPotentiometer implements Sendable, AutoCloseable { private AnalogInput m_analogInput; private boolean m_initAnalogInput; private double m_fullRange; private double m_offset; - protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement; /** * AnalogPotentiometer constructor. @@ -120,7 +118,6 @@ public class AnalogPotentiometer implements Potentiometer, Sendable, AutoCloseab * * @return The current position of the potentiometer. */ - @Override public double get() { if (m_analogInput == null) { return m_offset; @@ -129,29 +126,6 @@ public class AnalogPotentiometer implements Potentiometer, Sendable, AutoCloseab + m_offset; } - @Override - public void setPIDSourceType(PIDSourceType pidSource) { - if (!pidSource.equals(PIDSourceType.kDisplacement)) { - throw new IllegalArgumentException("Only displacement PID is allowed for potentiometers."); - } - m_pidSource = pidSource; - } - - @Override - public PIDSourceType getPIDSourceType() { - return m_pidSource; - } - - /** - * Implement the PIDSource interface. - * - * @return The current reading. - */ - @Override - public double pidGet() { - return get(); - } - @Override public void initSendable(SendableBuilder builder) { if (m_analogInput != null) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/CameraServer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/CameraServer.java deleted file mode 100644 index 890cc5a582..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/CameraServer.java +++ /dev/null @@ -1,814 +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 edu.wpi.first.wpilibj; - -import edu.wpi.cscore.AxisCamera; -import edu.wpi.cscore.CameraServerJNI; -import edu.wpi.cscore.CvSink; -import edu.wpi.cscore.CvSource; -import edu.wpi.cscore.MjpegServer; -import edu.wpi.cscore.UsbCamera; -import edu.wpi.cscore.VideoEvent; -import edu.wpi.cscore.VideoException; -import edu.wpi.cscore.VideoListener; -import edu.wpi.cscore.VideoMode; -import edu.wpi.cscore.VideoMode.PixelFormat; -import edu.wpi.cscore.VideoProperty; -import edu.wpi.cscore.VideoSink; -import edu.wpi.cscore.VideoSource; -import edu.wpi.first.cameraserver.CameraServerSharedStore; -import edu.wpi.first.networktables.EntryListenerFlags; -import edu.wpi.first.networktables.NetworkTable; -import edu.wpi.first.networktables.NetworkTableEntry; -import edu.wpi.first.networktables.NetworkTableInstance; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Hashtable; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Singleton class for creating and keeping camera servers. Also publishes camera information to - * NetworkTables. - * - * @deprecated Replaced with edu.wpi.first.cameraserver.CameraServer - */ -@Deprecated -public final class CameraServer { - public static final int kBasePort = 1181; - - @Deprecated public static final int kSize640x480 = 0; - @Deprecated public static final int kSize320x240 = 1; - @Deprecated public static final int kSize160x120 = 2; - - private static final String kPublishName = "/CameraPublisher"; - private static CameraServer server; - - /** Get the CameraServer instance. */ - public static synchronized CameraServer getInstance() { - if (server == null) { - server = new CameraServer(); - } - return server; - } - - private final AtomicInteger m_defaultUsbDevice; - private String m_primarySourceName; - private final Map m_sources; - private final Map m_sinks; - private final Map m_tables; // indexed by source handle - private final NetworkTable m_publishTable; - private final VideoListener m_videoListener; // NOPMD - private final int m_tableListener; // NOPMD - private int m_nextPort; - private String[] m_addresses; - - @SuppressWarnings("MissingJavadocMethod") - private static String makeSourceValue(int source) { - switch (VideoSource.getKindFromInt(CameraServerJNI.getSourceKind(source))) { - case kUsb: - return "usb:" + CameraServerJNI.getUsbCameraPath(source); - case kHttp: - { - String[] urls = CameraServerJNI.getHttpCameraUrls(source); - if (urls.length > 0) { - return "ip:" + urls[0]; - } else { - return "ip:"; - } - } - case kCv: - // FIXME: Should be "cv:", but LabVIEW dashboard requires "usb:". - // https://github.com/wpilibsuite/allwpilib/issues/407 - return "usb:"; - default: - return "unknown:"; - } - } - - @SuppressWarnings("MissingJavadocMethod") - private static String makeStreamValue(String address, int port) { - return "mjpg:http://" + address + ":" + port + "/?action=stream"; - } - - @SuppressWarnings({"MissingJavadocMethod", "PMD.AvoidUsingHardCodedIP"}) - private synchronized String[] getSinkStreamValues(int sink) { - // Ignore all but MjpegServer - if (VideoSink.getKindFromInt(CameraServerJNI.getSinkKind(sink)) != VideoSink.Kind.kMjpeg) { - return new String[0]; - } - - // Get port - int port = CameraServerJNI.getMjpegServerPort(sink); - - // Generate values - ArrayList values = new ArrayList<>(m_addresses.length + 1); - String listenAddress = CameraServerJNI.getMjpegServerListenAddress(sink); - if (!listenAddress.isEmpty()) { - // If a listen address is specified, only use that - values.add(makeStreamValue(listenAddress, port)); - } else { - // Otherwise generate for hostname and all interface addresses - values.add(makeStreamValue(CameraServerJNI.getHostname() + ".local", port)); - for (String addr : m_addresses) { - if ("127.0.0.1".equals(addr)) { - continue; // ignore localhost - } - values.add(makeStreamValue(addr, port)); - } - } - - return values.toArray(new String[0]); - } - - @SuppressWarnings({"MissingJavadocMethod", "PMD.AvoidUsingHardCodedIP"}) - private synchronized String[] getSourceStreamValues(int source) { - // Ignore all but HttpCamera - if (VideoSource.getKindFromInt(CameraServerJNI.getSourceKind(source)) - != VideoSource.Kind.kHttp) { - return new String[0]; - } - - // Generate values - String[] values = CameraServerJNI.getHttpCameraUrls(source); - for (int j = 0; j < values.length; j++) { - values[j] = "mjpg:" + values[j]; - } - - if (CameraServerSharedStore.getCameraServerShared().isRoboRIO()) { - // Look to see if we have a passthrough server for this source - // Only do this on the roboRIO - for (VideoSink i : m_sinks.values()) { - int sink = i.getHandle(); - int sinkSource = CameraServerJNI.getSinkSource(sink); - if (source == sinkSource - && VideoSink.getKindFromInt(CameraServerJNI.getSinkKind(sink)) - == VideoSink.Kind.kMjpeg) { - // Add USB-only passthrough - String[] finalValues = Arrays.copyOf(values, values.length + 1); - int port = CameraServerJNI.getMjpegServerPort(sink); - finalValues[values.length] = makeStreamValue("172.22.11.2", port); - return finalValues; - } - } - } - - return values; - } - - @SuppressWarnings({"MissingJavadocMethod", "PMD.AvoidUsingHardCodedIP"}) - private synchronized void updateStreamValues() { - // Over all the sinks... - for (VideoSink i : m_sinks.values()) { - int sink = i.getHandle(); - - // Get the source's subtable (if none exists, we're done) - int source = CameraServerJNI.getSinkSource(sink); - if (source == 0) { - continue; - } - NetworkTable table = m_tables.get(source); - if (table != null) { - // Don't set stream values if this is a HttpCamera passthrough - if (VideoSource.getKindFromInt(CameraServerJNI.getSourceKind(source)) - == VideoSource.Kind.kHttp) { - continue; - } - - // Set table value - String[] values = getSinkStreamValues(sink); - if (values.length > 0) { - table.getEntry("streams").setStringArray(values); - } - } - } - - // Over all the sources... - for (VideoSource i : m_sources.values()) { - int source = i.getHandle(); - - // Get the source's subtable (if none exists, we're done) - NetworkTable table = m_tables.get(source); - if (table != null) { - // Set table value - String[] values = getSourceStreamValues(source); - if (values.length > 0) { - table.getEntry("streams").setStringArray(values); - } - } - } - } - - @SuppressWarnings("MissingJavadocMethod") - private static String pixelFormatToString(PixelFormat pixelFormat) { - switch (pixelFormat) { - case kMJPEG: - return "MJPEG"; - case kYUYV: - return "YUYV"; - case kRGB565: - return "RGB565"; - case kBGR: - return "BGR"; - case kGray: - return "Gray"; - default: - return "Unknown"; - } - } - - /// Provide string description of video mode. - /// The returned string is "{width}x{height} {format} {fps} fps". - @SuppressWarnings("MissingJavadocMethod") - private static String videoModeToString(VideoMode mode) { - return mode.width - + "x" - + mode.height - + " " - + pixelFormatToString(mode.pixelFormat) - + " " - + mode.fps - + " fps"; - } - - @SuppressWarnings("MissingJavadocMethod") - private static String[] getSourceModeValues(int sourceHandle) { - VideoMode[] modes = CameraServerJNI.enumerateSourceVideoModes(sourceHandle); - String[] modeStrings = new String[modes.length]; - for (int i = 0; i < modes.length; i++) { - modeStrings[i] = videoModeToString(modes[i]); - } - return modeStrings; - } - - @SuppressWarnings({"MissingJavadocMethod", "PMD.CyclomaticComplexity"}) - private static void putSourcePropertyValue(NetworkTable table, VideoEvent event, boolean isNew) { - String name; - String infoName; - if (event.name.startsWith("raw_")) { - name = "RawProperty/" + event.name; - infoName = "RawPropertyInfo/" + event.name; - } else { - name = "Property/" + event.name; - infoName = "PropertyInfo/" + event.name; - } - - NetworkTableEntry entry = table.getEntry(name); - try { - switch (event.propertyKind) { - case kBoolean: - if (isNew) { - entry.setDefaultBoolean(event.value != 0); - } else { - entry.setBoolean(event.value != 0); - } - break; - case kInteger: - case kEnum: - if (isNew) { - entry.setDefaultDouble(event.value); - table - .getEntry(infoName + "/min") - .setDouble(CameraServerJNI.getPropertyMin(event.propertyHandle)); - table - .getEntry(infoName + "/max") - .setDouble(CameraServerJNI.getPropertyMax(event.propertyHandle)); - table - .getEntry(infoName + "/step") - .setDouble(CameraServerJNI.getPropertyStep(event.propertyHandle)); - table - .getEntry(infoName + "/default") - .setDouble(CameraServerJNI.getPropertyDefault(event.propertyHandle)); - } else { - entry.setDouble(event.value); - } - break; - case kString: - if (isNew) { - entry.setDefaultString(event.valueStr); - } else { - entry.setString(event.valueStr); - } - break; - default: - break; - } - } catch (VideoException ignored) { - // ignore - } - } - - @SuppressWarnings({ - "MissingJavadocMethod", - "PMD.UnusedLocalVariable", - "PMD.ExcessiveMethodLength", - "PMD.NPathComplexity" - }) - private CameraServer() { - m_defaultUsbDevice = new AtomicInteger(); - m_sources = new Hashtable<>(); - m_sinks = new Hashtable<>(); - m_tables = new Hashtable<>(); - m_publishTable = NetworkTableInstance.getDefault().getTable(kPublishName); - m_nextPort = kBasePort; - m_addresses = new String[0]; - - // We publish sources to NetworkTables using the following structure: - // "/CameraPublisher/{Source.Name}/" - root - // - "source" (string): Descriptive, prefixed with type (e.g. "usb:0") - // - "streams" (string array): URLs that can be used to stream data - // - "description" (string): Description of the source - // - "connected" (boolean): Whether source is connected - // - "mode" (string): Current video mode - // - "modes" (string array): Available video modes - // - "Property/{Property}" - Property values - // - "PropertyInfo/{Property}" - Property supporting information - - // Listener for video events - m_videoListener = - new VideoListener( - event -> { - switch (event.kind) { - case kSourceCreated: - { - // Create subtable for the camera - NetworkTable table = m_publishTable.getSubTable(event.name); - m_tables.put(event.sourceHandle, table); - table.getEntry("source").setString(makeSourceValue(event.sourceHandle)); - table - .getEntry("description") - .setString(CameraServerJNI.getSourceDescription(event.sourceHandle)); - table - .getEntry("connected") - .setBoolean(CameraServerJNI.isSourceConnected(event.sourceHandle)); - table - .getEntry("streams") - .setStringArray(getSourceStreamValues(event.sourceHandle)); - try { - VideoMode mode = CameraServerJNI.getSourceVideoMode(event.sourceHandle); - table.getEntry("mode").setDefaultString(videoModeToString(mode)); - table - .getEntry("modes") - .setStringArray(getSourceModeValues(event.sourceHandle)); - } catch (VideoException ignored) { - // Do nothing. Let the other event handlers update this if there is an error. - } - break; - } - case kSourceDestroyed: - { - NetworkTable table = m_tables.get(event.sourceHandle); - if (table != null) { - table.getEntry("source").setString(""); - table.getEntry("streams").setStringArray(new String[0]); - table.getEntry("modes").setStringArray(new String[0]); - } - break; - } - case kSourceConnected: - { - NetworkTable table = m_tables.get(event.sourceHandle); - if (table != null) { - // update the description too (as it may have changed) - table - .getEntry("description") - .setString(CameraServerJNI.getSourceDescription(event.sourceHandle)); - table.getEntry("connected").setBoolean(true); - } - break; - } - case kSourceDisconnected: - { - NetworkTable table = m_tables.get(event.sourceHandle); - if (table != null) { - table.getEntry("connected").setBoolean(false); - } - break; - } - case kSourceVideoModesUpdated: - { - NetworkTable table = m_tables.get(event.sourceHandle); - if (table != null) { - table - .getEntry("modes") - .setStringArray(getSourceModeValues(event.sourceHandle)); - } - break; - } - case kSourceVideoModeChanged: - { - NetworkTable table = m_tables.get(event.sourceHandle); - if (table != null) { - table.getEntry("mode").setString(videoModeToString(event.mode)); - } - break; - } - case kSourcePropertyCreated: - { - NetworkTable table = m_tables.get(event.sourceHandle); - if (table != null) { - putSourcePropertyValue(table, event, true); - } - break; - } - case kSourcePropertyValueUpdated: - { - NetworkTable table = m_tables.get(event.sourceHandle); - if (table != null) { - putSourcePropertyValue(table, event, false); - } - break; - } - case kSourcePropertyChoicesUpdated: - { - NetworkTable table = m_tables.get(event.sourceHandle); - if (table != null) { - try { - String[] choices = - CameraServerJNI.getEnumPropertyChoices(event.propertyHandle); - table - .getEntry("PropertyInfo/" + event.name + "/choices") - .setStringArray(choices); - } catch (VideoException ignored) { - // ignore - } - } - break; - } - case kSinkSourceChanged: - case kSinkCreated: - case kSinkDestroyed: - case kNetworkInterfacesChanged: - { - m_addresses = CameraServerJNI.getNetworkInterfaces(); - updateStreamValues(); - break; - } - default: - break; - } - }, - 0x4fff, - true); - - // Listener for NetworkTable events - // We don't currently support changing settings via NT due to - // synchronization issues, so just update to current setting if someone - // else tries to change it. - m_tableListener = - NetworkTableInstance.getDefault() - .addEntryListener( - kPublishName + "/", - event -> { - String relativeKey = event.name.substring(kPublishName.length() + 1); - - // get source (sourceName/...) - int subKeyIndex = relativeKey.indexOf('/'); - if (subKeyIndex == -1) { - return; - } - String sourceName = relativeKey.substring(0, subKeyIndex); - VideoSource source = m_sources.get(sourceName); - if (source == null) { - return; - } - - // get subkey - relativeKey = relativeKey.substring(subKeyIndex + 1); - - // handle standard names - String propName; - if ("mode".equals(relativeKey)) { - // reset to current mode - event.getEntry().setString(videoModeToString(source.getVideoMode())); - return; - } else if (relativeKey.startsWith("Property/")) { - propName = relativeKey.substring(9); - } else if (relativeKey.startsWith("RawProperty/")) { - propName = relativeKey.substring(12); - } else { - return; // ignore - } - - // everything else is a property - VideoProperty property = source.getProperty(propName); - switch (property.getKind()) { - case kNone: - return; - case kBoolean: - // reset to current setting - event.getEntry().setBoolean(property.get() != 0); - return; - case kInteger: - case kEnum: - // reset to current setting - event.getEntry().setDouble(property.get()); - return; - case kString: - // reset to current setting - event.getEntry().setString(property.getString()); - return; - default: - return; - } - }, - EntryListenerFlags.kImmediate | EntryListenerFlags.kUpdate); - } - - /** - * Start automatically capturing images to send to the dashboard. - * - *

You should call this method to see a camera feed on the dashboard. If you also want to - * perform vision processing on the roboRIO, use getVideo() to get access to the camera images. - * - *

The first time this overload is called, it calls {@link #startAutomaticCapture(int)} with - * device 0, creating a camera named "USB Camera 0". Subsequent calls increment the device number - * (e.g. 1, 2, etc). - */ - public UsbCamera startAutomaticCapture() { - UsbCamera camera = startAutomaticCapture(m_defaultUsbDevice.getAndIncrement()); - CameraServerSharedStore.getCameraServerShared().reportUsbCamera(camera.getHandle()); - return camera; - } - - /** - * Start automatically capturing images to send to the dashboard. - * - *

This overload calls {@link #startAutomaticCapture(String, int)} with a name of "USB Camera - * {dev}". - * - * @param dev The device number of the camera interface - */ - public UsbCamera startAutomaticCapture(int dev) { - UsbCamera camera = new UsbCamera("USB Camera " + dev, dev); - startAutomaticCapture(camera); - CameraServerSharedStore.getCameraServerShared().reportUsbCamera(camera.getHandle()); - return camera; - } - - /** - * Start automatically capturing images to send to the dashboard. - * - * @param name The name to give the camera - * @param dev The device number of the camera interface - */ - public UsbCamera startAutomaticCapture(String name, int dev) { - UsbCamera camera = new UsbCamera(name, dev); - startAutomaticCapture(camera); - CameraServerSharedStore.getCameraServerShared().reportUsbCamera(camera.getHandle()); - return camera; - } - - /** - * Start automatically capturing images to send to the dashboard. - * - * @param name The name to give the camera - * @param path The device path (e.g. "/dev/video0") of the camera - */ - public UsbCamera startAutomaticCapture(String name, String path) { - UsbCamera camera = new UsbCamera(name, path); - startAutomaticCapture(camera); - CameraServerSharedStore.getCameraServerShared().reportUsbCamera(camera.getHandle()); - return camera; - } - - /** - * Start automatically capturing images to send to the dashboard from an existing camera. - * - * @param camera Camera - */ - public void startAutomaticCapture(VideoSource camera) { - addCamera(camera); - VideoSink server = addServer("serve_" + camera.getName()); - server.setSource(camera); - } - - /** - * Adds an Axis IP camera. - * - *

This overload calls {@link #addAxisCamera(String, String)} with name "Axis Camera". - * - * @param host Camera host IP or DNS name (e.g. "10.x.y.11") - */ - public AxisCamera addAxisCamera(String host) { - return addAxisCamera("Axis Camera", host); - } - - /** - * Adds an Axis IP camera. - * - *

This overload calls {@link #addAxisCamera(String, String[])} with name "Axis Camera". - * - * @param hosts Array of Camera host IPs/DNS names - */ - public AxisCamera addAxisCamera(String[] hosts) { - return addAxisCamera("Axis Camera", hosts); - } - - /** - * Adds an Axis IP camera. - * - * @param name The name to give the camera - * @param host Camera host IP or DNS name (e.g. "10.x.y.11") - */ - public AxisCamera addAxisCamera(String name, String host) { - AxisCamera camera = new AxisCamera(name, host); - // Create a passthrough MJPEG server for USB access - startAutomaticCapture(camera); - CameraServerSharedStore.getCameraServerShared().reportAxisCamera(camera.getHandle()); - return camera; - } - - /** - * Adds an Axis IP camera. - * - * @param name The name to give the camera - * @param hosts Array of Camera host IPs/DNS names - */ - public AxisCamera addAxisCamera(String name, String[] hosts) { - AxisCamera camera = new AxisCamera(name, hosts); - // Create a passthrough MJPEG server for USB access - startAutomaticCapture(camera); - CameraServerSharedStore.getCameraServerShared().reportAxisCamera(camera.getHandle()); - return camera; - } - - /** - * Get OpenCV access to the primary camera feed. This allows you to get images from the camera for - * image processing on the roboRIO. - * - *

This is only valid to call after a camera feed has been added with startAutomaticCapture() - * or addServer(). - */ - public CvSink getVideo() { - VideoSource source; - synchronized (this) { - if (m_primarySourceName == null) { - throw new VideoException("no camera available"); - } - source = m_sources.get(m_primarySourceName); - } - if (source == null) { - throw new VideoException("no camera available"); - } - return getVideo(source); - } - - /** - * Get OpenCV access to the specified camera. This allows you to get images from the camera for - * image processing on the roboRIO. - * - * @param camera Camera (e.g. as returned by startAutomaticCapture). - */ - public CvSink getVideo(VideoSource camera) { - String name = "opencv_" + camera.getName(); - - synchronized (this) { - VideoSink sink = m_sinks.get(name); - if (sink != null) { - VideoSink.Kind kind = sink.getKind(); - if (kind != VideoSink.Kind.kCv) { - throw new VideoException("expected OpenCV sink, but got " + kind); - } - return (CvSink) sink; - } - } - - CvSink newsink = new CvSink(name); - newsink.setSource(camera); - addServer(newsink); - return newsink; - } - - /** - * Get OpenCV access to the specified camera. This allows you to get images from the camera for - * image processing on the roboRIO. - * - * @param name Camera name - */ - public CvSink getVideo(String name) { - VideoSource source; - synchronized (this) { - source = m_sources.get(name); - if (source == null) { - throw new VideoException("could not find camera " + name); - } - } - return getVideo(source); - } - - /** - * Create a MJPEG stream with OpenCV input. This can be called to pass custom annotated images to - * the dashboard. - * - * @param name Name to give the stream - * @param width Width of the image being sent - * @param height Height of the image being sent - */ - public CvSource putVideo(String name, int width, int height) { - CvSource source = new CvSource(name, VideoMode.PixelFormat.kMJPEG, width, height, 30); - startAutomaticCapture(source); - return source; - } - - /** - * Adds a MJPEG server at the next available port. - * - * @param name Server name - */ - public MjpegServer addServer(String name) { - int port; - synchronized (this) { - port = m_nextPort; - m_nextPort++; - } - return addServer(name, port); - } - - /** - * Adds a MJPEG server. - * - * @param name Server name - */ - public MjpegServer addServer(String name, int port) { - MjpegServer server = new MjpegServer(name, port); - addServer(server); - return server; - } - - /** - * Adds an already created server. - * - * @param server Server - */ - public void addServer(VideoSink server) { - synchronized (this) { - m_sinks.put(server.getName(), server); - } - } - - /** - * Removes a server by name. - * - * @param name Server name - */ - public void removeServer(String name) { - synchronized (this) { - m_sinks.remove(name); - } - } - - /** - * Get server for the primary camera feed. - * - *

This is only valid to call after a camera feed has been added with startAutomaticCapture() - * or addServer(). - */ - public VideoSink getServer() { - synchronized (this) { - if (m_primarySourceName == null) { - throw new VideoException("no camera available"); - } - return getServer("serve_" + m_primarySourceName); - } - } - - /** - * Gets a server by name. - * - * @param name Server name - */ - public VideoSink getServer(String name) { - synchronized (this) { - return m_sinks.get(name); - } - } - - /** - * Adds an already created camera. - * - * @param camera Camera - */ - public void addCamera(VideoSource camera) { - String name = camera.getName(); - synchronized (this) { - if (m_primarySourceName == null) { - m_primarySourceName = name; - } - m_sources.put(name, camera); - } - } - - /** - * Removes a camera by name. - * - * @param name Camera name - */ - public void removeCamera(String name) { - synchronized (this) { - m_sources.remove(name); - } - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Counter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Counter.java index 7cc082192f..5ed499497a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Counter.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Counter.java @@ -26,7 +26,7 @@ import java.nio.ByteOrder; *

All counters will immediately start counting - reset() them if you need them to be zeroed * before use. */ -public class Counter implements CounterBase, PIDSource, Sendable, AutoCloseable { +public class Counter implements CounterBase, Sendable, AutoCloseable { /** Mode determines how and what the counter counts. */ public enum Mode { /** mode: two pulse. */ @@ -51,7 +51,6 @@ public class Counter implements CounterBase, PIDSource, Sendable, AutoCloseable private boolean m_allocatedDownSource; private int m_counter; // /< The FPGA counter object. private int m_index; // /< The index of this counter. - private PIDSourceType m_pidSource; private double m_distancePerPulse; // distance of travel for each tick /** Create an instance of a counter with the given mode. */ @@ -507,39 +506,6 @@ public class Counter implements CounterBase, PIDSource, Sendable, AutoCloseable m_distancePerPulse = distancePerPulse; } - /** - * Set which parameter of the encoder you are using as a process control variable. The counter - * class supports the rate and distance parameters. - * - * @param pidSource An enum to select the parameter. - */ - @Override - public void setPIDSourceType(PIDSourceType pidSource) { - requireNonNullParam(pidSource, "pidSource", "setPIDSourceType"); - if (pidSource != PIDSourceType.kDisplacement && pidSource != PIDSourceType.kRate) { - throw new IllegalArgumentException("PID Source parameter was not valid type: " + pidSource); - } - - m_pidSource = pidSource; - } - - @Override - public PIDSourceType getPIDSourceType() { - return m_pidSource; - } - - @Override - public double pidGet() { - switch (m_pidSource) { - case kDisplacement: - return getDistance(); - case kRate: - return getRate(); - default: - return 0.0; - } - } - @Override public void initSendable(SendableBuilder builder) { builder.setSmartDashboardType("Counter"); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java index 019eaa5d93..2c9a204590 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Encoder.java @@ -27,7 +27,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

All encoders will immediately start counting - reset() them if you need them to be zeroed * before use. */ -public class Encoder implements CounterBase, PIDSource, Sendable, AutoCloseable { +public class Encoder implements CounterBase, Sendable, AutoCloseable { public enum IndexingType { kResetWhileHigh(0), kResetWhileLow(1), @@ -51,7 +51,6 @@ public class Encoder implements CounterBase, PIDSource, Sendable, AutoCloseable private boolean m_allocatedA; private boolean m_allocatedB; private boolean m_allocatedI; - private PIDSourceType m_pidSource; private int m_encoder; // the HAL encoder object @@ -73,8 +72,6 @@ public class Encoder implements CounterBase, PIDSource, Sendable, AutoCloseable reverseDirection, type.value); - m_pidSource = PIDSourceType.kDisplacement; - int fpgaIndex = getFPGAIndex(); HAL.report(tResourceType.kResourceType_Encoder, fpgaIndex + 1, type.value + 1); SendableRegistry.addLW(this, "Encoder", fpgaIndex); @@ -481,39 +478,6 @@ public class Encoder implements CounterBase, PIDSource, Sendable, AutoCloseable return EncoderJNI.getEncoderSamplesToAverage(m_encoder); } - /** - * Set which parameter of the encoder you are using as a process control variable. The encoder - * class supports the rate and distance parameters. - * - * @param pidSource An enum to select the parameter. - */ - @Override - public void setPIDSourceType(PIDSourceType pidSource) { - m_pidSource = pidSource; - } - - @Override - public PIDSourceType getPIDSourceType() { - return m_pidSource; - } - - /** - * Implement the PIDSource interface. - * - * @return The current value of the selected source parameter. - */ - @Override - public double pidGet() { - switch (m_pidSource) { - case kDisplacement: - return getDistance(); - case kRate: - return getRate(); - default: - return 0.0; - } - } - /** * Set the index source for the encoder. When this source is activated, the encoder count * automatically resets. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/GearTooth.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/GearTooth.java deleted file mode 100644 index 15a999c4b0..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/GearTooth.java +++ /dev/null @@ -1,97 +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 edu.wpi.first.wpilibj; - -import edu.wpi.first.hal.FRCNetComm.tResourceType; -import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; - -/** - * Alias for counter class. Implement the gear tooth sensor supplied by FIRST. Currently there is no - * reverse sensing on the gear tooth sensor, but in future versions we might implement the necessary - * timing in the FPGA to sense direction. - * - * @deprecated The only sensor this works with is no longer available and no teams use it according - * to FMS usage reporting. - */ -@Deprecated(since = "2020", forRemoval = true) -public class GearTooth extends Counter { - private static final double kGearToothThreshold = 55e-6; - - /** Common code called by the constructors. */ - public void enableDirectionSensing(boolean directionSensitive) { - if (directionSensitive) { - setPulseLengthMode(kGearToothThreshold); - } - } - - /** - * Construct a GearTooth sensor given a channel. - * - *

No direction sensing is assumed. - * - * @param channel The GPIO channel that the sensor is connected to. - */ - public GearTooth(final int channel) { - this(channel, false); - } - - /** - * Construct a GearTooth sensor given a channel. - * - * @param channel The DIO channel that the sensor is connected to. 0-9 are on-board, 10-25 are on - * the MXP port - * @param directionSensitive True to enable the pulse length decoding in hardware to specify count - * direction. - */ - public GearTooth(final int channel, boolean directionSensitive) { - super(channel); - enableDirectionSensing(directionSensitive); - if (directionSensitive) { - HAL.report(tResourceType.kResourceType_GearTooth, channel + 1, 0, "D"); - } else { - HAL.report(tResourceType.kResourceType_GearTooth, channel + 1, 0); - } - SendableRegistry.setName(this, "GearTooth", channel); - } - - /** - * Construct a GearTooth sensor given a digital input. This should be used when sharing digital - * inputs. - * - * @param source An existing DigitalSource object (such as a DigitalInput) - * @param directionSensitive True to enable the pulse length decoding in hardware to specify count - * direction. - */ - public GearTooth(DigitalSource source, boolean directionSensitive) { - super(source); - enableDirectionSensing(directionSensitive); - if (directionSensitive) { - HAL.report(tResourceType.kResourceType_GearTooth, source.getChannel() + 1, 0, "D"); - } else { - HAL.report(tResourceType.kResourceType_GearTooth, source.getChannel() + 1, 0); - } - SendableRegistry.setName(this, "GearTooth", source.getChannel()); - } - - /** - * Construct a GearTooth sensor given a digital input. This should be used when sharing digital - * inputs. - * - *

No direction sensing is assumed. - * - * @param source An object that fully describes the input that the sensor is connected to. - */ - public GearTooth(DigitalSource source) { - this(source, false); - } - - @Override - public void initSendable(SendableBuilder builder) { - super.initSendable(builder); - builder.setSmartDashboardType("Gear Tooth"); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/GyroBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/GyroBase.java deleted file mode 100644 index 4b180d5c92..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/GyroBase.java +++ /dev/null @@ -1,53 +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 edu.wpi.first.wpilibj; - -import edu.wpi.first.wpilibj.interfaces.Gyro; -import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; - -/** GyroBase is the common base class for Gyro implementations such as AnalogGyro. */ -public abstract class GyroBase implements Gyro, PIDSource, Sendable { - private PIDSourceType m_pidSource = PIDSourceType.kDisplacement; - - /** - * Set which parameter of the gyro you are using as a process control variable. The Gyro class - * supports the rate and displacement parameters - * - * @param pidSource An enum to select the parameter. - */ - @Override - public void setPIDSourceType(PIDSourceType pidSource) { - m_pidSource = pidSource; - } - - @Override - public PIDSourceType getPIDSourceType() { - return m_pidSource; - } - - /** - * Get the output of the gyro for use with PIDControllers. May be the angle or rate depending on - * the set PIDSourceType - * - * @return the output according to the gyro - */ - @Override - public double pidGet() { - switch (m_pidSource) { - case kRate: - return getRate(); - case kDisplacement: - return getAngle(); - default: - return 0.0; - } - } - - @Override - public void initSendable(SendableBuilder builder) { - builder.setSmartDashboardType("Gyro"); - builder.addDoubleProperty("Value", this::getAngle, null); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java deleted file mode 100644 index ba3cb2c40a..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ /dev/null @@ -1,64 +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 edu.wpi.first.wpilibj; - -import edu.wpi.first.hal.FRCNetComm.tInstances; -import edu.wpi.first.hal.FRCNetComm.tResourceType; -import edu.wpi.first.hal.HAL; - -/** - * IterativeRobot implements the IterativeRobotBase robot program framework. - * - *

The IterativeRobot class is intended to be subclassed by a user creating a robot program. - * - *

periodic() functions from the base class are called each time a new packet is received from - * the driver station. - * - * @deprecated Use TimedRobot instead. It's a drop-in replacement that provides more regular - * execution periods. - */ -@Deprecated -public class IterativeRobot extends IterativeRobotBase { - private static final double kPacketPeriod = 0.02; - private volatile boolean m_exit; - - /** Create a new IterativeRobot. */ - public IterativeRobot() { - super(kPacketPeriod); - - HAL.report(tResourceType.kResourceType_Framework, tInstances.kFramework_Iterative); - } - - /** Provide an alternate "main loop" via startCompetition(). */ - @Override - public void startCompetition() { - robotInit(); - - if (isSimulation()) { - simulationInit(); - } - - // Tell the DS that the robot is ready to be enabled - HAL.observeUserProgramStarting(); - - // Loop forever, calling the appropriate mode-dependent function - while (!Thread.currentThread().isInterrupted()) { - // Wait for new data to arrive - m_ds.waitForData(); - if (m_exit) { - break; - } - - loopFunc(); - } - } - - /** Ends the main loop in startCompetition(). */ - @Override - public void endCompetition() { - m_exit = true; - m_ds.wakeupWaitForData(); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java index 1fc3d964a2..ca15194632 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java @@ -32,8 +32,6 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; * disabledPeriodic() - autonomousPeriodic() - teleopPeriodic() - testPeriodic() */ public abstract class IterativeRobotBase extends RobotBase { - protected double m_period; - private enum Mode { kNone, kDisabled, @@ -43,6 +41,7 @@ public abstract class IterativeRobotBase extends RobotBase { } private Mode m_lastMode = Mode.kNone; + private final double m_period; private final Watchdog m_watchdog; private boolean m_ntFlushEnabled; @@ -204,6 +203,11 @@ public abstract class IterativeRobotBase extends RobotBase { m_ntFlushEnabled = enabled; } + /** Gets time period between calls to Periodic() functions. */ + public double getPeriod() { + return m_period; + } + @SuppressWarnings("PMD.CyclomaticComplexity") protected void loopFunc() { m_watchdog.reset(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java index ddfb39ec9a..df1db7ded4 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWM.java @@ -23,7 +23,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; * center value - 999 to 2 = linear scaling from "center" to "full reverse" - 1 = minimum pulse * width (currently .5ms) - 0 = disabled (i.e. PWM output is held low) */ -public class PWM extends MotorSafety implements Sendable, AutoCloseable { +public class PWM implements Sendable, AutoCloseable { /** Represents the amount to multiply the minimum servo-pulse pwm period by. */ public enum PeriodMultiplier { /** Period Multiplier: don't skip pulses. PWM pulses occur every 5.005 ms */ @@ -42,9 +42,24 @@ public class PWM extends MotorSafety implements Sendable, AutoCloseable { /** * Allocate a PWM given a channel. * + *

Checks channel value range and allocates the appropriate channel. The allocation is only + * done to help users ensure that they don't double assign channels. + * + *

By default, adds itself to SendableRegistry and LiveWindow. + * * @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port */ public PWM(final int channel) { + this(channel, true); + } + + /** + * Allocate a PWM given a channel. + * + * @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port + * @param registerSendable If true, adds this instance to SendableRegistry and LiveWindow + */ + public PWM(final int channel, final boolean registerSendable) { SensorUtil.checkPWMChannel(channel); m_channel = channel; @@ -55,9 +70,9 @@ public class PWM extends MotorSafety implements Sendable, AutoCloseable { PWMJNI.setPWMEliminateDeadband(m_handle, false); HAL.report(tResourceType.kResourceType_PWM, channel + 1); - SendableRegistry.addLW(this, "PWM", channel); - - setSafetyEnabled(false); + if (registerSendable) { + SendableRegistry.addLW(this, "PWM", channel); + } } /** Free the resource associated with the PWM channel and set the value to 0. */ @@ -72,16 +87,6 @@ public class PWM extends MotorSafety implements Sendable, AutoCloseable { m_handle = 0; } - @Override - public void stopMotor() { - setDisabled(); - } - - @Override - public String getDescription() { - return "PWM " + getChannel(); - } - /** * Optionally eliminate the deadband from a speed controller. * @@ -234,7 +239,7 @@ public class PWM extends MotorSafety implements Sendable, AutoCloseable { } } - protected void setZeroLatch() { + public void setZeroLatch() { PWMJNI.latchPWMZero(m_handle); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java index 018b0b24fd..43a8b02ac3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java @@ -75,14 +75,27 @@ public final class Preferences { * @param value the value * @throws NullPointerException if value is null */ - public void putString(String key, String value) { - requireNonNullParam(value, "value", "putString"); + public void setString(String key, String value) { + requireNonNullParam(value, "value", "setString"); NetworkTableEntry entry = m_table.getEntry(key); entry.setString(value); entry.setPersistent(); } + /** + * Puts the given string into the preferences table. + * + * @param key the key + * @param value the value + * @throws NullPointerException if value is null + * @deprecated Use {@link #setString(String, String)} + */ + @Deprecated + public void putString(String key, String value) { + setString(key, value); + } + /** * Puts the given string into the preferences table if it doesn't already exist. * @@ -100,12 +113,24 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putInt(String key, int value) { + public void setInt(String key, int value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setDouble(value); entry.setPersistent(); } + /** + * Puts the given int into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setInt(String, int)} + */ + @Deprecated + public void putInt(String key, int value) { + setInt(key, value); + } + /** * Puts the given int into the preferences table if it doesn't already exist. * @@ -123,12 +148,23 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putDouble(String key, double value) { + public void setDouble(String key, double value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setDouble(value); entry.setPersistent(); } + /** + * Puts the given double into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setDouble(String, double)} + */ + public void putDouble(String key, double value) { + setDouble(key, value); + } + /** * Puts the given double into the preferences table if it doesn't already exist. * @@ -146,12 +182,24 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putFloat(String key, float value) { + public void setFloat(String key, float value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setDouble(value); entry.setPersistent(); } + /** + * Puts the given float into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setFloat(String, float)} + */ + @Deprecated + public void putFloat(String key, float value) { + setFloat(key, value); + } + /** * Puts the given float into the preferences table if it doesn't already exist. * @@ -169,12 +217,24 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putBoolean(String key, boolean value) { + public void setBoolean(String key, boolean value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setBoolean(value); entry.setPersistent(); } + /** + * Puts the given boolean into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setBoolean(String, boolean)} + */ + @Deprecated + public void putBoolean(String key, boolean value) { + setBoolean(key, value); + } + /** * Puts the given boolean into the preferences table if it doesn't already exist. * @@ -192,12 +252,24 @@ public final class Preferences { * @param key the key * @param value the value */ - public void putLong(String key, long value) { + public void setLong(String key, long value) { NetworkTableEntry entry = m_table.getEntry(key); entry.setDouble(value); entry.setPersistent(); } + /** + * Puts the given long into the preferences table. + * + * @param key the key + * @param value the value + * @deprecated Use {@link #setLong(String, long)} + */ + @Deprecated + public void putLong(String key, long value) { + setLong(key, value); + } + /** * Puts the given long into the preferences table if it doesn't already exist. * 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 cf57de6c8b..06ba471ffd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -4,9 +4,9 @@ package edu.wpi.first.wpilibj; -import edu.wpi.cscore.CameraServerJNI; import edu.wpi.first.cameraserver.CameraServerShared; import edu.wpi.first.cameraserver.CameraServerSharedStore; +import edu.wpi.first.cscore.CameraServerJNI; import edu.wpi.first.hal.FRCNetComm.tInstances; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java deleted file mode 100644 index d038ac3d04..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java +++ /dev/null @@ -1,719 +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 edu.wpi.first.wpilibj; - -import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; - -import edu.wpi.first.hal.FRCNetComm.tInstances; -import edu.wpi.first.hal.FRCNetComm.tResourceType; -import edu.wpi.first.hal.HAL; - -/** - * Utility class for handling Robot drive based on a definition of the motor configuration. The - * robot drive class handles basic driving for a robot. Currently, 2 and 4 motor tank and mecanum - * drive trains are supported. In the future other drive types like swerve might be implemented. - * Motor channel numbers are supplied on creation of the class. Those are used for either the drive - * function (intended for hand created drive code, such as autonomous) or with the Tank/Arcade - * functions intended to be used for Operator Control driving. - * - * @deprecated Use {@link edu.wpi.first.wpilibj.drive.DifferentialDrive} or {@link - * edu.wpi.first.wpilibj.drive.MecanumDrive} classes instead. - */ -@Deprecated -@SuppressWarnings("PMD.GodClass") -public class RobotDrive extends MotorSafety implements AutoCloseable { - /** The location of a motor on the robot for the purpose of driving. */ - public enum MotorType { - kFrontLeft(0), - kFrontRight(1), - kRearLeft(2), - kRearRight(3); - - public final int value; - - MotorType(int value) { - this.value = value; - } - } - - public static final double kDefaultExpirationTime = 0.1; - public static final double kDefaultSensitivity = 0.5; - public static final double kDefaultMaxOutput = 1.0; - protected static final int kMaxNumberOfMotors = 4; - protected double m_sensitivity; - protected double m_maxOutput; - protected SpeedController m_frontLeftMotor; - protected SpeedController m_frontRightMotor; - protected SpeedController m_rearLeftMotor; - protected SpeedController m_rearRightMotor; - protected boolean m_allocatedSpeedControllers; - protected static boolean kArcadeRatioCurve_Reported; - protected static boolean kTank_Reported; - protected static boolean kArcadeStandard_Reported; - protected static boolean kMecanumCartesian_Reported; - protected static boolean kMecanumPolar_Reported; - - /** - * Constructor for RobotDrive with 2 motors specified with channel numbers. Set up parameters for - * a two wheel drive system where the left and right motor pwm channels are specified in the call. - * This call assumes Talons for controlling the motors. - * - * @param leftMotorChannel The PWM channel number that drives the left motor. - * @param rightMotorChannel The PWM channel number that drives the right motor. - */ - public RobotDrive(final int leftMotorChannel, final int rightMotorChannel) { - m_sensitivity = kDefaultSensitivity; - m_maxOutput = kDefaultMaxOutput; - m_frontLeftMotor = null; - m_rearLeftMotor = new Talon(leftMotorChannel); - m_frontRightMotor = null; - m_rearRightMotor = new Talon(rightMotorChannel); - m_allocatedSpeedControllers = true; - setSafetyEnabled(true); - drive(0, 0); - } - - /** - * Constructor for RobotDrive with 4 motors specified with channel numbers. Set up parameters for - * a four wheel drive system where all four motor pwm channels are specified in the call. This - * call assumes Talons for controlling the motors. - * - * @param frontLeftMotor Front left motor channel number - * @param rearLeftMotor Rear Left motor channel number - * @param frontRightMotor Front right motor channel number - * @param rearRightMotor Rear Right motor channel number - */ - public RobotDrive( - final int frontLeftMotor, - final int rearLeftMotor, - final int frontRightMotor, - final int rearRightMotor) { - m_sensitivity = kDefaultSensitivity; - m_maxOutput = kDefaultMaxOutput; - m_rearLeftMotor = new Talon(rearLeftMotor); - m_rearRightMotor = new Talon(rearRightMotor); - m_frontLeftMotor = new Talon(frontLeftMotor); - m_frontRightMotor = new Talon(frontRightMotor); - m_allocatedSpeedControllers = true; - setSafetyEnabled(true); - drive(0, 0); - } - - /** - * Constructor for RobotDrive with 2 motors specified as SpeedController objects. The - * SpeedController version of the constructor enables programs to use the RobotDrive classes with - * subclasses of the SpeedController objects, for example, versions with ramping or reshaping of - * the curve to suit motor bias or dead-band elimination. - * - * @param leftMotor The left SpeedController object used to drive the robot. - * @param rightMotor the right SpeedController object used to drive the robot. - */ - public RobotDrive(SpeedController leftMotor, SpeedController rightMotor) { - requireNonNullParam(leftMotor, "leftMotor", "RobotDrive"); - requireNonNullParam(rightMotor, "rightMotor", "RobotDrive"); - - m_frontLeftMotor = null; - m_rearLeftMotor = leftMotor; - m_frontRightMotor = null; - m_rearRightMotor = rightMotor; - m_sensitivity = kDefaultSensitivity; - m_maxOutput = kDefaultMaxOutput; - m_allocatedSpeedControllers = false; - setSafetyEnabled(true); - drive(0, 0); - } - - /** - * Constructor for RobotDrive with 4 motors specified as SpeedController objects. Speed controller - * input version of RobotDrive (see previous comments). - * - * @param frontLeftMotor The front left SpeedController object used to drive the robot - * @param rearLeftMotor The back left SpeedController object used to drive the robot. - * @param frontRightMotor The front right SpeedController object used to drive the robot. - * @param rearRightMotor The back right SpeedController object used to drive the robot. - */ - public RobotDrive( - SpeedController frontLeftMotor, - SpeedController rearLeftMotor, - SpeedController frontRightMotor, - SpeedController rearRightMotor) { - m_frontLeftMotor = requireNonNullParam(frontLeftMotor, "frontLeftMotor", "RobotDrive"); - m_rearLeftMotor = requireNonNullParam(rearLeftMotor, "rearLeftMotor", "RobotDrive"); - m_frontRightMotor = requireNonNullParam(frontRightMotor, "frontRightMotor", "RobotDrive"); - m_rearRightMotor = requireNonNullParam(rearRightMotor, "rearRightMotor", "RobotDrive"); - m_sensitivity = kDefaultSensitivity; - m_maxOutput = kDefaultMaxOutput; - m_allocatedSpeedControllers = false; - setSafetyEnabled(true); - drive(0, 0); - } - - /** - * Drive the motors at "outputMagnitude" and "curve". Both outputMagnitude and curve are -1.0 to - * +1.0 values, where 0.0 represents stopped and not turning. {@literal curve < 0 will turn left - * and curve > 0} will turn right. - * - *

The algorithm for steering provides a constant turn radius for any normal speed range, both - * forward and backward. Increasing sensitivity causes sharper turns for fixed values of curve. - * - *

This function will most likely be used in an autonomous routine. - * - * @param outputMagnitude The speed setting for the outside wheel in a turn, forward or backwards, - * +1 to -1. - * @param curve The rate of turn, constant for different forward speeds. Set {@literal curve < 0 - * for left turn or curve > 0 for right turn.} Set curve = e^(-r/w) to get a turn radius r for - * wheelbase w of your robot. Conversely, turn radius r = -ln(curve)*w for a given value of - * curve and wheelbase w. - */ - public void drive(double outputMagnitude, double curve) { - final double leftOutput; - final double rightOutput; - - if (!kArcadeRatioCurve_Reported) { - HAL.report( - tResourceType.kResourceType_RobotDrive, - tInstances.kRobotDrive_ArcadeRatioCurve, - getNumMotors()); - kArcadeRatioCurve_Reported = true; - } - if (curve < 0) { - double value = Math.log(-curve); - double ratio = (value - m_sensitivity) / (value + m_sensitivity); - if (ratio == 0) { - ratio = 0.0000000001; - } - leftOutput = outputMagnitude / ratio; - rightOutput = outputMagnitude; - } else if (curve > 0) { - double value = Math.log(curve); - double ratio = (value - m_sensitivity) / (value + m_sensitivity); - if (ratio == 0) { - ratio = 0.0000000001; - } - leftOutput = outputMagnitude; - rightOutput = outputMagnitude / ratio; - } else { - leftOutput = outputMagnitude; - rightOutput = outputMagnitude; - } - setLeftRightMotorOutputs(leftOutput, rightOutput); - } - - /** - * Provide tank steering using the stored robot configuration. drive the robot using two joystick - * inputs. The Y-axis will be selected from each Joystick object. The calculated values will be - * squared to decrease sensitivity at low speeds. - * - * @param leftStick The joystick to control the left side of the robot. - * @param rightStick The joystick to control the right side of the robot. - */ - public void tankDrive(GenericHID leftStick, GenericHID rightStick) { - requireNonNullParam(leftStick, "leftStick", "tankDrive"); - requireNonNullParam(rightStick, "rightStick", "tankDrive"); - - tankDrive(leftStick.getY(), rightStick.getY(), true); - } - - /** - * Provide tank steering using the stored robot configuration. drive the robot using two joystick - * inputs. The Y-axis will be selected from each Joystick object. - * - * @param leftStick The joystick to control the left side of the robot. - * @param rightStick The joystick to control the right side of the robot. - * @param squaredInputs Setting this parameter to true decreases the sensitivity at lower speeds - */ - public void tankDrive(GenericHID leftStick, GenericHID rightStick, boolean squaredInputs) { - requireNonNullParam(leftStick, "leftStick", "tankDrive"); - requireNonNullParam(rightStick, "rightStick", "tankDrive"); - - tankDrive(leftStick.getY(), rightStick.getY(), squaredInputs); - } - - /** - * Provide tank steering using the stored robot configuration. This function lets you pick the - * axis to be used on each Joystick object for the left and right sides of the robot. The - * calculated values will be squared to decrease sensitivity at low speeds. - * - * @param leftStick The Joystick object to use for the left side of the robot. - * @param leftAxis The axis to select on the left side Joystick object. - * @param rightStick The Joystick object to use for the right side of the robot. - * @param rightAxis The axis to select on the right side Joystick object. - */ - public void tankDrive( - GenericHID leftStick, final int leftAxis, GenericHID rightStick, final int rightAxis) { - requireNonNullParam(leftStick, "leftStick", "tankDrive"); - requireNonNullParam(rightStick, "rightStick", "tankDrive"); - - tankDrive(leftStick.getRawAxis(leftAxis), rightStick.getRawAxis(rightAxis), true); - } - - /** - * Provide tank steering using the stored robot configuration. This function lets you pick the - * axis to be used on each Joystick object for the left and right sides of the robot. - * - * @param leftStick The Joystick object to use for the left side of the robot. - * @param leftAxis The axis to select on the left side Joystick object. - * @param rightStick The Joystick object to use for the right side of the robot. - * @param rightAxis The axis to select on the right side Joystick object. - * @param squaredInputs Setting this parameter to true decreases the sensitivity at lower speeds - */ - public void tankDrive( - GenericHID leftStick, - final int leftAxis, - GenericHID rightStick, - final int rightAxis, - boolean squaredInputs) { - requireNonNullParam(leftStick, "leftStick", "tankDrive"); - requireNonNullParam(rightStick, "rightStick", "tankDrive"); - - tankDrive(leftStick.getRawAxis(leftAxis), rightStick.getRawAxis(rightAxis), squaredInputs); - } - - /** - * Provide tank steering using the stored robot configuration. This function lets you directly - * provide joystick values from any source. - * - * @param leftValue The value of the left stick. - * @param rightValue The value of the right stick. - * @param squaredInputs Setting this parameter to true decreases the sensitivity at lower speeds - */ - public void tankDrive(double leftValue, double rightValue, boolean squaredInputs) { - if (!kTank_Reported) { - HAL.report( - tResourceType.kResourceType_RobotDrive, tInstances.kRobotDrive_Tank, getNumMotors()); - kTank_Reported = true; - } - - leftValue = limit(leftValue); - rightValue = limit(rightValue); - - // square the inputs (while preserving the sign) to increase fine control - // while permitting full power - if (squaredInputs) { - leftValue = Math.copySign(leftValue * leftValue, leftValue); - rightValue = Math.copySign(rightValue * rightValue, rightValue); - } - setLeftRightMotorOutputs(leftValue, rightValue); - } - - /** - * Provide tank steering using the stored robot configuration. This function lets you directly - * provide joystick values from any source. The calculated values will be squared to decrease - * sensitivity at low speeds. - * - * @param leftValue The value of the left stick. - * @param rightValue The value of the right stick. - */ - public void tankDrive(double leftValue, double rightValue) { - tankDrive(leftValue, rightValue, true); - } - - /** - * Arcade drive implements single stick driving. Given a single Joystick, the class assumes the Y - * axis for the move value and the X axis for the rotate value. (Should add more information here - * regarding the way that arcade drive works.) - * - * @param stick The joystick to use for Arcade single-stick driving. The Y-axis will be selected - * for forwards/backwards and the X-axis will be selected for rotation rate. - * @param squaredInputs If true, the sensitivity will be decreased for small values - */ - public void arcadeDrive(GenericHID stick, boolean squaredInputs) { - // simply call the full-featured arcadeDrive with the appropriate values - arcadeDrive(stick.getY(), stick.getX(), squaredInputs); - } - - /** - * Arcade drive implements single stick driving. Given a single Joystick, the class assumes the Y - * axis for the move value and the X axis for the rotate value. (Should add more information here - * regarding the way that arcade drive works.) The calculated values will be squared to decrease - * sensitivity at low speeds. - * - * @param stick The joystick to use for Arcade single-stick driving. The Y-axis will be selected - * for forwards/backwards and the X-axis will be selected for rotation rate. - */ - public void arcadeDrive(GenericHID stick) { - arcadeDrive(stick, true); - } - - /** - * Arcade drive implements single stick driving. Given two joystick instances and two axis, - * compute the values to send to either two or four motors. - * - * @param moveStick The Joystick object that represents the forward/backward direction - * @param moveAxis The axis on the moveStick object to use for forwards/backwards (typically - * Y_AXIS) - * @param rotateStick The Joystick object that represents the rotation value - * @param rotateAxis The axis on the rotation object to use for the rotate right/left (typically - * X_AXIS) - * @param squaredInputs Setting this parameter to true decreases the sensitivity at lower speeds - */ - public void arcadeDrive( - GenericHID moveStick, - final int moveAxis, - GenericHID rotateStick, - final int rotateAxis, - boolean squaredInputs) { - double moveValue = moveStick.getRawAxis(moveAxis); - double rotateValue = rotateStick.getRawAxis(rotateAxis); - - arcadeDrive(moveValue, rotateValue, squaredInputs); - } - - /** - * Arcade drive implements single stick driving. Given two joystick instances and two axis, - * compute the values to send to either two or four motors. The calculated values will be squared - * to decrease sensitivity at low speeds. - * - * @param moveStick The Joystick object that represents the forward/backward direction - * @param moveAxis The axis on the moveStick object to use for forwards/backwards (typically - * Y_AXIS) - * @param rotateStick The Joystick object that represents the rotation value - * @param rotateAxis The axis on the rotation object to use for the rotate right/left (typically - * X_AXIS) - */ - public void arcadeDrive( - GenericHID moveStick, final int moveAxis, GenericHID rotateStick, final int rotateAxis) { - arcadeDrive(moveStick, moveAxis, rotateStick, rotateAxis, true); - } - - /** - * Arcade drive implements single stick driving. This function lets you directly provide joystick - * values from any source. - * - * @param moveValue The value to use for forwards/backwards - * @param rotateValue The value to use for the rotate right/left - * @param squaredInputs If set, decreases the sensitivity at low speeds - */ - public void arcadeDrive(double moveValue, double rotateValue, boolean squaredInputs) { - // local variables to hold the computed PWM values for the motors - if (!kArcadeStandard_Reported) { - HAL.report( - tResourceType.kResourceType_RobotDrive, - tInstances.kRobotDrive_ArcadeStandard, - getNumMotors()); - kArcadeStandard_Reported = true; - } - - double leftMotorSpeed; - double rightMotorSpeed; - - moveValue = limit(moveValue); - rotateValue = limit(rotateValue); - - // square the inputs (while preserving the sign) to increase fine control - // while permitting full power - if (squaredInputs) { - // square the inputs (while preserving the sign) to increase fine control - // while permitting full power - moveValue = Math.copySign(moveValue * moveValue, moveValue); - rotateValue = Math.copySign(rotateValue * rotateValue, rotateValue); - } - - if (moveValue > 0.0) { - if (rotateValue > 0.0) { - leftMotorSpeed = moveValue - rotateValue; - rightMotorSpeed = Math.max(moveValue, rotateValue); - } else { - leftMotorSpeed = Math.max(moveValue, -rotateValue); - rightMotorSpeed = moveValue + rotateValue; - } - } else { - if (rotateValue > 0.0) { - leftMotorSpeed = -Math.max(-moveValue, rotateValue); - rightMotorSpeed = moveValue + rotateValue; - } else { - leftMotorSpeed = moveValue - rotateValue; - rightMotorSpeed = -Math.max(-moveValue, -rotateValue); - } - } - - setLeftRightMotorOutputs(leftMotorSpeed, rightMotorSpeed); - } - - /** - * Arcade drive implements single stick driving. This function lets you directly provide joystick - * values from any source. The calculated values will be squared to decrease sensitivity at low - * speeds. - * - * @param moveValue The value to use for forwards/backwards - * @param rotateValue The value to use for the rotate right/left - */ - public void arcadeDrive(double moveValue, double rotateValue) { - arcadeDrive(moveValue, rotateValue, true); - } - - /** - * Drive method for Mecanum wheeled robots. - * - *

A method for driving with Mecanum wheeled robots. There are 4 wheels on the robot, arranged - * so that the front and back wheels are toed in 45 degrees. When looking at the wheels from the - * top, the roller axles should form an X across the robot. - * - *

This is designed to be directly driven by joystick axes. - * - * @param x The speed that the robot should drive in the X direction. [-1.0..1.0] - * @param y The speed that the robot should drive in the Y direction. This input is inverted to - * match the forward == -1.0 that joysticks produce. [-1.0..1.0] - * @param rotation The rate of rotation for the robot that is completely independent of the - * translation. [-1.0..1.0] - * @param gyroAngle The current angle reading from the gyro. Use this to implement field-oriented - * controls. - */ - public void mecanumDrive_Cartesian(double x, double y, double rotation, double gyroAngle) { - if (!kMecanumCartesian_Reported) { - HAL.report( - tResourceType.kResourceType_RobotDrive, - tInstances.kRobotDrive_MecanumCartesian, - getNumMotors()); - kMecanumCartesian_Reported = true; - } - // Negate y for the joystick. - y = -y; - // Compensate for gyro angle. - double[] rotated = rotateVector(x, y, gyroAngle); - x = rotated[0]; - y = rotated[1]; - - double[] wheelSpeeds = new double[kMaxNumberOfMotors]; - wheelSpeeds[MotorType.kFrontLeft.value] = x + y + rotation; - wheelSpeeds[MotorType.kFrontRight.value] = -x + y - rotation; - wheelSpeeds[MotorType.kRearLeft.value] = -x + y + rotation; - wheelSpeeds[MotorType.kRearRight.value] = x + y - rotation; - - normalize(wheelSpeeds); - m_frontLeftMotor.set(wheelSpeeds[MotorType.kFrontLeft.value] * m_maxOutput); - m_frontRightMotor.set(wheelSpeeds[MotorType.kFrontRight.value] * m_maxOutput); - m_rearLeftMotor.set(wheelSpeeds[MotorType.kRearLeft.value] * m_maxOutput); - m_rearRightMotor.set(wheelSpeeds[MotorType.kRearRight.value] * m_maxOutput); - - feed(); - } - - /** - * Drive method for Mecanum wheeled robots. - * - *

A method for driving with Mecanum wheeled robots. There are 4 wheels on the robot, arranged - * so that the front and back wheels are toed in 45 degrees. When looking at the wheels from the - * top, the roller axles should form an X across the robot. - * - * @param magnitude The speed that the robot should drive in a given direction. [-1.0..1.0] - * @param direction The angle the robot should drive in degrees. The direction and magnitude are - * independent of the rotation rate. [-180.0..180.0] - * @param rotation The rate of rotation for the robot that is completely independent of the - * magnitude or direction. [-1.0..1.0] - */ - public void mecanumDrive_Polar(double magnitude, double direction, double rotation) { - if (!kMecanumPolar_Reported) { - HAL.report( - tResourceType.kResourceType_RobotDrive, - tInstances.kRobotDrive_MecanumPolar, - getNumMotors()); - kMecanumPolar_Reported = true; - } - // Normalized for full power along the Cartesian axes. - magnitude = limit(magnitude) * Math.sqrt(2.0); - // The rollers are at 45 degree angles. - double dirInRad = (direction + 45.0) * Math.PI / 180.0; - double cosD = Math.cos(dirInRad); - double sinD = Math.sin(dirInRad); - - double[] wheelSpeeds = new double[kMaxNumberOfMotors]; - wheelSpeeds[MotorType.kFrontLeft.value] = sinD * magnitude + rotation; - wheelSpeeds[MotorType.kFrontRight.value] = cosD * magnitude - rotation; - wheelSpeeds[MotorType.kRearLeft.value] = cosD * magnitude + rotation; - wheelSpeeds[MotorType.kRearRight.value] = sinD * magnitude - rotation; - - normalize(wheelSpeeds); - - m_frontLeftMotor.set(wheelSpeeds[MotorType.kFrontLeft.value] * m_maxOutput); - m_frontRightMotor.set(wheelSpeeds[MotorType.kFrontRight.value] * m_maxOutput); - m_rearLeftMotor.set(wheelSpeeds[MotorType.kRearLeft.value] * m_maxOutput); - m_rearRightMotor.set(wheelSpeeds[MotorType.kRearRight.value] * m_maxOutput); - - feed(); - } - - /** - * Holonomic Drive method for Mecanum wheeled robots. - * - *

This is an alias to mecanumDrive_Polar() for backward compatibility - * - * @param magnitude The speed that the robot should drive in a given direction. [-1.0..1.0] - * @param direction The direction the robot should drive. The direction and maginitude are - * independent of the rotation rate. - * @param rotation The rate of rotation for the robot that is completely independent of the - * magnitute or direction. [-1.0..1.0] - */ - void holonomicDrive(double magnitude, double direction, double rotation) { - mecanumDrive_Polar(magnitude, direction, rotation); - } - - /** - * Set the speed of the right and left motors. This is used once an appropriate drive setup - * function is called such as twoWheelDrive(). The motors are set to "leftSpeed" and "rightSpeed" - * and includes flipping the direction of one side for opposing motors. - * - * @param leftOutput The speed to send to the left side of the robot. - * @param rightOutput The speed to send to the right side of the robot. - */ - public void setLeftRightMotorOutputs(double leftOutput, double rightOutput) { - - if (m_frontLeftMotor != null) { - m_frontLeftMotor.set(limit(leftOutput) * m_maxOutput); - } - m_rearLeftMotor.set(limit(leftOutput) * m_maxOutput); - - if (m_frontRightMotor != null) { - m_frontRightMotor.set(-limit(rightOutput) * m_maxOutput); - } - m_rearRightMotor.set(-limit(rightOutput) * m_maxOutput); - - feed(); - } - - /** Limit motor values to the -1.0 to +1.0 range. */ - protected static double limit(double number) { - if (number > 1.0) { - return 1.0; - } - if (number < -1.0) { - return -1.0; - } - return number; - } - - /** Normalize all wheel speeds if the magnitude of any wheel is greater than 1.0. */ - protected static void normalize(double[] wheelSpeeds) { - double maxMagnitude = Math.abs(wheelSpeeds[0]); - for (int i = 1; i < kMaxNumberOfMotors; i++) { - double temp = Math.abs(wheelSpeeds[i]); - if (maxMagnitude < temp) { - maxMagnitude = temp; - } - } - if (maxMagnitude > 1.0) { - for (int i = 0; i < kMaxNumberOfMotors; i++) { - wheelSpeeds[i] = wheelSpeeds[i] / maxMagnitude; - } - } - } - - /** Rotate a vector in Cartesian space. */ - protected static double[] rotateVector(double x, double y, double angle) { - double cosA = Math.cos(angle * (Math.PI / 180.0)); - double sinA = Math.sin(angle * (Math.PI / 180.0)); - double[] out = new double[2]; - out[0] = x * cosA - y * sinA; - out[1] = x * sinA + y * cosA; - return out; - } - - /** - * Invert a motor direction. This is used when a motor should run in the opposite direction as the - * drive code would normally run it. Motors that are direct drive would be inverted, the drive - * code assumes that the motors are geared with one reversal. - * - * @param motor The motor index to invert. - * @param isInverted True if the motor should be inverted when operated. - */ - public void setInvertedMotor(MotorType motor, boolean isInverted) { - switch (motor) { - case kFrontLeft: - m_frontLeftMotor.setInverted(isInverted); - break; - case kFrontRight: - m_frontRightMotor.setInverted(isInverted); - break; - case kRearLeft: - m_rearLeftMotor.setInverted(isInverted); - break; - case kRearRight: - m_rearRightMotor.setInverted(isInverted); - break; - default: - throw new IllegalArgumentException("Illegal motor type: " + motor); - } - } - - /** - * Set the turning sensitivity. - * - *

This only impacts the drive() entry-point. - * - * @param sensitivity Effectively sets the turning sensitivity (or turn radius for a given value) - */ - public void setSensitivity(double sensitivity) { - m_sensitivity = sensitivity; - } - - /** - * Configure the scaling factor for using RobotDrive with motor controllers in a mode other than - * PercentVbus. - * - * @param maxOutput Multiplied with the output percentage computed by the drive functions. - */ - public void setMaxOutput(double maxOutput) { - m_maxOutput = maxOutput; - } - - /** Free the speed controllers if they were allocated locally. */ - @Override - public void close() { - if (m_allocatedSpeedControllers) { - if (m_frontLeftMotor != null) { - ((PWM) m_frontLeftMotor).close(); - } - if (m_frontRightMotor != null) { - ((PWM) m_frontRightMotor).close(); - } - if (m_rearLeftMotor != null) { - ((PWM) m_rearLeftMotor).close(); - } - if (m_rearRightMotor != null) { - ((PWM) m_rearRightMotor).close(); - } - } - } - - @Override - public String getDescription() { - return "Robot Drive"; - } - - @Override - public void stopMotor() { - if (m_frontLeftMotor != null) { - m_frontLeftMotor.stopMotor(); - } - if (m_frontRightMotor != null) { - m_frontRightMotor.stopMotor(); - } - if (m_rearLeftMotor != null) { - m_rearLeftMotor.stopMotor(); - } - if (m_rearRightMotor != null) { - m_rearRightMotor.stopMotor(); - } - - feed(); - } - - protected int getNumMotors() { - int motors = 0; - if (m_frontLeftMotor != null) { - motors++; - } - if (m_frontRightMotor != null) { - motors++; - } - if (m_rearLeftMotor != null) { - motors++; - } - if (m_rearRightMotor != null) { - motors++; - } - return motors; - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Sendable.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Sendable.java index 84484ff8c5..eb57341c35 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Sendable.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Sendable.java @@ -5,102 +5,9 @@ package edu.wpi.first.wpilibj; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; /** The base interface for objects that can be sent over the network through network tables. */ public interface Sendable { - /** - * Gets the name of this {@link Sendable} object. - * - * @return Name - * @deprecated Use SendableRegistry.getName() - */ - @Deprecated(since = "2020", forRemoval = true) - default String getName() { - return SendableRegistry.getName(this); - } - - /** - * Sets the name of this {@link Sendable} object. - * - * @param name name - * @deprecated Use SendableRegistry.setName() - */ - @Deprecated(since = "2020", forRemoval = true) - default void setName(String name) { - SendableRegistry.setName(this, name); - } - - /** - * Sets both the subsystem name and device name of this {@link Sendable} object. - * - * @param subsystem subsystem name - * @param name device name - * @deprecated Use SendableRegistry.setName() - */ - @Deprecated(since = "2020", forRemoval = true) - default void setName(String subsystem, String name) { - SendableRegistry.setName(this, subsystem, name); - } - - /** - * Sets the name of the sensor with a channel number. - * - * @param moduleType A string that defines the module name in the label for the value - * @param channel The channel number the device is plugged into - * @deprecated Use SendableRegistry.setName() - */ - @Deprecated(since = "2020", forRemoval = true) - default void setName(String moduleType, int channel) { - SendableRegistry.setName(this, moduleType, channel); - } - - /** - * Sets the name of the sensor with a module and channel number. - * - * @param moduleType A string that defines the module name in the label for the value - * @param moduleNumber The number of the particular module type - * @param channel The channel number the device is plugged into (usually PWM) - * @deprecated Use SendableRegistry.setName() - */ - @Deprecated(since = "2020", forRemoval = true) - default void setName(String moduleType, int moduleNumber, int channel) { - SendableRegistry.setName(this, moduleType, moduleNumber, channel); - } - - /** - * Gets the subsystem name of this {@link Sendable} object. - * - * @return Subsystem name - * @deprecated Use SendableRegistry.getSubsystem() - */ - @Deprecated(since = "2020", forRemoval = true) - default String getSubsystem() { - return SendableRegistry.getSubsystem(this); - } - - /** - * Sets the subsystem name of this {@link Sendable} object. - * - * @param subsystem subsystem name - * @deprecated Use SendableRegistry.setSubsystem() - */ - @Deprecated(since = "2020", forRemoval = true) - default void setSubsystem(String subsystem) { - SendableRegistry.setSubsystem(this, subsystem); - } - - /** - * Add a child component. - * - * @param child child component - * @deprecated Use SendableRegistry.addChild() - */ - @Deprecated(since = "2020", forRemoval = true) - default void addChild(Object child) { - SendableRegistry.addChild(this, child); - } - /** * Initializes this {@link Sendable} object. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SendableBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SendableBase.java deleted file mode 100644 index 44b1d5080e..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SendableBase.java +++ /dev/null @@ -1,39 +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 edu.wpi.first.wpilibj; - -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; - -/** - * Base class for all sensors. Stores most recent status information as well as containing utility - * functions for checking channels and error processing. - * - * @deprecated Use Sendable and SendableRegistry - */ -@Deprecated(since = "2020", forRemoval = true) -public abstract class SendableBase implements Sendable, AutoCloseable { - /** Creates an instance of the sensor base. */ - public SendableBase() { - this(true); - } - - /** - * Creates an instance of the sensor base. - * - * @param addLiveWindow if true, add this Sendable to LiveWindow - */ - public SendableBase(boolean addLiveWindow) { - if (addLiveWindow) { - SendableRegistry.addLW(this, ""); - } else { - SendableRegistry.add(this, ""); - } - } - - @Override - public void close() { - SendableRegistry.remove(this); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SlewRateLimiter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SlewRateLimiter.java index 5569ba9ac0..849a869588 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SlewRateLimiter.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SlewRateLimiter.java @@ -4,13 +4,13 @@ package edu.wpi.first.wpilibj; -import edu.wpi.first.wpiutil.math.MathUtil; +import edu.wpi.first.math.MathUtil; /** * A class that limits the rate of change of an input value. Useful for implementing voltage, * setpoint, and/or output ramps. A slew-rate limit is most appropriate when the quantity being * controlled is a velocity or a voltage; when controlling a position, consider using a {@link - * edu.wpi.first.wpilibj.trajectory.TrapezoidProfile} instead. + * edu.wpi.first.math.trajectory.TrapezoidProfile} instead. */ public class SlewRateLimiter { private final double m_rateLimit; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedController.java index f795ca77a0..490455c791 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedController.java @@ -4,18 +4,22 @@ package edu.wpi.first.wpilibj; -/** Interface for speed controlling devices. */ -@SuppressWarnings("removal") -public interface SpeedController extends PIDOutput { +/** + * Interface for motor controlling devices. + * + * @deprecated Use {@link edu.wpi.first.wpilibj.motorcontrol.MotorController}. + */ +@Deprecated(since = "2022", forRemoval = true) +public interface SpeedController { /** - * Common interface for setting the speed of a speed controller. + * Common interface for setting the speed of a motor controller. * * @param speed The speed to set. Value should be between -1.0 and 1.0. */ void set(double speed); /** - * Sets the voltage output of the SpeedController. Compensates for the current bus voltage to + * Sets the voltage output of the MotorController. Compensates for the current bus voltage to * ensure that the desired voltage is output even if the battery voltage is below 12V - highly * useful when the voltage outputs are "meaningful" (e.g. they come from a feedforward * calculation). @@ -30,27 +34,27 @@ public interface SpeedController extends PIDOutput { } /** - * Common interface for getting the current set speed of a speed controller. + * Common interface for getting the current set speed of a motor controller. * * @return The current set speed. Value is between -1.0 and 1.0. */ double get(); /** - * Common interface for inverting direction of a speed controller. + * Common interface for inverting direction of a motor controller. * * @param isInverted The state of inversion true is inverted. */ void setInverted(boolean isInverted); /** - * Common interface for returning if a speed controller is in the inverted state or not. + * Common interface for returning if a motor controller is in the inverted state or not. * * @return isInverted The state of the inversion true is inverted. */ boolean getInverted(); - /** Disable the speed controller. */ + /** Disable the motor controller. */ void disable(); /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedControllerGroup.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedControllerGroup.java index f8a9fb2c5e..9327f50a4d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedControllerGroup.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SpeedControllerGroup.java @@ -4,12 +4,19 @@ package edu.wpi.first.wpilibj; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; import java.util.Arrays; -/** Allows multiple {@link SpeedController} objects to be linked together. */ -public class SpeedControllerGroup implements SpeedController, Sendable, AutoCloseable { +/** + * Allows multiple {@link SpeedController} objects to be linked together. + * + * @deprecated Use {@link edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup}. + */ +@Deprecated(since = "2022", forRemoval = true) +@SuppressWarnings("removal") +public class SpeedControllerGroup implements MotorController, Sendable, AutoCloseable { private boolean m_isInverted; private final SpeedController[] m_speedControllers; private static int instances; @@ -40,7 +47,7 @@ public class SpeedControllerGroup implements SpeedController, Sendable, AutoClos SendableRegistry.addChild(this, controller); } instances++; - SendableRegistry.addLW(this, "SpeedControllerGroup", instances); + SendableRegistry.addLW(this, "MotorControllerGroup", instances); } @Override @@ -87,14 +94,9 @@ public class SpeedControllerGroup implements SpeedController, Sendable, AutoClos } } - @Override - public void pidWrite(double output) { - set(output); - } - @Override public void initSendable(SendableBuilder builder) { - builder.setSmartDashboardType("Speed Controller"); + builder.setSmartDashboardType("Motor Controller"); builder.setActuator(true); builder.setSafeState(this::stopMotor); builder.addDoubleProperty("Value", this::get, this::set); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java index 655758b3de..561fbdc040 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java @@ -137,11 +137,6 @@ public class TimedRobot extends IterativeRobotBase { NotifierJNI.stopNotifier(m_notifier); } - /** Get time period between calls to Periodic() functions. */ - public double getPeriod() { - return m_period; - } - /** * Add a callback to run at a specific period. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java index 81c1bcf534..346ddb9738 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java @@ -26,15 +26,7 @@ import java.util.List; * echo is received. The time that the line is high determines the round trip distance (time of * flight). */ -public class Ultrasonic implements PIDSource, Sendable, AutoCloseable { - /** The units to return when PIDGet is called. */ - public enum Unit { - /** Use inches for PIDGet. */ - kInches, - /** Use millimeters for PIDGet. */ - kMillimeters - } - +public class Ultrasonic implements Sendable, AutoCloseable { // Time (sec) for the ping trigger pulse. private static final double kPingTime = 10 * 1e-6; private static final double kSpeedOfSoundInchesPerSec = 1130.0 * 12.0; @@ -44,14 +36,12 @@ public class Ultrasonic implements PIDSource, Sendable, AutoCloseable { private static volatile boolean m_automaticEnabled; private DigitalInput m_echoChannel; private DigitalOutput m_pingChannel; - private boolean m_allocatedChannels; + private final boolean m_allocatedChannels; private boolean m_enabled; private Counter m_counter; // task doing the round-robin automatic sensing private static Thread m_task; - private Unit m_units; private static int m_instances; - protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement; private SimDevice m_simDevice; private SimBoolean m_simRangeValid; @@ -128,31 +118,16 @@ public class Ultrasonic implements PIDSource, Sendable, AutoCloseable { * sending the ping. * @param echoChannel The digital input channel that receives the echo. The length of time that * the echo is high represents the round trip time of the ping, and the distance. - * @param units The units returned in either kInches or kMilliMeters */ - public Ultrasonic(final int pingChannel, final int echoChannel, Unit units) { + public Ultrasonic(final int pingChannel, final int echoChannel) { m_pingChannel = new DigitalOutput(pingChannel); m_echoChannel = new DigitalInput(echoChannel); SendableRegistry.addChild(this, m_pingChannel); SendableRegistry.addChild(this, m_echoChannel); m_allocatedChannels = true; - m_units = units; initialize(); } - /** - * Create an instance of the Ultrasonic Sensor. This is designed to supchannel the Daventech SRF04 - * and Vex ultrasonic sensors. Default unit is inches. - * - * @param pingChannel The digital output channel that sends the pulse to initiate the sensor - * sending the ping. - * @param echoChannel The digital input channel that receives the echo. The length of time that - * the echo is high represents the round trip time of the ping, and the distance. - */ - public Ultrasonic(final int pingChannel, final int echoChannel) { - this(pingChannel, echoChannel, Unit.kInches); - } - /** * Create an instance of an Ultrasonic Sensor from a DigitalInput for the echo channel and a * DigitalOutput for the ping channel. @@ -160,31 +135,17 @@ public class Ultrasonic implements PIDSource, Sendable, AutoCloseable { * @param pingChannel The digital output object that starts the sensor doing a ping. Requires a * 10uS pulse to start. * @param echoChannel The digital input object that times the return pulse to determine the range. - * @param units The units returned in either kInches or kMilliMeters */ - public Ultrasonic(DigitalOutput pingChannel, DigitalInput echoChannel, Unit units) { + public Ultrasonic(DigitalOutput pingChannel, DigitalInput echoChannel) { requireNonNull(pingChannel, "Provided ping channel was null"); requireNonNull(echoChannel, "Provided echo channel was null"); m_allocatedChannels = false; m_pingChannel = pingChannel; m_echoChannel = echoChannel; - m_units = units; initialize(); } - /** - * Create an instance of an Ultrasonic Sensor from a DigitalInput for the echo channel and a - * DigitalOutput for the ping channel. Default unit is inches. - * - * @param pingChannel The digital output object that starts the sensor doing a ping. Requires a - * 10uS pulse to start. - * @param echoChannel The digital input object that times the return pulse to determine the range. - */ - public Ultrasonic(DigitalOutput pingChannel, DigitalInput echoChannel) { - this(pingChannel, echoChannel, Unit.kInches); - } - /** * Destructor for the ultrasonic sensor. Delete the instance of the ultrasonic sensor by freeing * the allocated digital channels. If the system was in automatic mode (round robin), then it is @@ -326,54 +287,6 @@ public class Ultrasonic implements PIDSource, Sendable, AutoCloseable { return getRangeInches() * 25.4; } - @Override - public void setPIDSourceType(PIDSourceType pidSource) { - if (!pidSource.equals(PIDSourceType.kDisplacement)) { - throw new IllegalArgumentException("Only displacement PID is allowed for ultrasonics."); - } - m_pidSource = pidSource; - } - - @Override - public PIDSourceType getPIDSourceType() { - return m_pidSource; - } - - /** - * Get the range in the current DistanceUnit for the PIDSource base object. - * - * @return The range in DistanceUnit - */ - @Override - public double pidGet() { - switch (m_units) { - case kInches: - return getRangeInches(); - case kMillimeters: - return getRangeMM(); - default: - return 0.0; - } - } - - /** - * Set the current DistanceUnit that should be used for the PIDSource base object. - * - * @param units The DistanceUnit that should be used. - */ - public void setDistanceUnits(Unit units) { - m_units = units; - } - - /** - * Get the current DistanceUnit that is used for the PIDSource base object. - * - * @return The type of DistanceUnit that is being used. - */ - public Unit getDistanceUnits() { - return m_units; - } - /** * Is the ultrasonic enabled. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/HolonomicDriveController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/HolonomicDriveController.java index f1d7f81da7..6cadf487b9 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/HolonomicDriveController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/HolonomicDriveController.java @@ -4,10 +4,10 @@ package edu.wpi.first.wpilibj.controller; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.trajectory.Trajectory; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.trajectory.Trajectory; /** * This holonomic drive controller can be used to follow trajectories using a holonomic drive train diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java index 08a0e28ec5..68e648da60 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/PIDController.java @@ -6,10 +6,10 @@ package edu.wpi.first.wpilibj.controller; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; +import edu.wpi.first.math.MathUtil; import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; -import edu.wpi.first.wpiutil.math.MathUtil; /** Implements a PID control loop. */ @SuppressWarnings("PMD.TooManyFields") diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/ProfiledPIDController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/ProfiledPIDController.java index 427291875b..514bd31dd3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/ProfiledPIDController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/ProfiledPIDController.java @@ -6,10 +6,10 @@ package edu.wpi.first.wpilibj.controller; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; -import edu.wpi.first.wpiutil.math.MathUtil; /** * Implements a PID control loop whose setpoint is constrained by a trapezoid profile. Users should diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java index cb16ce3fad..90188ed91e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/DifferentialDrive.java @@ -7,12 +7,11 @@ package edu.wpi.first.wpilibj.drive; import edu.wpi.first.hal.FRCNetComm.tInstances; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; +import edu.wpi.first.math.MathUtil; import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.SpeedController; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; -import edu.wpi.first.wpiutil.math.MathUtil; import java.util.StringJoiner; /** @@ -20,21 +19,21 @@ import java.util.StringJoiner; * base, "tank drive", or West Coast Drive. * *

These drive bases typically have drop-center / skid-steer with two or more wheels per side - * (e.g., 6WD or 8WD). This class takes a SpeedController per side. For four and six motor - * drivetrains, construct and pass in {@link edu.wpi.first.wpilibj.SpeedControllerGroup} instances - * as follows. + * (e.g., 6WD or 8WD). This class takes a MotorController per side. For four and six motor + * drivetrains, construct and pass in {@link + * edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup} instances as follows. * *

Four motor drivetrain: * *


  * public class Robot {
- *   SpeedController m_frontLeft = new PWMVictorSPX(1);
- *   SpeedController m_rearLeft = new PWMVictorSPX(2);
- *   SpeedControllerGroup m_left = new SpeedControllerGroup(m_frontLeft, m_rearLeft);
+ *   MotorController m_frontLeft = new PWMVictorSPX(1);
+ *   MotorController m_rearLeft = new PWMVictorSPX(2);
+ *   MotorControllerGroup m_left = new MotorControllerGroup(m_frontLeft, m_rearLeft);
  *
- *   SpeedController m_frontRight = new PWMVictorSPX(3);
- *   SpeedController m_rearRight = new PWMVictorSPX(4);
- *   SpeedControllerGroup m_right = new SpeedControllerGroup(m_frontRight, m_rearRight);
+ *   MotorController m_frontRight = new PWMVictorSPX(3);
+ *   MotorController m_rearRight = new PWMVictorSPX(4);
+ *   MotorControllerGroup m_right = new MotorControllerGroup(m_frontRight, m_rearRight);
  *
  *   DifferentialDrive m_drive = new DifferentialDrive(m_left, m_right);
  * }
@@ -44,15 +43,15 @@ import java.util.StringJoiner;
  *
  * 

  * public class Robot {
- *   SpeedController m_frontLeft = new PWMVictorSPX(1);
- *   SpeedController m_midLeft = new PWMVictorSPX(2);
- *   SpeedController m_rearLeft = new PWMVictorSPX(3);
- *   SpeedControllerGroup m_left = new SpeedControllerGroup(m_frontLeft, m_midLeft, m_rearLeft);
+ *   MotorController m_frontLeft = new PWMVictorSPX(1);
+ *   MotorController m_midLeft = new PWMVictorSPX(2);
+ *   MotorController m_rearLeft = new PWMVictorSPX(3);
+ *   MotorControllerGroup m_left = new MotorControllerGroup(m_frontLeft, m_midLeft, m_rearLeft);
  *
- *   SpeedController m_frontRight = new PWMVictorSPX(4);
- *   SpeedController m_midRight = new PWMVictorSPX(5);
- *   SpeedController m_rearRight = new PWMVictorSPX(6);
- *   SpeedControllerGroup m_right = new SpeedControllerGroup(m_frontRight, m_midRight, m_rearRight);
+ *   MotorController m_frontRight = new PWMVictorSPX(4);
+ *   MotorController m_midRight = new PWMVictorSPX(5);
+ *   MotorController m_rearRight = new PWMVictorSPX(6);
+ *   MotorControllerGroup m_right = new MotorControllerGroup(m_frontRight, m_midRight, m_rearRight);
  *
  *   DifferentialDrive m_drive = new DifferentialDrive(m_left, m_right);
  * }
@@ -86,15 +85,15 @@ import java.util.StringJoiner;
  * value can be changed with {@link #setDeadband}.
  *
  * 

RobotDrive porting guide:
- * {@link #tankDrive(double, double)} is equivalent to {@link - * edu.wpi.first.wpilibj.RobotDrive#tankDrive(double, double)} if a deadband of 0 is used.
- * {@link #arcadeDrive(double, double)} is equivalent to {@link - * edu.wpi.first.wpilibj.RobotDrive#arcadeDrive(double, double)} if a deadband of 0 is used and the - * the rotation input is inverted eg arcadeDrive(y, -rotation)
- * {@link #curvatureDrive(double, double, boolean)} is similar in concept to {@link - * edu.wpi.first.wpilibj.RobotDrive#drive(double, double)} with the addition of a quick turn mode. - * However, it is not designed to give exactly the same response. + * {@link #tankDrive(double, double)} is equivalent to RobotDrive's tankDrive(double, double) if a + * deadband of 0 is used.
+ * {@link #arcadeDrive(double, double)} is equivalent to RobotDrive's arcadeDrive(double, double) if + * a deadband of 0 is used and the the rotation input is inverted eg arcadeDrive(y, -rotation)
+ * {@link #curvatureDrive(double, double, boolean)} is similar in concept to RobotDrive's + * drive(double, double) with the addition of a quick turn mode. However, it is not designed to give + * exactly the same response. */ +@SuppressWarnings("removal") public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoCloseable { public static final double kDefaultQuickStopThreshold = 0.2; public static final double kDefaultQuickStopAlpha = 0.1; @@ -113,8 +112,9 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC /** * Construct a DifferentialDrive. * - *

To pass multiple motors per side, use a {@link SpeedControllerGroup}. If a motor needs to be - * inverted, do so before passing it in. + *

To pass multiple motors per side, use a {@link + * edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup}. If a motor needs to be inverted, do + * so before passing it in. */ public DifferentialDrive(SpeedController leftMotor, SpeedController rightMotor) { verify(leftMotor, rightMotor); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java index fbc62ff1be..b7dff3db4c 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/KilloughDrive.java @@ -7,11 +7,11 @@ package edu.wpi.first.wpilibj.drive; import edu.wpi.first.hal.FRCNetComm.tInstances; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; +import edu.wpi.first.math.MathUtil; import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; -import edu.wpi.first.wpiutil.math.MathUtil; import java.util.StringJoiner; /** @@ -39,6 +39,7 @@ import java.util.StringJoiner; * points down. Rotations follow the right-hand rule, so clockwise rotation around the Z axis is * positive. */ +@SuppressWarnings("removal") public class KilloughDrive extends RobotDriveBase implements Sendable, AutoCloseable { public static final double kDefaultLeftMotorAngle = 60.0; public static final double kDefaultRightMotorAngle = 120.0; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java index 8189e68a58..0fda4a0bfa 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/drive/MecanumDrive.java @@ -7,11 +7,11 @@ package edu.wpi.first.wpilibj.drive; import edu.wpi.first.hal.FRCNetComm.tInstances; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; +import edu.wpi.first.math.MathUtil; import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; -import edu.wpi.first.wpiutil.math.MathUtil; import java.util.StringJoiner; /** @@ -50,14 +50,14 @@ import java.util.StringJoiner; *

RobotDrive porting guide:
* In MecanumDrive, the right side speed controllers are automatically inverted, while in * RobotDrive, no speed controllers are automatically inverted.
- * {@link #driveCartesian(double, double, double, double)} is equivalent to {@link - * edu.wpi.first.wpilibj.RobotDrive#mecanumDrive_Cartesian(double, double, double, double)} if a - * deadband of 0 is used, and the ySpeed and gyroAngle values are inverted compared to RobotDrive - * (eg driveCartesian(xSpeed, -ySpeed, zRotation, -gyroAngle).
- * {@link #drivePolar(double, double, double)} is equivalent to {@link - * edu.wpi.first.wpilibj.RobotDrive#mecanumDrive_Polar(double, double, double)} if a deadband of 0 - * is used. + * {@link #driveCartesian(double, double, double, double)} is equivalent to RobotDrive's + * mecanumDrive_Cartesian(double, double, double, double) if a deadband of 0 is used, and the ySpeed + * and gyroAngle values are inverted compared to RobotDrive (eg driveCartesian(xSpeed, -ySpeed, + * zRotation, -gyroAngle).
+ * {@link #drivePolar(double, double, double)} is equivalent to RobotDrive's + * mecanumDrive_Polar(double, double, double)} if a deadband of 0 is used. */ +@SuppressWarnings("removal") public class MecanumDrive extends RobotDriveBase implements Sendable, AutoCloseable { private static int instances; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/Filter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/Filter.java deleted file mode 100644 index f80eb30896..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/Filter.java +++ /dev/null @@ -1,54 +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 edu.wpi.first.wpilibj.filters; - -import edu.wpi.first.wpilibj.PIDSource; -import edu.wpi.first.wpilibj.PIDSourceType; - -/** - * Superclass for filters. - * - * @deprecated This class is no longer used. - */ -@Deprecated(since = "2020", forRemoval = true) -public abstract class Filter implements PIDSource { - private final PIDSource m_source; - - public Filter(PIDSource source) { - m_source = source; - } - - @Override - public void setPIDSourceType(PIDSourceType pidSource) { - m_source.setPIDSourceType(pidSource); - } - - @Override - public PIDSourceType getPIDSourceType() { - return m_source.getPIDSourceType(); - } - - @Override - public abstract double pidGet(); - - /** - * Returns the current filter estimate without also inserting new data as pidGet() would do. - * - * @return The current filter estimate - */ - public abstract double get(); - - /** Reset the filter state. */ - public abstract void reset(); - - /** - * Calls PIDGet() of source. - * - * @return Current value of source - */ - protected double pidGetSource() { - return m_source.pidGet(); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java deleted file mode 100644 index 4499f4b47f..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java +++ /dev/null @@ -1,187 +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 edu.wpi.first.wpilibj.filters; - -import edu.wpi.first.hal.FRCNetComm.tResourceType; -import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.PIDSource; -import edu.wpi.first.wpiutil.CircularBuffer; -import java.util.Arrays; - -/** - * This class implements a linear, digital filter. All types of FIR and IIR filters are supported. - * Static factory methods are provided to create commonly used types of filters. - * - *

Filters are of the form: y[n] = (b0*x[n] + b1*x[n-1] + ... + bP*x[n-P]) - (a0*y[n-1] + - * a2*y[n-2] + ... + aQ*y[n-Q]) - * - *

Where: y[n] is the output at time "n" x[n] is the input at time "n" y[n-1] is the output from - * the LAST time step ("n-1") x[n-1] is the input from the LAST time step ("n-1") b0...bP are the - * "feedforward" (FIR) gains a0...aQ are the "feedback" (IIR) gains IMPORTANT! Note the "-" sign in - * front of the feedback term! This is a common convention in signal processing. - * - *

What can linear filters do? Basically, they can filter, or diminish, the effects of - * undesirable input frequencies. High frequencies, or rapid changes, can be indicative of sensor - * noise or be otherwise undesirable. A "low pass" filter smooths out the signal, reducing the - * impact of these high frequency components. Likewise, a "high pass" filter gets rid of slow-moving - * signal components, letting you detect large changes more easily. - * - *

Example FRC applications of filters: - Getting rid of noise from an analog sensor input (note: - * the roboRIO's FPGA can do this faster in hardware) - Smoothing out joystick input to prevent the - * wheels from slipping or the robot from tipping - Smoothing motor commands so that unnecessary - * strain isn't put on electrical or mechanical components - If you use clever gains, you can make a - * PID controller out of this class! - * - *

For more on filters, I highly recommend the following articles: http://en.wikipedia - * .org/wiki/Linear_filter http://en.wikipedia.org/wiki/Iir_filter http://en.wikipedia - * .org/wiki/Fir_filter - * - *

Note 1: PIDGet() should be called by the user on a known, regular period. You can set up a - * Notifier to do this (look at the WPILib PIDController class), or do it "inline" with code in a - * periodic function. - * - *

Note 2: For ALL filters, gains are necessarily a function of frequency. If you make a filter - * that works well for you at, say, 100Hz, you will most definitely need to adjust the gains if you - * then want to run it at 200Hz! Combining this with Note 1 - the impetus is on YOU as a developer - * to make sure PIDGet() gets called at the desired, constant frequency! - * - * @deprecated Use LinearFilter class instead. - */ -@Deprecated -public class LinearDigitalFilter extends Filter { - private static int instances; - - private final CircularBuffer m_inputs; - private final CircularBuffer m_outputs; - private final double[] m_inputGains; - private final double[] m_outputGains; - - /** - * Create a linear FIR or IIR filter. - * - * @param source The PIDSource object that is used to get values - * @param ffGains The "feed forward" or FIR gains - * @param fbGains The "feed back" or IIR gains - */ - public LinearDigitalFilter(PIDSource source, double[] ffGains, double[] fbGains) { - super(source); - m_inputs = new CircularBuffer(ffGains.length); - m_outputs = new CircularBuffer(fbGains.length); - m_inputGains = Arrays.copyOf(ffGains, ffGains.length); - m_outputGains = Arrays.copyOf(fbGains, fbGains.length); - - instances++; - HAL.report(tResourceType.kResourceType_LinearFilter, instances); - } - - /** - * Creates a one-pole IIR low-pass filter of the form: y[n] = (1-gain)*x[n] + gain*y[n-1] where - * gain = e^(-dt / T), T is the time constant in seconds. - * - *

This filter is stable for time constants greater than zero. - * - * @param source The PIDSource object that is used to get values - * @param timeConstant The discrete-time time constant in seconds - * @param period The period in seconds between samples taken by the user - */ - public static LinearDigitalFilter singlePoleIIR( - PIDSource source, double timeConstant, double period) { - double gain = Math.exp(-period / timeConstant); - double[] ffGains = {1.0 - gain}; - double[] fbGains = {-gain}; - - return new LinearDigitalFilter(source, ffGains, fbGains); - } - - /** - * Creates a first-order high-pass filter of the form: y[n] = gain*x[n] + (-gain)*x[n-1] + - * gain*y[n-1] where gain = e^(-dt / T), T is the time constant in seconds. - * - *

This filter is stable for time constants greater than zero. - * - * @param source The PIDSource object that is used to get values - * @param timeConstant The discrete-time time constant in seconds - * @param period The period in seconds between samples taken by the user - */ - public static LinearDigitalFilter highPass(PIDSource source, double timeConstant, double period) { - double gain = Math.exp(-period / timeConstant); - double[] ffGains = {gain, -gain}; - double[] fbGains = {-gain}; - - return new LinearDigitalFilter(source, ffGains, fbGains); - } - - /** - * Creates a K-tap FIR moving average filter of the form: y[n] = 1/k * (x[k] + x[k-1] + ... + - * x[0]). - * - *

This filter is always stable. - * - * @param source The PIDSource object that is used to get values - * @param taps The number of samples to average over. Higher = smoother but slower - * @throws IllegalArgumentException if number of taps is less than 1 - */ - public static LinearDigitalFilter movingAverage(PIDSource source, int taps) { - if (taps <= 0) { - throw new IllegalArgumentException("Number of taps was not at least 1"); - } - - double[] ffGains = new double[taps]; - for (int i = 0; i < ffGains.length; i++) { - ffGains[i] = 1.0 / taps; - } - - double[] fbGains = new double[0]; - - return new LinearDigitalFilter(source, ffGains, fbGains); - } - - @Override - public double get() { - double retVal = 0.0; - - // Calculate the new value - for (int i = 0; i < m_inputGains.length; i++) { - retVal += m_inputs.get(i) * m_inputGains[i]; - } - for (int i = 0; i < m_outputGains.length; i++) { - retVal -= m_outputs.get(i) * m_outputGains[i]; - } - - return retVal; - } - - @Override - public void reset() { - m_inputs.clear(); - m_outputs.clear(); - } - - /** - * Calculates the next value of the filter. - * - * @return The filtered value at this step - */ - @Override - public double pidGet() { - double retVal = 0.0; - - // Rotate the inputs - m_inputs.addFirst(pidGetSource()); - - // Calculate the new value - for (int i = 0; i < m_inputGains.length; i++) { - retVal += m_inputs.get(i) * m_inputGains[i]; - } - for (int i = 0; i < m_outputGains.length; i++) { - retVal -= m_outputs.get(i) * m_outputGains[i]; - } - - // Rotate the outputs - m_outputs.addFirst(retVal); - - return retVal; - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Gyro.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Gyro.java index 8b9f9a7206..27377be03e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Gyro.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Gyro.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.interfaces; -import edu.wpi.first.wpilibj.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Rotation2d; /** Interface for yaw rate gyros. */ public interface Gyro extends AutoCloseable { @@ -50,7 +50,7 @@ public interface Gyro extends AutoCloseable { double getRate(); /** - * Return the heading of the robot as a {@link edu.wpi.first.wpilibj.geometry.Rotation2d}. + * Return the heading of the robot as a {@link edu.wpi.first.math.geometry.Rotation2d}. * *

The angle is continuous, that is it will continue from 360 to 361 degrees. This allows * algorithms that wouldn't want to see a discontinuity in the gyro output as it sweeps past from @@ -61,8 +61,7 @@ public interface Gyro extends AutoCloseable { * *

This heading is based on integration of the returned rate from the gyro. * - * @return the current heading of the robot as a {@link - * edu.wpi.first.wpilibj.geometry.Rotation2d}. + * @return the current heading of the robot as a {@link edu.wpi.first.math.geometry.Rotation2d}. */ default Rotation2d getRotation2d() { return Rotation2d.fromDegrees(-getAngle()); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Potentiometer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Potentiometer.java deleted file mode 100644 index e0178273b0..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/interfaces/Potentiometer.java +++ /dev/null @@ -1,12 +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 edu.wpi.first.wpilibj.interfaces; - -import edu.wpi.first.wpilibj.PIDSource; - -/** Interface for a Potentiometer. */ -public interface Potentiometer extends PIDSource { - double get(); -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DMC60.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/DMC60.java similarity index 75% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/DMC60.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/DMC60.java index dfe37bfb15..c003b566ed 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DMC60.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/DMC60.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * Digilent DMC 60 Speed Controller. + * Digilent DMC 60 Motor Controller. * *

Note that the DMC uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -25,7 +25,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.997ms = full "reverse" * */ -public class DMC60 extends PWMSpeedController { +public class DMC60 extends PWMMotorController { /** * Constructor. * @@ -33,14 +33,13 @@ public class DMC60 extends PWMSpeedController { * the MXP port */ public DMC60(final int channel) { - super(channel); + super("DMC60", channel); - setBounds(2.004, 1.52, 1.50, 1.48, 0.997); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_DigilentDMC60, getChannel() + 1); - SendableRegistry.setName(this, "DMC60", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Jaguar.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Jaguar.java similarity index 74% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/Jaguar.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Jaguar.java index 388b286144..32e6417edd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Jaguar.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Jaguar.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * Texas Instruments / Vex Robotics Jaguar Speed Controller as a PWM device. + * Texas Instruments / Vex Robotics Jaguar Motor Controller as a PWM device. * *

    Note that the Jaguar uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -24,7 +24,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.697ms = full "reverse" * */ -public class Jaguar extends PWMSpeedController { +public class Jaguar extends PWMMotorController { /** * Constructor. * @@ -32,14 +32,13 @@ public class Jaguar extends PWMSpeedController { * the MXP port */ public Jaguar(final int channel) { - super(channel); + super("Jaguar", channel); - setBounds(2.31, 1.55, 1.507, 1.454, 0.697); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.31, 1.55, 1.507, 1.454, 0.697); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_Jaguar, getChannel() + 1); - SendableRegistry.setName(this, "Jaguar", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/MotorController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/MotorController.java new file mode 100644 index 0000000000..09890196ff --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/MotorController.java @@ -0,0 +1,11 @@ +// 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 edu.wpi.first.wpilibj.motorcontrol; + +import edu.wpi.first.wpilibj.SpeedController; + +/** Interface for motor controlling devices. */ +@SuppressWarnings("removal") +public interface MotorController extends SpeedController {} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/MotorControllerGroup.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/MotorControllerGroup.java new file mode 100644 index 0000000000..b0b11129eb --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/MotorControllerGroup.java @@ -0,0 +1,98 @@ +// 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 edu.wpi.first.wpilibj.motorcontrol; + +import edu.wpi.first.wpilibj.Sendable; +import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; +import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import java.util.Arrays; + +/** Allows multiple {@link MotorController} objects to be linked together. */ +public class MotorControllerGroup implements MotorController, Sendable, AutoCloseable { + private boolean m_isInverted; + private final MotorController[] m_motorControllers; + private static int instances; + + /** + * Create a new MotorControllerGroup with the provided MotorControllers. + * + * @param motorControllers The MotorControllers to add + */ + @SuppressWarnings("PMD.AvoidArrayLoops") + public MotorControllerGroup( + MotorController motorController, MotorController... motorControllers) { + m_motorControllers = new MotorController[motorControllers.length + 1]; + m_motorControllers[0] = motorController; + for (int i = 0; i < motorControllers.length; i++) { + m_motorControllers[i + 1] = motorControllers[i]; + } + init(); + } + + public MotorControllerGroup(MotorController[] motorControllers) { + m_motorControllers = Arrays.copyOf(motorControllers, motorControllers.length); + init(); + } + + private void init() { + for (MotorController controller : m_motorControllers) { + SendableRegistry.addChild(this, controller); + } + instances++; + SendableRegistry.addLW(this, "MotorControllerGroup", instances); + } + + @Override + public void close() { + SendableRegistry.remove(this); + } + + @Override + public void set(double speed) { + for (MotorController motorController : m_motorControllers) { + motorController.set(m_isInverted ? -speed : speed); + } + } + + @Override + public double get() { + if (m_motorControllers.length > 0) { + return m_motorControllers[0].get() * (m_isInverted ? -1 : 1); + } + return 0.0; + } + + @Override + public void setInverted(boolean isInverted) { + m_isInverted = isInverted; + } + + @Override + public boolean getInverted() { + return m_isInverted; + } + + @Override + public void disable() { + for (MotorController motorController : m_motorControllers) { + motorController.disable(); + } + } + + @Override + public void stopMotor() { + for (MotorController motorController : m_motorControllers) { + motorController.stopMotor(); + } + } + + @Override + public void initSendable(SendableBuilder builder) { + builder.setSmartDashboardType("Motor Controller"); + builder.setActuator(true); + builder.setSafeState(this::stopMotor); + builder.addDoubleProperty("Value", this::get, this::set); + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/NidecBrushless.java similarity index 91% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/NidecBrushless.java index c051d314b7..c23827c8af 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/NidecBrushless.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/NidecBrushless.java @@ -2,16 +2,20 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; +import edu.wpi.first.wpilibj.DigitalOutput; +import edu.wpi.first.wpilibj.MotorSafety; +import edu.wpi.first.wpilibj.PWM; +import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; /** Nidec Brushless Motor. */ public class NidecBrushless extends MotorSafety - implements SpeedController, Sendable, AutoCloseable { + implements MotorController, Sendable, AutoCloseable { private boolean m_isInverted; private final DigitalOutput m_dio; private final PWM m_pwm; @@ -89,16 +93,6 @@ public class NidecBrushless extends MotorSafety return m_isInverted; } - /** - * Write out the PID value as seen in the PIDOutput base object. - * - * @param output Write out the PWM value as was found in the PIDController - */ - @Override - public void pidWrite(double output) { - set(output); - } - /** * Stop the motor. This is called by the MotorSafety object when it has a timeout for this PWM and * needs to stop it from running. Calling set() will re-enable the motor. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSpeedController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMMotorController.java similarity index 52% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSpeedController.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMMotorController.java index 1c9801fc40..34e712102c 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSpeedController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMMotorController.java @@ -2,27 +2,37 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; +import edu.wpi.first.wpilibj.MotorSafety; +import edu.wpi.first.wpilibj.PWM; +import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; +import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; -/** Common base class for all PWM Speed Controllers. */ -public abstract class PWMSpeedController extends PWM implements SpeedController { +/** Common base class for all PWM Motor Controllers. */ +public abstract class PWMMotorController extends MotorSafety + implements MotorController, Sendable, AutoCloseable { private boolean m_isInverted; + protected PWM m_pwm; /** * Constructor. * + * @param name Name to use for SendableRegistry * @param channel The PWM channel that the controller is attached to. 0-9 are on-board, 10-19 are * on the MXP port */ - protected PWMSpeedController(int channel) { - super(channel); + protected PWMMotorController(final String name, final int channel) { + m_pwm = new PWM(channel, false); + SendableRegistry.addLW(this, name, channel); } + /** Free the resource associated with the PWM channel and set the value to 0. */ @Override - public String getDescription() { - return "PWM " + getChannel(); + public void close() { + SendableRegistry.remove(this); + m_pwm.close(); } /** @@ -35,20 +45,20 @@ public abstract class PWMSpeedController extends PWM implements SpeedController */ @Override public void set(double speed) { - setSpeed(m_isInverted ? -speed : speed); + m_pwm.setSpeed(m_isInverted ? -speed : speed); feed(); } /** * Get the recently set value of the PWM. This value is affected by the inversion property. If you - * want the value that is sent directly to the SpeedController, use {@link + * want the value that is sent directly to the MotorController, use {@link * edu.wpi.first.wpilibj.PWM#getSpeed()} instead. * * @return The most recently set value for the PWM between -1.0 and 1.0. */ @Override public double get() { - return getSpeed() * (m_isInverted ? -1.0 : 1.0); + return m_pwm.getSpeed() * (m_isInverted ? -1.0 : 1.0); } @Override @@ -63,24 +73,33 @@ public abstract class PWMSpeedController extends PWM implements SpeedController @Override public void disable() { - setDisabled(); + m_pwm.setDisabled(); + } + + @Override + public void stopMotor() { + disable(); + } + + @Override + public String getDescription() { + return "PWM " + getChannel(); } /** - * Write out the PID value as seen in the PIDOutput base object. + * Gets the PWM channel number. * - * @param output Write out the PWM value as was found in the PIDController + * @return The channel number. */ - @Override - public void pidWrite(double output) { - set(output); + public int getChannel() { + return m_pwm.getChannel(); } @Override public void initSendable(SendableBuilder builder) { - builder.setSmartDashboardType("Speed Controller"); + builder.setSmartDashboardType("Motor Controller"); builder.setActuator(true); - builder.setSafeState(this::setDisabled); - builder.addDoubleProperty("Value", this::getSpeed, this::setSpeed); + builder.setSafeState(this::disable); + builder.addDoubleProperty("Value", this::get, this::set); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSparkMax.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMSparkMax.java similarity index 72% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSparkMax.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMSparkMax.java index 72a4303949..f14fdc7435 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSparkMax.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMSparkMax.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * REV Robotics SPARK MAX Speed Controller with PWM control. + * REV Robotics SPARK MAX Motor Controller with PWM control. * *

    Note that the SPARK MAX uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -25,17 +25,16 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.999ms = full "reverse" * */ -public class PWMSparkMax extends PWMSpeedController { +public class PWMSparkMax extends PWMMotorController { /** Common initialization code called by all constructors. */ public PWMSparkMax(final int channel) { - super(channel); + super("PWMSparkMax", channel); - setBounds(2.003, 1.55, 1.50, 1.46, 0.999); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.003, 1.55, 1.50, 1.46, 0.999); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_RevSparkMaxPWM, getChannel() + 1); - SendableRegistry.setName(this, "PWMSparkMax", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonFX.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMTalonFX.java similarity index 74% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonFX.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMTalonFX.java index d970f5d3e7..d5217459a1 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonFX.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMTalonFX.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * Cross the Road Electronics (CTRE) Talon FX Speed Controller with PWM control. + * Cross the Road Electronics (CTRE) Talon FX Motor Controller with PWM control. * *

    Note that the TalonFX uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -25,7 +25,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.997ms = full "reverse" * */ -public class PWMTalonFX extends PWMSpeedController { +public class PWMTalonFX extends PWMMotorController { /** * Constructor for a TalonFX connected via PWM. * @@ -33,14 +33,13 @@ public class PWMTalonFX extends PWMSpeedController { * the MXP port */ public PWMTalonFX(final int channel) { - super(channel); + super("PWMTalonFX", channel); - setBounds(2.004, 1.52, 1.50, 1.48, 0.997); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_TalonFX, getChannel() + 1); - SendableRegistry.setName(this, "PWMTalonFX", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonSRX.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMTalonSRX.java similarity index 74% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonSRX.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMTalonSRX.java index 5bf5fc620c..81f183407d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonSRX.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMTalonSRX.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * Cross the Road Electronics (CTRE) Talon SRX Speed Controller with PWM control. + * Cross the Road Electronics (CTRE) Talon SRX Motor Controller with PWM control. * *

    Note that the TalonSRX uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -25,7 +25,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.997ms = full "reverse" * */ -public class PWMTalonSRX extends PWMSpeedController { +public class PWMTalonSRX extends PWMMotorController { /** * Constructor for a TalonSRX connected via PWM. * @@ -33,14 +33,13 @@ public class PWMTalonSRX extends PWMSpeedController { * on the MXP port */ public PWMTalonSRX(final int channel) { - super(channel); + super("PWMTalonSRX", channel); - setBounds(2.004, 1.52, 1.50, 1.48, 0.997); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_PWMTalonSRX, getChannel() + 1); - SendableRegistry.setName(this, "PWMTalonSRX", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVenom.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMVenom.java similarity index 77% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVenom.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMVenom.java index cdf07754ec..9f7a885d51 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVenom.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMVenom.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** * Playing with Fusion Venom Smart Motor with PWM control. @@ -24,7 +24,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *
  • 0.997ms = full "reverse" * */ -public class PWMVenom extends PWMSpeedController { +public class PWMVenom extends PWMMotorController { /** * Constructor for a Venom connected via PWM. * @@ -32,14 +32,13 @@ public class PWMVenom extends PWMSpeedController { * the MXP port */ public PWMVenom(final int channel) { - super(channel); + super("PWMVenom", channel); - setBounds(2.004, 1.52, 1.50, 1.48, 0.997); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_FusionVenom, getChannel() + 1); - SendableRegistry.setName(this, "PWMVenom", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVictorSPX.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMVictorSPX.java similarity index 75% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVictorSPX.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMVictorSPX.java index 976eb67fc3..9880464637 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVictorSPX.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/PWMVictorSPX.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * Cross the Road Electronics (CTRE) Victor SPX Speed Controller with PWM control. + * Cross the Road Electronics (CTRE) Victor SPX Motor Controller with PWM control. * *

    Note that the Victor SPX uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -25,7 +25,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.997ms = full "reverse" * */ -public class PWMVictorSPX extends PWMSpeedController { +public class PWMVictorSPX extends PWMMotorController { /** * Constructor for a Victor SPX connected via PWM. * @@ -33,14 +33,13 @@ public class PWMVictorSPX extends PWMSpeedController { * are on the MXP port */ public PWMVictorSPX(final int channel) { - super(channel); + super("PWMVictorSPX", channel); - setBounds(2.004, 1.52, 1.50, 1.48, 0.997); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_PWMVictorSPX, getChannel() + 1); - SendableRegistry.setName(this, "PWMVictorSPX", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SD540.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/SD540.java similarity index 70% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/SD540.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/SD540.java index 58867334a5..3876dfc500 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SD540.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/SD540.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * Mindsensors SD540 Speed Controller. + * Mindsensors SD540 Motor Controller. * *

    Note that the SD540 uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -25,18 +25,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.94ms = full "reverse" * */ -public class SD540 extends PWMSpeedController { - /** Common initialization code called by all constructors. */ - protected void initSD540() { - setBounds(2.05, 1.55, 1.50, 1.44, 0.94); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); - - HAL.report(tResourceType.kResourceType_MindsensorsSD540, getChannel() + 1); - SendableRegistry.setName(this, "SD540", getChannel()); - } - +public class SD540 extends PWMMotorController { /** * Constructor. * @@ -44,7 +33,13 @@ public class SD540 extends PWMSpeedController { * the MXP port */ public SD540(final int channel) { - super(channel); - initSD540(); + super("SD540", channel); + + m_pwm.setBounds(2.05, 1.55, 1.50, 1.44, 0.94); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); + + HAL.report(tResourceType.kResourceType_MindsensorsSD540, getChannel() + 1); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Spark.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Spark.java similarity index 70% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/Spark.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Spark.java index 1e6f55c697..1b99228ce0 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Spark.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Spark.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * REV Robotics SPARK Speed Controller. + * REV Robotics SPARK Motor Controller. * *

    Note that the SPARK uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -25,18 +25,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.999ms = full "reverse" * */ -public class Spark extends PWMSpeedController { - /** Common initialization code called by all constructors. */ - protected void initSpark() { - setBounds(2.003, 1.55, 1.50, 1.46, 0.999); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); - - HAL.report(tResourceType.kResourceType_RevSPARK, getChannel() + 1); - SendableRegistry.setName(this, "Spark", getChannel()); - } - +public class Spark extends PWMMotorController { /** * Constructor. * @@ -44,7 +33,13 @@ public class Spark extends PWMSpeedController { * the MXP port */ public Spark(final int channel) { - super(channel); - initSpark(); + super("Spark", channel); + + m_pwm.setBounds(2.003, 1.55, 1.50, 1.46, 0.999); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); + + HAL.report(tResourceType.kResourceType_RevSPARK, getChannel() + 1); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Talon.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Talon.java similarity index 74% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/Talon.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Talon.java index 355e7934a2..576ba6aefa 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Talon.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Talon.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * Cross the Road Electronics (CTRE) Talon and Talon SR Speed Controller. + * Cross the Road Electronics (CTRE) Talon and Talon SR Motor Controller. * *

    Note that the Talon uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -24,7 +24,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.989ms = full "reverse" * */ -public class Talon extends PWMSpeedController { +public class Talon extends PWMMotorController { /** * Constructor for a Talon (original or Talon SR). * @@ -32,14 +32,13 @@ public class Talon extends PWMSpeedController { * the MXP port */ public Talon(final int channel) { - super(channel); + super("Talon", channel); - setBounds(2.037, 1.539, 1.513, 1.487, 0.989); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.037, 1.539, 1.513, 1.487, 0.989); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_Talon, getChannel() + 1); - SendableRegistry.setName(this, "Talon", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Victor.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Victor.java similarity index 76% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/Victor.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Victor.java index 0c4229cad7..fac6c4ff90 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Victor.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/Victor.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * VEX Robotics Victor 888 Speed Controller The Vex Robotics Victor 884 Speed Controller can also be + * VEX Robotics Victor 888 Motor Controller The Vex Robotics Victor 884 Motor Controller can also be * used with this class but may need to be calibrated per the Victor 884 user manual. * *

    Note that the Victor uses the following bounds for PWM values. These values were determined @@ -27,7 +27,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 1.026ms = full "reverse" * */ -public class Victor extends PWMSpeedController { +public class Victor extends PWMMotorController { /** * Constructor. * @@ -35,14 +35,13 @@ public class Victor extends PWMSpeedController { * the MXP port */ public Victor(final int channel) { - super(channel); + super("Victor", channel); - setBounds(2.027, 1.525, 1.507, 1.49, 1.026); - setPeriodMultiplier(PeriodMultiplier.k2X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.027, 1.525, 1.507, 1.49, 1.026); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k2X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_Victor, getChannel() + 1); - SendableRegistry.setName(this, "Victor", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/VictorSP.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/VictorSP.java similarity index 75% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/VictorSP.java rename to wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/VictorSP.java index 2f04f79370..10dba67cff 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/VictorSP.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/motorcontrol/VictorSP.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; +import edu.wpi.first.wpilibj.PWM; /** - * VEX Robotics Victor SP Speed Controller. + * VEX Robotics Victor SP Motor Controller. * *

    Note that the VictorSP uses the following bounds for PWM values. These values should work * reasonably well for most controllers, but if users experience issues such as asymmetric behavior @@ -25,7 +25,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; *

  • 0.997ms = full "reverse" * */ -public class VictorSP extends PWMSpeedController { +public class VictorSP extends PWMMotorController { /** * Constructor. * @@ -33,14 +33,13 @@ public class VictorSP extends PWMSpeedController { * the MXP port */ public VictorSP(final int channel) { - super(channel); + super("VictorSP", channel); - setBounds(2.004, 1.52, 1.50, 1.48, 0.997); - setPeriodMultiplier(PeriodMultiplier.k1X); - setSpeed(0.0); - setZeroLatch(); + m_pwm.setBounds(2.004, 1.52, 1.50, 1.48, 0.997); + m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k1X); + m_pwm.setSpeed(0.0); + m_pwm.setZeroLatch(); HAL.report(tResourceType.kResourceType_VictorSP, getChannel() + 1); - SendableRegistry.setName(this, "VictorSP", getChannel()); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInWidgets.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInWidgets.java index 84645c794e..f518a04830 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInWidgets.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInWidgets.java @@ -245,27 +245,27 @@ public enum BuiltInWidgets implements WidgetType { */ kEncoder("Encoder"), /** - * Displays a {@link edu.wpi.first.wpilibj.SpeedController SpeedController}. The speed controller - * will be controllable from the dashboard when test mode is enabled, but will otherwise be - * view-only.
    + * Displays a {@link edu.wpi.first.wpilibj.motorcontrol.MotorController MotorController}. The + * speed controller will be controllable from the dashboard when test mode is enabled, but will + * otherwise be view-only.
    * Supported types: * *
      - *
    • {@link edu.wpi.first.wpilibj.PWMSpeedController} - *
    • {@link edu.wpi.first.wpilibj.DMC60} - *
    • {@link edu.wpi.first.wpilibj.Jaguar} - *
    • {@link edu.wpi.first.wpilibj.PWMSparkMax} - *
    • {@link edu.wpi.first.wpilibj.PWMTalonFX} - *
    • {@link edu.wpi.first.wpilibj.PWMTalonSRX} - *
    • {@link edu.wpi.first.wpilibj.PWMVenom} - *
    • {@link edu.wpi.first.wpilibj.PWMVictorSPX} - *
    • {@link edu.wpi.first.wpilibj.SD540} - *
    • {@link edu.wpi.first.wpilibj.Spark} - *
    • {@link edu.wpi.first.wpilibj.Talon} - *
    • {@link edu.wpi.first.wpilibj.Victor} - *
    • {@link edu.wpi.first.wpilibj.VictorSP} - *
    • {@link edu.wpi.first.wpilibj.SpeedControllerGroup} - *
    • Any custom subclass of {@code SpeedController} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.PWMMotorController} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.DMC60} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.Jaguar} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.PWMTalonFX} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.PWMTalonSRX} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.PWMVenom} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.PWMVictorSPX} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.SD540} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.Spark} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.Talon} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.Victor} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.VictorSP} + *
    • {@link edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup} + *
    • Any custom subclass of {@code MotorController} *
    * *
    @@ -277,7 +277,7 @@ public enum BuiltInWidgets implements WidgetType { * One of {@code ["HORIZONTAL", "VERTICAL"]} * */ - kSpeedController("Speed Controller"), + kMotorController("Motor Controller"), /** * Displays a command with a toggle button. Pressing the button will start the command, and the * button will automatically release when the command completes.
    @@ -453,7 +453,7 @@ public enum BuiltInWidgets implements WidgetType { * Supported types: * *
      - *
    • {@link edu.wpi.cscore.VideoSource} (as long as it is streaming on an MJPEG server) + *
    • {@link edu.wpi.first.cscore.VideoSource} (as long as it is streaming on an MJPEG server) *
    * *
    diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapper.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapper.java index 3cfdc24b08..b80831c786 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapper.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapper.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.shuffleboard; -import edu.wpi.cscore.VideoSource; +import edu.wpi.first.cscore.VideoSource; import edu.wpi.first.wpilibj.Sendable; import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder; import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardContainer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardContainer.java index c81e372213..1f0ef5e70d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardContainer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardContainer.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.shuffleboard; -import edu.wpi.cscore.VideoSource; +import edu.wpi.first.cscore.VideoSource; import edu.wpi.first.wpilibj.Sendable; import java.util.List; import java.util.NoSuchElementException; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogEncoderSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogEncoderSim.java index 676b13c49d..12c9b6d576 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogEncoderSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogEncoderSim.java @@ -5,8 +5,8 @@ package edu.wpi.first.wpilibj.simulation; import edu.wpi.first.hal.SimDouble; +import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.wpilibj.AnalogEncoder; -import edu.wpi.first.wpilibj.geometry.Rotation2d; /** Class to control a simulated analog encoder. */ public class AnalogEncoderSim { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java index f86f496319..f0e5041133 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java @@ -4,21 +4,21 @@ package edu.wpi.first.wpilibj.simulation; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.numbers.N7; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.NumericalIntegration; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.RobotController; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.NumericalIntegration; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; -import edu.wpi.first.wpiutil.math.numbers.N7; /** * This class simulates the state of the drivetrain. In simulationPeriodic, users should first set @@ -101,9 +101,9 @@ public class DifferentialDrivetrainSim { * * @param drivetrainPlant The {@link LinearSystem} representing the robot's drivetrain. This * system can be created with {@link - * edu.wpi.first.wpilibj.system.plant.LinearSystemId#createDrivetrainVelocitySystem(DCMotor, + * edu.wpi.first.math.system.plant.LinearSystemId#createDrivetrainVelocitySystem(DCMotor, * double, double, double, double, double)} or {@link - * edu.wpi.first.wpilibj.system.plant.LinearSystemId#identifyDrivetrainSystem(double, double, + * edu.wpi.first.math.system.plant.LinearSystemId#identifyDrivetrainSystem(double, double, * double, double)}. * @param driveMotor A {@link DCMotor} representing the drivetrain. * @param gearing The gearingRatio ratio of the robot, as output over input. This must be the same diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ElevatorSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ElevatorSim.java index cc271e21a5..753d61afb7 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ElevatorSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ElevatorSim.java @@ -4,14 +4,14 @@ package edu.wpi.first.wpilibj.simulation; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.NumericalIntegration; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.NumericalIntegration; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; /** Represents a simulated elevator mechanism. */ public class ElevatorSim extends LinearSystemSim { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSim.java index 8dd7bc43dd..aaf13de0e4 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSim.java @@ -4,12 +4,12 @@ package edu.wpi.first.wpilibj.simulation; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.util.Units; /** Represents a simulated flywheel mechanism. */ public class FlywheelSim extends LinearSystemSim { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java index aec9ce7273..155ec23ca3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java @@ -4,12 +4,12 @@ package edu.wpi.first.wpilibj.simulation; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.LinearSystem; import edu.wpi.first.wpilibj.RobotController; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; import org.ejml.MatrixDimensionException; import org.ejml.simple.SimpleMatrix; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java index 4aee29fe42..84b062cafe 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java @@ -13,7 +13,6 @@ import edu.wpi.first.hal.SimValue; import edu.wpi.first.hal.simulation.SimDeviceCallback; import edu.wpi.first.hal.simulation.SimDeviceDataJNI; import edu.wpi.first.hal.simulation.SimValueCallback; -import edu.wpi.first.hal.simulation.SimValueCallback2; /** Class to control the simulation side of a SimDevice. */ public class SimDeviceSim { @@ -191,22 +190,6 @@ public class SimDeviceSim { return new CallbackStore(uid, SimDeviceDataJNI::cancelSimValueChangedCallback); } - /** - * Register a callback to be run every time a value is changed on this device. - * - * @param callback the callback - * @param initialNotify should the callback be run with the initial state - * @return the {@link CallbackStore} object associated with this callback. Save a reference to - * this object so GC doesn't cancel the callback. - */ - public CallbackStore registerValueChangedCallback2( - SimValue value, SimValueCallback2 callback, boolean initialNotify) { - int uid = - SimDeviceDataJNI.registerSimValueChangedCallback2( - value.getNativeHandle(), callback, initialNotify); - return new CallbackStore(uid, SimDeviceDataJNI::cancelSimValueChangedCallback); - } - /** * Register a callback for SimDouble.reset() and similar functions. The callback is called with * the old value. @@ -216,7 +199,7 @@ public class SimDeviceSim { * @param initialNotify ignored (present for consistency) */ public CallbackStore registerValueResetCallback( - SimValue value, SimValueCallback2 callback, boolean initialNotify) { + SimValue value, SimValueCallback callback, boolean initialNotify) { int uid = SimDeviceDataJNI.registerSimValueResetCallback( value.getNativeHandle(), callback, initialNotify); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSim.java index c0ecc9bede..3891090892 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSim.java @@ -4,14 +4,14 @@ package edu.wpi.first.wpilibj.simulation; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.NumericalIntegration; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.NumericalIntegration; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; /** Represents a simulated single jointed arm mechanism. */ public class SingleJointedArmSim extends LinearSystemSim { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/Field2d.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/Field2d.java index 01181443f6..ad4ba32e97 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/Field2d.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/Field2d.java @@ -4,10 +4,10 @@ package edu.wpi.first.wpilibj.smartdashboard; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.networktables.NetworkTable; import edu.wpi.first.wpilibj.Sendable; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; import java.util.ArrayList; import java.util.List; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/FieldObject2d.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/FieldObject2d.java index aee7e13dac..ae06494e3f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/FieldObject2d.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/FieldObject2d.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj.smartdashboard; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.trajectory.Trajectory; import edu.wpi.first.networktables.NetworkTableEntry; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.trajectory.Trajectory; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/MechanismLigament2d.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/MechanismLigament2d.java index 1a2dda0bb4..0ce2e86a38 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/MechanismLigament2d.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/MechanismLigament2d.java @@ -4,9 +4,9 @@ package edu.wpi.first.wpilibj.smartdashboard; +import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.networktables.NetworkTable; import edu.wpi.first.networktables.NetworkTableEntry; -import edu.wpi.first.wpilibj.geometry.Rotation2d; import edu.wpi.first.wpilibj.util.Color8Bit; /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java index eec2cdc774..ac031378da 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.util; -import edu.wpi.first.wpiutil.math.MathUtil; +import edu.wpi.first.math.MathUtil; import java.util.Objects; /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color8Bit.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color8Bit.java index 4e47480b6d..cd7154ddde 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color8Bit.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color8Bit.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.util; -import edu.wpi.first.wpiutil.math.MathUtil; +import edu.wpi.first.math.MathUtil; import java.util.Objects; /** Represents colors with 8 bits of precision. */ diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionRunner.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionRunner.java index 21ca13c2a1..a1002f5349 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionRunner.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionRunner.java @@ -4,9 +4,9 @@ package edu.wpi.first.wpilibj.vision; -import edu.wpi.cscore.CvSink; -import edu.wpi.cscore.VideoSource; import edu.wpi.first.cameraserver.CameraServerSharedStore; +import edu.wpi.first.cscore.CvSink; +import edu.wpi.first.cscore.VideoSource; import org.opencv.core.Mat; /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionThread.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionThread.java index 78bb961a0a..5f23fe180f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionThread.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionThread.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.vision; -import edu.wpi.cscore.VideoSource; +import edu.wpi.first.cscore.VideoSource; /** * A vision thread is a special thread that runs a vision pipeline. It is a daemon thread; it diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/package-info.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/package-info.java index 371d30e15c..ba3e1e1914 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/package-info.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/package-info.java @@ -13,7 +13,7 @@ * implements VisionRunner.Listener<MyFindTotePipeline> { * * // A USB camera connected to the roboRIO. - * private {@link edu.wpi.cscore.VideoSource VideoSource} usbCamera; + * private {@link edu.wpi.first.cscore.VideoSource VideoSource} usbCamera; * * // A vision pipeline. This could be handwritten or generated by GRIP. * // This has to implement {@link edu.wpi.first.wpilibj.vision.VisionPipeline}. diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ColorTest.java b/wpilibj/src/test/java/edu/wpi/first/math/util/ColorTest.java similarity index 95% rename from wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ColorTest.java rename to wpilibj/src/test/java/edu/wpi/first/math/util/ColorTest.java index 64001d231b..668531427d 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ColorTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/math/util/ColorTest.java @@ -2,12 +2,13 @@ // 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 edu.wpi.first.wpilibj.util; +package edu.wpi.first.math.util; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.params.provider.Arguments.arguments; +import edu.wpi.first.wpilibj.util.Color; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ErrorMessagesTest.java b/wpilibj/src/test/java/edu/wpi/first/math/util/ErrorMessagesTest.java similarity index 91% rename from wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ErrorMessagesTest.java rename to wpilibj/src/test/java/edu/wpi/first/math/util/ErrorMessagesTest.java index e68fe65eb6..5153b00f3e 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/util/ErrorMessagesTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/math/util/ErrorMessagesTest.java @@ -2,13 +2,14 @@ // 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 edu.wpi.first.wpilibj.util; +package edu.wpi.first.math.util; import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertThrows; import edu.wpi.first.wpilibj.UtilityClassTest; +import edu.wpi.first.wpilibj.util.ErrorMessages; import org.junit.jupiter.api.Test; class ErrorMessagesTest extends UtilityClassTest { diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/SpeedControllerGroupTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/SpeedControllerGroupTest.java deleted file mode 100644 index c421471a9c..0000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/SpeedControllerGroupTest.java +++ /dev/null @@ -1,112 +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 edu.wpi.first.wpilibj; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Arrays; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; -import java.util.stream.Stream; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -class SpeedControllerGroupTest { - private static Stream speedControllerArguments() { - return IntStream.of(1, 2, 3) - .mapToObj( - number -> { - SpeedController[] speedControllers = - Stream.generate(MockSpeedController::new) - .limit(number) - .toArray(SpeedController[]::new); - SpeedControllerGroup group = - new SpeedControllerGroup( - speedControllers[0], - Arrays.copyOfRange(speedControllers, 1, speedControllers.length)); - return Arguments.of(group, speedControllers); - }); - } - - @ParameterizedTest - @MethodSource("speedControllerArguments") - void setTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) { - group.set(1.0); - - assertArrayEquals( - DoubleStream.generate(() -> 1.0).limit(speedControllers.length).toArray(), - Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(), - 0.00005); - } - - @ParameterizedTest - @MethodSource("speedControllerArguments") - void getInvertedTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) { - group.setInverted(true); - - assertTrue(group.getInverted()); - } - - @ParameterizedTest - @MethodSource("speedControllerArguments") - void setInvertedDoesNotModifySpeedControllersTest( - final SpeedControllerGroup group, final SpeedController[] speedControllers) { - group.setInverted(true); - - assertArrayEquals( - Stream.generate(() -> false).limit(speedControllers.length).toArray(), - Arrays.stream(speedControllers).map(SpeedController::getInverted).toArray()); - } - - @ParameterizedTest - @MethodSource("speedControllerArguments") - void setInvertedDoesInvertTest( - final SpeedControllerGroup group, final SpeedController[] speedControllers) { - group.setInverted(true); - group.set(1.0); - - assertArrayEquals( - DoubleStream.generate(() -> -1.0).limit(speedControllers.length).toArray(), - Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(), - 0.00005); - } - - @ParameterizedTest - @MethodSource("speedControllerArguments") - void disableTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) { - group.set(1.0); - group.disable(); - - assertArrayEquals( - DoubleStream.generate(() -> 0.0).limit(speedControllers.length).toArray(), - Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(), - 0.00005); - } - - @ParameterizedTest - @MethodSource("speedControllerArguments") - void stopMotorTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) { - group.set(1.0); - group.stopMotor(); - - assertArrayEquals( - DoubleStream.generate(() -> 0.0).limit(speedControllers.length).toArray(), - Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(), - 0.00005); - } - - @ParameterizedTest - @MethodSource("speedControllerArguments") - void pidWriteTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) { - group.pidWrite(1.0); - - assertArrayEquals( - DoubleStream.generate(() -> 1.0).limit(speedControllers.length).toArray(), - Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(), - 0.00005); - } -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/HolonomicDriveControllerTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/HolonomicDriveControllerTest.java index c7610b8329..12cf829f24 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/HolonomicDriveControllerTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/HolonomicDriveControllerTest.java @@ -7,15 +7,15 @@ package edu.wpi.first.wpilibj.controller; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Twist2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.trajectory.Trajectory; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; -import edu.wpi.first.wpiutil.math.MathUtil; +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Twist2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.trajectory.Trajectory; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/ProfiledPIDControllerTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/ProfiledPIDControllerTest.java index c0f4fb04e8..c13e8b856e 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/ProfiledPIDControllerTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/ProfiledPIDControllerTest.java @@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj.controller; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import org.junit.jupiter.api.Test; class ProfiledPIDControllerTest { diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/ProfiledPIDInputOutputTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/ProfiledPIDInputOutputTest.java index 373bfc8a18..37265d494a 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/ProfiledPIDInputOutputTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/ProfiledPIDInputOutputTest.java @@ -7,7 +7,7 @@ package edu.wpi.first.wpilibj.controller; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/drive/DriveTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/drive/DriveTest.java deleted file mode 100644 index 388801a9be..0000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/drive/DriveTest.java +++ /dev/null @@ -1,265 +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 edu.wpi.first.wpilibj.drive; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import edu.wpi.first.wpilibj.MockSpeedController; -import edu.wpi.first.wpilibj.RobotDrive; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** Tests DifferentialDrive and MecanumDrive. */ -public class DriveTest { - private final MockSpeedController m_rdFrontLeft = new MockSpeedController(); - private final MockSpeedController m_rdRearLeft = new MockSpeedController(); - private final MockSpeedController m_rdFrontRight = new MockSpeedController(); - private final MockSpeedController m_rdRearRight = new MockSpeedController(); - private final MockSpeedController m_frontLeft = new MockSpeedController(); - private final MockSpeedController m_rearLeft = new MockSpeedController(); - private final MockSpeedController m_frontRight = new MockSpeedController(); - private final MockSpeedController m_rearRight = new MockSpeedController(); - private final RobotDrive m_robotDrive = - new RobotDrive(m_rdFrontLeft, m_rdRearLeft, m_rdFrontRight, m_rdRearRight); - private final DifferentialDrive m_differentialDrive = - new DifferentialDrive(m_frontLeft, m_frontRight); - private final MecanumDrive m_mecanumDrive = - new MecanumDrive(m_frontLeft, m_rearLeft, m_frontRight, m_rearRight); - - private final double[] m_testJoystickValues = {1.0, 0.9, 0.5, 0.01, 0.0, -0.01, -0.5, -0.9, -1.0}; - private final double[] m_testGyroValues = { - 0, 30, 45, 90, 135, 180, 225, 270, 305, 360, 540, -45, -90, -135, -180, -225, -270, -305, -360, - -540 - }; - - @BeforeEach - void setUp() { - m_differentialDrive.setDeadband(0.0); - m_differentialDrive.setSafetyEnabled(false); - m_mecanumDrive.setDeadband(0.0); - m_mecanumDrive.setSafetyEnabled(false); - m_robotDrive.setSafetyEnabled(false); - } - - @Test - public void testTankDriveSquared() { - for (double leftJoystick : m_testJoystickValues) { - for (double rightJoystick : m_testJoystickValues) { - m_robotDrive.tankDrive(leftJoystick, rightJoystick); - m_differentialDrive.tankDrive(leftJoystick, rightJoystick); - assertEquals( - m_rdFrontLeft.get(), - m_frontLeft.get(), - 0.01, - "Left Motor squared didn't match. Left Joystick: " - + leftJoystick - + " Right Joystick: " - + rightJoystick); - assertEquals( - m_rdFrontRight.get(), - m_frontRight.get(), - 0.01, - "Right Motor squared didn't match. Left Joystick: " - + leftJoystick - + " Right Joystick: " - + rightJoystick); - } - } - } - - @Test - void testTankDrive() { - for (double leftJoystick : m_testJoystickValues) { - for (double rightJoystick : m_testJoystickValues) { - m_robotDrive.tankDrive(leftJoystick, rightJoystick, false); - m_differentialDrive.tankDrive(leftJoystick, rightJoystick, false); - assertEquals( - m_rdFrontLeft.get(), - m_frontLeft.get(), - 0.01, - "Left Motor didn't match. Left Joystick: " - + leftJoystick - + " Right Joystick: " - + rightJoystick); - assertEquals( - m_rdFrontRight.get(), - m_frontRight.get(), - 0.01, - "Right Motor didn't match. Left Joystick: " - + leftJoystick - + " Right Joystick: " - + rightJoystick); - } - } - } - - @Test - void testArcadeDriveSquared() { - for (double moveJoystick : m_testJoystickValues) { - for (double rotateJoystick : m_testJoystickValues) { - m_robotDrive.arcadeDrive(moveJoystick, rotateJoystick); - m_differentialDrive.arcadeDrive(moveJoystick, -rotateJoystick); - assertEquals( - m_rdFrontLeft.get(), - m_frontLeft.get(), - 0.01, - "Left Motor squared didn't match. Move Joystick: " - + moveJoystick - + " Rotate Joystick: " - + rotateJoystick); - assertEquals( - m_rdFrontRight.get(), - m_frontRight.get(), - 0.01, - "Right Motor squared didn't match. Move Joystick: " - + moveJoystick - + " Rotate Joystick: " - + rotateJoystick); - } - } - } - - @Test - void testArcadeDrive() { - for (double moveJoystick : m_testJoystickValues) { - for (double rotateJoystick : m_testJoystickValues) { - m_robotDrive.arcadeDrive(moveJoystick, rotateJoystick, false); - m_differentialDrive.arcadeDrive(moveJoystick, -rotateJoystick, false); - assertEquals( - m_rdFrontLeft.get(), - m_frontLeft.get(), - 0.01, - "Left Motor didn't match. Move Joystick: " - + moveJoystick - + " Rotate Joystick: " - + rotateJoystick); - assertEquals( - m_rdFrontRight.get(), - m_frontRight.get(), - 0.01, - "Right Motor didn't match. Move Joystick: " - + moveJoystick - + " Rotate Joystick: " - + rotateJoystick); - } - } - } - - @Test - void testMecanumPolar() { - for (double magnitudeJoystick : m_testJoystickValues) { - for (double directionJoystick : m_testGyroValues) { - for (double rotationJoystick : m_testJoystickValues) { - m_robotDrive.mecanumDrive_Polar(magnitudeJoystick, directionJoystick, rotationJoystick); - m_mecanumDrive.drivePolar(magnitudeJoystick, directionJoystick, rotationJoystick); - assertEquals( - m_rdFrontLeft.get(), - m_frontLeft.get(), - 0.01, - "Left Front Motor didn't match. Magnitude Joystick: " - + magnitudeJoystick - + " Direction Joystick: " - + directionJoystick - + " RotationJoystick: " - + rotationJoystick); - assertEquals( - m_rdFrontRight.get(), - -m_frontRight.get(), - 0.01, - "Right Front Motor didn't match. Magnitude Joystick: " - + magnitudeJoystick - + " Direction Joystick: " - + directionJoystick - + " RotationJoystick: " - + rotationJoystick); - assertEquals( - m_rdRearLeft.get(), - m_rearLeft.get(), - 0.01, - "Left Rear Motor didn't match. Magnitude Joystick: " - + magnitudeJoystick - + " Direction Joystick: " - + directionJoystick - + " RotationJoystick: " - + rotationJoystick); - assertEquals( - m_rdRearRight.get(), - -m_rearRight.get(), - 0.01, - "Right Rear Motor didn't match. Magnitude Joystick: " - + magnitudeJoystick - + " Direction Joystick: " - + directionJoystick - + " RotationJoystick: " - + rotationJoystick); - } - } - } - } - - @Test - @SuppressWarnings("checkstyle:LocalVariableName") - void testMecanumCartesian() { - for (double x_Joystick : m_testJoystickValues) { - for (double y_Joystick : m_testJoystickValues) { - for (double rotationJoystick : m_testJoystickValues) { - for (double gyroValue : m_testGyroValues) { - m_robotDrive.mecanumDrive_Cartesian( - x_Joystick, y_Joystick, rotationJoystick, gyroValue); - m_mecanumDrive.driveCartesian(x_Joystick, -y_Joystick, rotationJoystick, -gyroValue); - assertEquals( - m_rdFrontLeft.get(), - m_frontLeft.get(), - 0.01, - "Left Front Motor didn't match. X Joystick: " - + x_Joystick - + " Y Joystick: " - + y_Joystick - + " RotationJoystick: " - + rotationJoystick - + " Gyro: " - + gyroValue); - assertEquals( - m_rdFrontRight.get(), - -m_frontRight.get(), - 0.01, - "Right Front Motor didn't match. X Joystick: " - + x_Joystick - + " Y Joystick: " - + y_Joystick - + " RotationJoystick: " - + rotationJoystick - + " Gyro: " - + gyroValue); - assertEquals( - m_rdRearLeft.get(), - m_rearLeft.get(), - 0.01, - "Left Rear Motor didn't match. X Joystick: " - + x_Joystick - + " Y Joystick: " - + y_Joystick - + " RotationJoystick: " - + rotationJoystick - + " Gyro: " - + gyroValue); - assertEquals( - m_rdRearRight.get(), - -m_rearRight.get(), - 0.01, - "Right Rear Motor didn't match. X Joystick: " - + x_Joystick - + " Y Joystick: " - + y_Joystick - + " RotationJoystick: " - + rotationJoystick - + " Gyro: " - + gyroValue); - } - } - } - } - } -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockSpeedController.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/motorcontrol/MockMotorController.java similarity index 80% rename from wpilibj/src/test/java/edu/wpi/first/wpilibj/MockSpeedController.java rename to wpilibj/src/test/java/edu/wpi/first/wpilibj/motorcontrol/MockMotorController.java index 4d55b9fef8..e7a6b8eb36 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/MockSpeedController.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/motorcontrol/MockMotorController.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; -public class MockSpeedController implements SpeedController { +public class MockMotorController implements MotorController { private double m_speed; private boolean m_isInverted; @@ -37,9 +37,4 @@ public class MockSpeedController implements SpeedController { public void stopMotor() { disable(); } - - @Override - public void pidWrite(double output) { - set(output); - } } diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/motorcontrol/MotorControllerGroupTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/motorcontrol/MotorControllerGroupTest.java new file mode 100644 index 0000000000..6efb3def8b --- /dev/null +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/motorcontrol/MotorControllerGroupTest.java @@ -0,0 +1,101 @@ +// 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 edu.wpi.first.wpilibj.motorcontrol; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class MotorControllerGroupTest { + private static Stream motorControllerArguments() { + return IntStream.of(1, 2, 3) + .mapToObj( + number -> { + MotorController[] motorControllers = + Stream.generate(MockMotorController::new) + .limit(number) + .toArray(MotorController[]::new); + MotorControllerGroup group = + new MotorControllerGroup( + motorControllers[0], + Arrays.copyOfRange(motorControllers, 1, motorControllers.length)); + return Arguments.of(group, motorControllers); + }); + } + + @ParameterizedTest + @MethodSource("motorControllerArguments") + void setTest(final MotorControllerGroup group, final MotorController[] motorControllers) { + group.set(1.0); + + assertArrayEquals( + DoubleStream.generate(() -> 1.0).limit(motorControllers.length).toArray(), + Arrays.stream(motorControllers).mapToDouble(MotorController::get).toArray(), + 0.00005); + } + + @ParameterizedTest + @MethodSource("motorControllerArguments") + void getInvertedTest(final MotorControllerGroup group, final MotorController[] motorControllers) { + group.setInverted(true); + + assertTrue(group.getInverted()); + } + + @ParameterizedTest + @MethodSource("motorControllerArguments") + void setInvertedDoesNotModifyMotorControllersTest( + final MotorControllerGroup group, final MotorController[] motorControllers) { + group.setInverted(true); + + assertArrayEquals( + Stream.generate(() -> false).limit(motorControllers.length).toArray(), + Arrays.stream(motorControllers).map(MotorController::getInverted).toArray()); + } + + @ParameterizedTest + @MethodSource("motorControllerArguments") + void setInvertedDoesInvertTest( + final MotorControllerGroup group, final MotorController[] motorControllers) { + group.setInverted(true); + group.set(1.0); + + assertArrayEquals( + DoubleStream.generate(() -> -1.0).limit(motorControllers.length).toArray(), + Arrays.stream(motorControllers).mapToDouble(MotorController::get).toArray(), + 0.00005); + } + + @ParameterizedTest + @MethodSource("motorControllerArguments") + void disableTest(final MotorControllerGroup group, final MotorController[] motorControllers) { + group.set(1.0); + group.disable(); + + assertArrayEquals( + DoubleStream.generate(() -> 0.0).limit(motorControllers.length).toArray(), + Arrays.stream(motorControllers).mapToDouble(MotorController::get).toArray(), + 0.00005); + } + + @ParameterizedTest + @MethodSource("motorControllerArguments") + void stopMotorTest(final MotorControllerGroup group, final MotorController[] motorControllers) { + group.set(1.0); + group.stopMotor(); + + assertArrayEquals( + DoubleStream.generate(() -> 0.0).limit(motorControllers.length).toArray(), + Arrays.stream(motorControllers).mapToDouble(MotorController::get).toArray(), + 0.00005); + } +} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogEncoderSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogEncoderSimTest.java index a5d78871c1..a3736e89af 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogEncoderSimTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogEncoderSimTest.java @@ -6,9 +6,9 @@ package edu.wpi.first.wpilibj.simulation; import static org.junit.jupiter.api.Assertions.assertEquals; +import edu.wpi.first.math.geometry.Rotation2d; import edu.wpi.first.wpilibj.AnalogEncoder; import edu.wpi.first.wpilibj.AnalogInput; -import edu.wpi.first.wpilibj.geometry.Rotation2d; import org.junit.jupiter.api.Test; public class AnalogEncoderSimTest { diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSimTest.java index f9ecdfed69..246236ae0d 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSimTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSimTest.java @@ -7,24 +7,24 @@ package edu.wpi.first.wpilibj.simulation; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.controller.LinearPlantInversionFeedforward; -import edu.wpi.first.wpilibj.controller.RamseteController; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.system.NumericalIntegration; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpilibj.trajectory.constraint.DifferentialDriveKinematicsConstraint; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.Vector; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N7; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.Vector; +import edu.wpi.first.math.controller.LinearPlantInversionFeedforward; +import edu.wpi.first.math.controller.RamseteController; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N7; +import edu.wpi.first.math.system.NumericalIntegration; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; +import edu.wpi.first.math.trajectory.constraint.DifferentialDriveKinematicsConstraint; +import edu.wpi.first.math.util.Units; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/ElevatorSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/ElevatorSimTest.java index 0b954415a5..b59b438960 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/ElevatorSimTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/ElevatorSimTest.java @@ -7,14 +7,14 @@ package edu.wpi.first.wpilibj.simulation; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMVictorSPX; import edu.wpi.first.wpilibj.RobotController; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.wpilibj.motorcontrol.PWMVictorSPX; import org.junit.jupiter.api.Test; public class ElevatorSimTest { diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSimTest.java index a1449c2d2f..26aa6b9730 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSimTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSimTest.java @@ -6,9 +6,9 @@ package edu.wpi.first.wpilibj.simulation; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.util.Units; import org.junit.jupiter.api.Test; public class SingleJointedArmSimTest { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.java index 8e0ca10eee..b1d194d024 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidcommand/ReplaceMeProfiledPIDCommand.java @@ -4,8 +4,8 @@ package edu.wpi.first.wpilibj.commands.profiledpidcommand; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj2.command.ProfiledPIDCommand; // NOTE: Consider using this command inline, rather than writing a subclass. For more diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.java index c46afd964d..38240a9c52 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/profiledpidsubsystem/ReplaceMeProfiledPIDSubsystem.java @@ -4,8 +4,8 @@ package edu.wpi.first.wpilibj.commands.profiledpidsubsystem; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj2.command.ProfiledPIDSubsystem; public class ReplaceMeProfiledPIDSubsystem extends ProfiledPIDSubsystem { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java index c31819b928..7a5571983b 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilecommand/ReplaceMeTrapezoidProfileCommand.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.commands.trapezoidprofilecommand; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj2.command.TrapezoidProfileCommand; // NOTE: Consider using this command inline, rather than writing a subclass. For more diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.java index c0660abf5b..e95f95792f 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/commands/trapezoidprofilesubsystem/ReplaceMeTrapezoidProfileSubsystem.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.commands.trapezoidprofilesubsystem; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj2.command.TrapezoidProfileSubsystem; public class ReplaceMeTrapezoidProfileSubsystem extends TrapezoidProfileSubsystem { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java index e7bd6372c5..e35243de58 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrive/Robot.java @@ -5,9 +5,9 @@ package edu.wpi.first.wpilibj.examples.arcadedrive; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a demo program showing the use of the DifferentialDrive class. Runs the motors with diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java index b382ac54ea..f78d49e25e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/arcadedrivexboxcontroller/Robot.java @@ -5,10 +5,10 @@ package edu.wpi.first.wpilibj.examples.arcadedrivexboxcontroller; import edu.wpi.first.wpilibj.GenericHID.Hand; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a demo program showing the use of the DifferentialDrive class. Runs the motors with split diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/subsystems/ArmSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/subsystems/ArmSubsystem.java index a4459a5a20..12d56c2a79 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/subsystems/ArmSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/subsystems/ArmSubsystem.java @@ -4,12 +4,12 @@ package edu.wpi.first.wpilibj.examples.armbot.subsystems; +import edu.wpi.first.math.controller.ArmFeedforward; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.controller.ArmFeedforward; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; import edu.wpi.first.wpilibj.examples.armbot.Constants.ArmConstants; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.ProfiledPIDSubsystem; /** A robot arm subsystem that moves with a motion profile. */ diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/subsystems/DriveSubsystem.java index 104b685b3f..9338f309f7 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbot/subsystems/DriveSubsystem.java @@ -5,22 +5,22 @@ package edu.wpi.first.wpilibj.examples.armbot.subsystems; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.armbot.Constants.DriveConstants; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final SpeedControllerGroup m_leftMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_leftMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kLeftMotor1Port), new PWMSparkMax(DriveConstants.kLeftMotor2Port)); // The motors on the right side of the drive. - private final SpeedControllerGroup m_rightMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_rightMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kRightMotor1Port), new PWMSparkMax(DriveConstants.kRightMotor2Port)); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/ExampleSmartMotorController.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/ExampleSmartMotorController.java index fa31d457fe..4f95b4003e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/ExampleSmartMotorController.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/ExampleSmartMotorController.java @@ -4,14 +4,14 @@ package edu.wpi.first.wpilibj.examples.armbotoffboard; -import edu.wpi.first.wpilibj.SpeedController; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; /** * A simplified stub class that simulates the API of a common "smart" motor controller. * *

    Has no actual functionality. */ -public class ExampleSmartMotorController implements SpeedController { +public class ExampleSmartMotorController implements MotorController { public enum PIDMode { kPosition, kVelocity, @@ -93,7 +93,4 @@ public class ExampleSmartMotorController implements SpeedController { @Override public void stopMotor() {} - - @Override - public void pidWrite(double output) {} } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/ArmSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/ArmSubsystem.java index acac10fabc..152700e367 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/ArmSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/ArmSubsystem.java @@ -4,10 +4,10 @@ package edu.wpi.first.wpilibj.examples.armbotoffboard.subsystems; -import edu.wpi.first.wpilibj.controller.ArmFeedforward; +import edu.wpi.first.math.controller.ArmFeedforward; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.examples.armbotoffboard.Constants.ArmConstants; import edu.wpi.first.wpilibj.examples.armbotoffboard.ExampleSmartMotorController; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj2.command.TrapezoidProfileSubsystem; /** A robot arm subsystem that moves with a motion profile. */ diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/DriveSubsystem.java index 96d90d4a83..8017719044 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armbotoffboard/subsystems/DriveSubsystem.java @@ -5,22 +5,22 @@ package edu.wpi.first.wpilibj.examples.armbotoffboard.subsystems; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.armbotoffboard.Constants.DriveConstants; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final SpeedControllerGroup m_leftMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_leftMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kLeftMotor1Port), new PWMSparkMax(DriveConstants.kLeftMotor2Port)); // The motors on the right side of the drive. - private final SpeedControllerGroup m_rightMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_rightMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kRightMotor1Port), new PWMSparkMax(DriveConstants.kRightMotor2Port)); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armsimulation/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armsimulation/Robot.java index d407854300..ad376e7528 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armsimulation/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/armsimulation/Robot.java @@ -4,19 +4,19 @@ package edu.wpi.first.wpilibj.examples.armsimulation; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.RobotController; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.controller.PIDController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj.simulation.BatterySim; import edu.wpi.first.wpilibj.simulation.EncoderSim; import edu.wpi.first.wpilibj.simulation.RoboRioSim; import edu.wpi.first.wpilibj.simulation.SingleJointedArmSim; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.VecBuilder; /** This is a sample program to demonstrate the use of elevator simulation with existing code. */ public class Robot extends TimedRobot { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/axiscamera/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/axiscamera/Robot.java index 4d827fb7b8..e2766814a4 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/axiscamera/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/axiscamera/Robot.java @@ -4,10 +4,10 @@ package edu.wpi.first.wpilibj.examples.axiscamera; -import edu.wpi.cscore.AxisCamera; -import edu.wpi.cscore.CvSink; -import edu.wpi.cscore.CvSource; import edu.wpi.first.cameraserver.CameraServer; +import edu.wpi.first.cscore.AxisCamera; +import edu.wpi.first.cscore.CvSink; +import edu.wpi.first.cscore.CvSource; import edu.wpi.first.wpilibj.TimedRobot; import org.opencv.core.Mat; import org.opencv.core.Point; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdrivebot/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdrivebot/Drivetrain.java index 759c12924d..ee5e804f70 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdrivebot/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdrivebot/Drivetrain.java @@ -4,17 +4,17 @@ package edu.wpi.first.wpilibj.examples.differentialdrivebot; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.kinematics.DifferentialDriveOdometry; +import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** Represents a differential drive style drivetrain. */ public class Drivetrain { @@ -25,18 +25,18 @@ public class Drivetrain { private static final double kWheelRadius = 0.0508; // meters private static final int kEncoderResolution = 4096; - private final SpeedController m_leftLeader = new PWMSparkMax(1); - private final SpeedController m_leftFollower = new PWMSparkMax(2); - private final SpeedController m_rightLeader = new PWMSparkMax(3); - private final SpeedController m_rightFollower = new PWMSparkMax(4); + private final MotorController m_leftLeader = new PWMSparkMax(1); + private final MotorController m_leftFollower = new PWMSparkMax(2); + private final MotorController m_rightLeader = new PWMSparkMax(3); + private final MotorController m_rightFollower = new PWMSparkMax(4); private final Encoder m_leftEncoder = new Encoder(0, 1); private final Encoder m_rightEncoder = new Encoder(2, 3); - private final SpeedControllerGroup m_leftGroup = - new SpeedControllerGroup(m_leftLeader, m_leftFollower); - private final SpeedControllerGroup m_rightGroup = - new SpeedControllerGroup(m_rightLeader, m_rightFollower); + private final MotorControllerGroup m_leftGroup = + new MotorControllerGroup(m_leftLeader, m_leftFollower); + private final MotorControllerGroup m_rightGroup = + new MotorControllerGroup(m_rightLeader, m_rightFollower); private final AnalogGyro m_gyro = new AnalogGyro(0); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java index 947abc4721..4c6e48259e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java @@ -4,22 +4,22 @@ package edu.wpi.first.wpilibj.examples.differentialdriveposeestimator; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.estimator.DifferentialDrivePoseEstimator; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.estimator.DifferentialDrivePoseEstimator; import edu.wpi.first.wpilibj.examples.swervesdriveposeestimator.ExampleGlobalMeasurementSensor; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** Represents a differential drive style drivetrain. */ public class Drivetrain { @@ -30,18 +30,18 @@ public class Drivetrain { private static final double kWheelRadius = 0.0508; // meters private static final int kEncoderResolution = 4096; - private final SpeedController m_leftLeader = new PWMSparkMax(1); - private final SpeedController m_leftFollower = new PWMSparkMax(2); - private final SpeedController m_rightLeader = new PWMSparkMax(3); - private final SpeedController m_rightFollower = new PWMSparkMax(4); + private final MotorController m_leftLeader = new PWMSparkMax(1); + private final MotorController m_leftFollower = new PWMSparkMax(2); + private final MotorController m_rightLeader = new PWMSparkMax(3); + private final MotorController m_rightFollower = new PWMSparkMax(4); private final Encoder m_leftEncoder = new Encoder(0, 1); private final Encoder m_rightEncoder = new Encoder(2, 3); - private final SpeedControllerGroup m_leftGroup = - new SpeedControllerGroup(m_leftLeader, m_leftFollower); - private final SpeedControllerGroup m_rightGroup = - new SpeedControllerGroup(m_rightLeader, m_rightFollower); + private final MotorControllerGroup m_leftGroup = + new MotorControllerGroup(m_leftLeader, m_leftFollower); + private final MotorControllerGroup m_rightGroup = + new MotorControllerGroup(m_rightLeader, m_rightFollower); private final AnalogGyro m_gyro = new AnalogGyro(0); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/ExampleSmartMotorController.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/ExampleSmartMotorController.java index bacac9e4be..487974cadb 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/ExampleSmartMotorController.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/ExampleSmartMotorController.java @@ -4,14 +4,14 @@ package edu.wpi.first.wpilibj.examples.drivedistanceoffboard; -import edu.wpi.first.wpilibj.SpeedController; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; /** * A simplified stub class that simulates the API of a common "smart" motor controller. * *

    Has no actual functionality. */ -public class ExampleSmartMotorController implements SpeedController { +public class ExampleSmartMotorController implements MotorController { public enum PIDMode { kPosition, kVelocity, @@ -97,7 +97,4 @@ public class ExampleSmartMotorController implements SpeedController { @Override public void stopMotor() {} - - @Override - public void pidWrite(double output) {} } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/RobotContainer.java index d70fdc16fd..c9705d6d18 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/RobotContainer.java @@ -6,13 +6,13 @@ package edu.wpi.first.wpilibj.examples.drivedistanceoffboard; import static edu.wpi.first.wpilibj.XboxController.Button; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.Constants.DriveConstants; import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.Constants.OIConstants; import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.commands.DriveDistanceProfiled; import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.subsystems.DriveSubsystem; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.RunCommand; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/commands/DriveDistanceProfiled.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/commands/DriveDistanceProfiled.java index 30dc602605..5bfa10d177 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/commands/DriveDistanceProfiled.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/commands/DriveDistanceProfiled.java @@ -4,9 +4,9 @@ package edu.wpi.first.wpilibj.examples.drivedistanceoffboard.commands; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.Constants.DriveConstants; import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.subsystems.DriveSubsystem; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj2.command.TrapezoidProfileCommand; /** Drives a set distance using a motion profile. */ diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/subsystems/DriveSubsystem.java index 82373a834e..9e895acb40 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/drivedistanceoffboard/subsystems/DriveSubsystem.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj.examples.drivedistanceoffboard.subsystems; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.Constants.DriveConstants; import edu.wpi.first.wpilibj.examples.drivedistanceoffboard.ExampleSmartMotorController; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class DriveSubsystem extends SubsystemBase { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorprofiledpid/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorprofiledpid/Robot.java index 06bb3cff5c..44771bc936 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorprofiledpid/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorprofiledpid/Robot.java @@ -4,20 +4,20 @@ package edu.wpi.first.wpilibj.examples.elevatorprofiledpid; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; public class Robot extends TimedRobot { private static double kDt = 0.02; private final Joystick m_joystick = new Joystick(1); private final Encoder m_encoder = new Encoder(1, 2); - private final SpeedController m_motor = new PWMSparkMax(1); + private final MotorController m_motor = new PWMSparkMax(1); // Create a PID controller whose setpoint's change is subject to maximum // velocity and acceleration constraints. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java index 5cab4a16c7..f8166c0720 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatorsimulation/Robot.java @@ -4,19 +4,19 @@ package edu.wpi.first.wpilibj.examples.elevatorsimulation; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.RobotController; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.controller.PIDController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj.simulation.BatterySim; import edu.wpi.first.wpilibj.simulation.ElevatorSim; import edu.wpi.first.wpilibj.simulation.EncoderSim; import edu.wpi.first.wpilibj.simulation.RoboRioSim; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.VecBuilder; /** This is a sample program to demonstrate the use of elevator simulation with existing code. */ public class Robot extends TimedRobot { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/ExampleSmartMotorController.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/ExampleSmartMotorController.java index 1577770e6b..a1366e6f35 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/ExampleSmartMotorController.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/ExampleSmartMotorController.java @@ -4,14 +4,14 @@ package edu.wpi.first.wpilibj.examples.elevatortrapezoidprofile; -import edu.wpi.first.wpilibj.SpeedController; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; /** * A simplified stub class that simulates the API of a common "smart" motor controller. * *

    Has no actual functionality. */ -public class ExampleSmartMotorController implements SpeedController { +public class ExampleSmartMotorController implements MotorController { public enum PIDMode { kPosition, kVelocity, @@ -93,7 +93,4 @@ public class ExampleSmartMotorController implements SpeedController { @Override public void stopMotor() {} - - @Override - public void pidWrite(double output) {} } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/Robot.java index 5c574d6211..d459eeb899 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/elevatortrapezoidprofile/Robot.java @@ -4,10 +4,10 @@ package edu.wpi.first.wpilibj.examples.elevatortrapezoidprofile; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.TimedRobot; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; public class Robot extends TimedRobot { private static double kDt = 0.02; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json index 110988d4cc..2a5d6d3045 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json @@ -12,7 +12,7 @@ }, { "name": "Tank Drive", - "description": "Demonstrate the use of the RobotDrive class doing teleop driving with tank steering", + "description": "Demonstrate the use of the DifferentialDrive class doing teleop driving with tank steering", "tags": [ "Actuators", "Joystick", @@ -37,7 +37,7 @@ }, { "name": "Mecanum Drive", - "description": "Demonstrate the use of the RobotDrive class doing teleop driving with Mecanum steering", + "description": "Demonstrate the use of the MecanumDrive class doing teleop driving with Mecanum steering", "tags": [ "Actuators", "Joystick", diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/subsystems/DriveSubsystem.java index 2fd62737a2..b1c580a9c5 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/subsystems/DriveSubsystem.java @@ -5,22 +5,22 @@ package edu.wpi.first.wpilibj.examples.frisbeebot.subsystems; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.frisbeebot.Constants.DriveConstants; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final SpeedControllerGroup m_leftMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_leftMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kLeftMotor1Port), new PWMSparkMax(DriveConstants.kLeftMotor2Port)); // The motors on the right side of the drive. - private final SpeedControllerGroup m_rightMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_rightMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kRightMotor1Port), new PWMSparkMax(DriveConstants.kRightMotor2Port)); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/subsystems/ShooterSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/subsystems/ShooterSubsystem.java index d5f4844527..8f23abcccd 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/subsystems/ShooterSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/frisbeebot/subsystems/ShooterSubsystem.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj.examples.frisbeebot.subsystems; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; import edu.wpi.first.wpilibj.examples.frisbeebot.Constants.ShooterConstants; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.PIDSubsystem; public class ShooterSubsystem extends PIDSubsystem { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java index b25c7ea428..d34d12a26e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java @@ -5,7 +5,7 @@ package edu.wpi.first.wpilibj.examples.gearsbot.subsystems; import edu.wpi.first.wpilibj.DigitalInput; -import edu.wpi.first.wpilibj.Victor; +import edu.wpi.first.wpilibj.motorcontrol.Victor; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.SubsystemBase; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java index fdbf1a51e4..b6e223c553 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java @@ -7,11 +7,11 @@ package edu.wpi.first.wpilibj.examples.gearsbot.subsystems; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.AnalogInput; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.gearsbot.Robot; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.SubsystemBase; @@ -20,11 +20,11 @@ public class DriveTrain extends SubsystemBase { * The DriveTrain subsystem incorporates the sensors and actuators attached to the robots chassis. * These include four drive motors, a left and right encoder and a gyro. */ - private final SpeedController m_leftMotor = - new SpeedControllerGroup(new PWMSparkMax(0), new PWMSparkMax(1)); + private final MotorController m_leftMotor = + new MotorControllerGroup(new PWMSparkMax(0), new PWMSparkMax(1)); - private final SpeedController m_rightMotor = - new SpeedControllerGroup(new PWMSparkMax(2), new PWMSparkMax(3)); + private final MotorController m_rightMotor = + new MotorControllerGroup(new PWMSparkMax(2), new PWMSparkMax(3)); private final DifferentialDrive m_drive = new DifferentialDrive(m_leftMotor, m_rightMotor); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java index fc38bf8717..ceb809f550 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java @@ -5,9 +5,9 @@ package edu.wpi.first.wpilibj.examples.gearsbot.subsystems; import edu.wpi.first.wpilibj.AnalogPotentiometer; -import edu.wpi.first.wpilibj.Victor; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.examples.gearsbot.Robot; +import edu.wpi.first.wpilibj.motorcontrol.Victor; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.PIDSubsystem; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java index 7421433be3..661e3944fd 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java @@ -5,9 +5,9 @@ package edu.wpi.first.wpilibj.examples.gearsbot.subsystems; import edu.wpi.first.wpilibj.AnalogPotentiometer; -import edu.wpi.first.wpilibj.Victor; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.examples.gearsbot.Robot; +import edu.wpi.first.wpilibj.motorcontrol.Victor; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.PIDSubsystem; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java index ee0678cb7b..0a9a2b034d 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Robot.java @@ -5,10 +5,10 @@ package edu.wpi.first.wpilibj.examples.gettingstarted; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * The VM is configured to automatically run this class, and to call the functions corresponding to diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java index c1f3d2d365..3d8353bd90 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Robot.java @@ -6,9 +6,9 @@ package edu.wpi.first.wpilibj.examples.gyro; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a sample program to demonstrate how to use a gyro sensor to make a robot drive straight. @@ -39,8 +39,8 @@ public class Robot extends TimedRobot { } /** - * The motor speed is set from the joystick while the RobotDrive turning value is assigned from - * the error between the setpoint and the gyro angle. + * The motor speed is set from the joystick while the DifferentialDrive turning value is assigned + * from the error between the setpoint and the gyro angle. */ @Override public void teleopPeriodic() { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/commands/TurnToAngleProfiled.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/commands/TurnToAngleProfiled.java index 14bcfed26a..671298c146 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/commands/TurnToAngleProfiled.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/commands/TurnToAngleProfiled.java @@ -4,10 +4,10 @@ package edu.wpi.first.wpilibj.examples.gyrodrivecommands.commands; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; import edu.wpi.first.wpilibj.examples.gyrodrivecommands.Constants.DriveConstants; import edu.wpi.first.wpilibj.examples.gyrodrivecommands.subsystems.DriveSubsystem; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj2.command.ProfiledPIDCommand; /** A command that will turn the robot to the specified angle using a motion profile. */ diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/subsystems/DriveSubsystem.java index 439b503673..c16034cd00 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyrodrivecommands/subsystems/DriveSubsystem.java @@ -6,23 +6,23 @@ package edu.wpi.first.wpilibj.examples.gyrodrivecommands.subsystems; import edu.wpi.first.wpilibj.ADXRS450_Gyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.gyrodrivecommands.Constants.DriveConstants; import edu.wpi.first.wpilibj.interfaces.Gyro; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final SpeedControllerGroup m_leftMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_leftMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kLeftMotor1Port), new PWMSparkMax(DriveConstants.kLeftMotor2Port)); // The motors on the right side of the drive. - private final SpeedControllerGroup m_rightMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_rightMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kRightMotor1Port), new PWMSparkMax(DriveConstants.kRightMotor2Port)); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java index b607c916ae..f4b9a97e8c 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Robot.java @@ -6,9 +6,9 @@ package edu.wpi.first.wpilibj.examples.gyromecanum; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.drive.MecanumDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a sample program that uses mecanum drive with a gyro sensor to maintain rotation diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/subsystems/DriveSubsystem.java index faa61f4e41..87767d5227 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/subsystems/DriveSubsystem.java @@ -5,22 +5,22 @@ package edu.wpi.first.wpilibj.examples.hatchbotinlined.subsystems; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.hatchbotinlined.Constants.DriveConstants; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final SpeedControllerGroup m_leftMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_leftMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kLeftMotor1Port), new PWMSparkMax(DriveConstants.kLeftMotor2Port)); // The motors on the right side of the drive. - private final SpeedControllerGroup m_rightMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_rightMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kRightMotor1Port), new PWMSparkMax(DriveConstants.kRightMotor2Port)); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/subsystems/DriveSubsystem.java index acf3189c1a..b88e9005f8 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/subsystems/DriveSubsystem.java @@ -5,22 +5,22 @@ package edu.wpi.first.wpilibj.examples.hatchbottraditional.subsystems; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.hatchbottraditional.Constants.DriveConstants; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final SpeedControllerGroup m_leftMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_leftMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kLeftMotor1Port), new PWMSparkMax(DriveConstants.kLeftMotor2Port)); // The motors on the right side of the drive. - private final SpeedControllerGroup m_rightMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_rightMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kRightMotor1Port), new PWMSparkMax(DriveConstants.kRightMotor2Port)); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/intermediatevision/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/intermediatevision/Robot.java index 6395da29b4..57ad77e11b 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/intermediatevision/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/intermediatevision/Robot.java @@ -4,10 +4,10 @@ package edu.wpi.first.wpilibj.examples.intermediatevision; -import edu.wpi.cscore.CvSink; -import edu.wpi.cscore.CvSource; -import edu.wpi.cscore.UsbCamera; import edu.wpi.first.cameraserver.CameraServer; +import edu.wpi.first.cscore.CvSink; +import edu.wpi.first.cscore.CvSource; +import edu.wpi.first.cscore.UsbCamera; import edu.wpi.first.wpilibj.TimedRobot; import org.opencv.core.Mat; import org.opencv.core.Point; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot/Drivetrain.java index ab95a7aab0..acb4a8d6b1 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot/Drivetrain.java @@ -4,17 +4,17 @@ package edu.wpi.first.wpilibj.examples.mecanumbot; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.MecanumDriveKinematics; +import edu.wpi.first.math.kinematics.MecanumDriveOdometry; +import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveWheelSpeeds; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** Represents a mecanum drive style drivetrain. */ @SuppressWarnings("PMD.TooManyFields") @@ -22,10 +22,10 @@ public class Drivetrain { public static final double kMaxSpeed = 3.0; // 3 meters per second public static final double kMaxAngularSpeed = Math.PI; // 1/2 rotation per second - private final SpeedController m_frontLeftMotor = new PWMSparkMax(1); - private final SpeedController m_frontRightMotor = new PWMSparkMax(2); - private final SpeedController m_backLeftMotor = new PWMSparkMax(3); - private final SpeedController m_backRightMotor = new PWMSparkMax(4); + private final MotorController m_frontLeftMotor = new PWMSparkMax(1); + private final MotorController m_frontRightMotor = new PWMSparkMax(2); + private final MotorController m_backLeftMotor = new PWMSparkMax(3); + private final MotorController m_backRightMotor = new PWMSparkMax(4); private final Encoder m_frontLeftEncoder = new Encoder(0, 1); private final Encoder m_frontRightEncoder = new Encoder(2, 3); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Constants.java index 5d3070fa45..895983d272 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/Constants.java @@ -4,10 +4,10 @@ package edu.wpi.first.wpilibj.examples.mecanumcontrollercommand; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.MecanumDriveKinematics; +import edu.wpi.first.math.trajectory.TrapezoidProfile; /** * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/RobotContainer.java index f66a7c98ab..a2df728252 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/RobotContainer.java @@ -4,6 +4,12 @@ package edu.wpi.first.wpilibj.examples.mecanumcontrollercommand; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.trajectory.Trajectory; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.XboxController.Button; @@ -13,12 +19,6 @@ import edu.wpi.first.wpilibj.examples.mecanumcontrollercommand.Constants.AutoCon import edu.wpi.first.wpilibj.examples.mecanumcontrollercommand.Constants.DriveConstants; import edu.wpi.first.wpilibj.examples.mecanumcontrollercommand.Constants.OIConstants; import edu.wpi.first.wpilibj.examples.mecanumcontrollercommand.subsystems.DriveSubsystem; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.trajectory.Trajectory; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.MecanumControllerCommand; import edu.wpi.first.wpilibj2.command.RunCommand; @@ -118,7 +118,7 @@ public class RobotContainer { new PIDController(DriveConstants.kPFrontRightVel, 0, 0), new PIDController(DriveConstants.kPRearRightVel, 0, 0), m_robotDrive::getCurrentWheelSpeeds, - m_robotDrive::setDriveSpeedControllersVolts, // Consumer for the output motor voltages + m_robotDrive::setDriveMotorControllersVolts, // Consumer for the output motor voltages m_robotDrive); // Reset odometry to the starting pose of the trajectory. diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/subsystems/DriveSubsystem.java index 8ee318bc6b..23da86770e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumcontrollercommand/subsystems/DriveSubsystem.java @@ -4,16 +4,16 @@ package edu.wpi.first.wpilibj.examples.mecanumcontrollercommand.subsystems; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.MecanumDriveMotorVoltages; +import edu.wpi.first.math.kinematics.MecanumDriveOdometry; +import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds; import edu.wpi.first.wpilibj.ADXRS450_Gyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.drive.MecanumDrive; import edu.wpi.first.wpilibj.examples.mecanumcontrollercommand.Constants.DriveConstants; -import edu.wpi.first.wpilibj.geometry.Pose2d; import edu.wpi.first.wpilibj.interfaces.Gyro; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveMotorVoltages; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveWheelSpeeds; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class DriveSubsystem extends SubsystemBase { @@ -117,8 +117,8 @@ public class DriveSubsystem extends SubsystemBase { } } - /** Sets the front left drive SpeedController to a voltage. */ - public void setDriveSpeedControllersVolts(MecanumDriveMotorVoltages volts) { + /** Sets the front left drive MotorController to a voltage. */ + public void setDriveMotorControllersVolts(MecanumDriveMotorVoltages volts) { m_frontLeft.setVoltage(volts.frontLeftVoltage); m_rearLeft.setVoltage(volts.rearLeftVoltage); m_frontRight.setVoltage(volts.frontRightVoltage); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Robot.java index 34bb9f5930..80c16b52fb 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Robot.java @@ -5,11 +5,11 @@ package edu.wpi.first.wpilibj.examples.mecanumdrive; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.drive.MecanumDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; -/** This is a demo program showing how to use Mecanum control with the RobotDrive class. */ +/** This is a demo program showing how to use Mecanum control with the MecanumDrive class. */ public class Robot extends TimedRobot { private static final int kFrontLeftChannel = 2; private static final int kRearLeftChannel = 3; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/Drivetrain.java index bd1a3fe8d9..547dc70dda 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/Drivetrain.java @@ -4,22 +4,22 @@ package edu.wpi.first.wpilibj.examples.mecanumdriveposeestimator; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.estimator.MecanumDrivePoseEstimator; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.MecanumDriveKinematics; +import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.estimator.MecanumDrivePoseEstimator; import edu.wpi.first.wpilibj.examples.swervesdriveposeestimator.ExampleGlobalMeasurementSensor; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveWheelSpeeds; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** Represents a mecanum drive style drivetrain. */ @SuppressWarnings("PMD.TooManyFields") @@ -27,10 +27,10 @@ public class Drivetrain { public static final double kMaxSpeed = 3.0; // 3 meters per second public static final double kMaxAngularSpeed = Math.PI; // 1/2 rotation per second - private final SpeedController m_frontLeftMotor = new PWMSparkMax(1); - private final SpeedController m_frontRightMotor = new PWMSparkMax(2); - private final SpeedController m_backLeftMotor = new PWMSparkMax(3); - private final SpeedController m_backRightMotor = new PWMSparkMax(4); + private final MotorController m_frontLeftMotor = new PWMSparkMax(1); + private final MotorController m_frontRightMotor = new PWMSparkMax(2); + private final MotorController m_backLeftMotor = new PWMSparkMax(3); + private final MotorController m_backRightMotor = new PWMSparkMax(4); private final Encoder m_frontLeftEncoder = new Encoder(0, 1); private final Encoder m_frontRightEncoder = new Encoder(2, 3); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/ExampleGlobalMeasurementSensor.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/ExampleGlobalMeasurementSensor.java index c38cf1799d..4059768b70 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/ExampleGlobalMeasurementSensor.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdriveposeestimator/ExampleGlobalMeasurementSensor.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj.examples.mecanumdriveposeestimator; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.util.Units; /** This dummy class represents a global measurement sensor, such as a computer vision solution. */ public final class ExampleGlobalMeasurementSensor { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mechanism2d/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mechanism2d/Robot.java index a7b8644786..b4d638fe06 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mechanism2d/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mechanism2d/Robot.java @@ -7,8 +7,8 @@ package edu.wpi.first.wpilibj.examples.mechanism2d; import edu.wpi.first.wpilibj.AnalogPotentiometer; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj.smartdashboard.Mechanism2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Robot.java index e9105d8bd5..9976381baf 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Robot.java @@ -5,9 +5,9 @@ package edu.wpi.first.wpilibj.examples.motorcontrol; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This sample program shows how to control a motor using a joystick. In the operator control part @@ -20,7 +20,7 @@ public class Robot extends TimedRobot { private static final int kMotorPort = 0; private static final int kJoystickPort = 0; - private SpeedController m_motor; + private MotorController m_motor; private Joystick m_joystick; @Override diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Robot.java index 1b0b617d0e..9b68965821 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Robot.java @@ -6,9 +6,9 @@ package edu.wpi.first.wpilibj.examples.motorcontrolencoder; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; /** @@ -27,7 +27,7 @@ public class Robot extends TimedRobot { private static final int kEncoderPortA = 0; private static final int kEncoderPortB = 1; - private SpeedController m_motor; + private MotorController m_motor; private Joystick m_joystick; private Encoder m_encoder; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Collector.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Collector.java index 5dd83e6373..8123b06a74 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Collector.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Collector.java @@ -6,9 +6,9 @@ package edu.wpi.first.wpilibj.examples.pacgoat.subsystems; import edu.wpi.first.wpilibj.DigitalInput; import edu.wpi.first.wpilibj.Solenoid; -import edu.wpi.first.wpilibj.SpeedController; -import edu.wpi.first.wpilibj.Victor; import edu.wpi.first.wpilibj.command.Subsystem; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.Victor; /** * The Collector subsystem has one motor for the rollers, a limit switch for ball detection, a @@ -21,7 +21,7 @@ public class Collector extends Subsystem { public static final double kReverse = -1; // Subsystem devices - private final SpeedController m_rollerMotor = new Victor(6); + private final MotorController m_rollerMotor = new Victor(6); private final DigitalInput m_ballDetector = new DigitalInput(10); private final DigitalInput m_openDetector = new DigitalInput(6); private final Solenoid m_piston = new Solenoid(1, 1); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/DriveTrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/DriveTrain.java index 2ce6a7cf41..ce671bc8ed 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/DriveTrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/DriveTrain.java @@ -8,13 +8,13 @@ import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.CounterBase.EncodingType; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.SpeedController; -import edu.wpi.first.wpilibj.SpeedControllerGroup; -import edu.wpi.first.wpilibj.Victor; import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.pacgoat.Robot; import edu.wpi.first.wpilibj.examples.pacgoat.commands.DriveWithJoystick; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.Victor; /** * The DriveTrain subsystem controls the robot's chassis and reads in information about it's speed @@ -22,14 +22,14 @@ import edu.wpi.first.wpilibj.examples.pacgoat.commands.DriveWithJoystick; */ public class DriveTrain extends Subsystem { // Subsystem devices - private final SpeedController m_frontLeftCIM = new Victor(1); - private final SpeedController m_frontRightCIM = new Victor(2); - private final SpeedController m_rearLeftCIM = new Victor(3); - private final SpeedController m_rearRightCIM = new Victor(4); - private final SpeedControllerGroup m_leftCIMs = - new SpeedControllerGroup(m_frontLeftCIM, m_rearLeftCIM); - private final SpeedControllerGroup m_rightCIMs = - new SpeedControllerGroup(m_frontRightCIM, m_rearRightCIM); + private final MotorController m_frontLeftCIM = new Victor(1); + private final MotorController m_frontRightCIM = new Victor(2); + private final MotorController m_rearLeftCIM = new Victor(3); + private final MotorController m_rearRightCIM = new Victor(4); + private final MotorControllerGroup m_leftCIMs = + new MotorControllerGroup(m_frontLeftCIM, m_rearLeftCIM); + private final MotorControllerGroup m_rightCIMs = + new MotorControllerGroup(m_frontRightCIM, m_rearRightCIM); private final DifferentialDrive m_drive; private final Encoder m_rightEncoder = new Encoder(1, 2, true, EncodingType.k4X); private final Encoder m_leftEncoder = new Encoder(3, 4, false, EncodingType.k4X); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Pivot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Pivot.java index 916ef56a1f..1e65c64068 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Pivot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/subsystems/Pivot.java @@ -6,11 +6,10 @@ package edu.wpi.first.wpilibj.examples.pacgoat.subsystems; import edu.wpi.first.wpilibj.AnalogPotentiometer; import edu.wpi.first.wpilibj.DigitalInput; -import edu.wpi.first.wpilibj.SpeedController; -import edu.wpi.first.wpilibj.Victor; import edu.wpi.first.wpilibj.command.PIDSubsystem; import edu.wpi.first.wpilibj.examples.pacgoat.Robot; -import edu.wpi.first.wpilibj.interfaces.Potentiometer; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.Victor; /** * The Pivot subsystem contains the Van-door motor and the pot for PID control of angle of the pivot @@ -29,10 +28,10 @@ public class Pivot extends PIDSubsystem { // 0 degrees is vertical facing up. // Angle increases the more forward the pivot goes. - private final Potentiometer m_pot = new AnalogPotentiometer(1); + private final AnalogPotentiometer m_pot = new AnalogPotentiometer(1); // Motor to move the pivot. - private final SpeedController m_motor = new Victor(5); + private final MotorController m_motor = new Victor(5); /** Create a new pivot subsystem. */ public Pivot() { @@ -65,7 +64,7 @@ public class Pivot extends PIDSubsystem { /** Set the motor speed based off of the PID output. */ @Override protected void usePIDOutput(double output) { - m_motor.pidWrite(output); + m_motor.set(output); } /** If the pivot is at its upper limit. */ diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Robot.java index 148a4760fd..72d06fc0d3 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Robot.java @@ -6,10 +6,10 @@ package edu.wpi.first.wpilibj.examples.potentiometerpid; import edu.wpi.first.wpilibj.AnalogInput; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.controller.PIDController; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a sample program to demonstrate how to use a soft potentiometer and a PID controller to @@ -33,7 +33,7 @@ public class Robot extends TimedRobot { private PIDController m_pidController; private AnalogInput m_potentiometer; - private SpeedController m_elevatorMotor; + private MotorController m_elevatorMotor; private Joystick m_joystick; private int m_index; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/Constants.java index e3f2a43fa9..8b73220b7b 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/Constants.java @@ -4,7 +4,7 @@ package edu.wpi.first.wpilibj.examples.ramsetecommand; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; /** * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/RobotContainer.java index 12d361e84a..a51672b26e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/RobotContainer.java @@ -6,22 +6,22 @@ package edu.wpi.first.wpilibj.examples.ramsetecommand; import static edu.wpi.first.wpilibj.XboxController.Button; +import edu.wpi.first.math.controller.RamseteController; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.trajectory.Trajectory; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; +import edu.wpi.first.math.trajectory.constraint.DifferentialDriveVoltageConstraint; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.RamseteController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; import edu.wpi.first.wpilibj.examples.ramsetecommand.Constants.AutoConstants; import edu.wpi.first.wpilibj.examples.ramsetecommand.Constants.DriveConstants; import edu.wpi.first.wpilibj.examples.ramsetecommand.Constants.OIConstants; import edu.wpi.first.wpilibj.examples.ramsetecommand.subsystems.DriveSubsystem; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.trajectory.Trajectory; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpilibj.trajectory.constraint.DifferentialDriveVoltageConstraint; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.RamseteCommand; import edu.wpi.first.wpilibj2.command.RunCommand; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/subsystems/DriveSubsystem.java index 7ccb1f27f4..f64f3b7bc0 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecommand/subsystems/DriveSubsystem.java @@ -4,28 +4,28 @@ package edu.wpi.first.wpilibj.examples.ramsetecommand.subsystems; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.DifferentialDriveOdometry; +import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; import edu.wpi.first.wpilibj.ADXRS450_Gyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.ramsetecommand.Constants.DriveConstants; -import edu.wpi.first.wpilibj.geometry.Pose2d; import edu.wpi.first.wpilibj.interfaces.Gyro; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final SpeedControllerGroup m_leftMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_leftMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kLeftMotor1Port), new PWMSparkMax(DriveConstants.kLeftMotor2Port)); // The motors on the right side of the drive. - private final SpeedControllerGroup m_rightMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_rightMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kRightMotor1Port), new PWMSparkMax(DriveConstants.kRightMotor2Port)); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Drivetrain.java index 1c40b944bb..76cf574f6f 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Drivetrain.java @@ -4,18 +4,18 @@ package edu.wpi.first.wpilibj.examples.ramsetecontroller; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.kinematics.DifferentialDriveOdometry; +import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** Represents a differential drive style drivetrain. */ public class Drivetrain { @@ -26,18 +26,18 @@ public class Drivetrain { private static final double kWheelRadius = 0.0508; // meters private static final int kEncoderResolution = 4096; - private final SpeedController m_leftLeader = new PWMSparkMax(1); - private final SpeedController m_leftFollower = new PWMSparkMax(2); - private final SpeedController m_rightLeader = new PWMSparkMax(3); - private final SpeedController m_rightFollower = new PWMSparkMax(4); + private final MotorController m_leftLeader = new PWMSparkMax(1); + private final MotorController m_leftFollower = new PWMSparkMax(2); + private final MotorController m_rightLeader = new PWMSparkMax(3); + private final MotorController m_rightFollower = new PWMSparkMax(4); private final Encoder m_leftEncoder = new Encoder(0, 1); private final Encoder m_rightEncoder = new Encoder(2, 3); - private final SpeedControllerGroup m_leftGroup = - new SpeedControllerGroup(m_leftLeader, m_leftFollower); - private final SpeedControllerGroup m_rightGroup = - new SpeedControllerGroup(m_rightLeader, m_rightFollower); + private final MotorControllerGroup m_leftGroup = + new MotorControllerGroup(m_leftLeader, m_leftFollower); + private final MotorControllerGroup m_rightGroup = + new MotorControllerGroup(m_rightLeader, m_rightFollower); private final AnalogGyro m_gyro = new AnalogGyro(0); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java index 0697473e26..14cb73ba1a 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ramsetecontroller/Robot.java @@ -4,19 +4,19 @@ package edu.wpi.first.wpilibj.examples.ramsetecontroller; +import edu.wpi.first.math.controller.RamseteController; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.trajectory.Trajectory; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.SlewRateLimiter; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.XboxController; -import edu.wpi.first.wpilibj.controller.RamseteController; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.trajectory.Trajectory; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpilibj.util.Units; import java.util.List; public class Robot extends TimedRobot { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/Drivetrain.java index 40d2d2feb1..35ea1a511d 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/romireference/subsystems/Drivetrain.java @@ -6,9 +6,9 @@ package edu.wpi.first.wpilibj.examples.romireference.subsystems; import edu.wpi.first.wpilibj.BuiltInAccelerometer; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.Spark; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.romireference.sensors.RomiGyro; +import edu.wpi.first.wpilibj.motorcontrol.Spark; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class Drivetrain extends SubsystemBase { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java index bc1704f71c..eb6a6d94c8 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java @@ -7,9 +7,9 @@ package edu.wpi.first.wpilibj.examples.shuffleboard; import edu.wpi.first.networktables.NetworkTableEntry; import edu.wpi.first.wpilibj.AnalogPotentiometer; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java index 9fa5e6b54c..221966ab59 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java @@ -4,27 +4,27 @@ package edu.wpi.first.wpilibj.examples.simpledifferentialdrivesimulation; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.kinematics.DifferentialDriveOdometry; +import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.RobotController; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj.simulation.AnalogGyroSim; import edu.wpi.first.wpilibj.simulation.DifferentialDrivetrainSim; import edu.wpi.first.wpilibj.simulation.EncoderSim; import edu.wpi.first.wpilibj.smartdashboard.Field2d; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpiutil.math.numbers.N2; @SuppressWarnings("PMD.TooManyFields") public class Drivetrain { @@ -42,10 +42,10 @@ public class Drivetrain { private final PWMSparkMax m_rightLeader = new PWMSparkMax(3); private final PWMSparkMax m_rightFollower = new PWMSparkMax(4); - private final SpeedControllerGroup m_leftGroup = - new SpeedControllerGroup(m_leftLeader, m_leftFollower); - private final SpeedControllerGroup m_rightGroup = - new SpeedControllerGroup(m_rightLeader, m_rightFollower); + private final MotorControllerGroup m_leftGroup = + new MotorControllerGroup(m_leftLeader, m_leftFollower); + private final MotorControllerGroup m_rightGroup = + new MotorControllerGroup(m_rightLeader, m_rightFollower); private final Encoder m_leftEncoder = new Encoder(0, 1); private final Encoder m_rightEncoder = new Encoder(2, 3); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Robot.java index 130721f6d8..f256cc8aff 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Robot.java @@ -4,18 +4,18 @@ package edu.wpi.first.wpilibj.examples.simpledifferentialdrivesimulation; +import edu.wpi.first.math.controller.RamseteController; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.trajectory.Trajectory; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.SlewRateLimiter; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.XboxController; -import edu.wpi.first.wpilibj.controller.RamseteController; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.trajectory.Trajectory; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; import java.util.List; public class Robot extends TimedRobot { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacearm/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacearm/Robot.java index aa43dff01f..9877906c05 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacearm/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacearm/Robot.java @@ -4,23 +4,23 @@ package edu.wpi.first.wpilibj.examples.statespacearm; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.controller.LinearQuadraticRegulator; +import edu.wpi.first.math.estimator.KalmanFilter; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.LinearSystemLoop; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.trajectory.TrapezoidProfile; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.TimedRobot; -import edu.wpi.first.wpilibj.controller.LinearQuadraticRegulator; -import edu.wpi.first.wpilibj.estimator.KalmanFilter; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.LinearSystemLoop; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a sample program to demonstrate how to use a state-space controller to control an arm. @@ -91,7 +91,7 @@ public class Robot extends TimedRobot { // An encoder set up to measure arm position in radians. private final Encoder m_encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); - private final SpeedController m_motor = new PWMSparkMax(kMotorPort); + private final MotorController m_motor = new PWMSparkMax(kMotorPort); // A joystick to read the trigger from. private final Joystick m_joystick = new Joystick(kJoystickPort); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/Constants.java index 2c8036a122..2177bd7145 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/Constants.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj.examples.statespacedifferentialdrivesimulation; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; /** * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java index 4db41a60fc..b2999708c0 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java @@ -4,22 +4,20 @@ package edu.wpi.first.wpilibj.examples.statespacedifferentialdrivesimulation; -import static edu.wpi.first.wpilibj.XboxController.Button; - +import edu.wpi.first.math.controller.RamseteController; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.trajectory.Trajectory; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; +import edu.wpi.first.math.trajectory.constraint.DifferentialDriveVoltageConstraint; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.XboxController.Button; import edu.wpi.first.wpilibj.controller.PIDController; -import edu.wpi.first.wpilibj.controller.RamseteController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; import edu.wpi.first.wpilibj.examples.statespacedifferentialdrivesimulation.subsystems.DriveSubsystem; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.trajectory.Trajectory; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpilibj.trajectory.constraint.DifferentialDriveVoltageConstraint; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.RamseteCommand; import edu.wpi.first.wpilibj2.command.RunCommand; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java index 1e70efe380..fe2fd39c79 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java @@ -4,36 +4,36 @@ package edu.wpi.first.wpilibj.examples.statespacedifferentialdrivesimulation.subsystems; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.DifferentialDriveOdometry; +import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; import edu.wpi.first.wpilibj.ADXRS450_Gyro; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.RobotBase; import edu.wpi.first.wpilibj.RobotController; -import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import edu.wpi.first.wpilibj.examples.statespacedifferentialdrivesimulation.Constants.DriveConstants; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; import edu.wpi.first.wpilibj.simulation.ADXRS450_GyroSim; import edu.wpi.first.wpilibj.simulation.DifferentialDrivetrainSim; import edu.wpi.first.wpilibj.simulation.EncoderSim; import edu.wpi.first.wpilibj.smartdashboard.Field2d; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.SubsystemBase; -import edu.wpi.first.wpiutil.math.VecBuilder; public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final SpeedControllerGroup m_leftMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_leftMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kLeftMotor1Port), new PWMSparkMax(DriveConstants.kLeftMotor2Port)); // The motors on the right side of the drive. - private final SpeedControllerGroup m_rightMotors = - new SpeedControllerGroup( + private final MotorControllerGroup m_rightMotors = + new MotorControllerGroup( new PWMSparkMax(DriveConstants.kRightMotor1Port), new PWMSparkMax(DriveConstants.kRightMotor2Port)); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceelevator/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceelevator/Robot.java index 57ce6c3ae7..f1aca19c81 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceelevator/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceelevator/Robot.java @@ -4,23 +4,23 @@ package edu.wpi.first.wpilibj.examples.statespaceelevator; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.controller.LinearQuadraticRegulator; +import edu.wpi.first.math.estimator.KalmanFilter; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.LinearSystemLoop; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.trajectory.TrapezoidProfile; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.TimedRobot; -import edu.wpi.first.wpilibj.controller.LinearQuadraticRegulator; -import edu.wpi.first.wpilibj.estimator.KalmanFilter; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.LinearSystemLoop; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a sample program to demonstrate how to use a state-space controller to control an @@ -94,7 +94,7 @@ public class Robot extends TimedRobot { // An encoder set up to measure elevator height in meters. private final Encoder m_encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); - private final SpeedController m_motor = new PWMSparkMax(kMotorPort); + private final MotorController m_motor = new PWMSparkMax(kMotorPort); // A joystick to read the trigger from. private final Joystick m_joystick = new Joystick(kJoystickPort); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java index bf1f4f78c9..06e8d29bb6 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheel/Robot.java @@ -4,21 +4,21 @@ package edu.wpi.first.wpilibj.examples.statespaceflywheel; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.controller.LinearQuadraticRegulator; +import edu.wpi.first.math.estimator.KalmanFilter; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.LinearSystemLoop; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.TimedRobot; -import edu.wpi.first.wpilibj.controller.LinearQuadraticRegulator; -import edu.wpi.first.wpilibj.estimator.KalmanFilter; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.LinearSystemLoop; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a sample program to demonstrate how to use a state-space controller to control a @@ -77,7 +77,7 @@ public class Robot extends TimedRobot { // An encoder set up to measure flywheel velocity in radians per second. private final Encoder m_encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); - private final SpeedController m_motor = new PWMSparkMax(kMotorPort); + private final MotorController m_motor = new PWMSparkMax(kMotorPort); // A joystick to read the trigger from. private final Joystick m_joystick = new Joystick(kJoystickPort); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheelsysid/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheelsysid/Robot.java index 9c080346ee..538f3f7484 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheelsysid/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespaceflywheelsysid/Robot.java @@ -4,20 +4,20 @@ package edu.wpi.first.wpilibj.examples.statespaceflywheelsysid; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.controller.LinearQuadraticRegulator; +import edu.wpi.first.math.estimator.KalmanFilter; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.LinearSystemLoop; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.TimedRobot; -import edu.wpi.first.wpilibj.controller.LinearQuadraticRegulator; -import edu.wpi.first.wpilibj.estimator.KalmanFilter; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.LinearSystemLoop; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a sample program to demonstrate how to use a state-space controller to control a @@ -72,7 +72,7 @@ public class Robot extends TimedRobot { // An encoder set up to measure flywheel velocity in radians per second. private final Encoder m_encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); - private final SpeedController m_motor = new PWMSparkMax(kMotorPort); + private final MotorController m_motor = new PWMSparkMax(kMotorPort); // A joystick to read the trigger from. private final Joystick m_joystick = new Joystick(kJoystickPort); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/Drivetrain.java index 10ab169224..acfff2112e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/Drivetrain.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj.examples.swervebot; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.kinematics.SwerveDriveOdometry; import edu.wpi.first.wpilibj.AnalogGyro; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveOdometry; /** Represents a swerve drive style drivetrain. */ public class Drivetrain { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java index 887001c090..9fcf669d23 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervebot/SwerveModule.java @@ -4,15 +4,15 @@ package edu.wpi.first.wpilibj.examples.swervebot; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.SwerveModuleState; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.SwerveModuleState; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; public class SwerveModule { private static final double kWheelRadius = 0.0508; @@ -22,8 +22,8 @@ public class SwerveModule { private static final double kModuleMaxAngularAcceleration = 2 * Math.PI; // radians per second squared - private final SpeedController m_driveMotor; - private final SpeedController m_turningMotor; + private final MotorController m_driveMotor; + private final MotorController m_turningMotor; private final Encoder m_driveEncoder = new Encoder(0, 1); private final Encoder m_turningEncoder = new Encoder(2, 3); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Constants.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Constants.java index 3352deed82..40a352237c 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Constants.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/Constants.java @@ -4,9 +4,9 @@ package edu.wpi.first.wpilibj.examples.swervecontrollercommand; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.trajectory.TrapezoidProfile; /** * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/RobotContainer.java index 20075a95d3..3a8f903dc0 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/RobotContainer.java @@ -4,6 +4,12 @@ package edu.wpi.first.wpilibj.examples.swervecontrollercommand; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.trajectory.Trajectory; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.controller.PIDController; @@ -12,12 +18,6 @@ import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.AutoCons import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.DriveConstants; import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.OIConstants; import edu.wpi.first.wpilibj.examples.swervecontrollercommand.subsystems.DriveSubsystem; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.trajectory.Trajectory; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.SwerveControllerCommand; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/DriveSubsystem.java index e65ea481f1..0484ae6da3 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/DriveSubsystem.java @@ -4,14 +4,14 @@ package edu.wpi.first.wpilibj.examples.swervecontrollercommand.subsystems; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.kinematics.SwerveDriveOdometry; +import edu.wpi.first.math.kinematics.SwerveModuleState; import edu.wpi.first.wpilibj.ADXRS450_Gyro; import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.DriveConstants; -import edu.wpi.first.wpilibj.geometry.Pose2d; import edu.wpi.first.wpilibj.interfaces.Gyro; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveOdometry; -import edu.wpi.first.wpilibj.kinematics.SwerveModuleState; import edu.wpi.first.wpilibj2.command.SubsystemBase; @SuppressWarnings("PMD.ExcessiveImports") diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/SwerveModule.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/SwerveModule.java index 4ec1545da0..2bc737f42b 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/SwerveModule.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervecontrollercommand/subsystems/SwerveModule.java @@ -4,14 +4,14 @@ package edu.wpi.first.wpilibj.examples.swervecontrollercommand.subsystems; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.SwerveModuleState; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.Spark; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.ModuleConstants; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.SwerveModuleState; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.wpilibj.motorcontrol.Spark; public class SwerveModule { private final Spark m_driveMotor; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/Drivetrain.java index 3900225268..dd6843be8a 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/Drivetrain.java @@ -4,15 +4,15 @@ package edu.wpi.first.wpilibj.examples.swervesdriveposeestimator; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.estimator.SwerveDrivePoseEstimator; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.util.Units; import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj.estimator.SwerveDrivePoseEstimator; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.VecBuilder; /** Represents a swerve drive style drivetrain. */ public class Drivetrain { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/ExampleGlobalMeasurementSensor.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/ExampleGlobalMeasurementSensor.java index 232d6fd22f..3aeceb8564 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/ExampleGlobalMeasurementSensor.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/ExampleGlobalMeasurementSensor.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj.examples.swervesdriveposeestimator; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.util.Units; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.util.Units; /** This dummy class represents a global measurement sensor, such as a computer vision solution. */ public final class ExampleGlobalMeasurementSensor { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/SwerveModule.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/SwerveModule.java index 236de7df97..3110bc2040 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/SwerveModule.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/swervesdriveposeestimator/SwerveModule.java @@ -4,15 +4,15 @@ package edu.wpi.first.wpilibj.examples.swervesdriveposeestimator; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.SwerveModuleState; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.PWMSparkMax; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.controller.ProfiledPIDController; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.SwerveModuleState; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; public class SwerveModule { private static final double kWheelRadius = 0.0508; @@ -22,8 +22,8 @@ public class SwerveModule { private static final double kModuleMaxAngularAcceleration = 2 * Math.PI; // radians per second squared - private final SpeedController m_driveMotor; - private final SpeedController m_turningMotor; + private final MotorController m_driveMotor; + private final MotorController m_turningMotor; private final Encoder m_driveEncoder = new Encoder(0, 1); private final Encoder m_turningEncoder = new Encoder(2, 3); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Robot.java index 71bf29084e..1d934ff68a 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Robot.java @@ -5,13 +5,13 @@ package edu.wpi.first.wpilibj.examples.tankdrive; import edu.wpi.first.wpilibj.Joystick; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** - * This is a demo program showing the use of the RobotDrive class, specifically it contains the code - * necessary to operate a robot with tank drive. + * This is a demo program showing the use of the DifferentialDrive class, specifically it contains + * the code necessary to operate a robot with tank drive. */ public class Robot extends TimedRobot { private DifferentialDrive m_myRobot; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrivexboxcontroller/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrivexboxcontroller/Robot.java index e54d44da66..a2579f38a8 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrivexboxcontroller/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrivexboxcontroller/Robot.java @@ -5,10 +5,10 @@ package edu.wpi.first.wpilibj.examples.tankdrivexboxcontroller; import edu.wpi.first.wpilibj.GenericHID.Hand; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a demo program showing the use of the DifferentialDrive class. Runs the motors with tank diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java index 58de666e31..199d6f6a93 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java @@ -4,11 +4,11 @@ package edu.wpi.first.wpilibj.examples.ultrasonic; +import edu.wpi.first.math.filter.MedianFilter; import edu.wpi.first.wpilibj.AnalogInput; -import edu.wpi.first.wpilibj.MedianFilter; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a sample program demonstrating how to use an ultrasonic sensor and proportional control diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Robot.java index c1fcb60804..61e2bf7818 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Robot.java @@ -4,12 +4,12 @@ package edu.wpi.first.wpilibj.examples.ultrasonicpid; +import edu.wpi.first.math.filter.MedianFilter; import edu.wpi.first.wpilibj.AnalogInput; -import edu.wpi.first.wpilibj.MedianFilter; -import edu.wpi.first.wpilibj.PWMSparkMax; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; /** * This is a sample program to demonstrate the use of a PIDController with an ultrasonic sensor to diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romicommandbased/subsystems/RomiDrivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romicommandbased/subsystems/RomiDrivetrain.java index 3d256e0cf3..80543c6f3c 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romicommandbased/subsystems/RomiDrivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romicommandbased/subsystems/RomiDrivetrain.java @@ -5,8 +5,8 @@ package edu.wpi.first.wpilibj.templates.romicommandbased.subsystems; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.Spark; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.Spark; import edu.wpi.first.wpilibj2.command.SubsystemBase; public class RomiDrivetrain extends SubsystemBase { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romitimed/RomiDrivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romitimed/RomiDrivetrain.java index 84d627280a..96c81b1bb0 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romitimed/RomiDrivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/romitimed/RomiDrivetrain.java @@ -5,8 +5,8 @@ package edu.wpi.first.wpilibj.templates.romitimed; import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.Spark; import edu.wpi.first.wpilibj.drive.DifferentialDrive; +import edu.wpi.first.wpilibj.motorcontrol.Spark; public class RomiDrivetrain { private static final double kCountsPerRevolution = 1440.0; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java index 87e594dfac..690ec42cb1 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorEncoderTest.java @@ -8,11 +8,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.math.filter.LinearFilter; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture; import edu.wpi.first.wpilibj.test.AbstractComsSetup; import edu.wpi.first.wpilibj.test.TestBench; -import edu.wpi.first.wpiutil.math.MathUtil; import java.util.Arrays; import java.util.Collection; import java.util.logging.Logger; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorInvertingTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorInvertingTest.java index dc44ecbe71..af9a272254 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorInvertingTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MotorInvertingTest.java @@ -20,7 +20,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -/** Tests Inversion of motors using the SpeedController setInverted. */ +/** Tests Inversion of motors using the MotorController setInverted. */ @RunWith(Parameterized.class) public class MotorInvertingTest extends AbstractComsSetup { static MotorEncoderFixture fixture = null; diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java index 1c30544a65..127e4c21bb 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/PDPTest.java @@ -70,7 +70,7 @@ public class PDPTest extends AbstractComsSetup { /** Test if the current changes when the motor is driven using a talon. */ @Test - public void checkStoppedCurrentForSpeedController() throws CANMessageNotFoundException { + public void checkStoppedCurrentForMotorController() throws CANMessageNotFoundException { Timer.delay(0.25); /* The Current should be 0 */ @@ -83,7 +83,7 @@ public class PDPTest extends AbstractComsSetup { /** Test if the current changes when the motor is driven using a talon. */ @Test - public void checkRunningCurrentForSpeedController() throws CANMessageNotFoundException { + public void checkRunningCurrentForMotorController() throws CANMessageNotFoundException { /* Set the motor to full forward */ me.getMotor().set(1.0); Timer.delay(2); diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/MotorEncoderFixture.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/MotorEncoderFixture.java index fcc5b2cd6e..492c2d5c3e 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/MotorEncoderFixture.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/fixtures/MotorEncoderFixture.java @@ -8,8 +8,8 @@ import edu.wpi.first.wpilibj.Counter; import edu.wpi.first.wpilibj.DigitalInput; import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.PWM; -import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj.motorcontrol.MotorController; import edu.wpi.first.wpilibj.test.TestBench; import java.lang.reflect.ParameterizedType; import java.util.logging.Logger; @@ -22,7 +22,7 @@ import java.util.logging.Logger; * fixture. This allows tests to be mailable so that you can easily reconfigure the physical testbed * without breaking the tests. */ -public abstract class MotorEncoderFixture implements ITestFixture { +public abstract class MotorEncoderFixture implements ITestFixture { private static final Logger logger = Logger.getLogger(MotorEncoderFixture.class.getName()); private boolean m_initialized = false; private boolean m_tornDown = false; @@ -39,12 +39,12 @@ public abstract class MotorEncoderFixture implements /** * Where the implementer of this class should pass the speed controller Constructor should only be - * called from outside this class if the Speed controller is not also an implementation of PWM + * called from outside this class if the Motor controller is not also an implementation of PWM * interface. * - * @return SpeedController + * @return MotorController */ - protected abstract T giveSpeedController(); + protected abstract T giveMotorController(); /** * Where the implementer of this class should pass one of the digital inputs. @@ -76,7 +76,7 @@ public abstract class MotorEncoderFixture implements m_counters[0] = new Counter(m_alphaSource); m_counters[1] = new Counter(m_betaSource); logger.fine("Creating the speed controller!"); - m_motor = giveSpeedController(); + m_motor = giveMotorController(); } } } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MockSpeedController.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/motorcontrol/MockMotorController.java similarity index 80% rename from wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MockSpeedController.java rename to wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/motorcontrol/MockMotorController.java index 4d55b9fef8..e7a6b8eb36 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/MockSpeedController.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/motorcontrol/MockMotorController.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.motorcontrol; -public class MockSpeedController implements SpeedController { +public class MockMotorController implements MotorController { private double m_speed; private boolean m_isInverted; @@ -37,9 +37,4 @@ public class MockSpeedController implements SpeedController { public void stopMotor() { disable(); } - - @Override - public void pidWrite(double output) { - set(output); - } } diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestBench.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestBench.java index bee3787076..89713c6945 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestBench.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestBench.java @@ -8,16 +8,16 @@ import edu.wpi.first.wpilibj.AnalogGyro; import edu.wpi.first.wpilibj.AnalogInput; import edu.wpi.first.wpilibj.AnalogOutput; import edu.wpi.first.wpilibj.DigitalInput; -import edu.wpi.first.wpilibj.Jaguar; import edu.wpi.first.wpilibj.Relay; import edu.wpi.first.wpilibj.Servo; -import edu.wpi.first.wpilibj.Talon; -import edu.wpi.first.wpilibj.Victor; import edu.wpi.first.wpilibj.fixtures.AnalogCrossConnectFixture; import edu.wpi.first.wpilibj.fixtures.DIOCrossConnectFixture; import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture; import edu.wpi.first.wpilibj.fixtures.RelayCrossConnectFixture; import edu.wpi.first.wpilibj.fixtures.TiltPanCameraFixture; +import edu.wpi.first.wpilibj.motorcontrol.Jaguar; +import edu.wpi.first.wpilibj.motorcontrol.Talon; +import edu.wpi.first.wpilibj.motorcontrol.Victor; import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; @@ -74,7 +74,7 @@ public final class TestBench { public MotorEncoderFixture getTalonPair() { return new MotorEncoderFixture() { @Override - protected Talon giveSpeedController() { + protected Talon giveMotorController() { return new Talon(kTalonChannel); } @@ -104,7 +104,7 @@ public final class TestBench { public MotorEncoderFixture getVictorPair() { return new MotorEncoderFixture() { @Override - protected Victor giveSpeedController() { + protected Victor giveMotorController() { return new Victor(kVictorChannel); } @@ -134,7 +134,7 @@ public final class TestBench { public MotorEncoderFixture getJaguarPair() { return new MotorEncoderFixture() { @Override - protected Jaguar giveSpeedController() { + protected Jaguar giveMotorController() { return new Jaguar(kJaguarChannel); } diff --git a/wpimath/build.gradle b/wpimath/build.gradle index 8464f87e08..2e002ca461 100644 --- a/wpimath/build.gradle +++ b/wpimath/build.gradle @@ -5,7 +5,7 @@ ext { groupId = 'edu.wpi.first.wpimath' nativeName = 'wpimath' - devMain = 'edu.wpi.first.wpiutil.math.DevMain' + devMain = 'edu.wpi.first.math.DevMain' } apply from: "${rootDir}/shared/jni/setupBuild.gradle" @@ -69,8 +69,8 @@ dependencies { def wpilibNumberFileInput = file("src/generate/GenericNumber.java.in") def natFileInput = file("src/generate/Nat.java.in") def natGetterInput = file("src/generate/NatGetter.java.in") -def wpilibNumberFileOutputDir = file("$buildDir/generated/java/edu/wpi/first/wpiutil/math/numbers") -def wpilibNatFileOutput = file("$buildDir/generated/java/edu/wpi/first/wpiutil/math/Nat.java") +def wpilibNumberFileOutputDir = file("$buildDir/generated/java/edu/wpi/first/math/numbers") +def wpilibNatFileOutput = file("$buildDir/generated/java/edu/wpi/first/math/Nat.java") def maxNum = 20 task generateNumbers() { @@ -111,7 +111,7 @@ task generateNat() { def importsString = ""; for(i in 0..maxNum) { - importsString += "import edu.wpi.first.wpiutil.math.numbers.N${i};\n" + importsString += "import edu.wpi.first.math.numbers.N${i};\n" template += natGetterInput.text.replace('${num}', i.toString()) + "\n" } template += "}\n" // Close the class body diff --git a/wpimath/generate_numbers.py b/wpimath/generate_numbers.py index 701f3e652b..14c9cb7cd8 100644 --- a/wpimath/generate_numbers.py +++ b/wpimath/generate_numbers.py @@ -11,7 +11,7 @@ def main(): with open(f"{dirname}/src/generate/GenericNumber.java.in", "r") as templateFile: template = templateFile.read() - rootPath = f"{cmake_binary_dir}/generated/main/java/edu/wpi/first/wpiutil/math/numbers" + rootPath = f"{cmake_binary_dir}/generated/main/java/edu/wpi/first/math/numbers" if not os.path.exists(rootPath): os.makedirs(rootPath) @@ -30,7 +30,7 @@ def main(): with open(f"{dirname}/src/generate/Nat.java.in", "r") as templateFile: template = templateFile.read() - outputPath = f"{cmake_binary_dir}/generated/main/java/edu/wpi/first/wpiutil/math/Nat.java" + outputPath = f"{cmake_binary_dir}/generated/main/java/edu/wpi/first/math/Nat.java" with open(f"{dirname}/src/generate/NatGetter.java.in", "r") as getterFile: getter = getterFile.read() @@ -38,7 +38,7 @@ def main(): importsString = "" for i in range(MAX_NUM + 1): - importsString += f"import edu.wpi.first.wpiutil.math.numbers.N{i};\n" + importsString += f"import edu.wpi.first.math.numbers.N{i};\n" template += getter.replace("${num}", str(i)) template += "}\n" diff --git a/wpimath/src/dev/java/edu/wpi/first/wpiutil/math/DevMain.java b/wpimath/src/dev/java/edu/wpi/first/math/DevMain.java similarity index 92% rename from wpimath/src/dev/java/edu/wpi/first/wpiutil/math/DevMain.java rename to wpimath/src/dev/java/edu/wpi/first/math/DevMain.java index b2a8254917..c7b779e007 100644 --- a/wpimath/src/dev/java/edu/wpi/first/wpiutil/math/DevMain.java +++ b/wpimath/src/dev/java/edu/wpi/first/math/DevMain.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; public final class DevMain { /** Main entry point. */ diff --git a/wpimath/src/generate/GenericNumber.java.in b/wpimath/src/generate/GenericNumber.java.in index 5a36582e4d..3bdc1b6ba2 100644 --- a/wpimath/src/generate/GenericNumber.java.in +++ b/wpimath/src/generate/GenericNumber.java.in @@ -5,10 +5,10 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -package edu.wpi.first.wpiutil.math.numbers; +package edu.wpi.first.math.numbers; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; /** * A class representing the number ${num}. diff --git a/wpimath/src/generate/Nat.java.in b/wpimath/src/generate/Nat.java.in index 666bd1c32a..2719df0c39 100644 --- a/wpimath/src/generate/Nat.java.in +++ b/wpimath/src/generate/Nat.java.in @@ -5,7 +5,7 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -package edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; //CHECKSTYLE.OFF: ImportOrder {{REPLACEWITHIMPORTS}} diff --git a/wpimath/src/main/java/edu/wpi/first/math/Drake.java b/wpimath/src/main/java/edu/wpi/first/math/Drake.java index 70c07391df..886f7da6f4 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/Drake.java +++ b/wpimath/src/main/java/edu/wpi/first/math/Drake.java @@ -4,8 +4,6 @@ package edu.wpi.first.math; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Num; import org.ejml.simple.SimpleMatrix; public final class Drake { diff --git a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/MatBuilder.java b/wpimath/src/main/java/edu/wpi/first/math/MatBuilder.java similarity index 97% rename from wpimath/src/main/java/edu/wpi/first/wpiutil/math/MatBuilder.java rename to wpimath/src/main/java/edu/wpi/first/math/MatBuilder.java index b75ef91ce6..e5b195224c 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/MatBuilder.java +++ b/wpimath/src/main/java/edu/wpi/first/math/MatBuilder.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; import java.util.Objects; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java b/wpimath/src/main/java/edu/wpi/first/math/MathUtil.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java rename to wpimath/src/main/java/edu/wpi/first/math/MathUtil.java index c57ca98422..c4a661a125 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java +++ b/wpimath/src/main/java/edu/wpi/first/math/MathUtil.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; public final class MathUtil { private MathUtil() { diff --git a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/Matrix.java b/wpimath/src/main/java/edu/wpi/first/math/Matrix.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpiutil/math/Matrix.java rename to wpimath/src/main/java/edu/wpi/first/math/Matrix.java index a49273d3ff..be9d56d66c 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/Matrix.java +++ b/wpimath/src/main/java/edu/wpi/first/math/Matrix.java @@ -2,10 +2,9 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; -import edu.wpi.first.math.WPIMathJNI; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.numbers.N1; import java.util.Objects; import org.ejml.MatrixDimensionException; import org.ejml.data.DMatrixRMaj; diff --git a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/MatrixUtils.java b/wpimath/src/main/java/edu/wpi/first/math/MatrixUtils.java similarity index 97% rename from wpimath/src/main/java/edu/wpi/first/wpiutil/math/MatrixUtils.java rename to wpimath/src/main/java/edu/wpi/first/math/MatrixUtils.java index ac0e5fd670..7600e31573 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/MatrixUtils.java +++ b/wpimath/src/main/java/edu/wpi/first/math/MatrixUtils.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.numbers.N1; import java.util.Objects; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/Num.java b/wpimath/src/main/java/edu/wpi/first/math/Num.java similarity index 91% rename from wpimath/src/main/java/edu/wpi/first/wpiutil/math/Num.java rename to wpimath/src/main/java/edu/wpi/first/math/Num.java index 8201255e09..ef0fd2d815 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/Num.java +++ b/wpimath/src/main/java/edu/wpi/first/math/Num.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; /** A number expressed as a java class. */ public abstract class Num { diff --git a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/Pair.java b/wpimath/src/main/java/edu/wpi/first/math/Pair.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpiutil/math/Pair.java rename to wpimath/src/main/java/edu/wpi/first/math/Pair.java index 26229a047d..d1a68c7099 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/Pair.java +++ b/wpimath/src/main/java/edu/wpi/first/math/Pair.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; public class Pair { private final A m_first; diff --git a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/SimpleMatrixUtils.java b/wpimath/src/main/java/edu/wpi/first/math/SimpleMatrixUtils.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpiutil/math/SimpleMatrixUtils.java rename to wpimath/src/main/java/edu/wpi/first/math/SimpleMatrixUtils.java index eb042aaac2..c93ad320b9 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/SimpleMatrixUtils.java +++ b/wpimath/src/main/java/edu/wpi/first/math/SimpleMatrixUtils.java @@ -2,9 +2,8 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; -import edu.wpi.first.math.WPIMathJNI; import java.util.function.BiFunction; import org.ejml.data.DMatrixRMaj; import org.ejml.dense.row.NormOps_DDRM; diff --git a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/VecBuilder.java b/wpimath/src/main/java/edu/wpi/first/math/VecBuilder.java similarity index 91% rename from wpimath/src/main/java/edu/wpi/first/wpiutil/math/VecBuilder.java rename to wpimath/src/main/java/edu/wpi/first/math/VecBuilder.java index 29e5a7a6a1..7bf10615ba 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/VecBuilder.java +++ b/wpimath/src/main/java/edu/wpi/first/math/VecBuilder.java @@ -2,18 +2,18 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N10; -import edu.wpi.first.wpiutil.math.numbers.N2; -import edu.wpi.first.wpiutil.math.numbers.N3; -import edu.wpi.first.wpiutil.math.numbers.N4; -import edu.wpi.first.wpiutil.math.numbers.N5; -import edu.wpi.first.wpiutil.math.numbers.N6; -import edu.wpi.first.wpiutil.math.numbers.N7; -import edu.wpi.first.wpiutil.math.numbers.N8; -import edu.wpi.first.wpiutil.math.numbers.N9; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N10; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.numbers.N3; +import edu.wpi.first.math.numbers.N4; +import edu.wpi.first.math.numbers.N5; +import edu.wpi.first.math.numbers.N6; +import edu.wpi.first.math.numbers.N7; +import edu.wpi.first.math.numbers.N8; +import edu.wpi.first.math.numbers.N9; /** * A specialization of {@link MatBuilder} for constructing vectors (Nx1 matrices). diff --git a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/Vector.java b/wpimath/src/main/java/edu/wpi/first/math/Vector.java similarity index 95% rename from wpimath/src/main/java/edu/wpi/first/wpiutil/math/Vector.java rename to wpimath/src/main/java/edu/wpi/first/math/Vector.java index 276ee34f6e..b2d989a039 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpiutil/math/Vector.java +++ b/wpimath/src/main/java/edu/wpi/first/math/Vector.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.numbers.N1; import org.ejml.simple.SimpleMatrix; /** diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/ArmFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/controller/ArmFeedforward.java rename to wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java index 967b1742f4..2991511237 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/ArmFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; /** * A helper class that computes feedforward outputs for a simple arm (modeled as a motor acting diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/ControlAffinePlantInversionFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/controller/ControlAffinePlantInversionFeedforward.java rename to wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java index 9b3dc8c460..c01638ce10 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/ControlAffinePlantInversionFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; -import edu.wpi.first.wpilibj.system.NumericalJacobian; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.NumericalJacobian; import java.util.function.BiFunction; import java.util.function.Function; @@ -17,7 +17,7 @@ import java.util.function.Function; * *

    If given the vector valued function as f(x, u) where x is the state vector and u is the input * vector, the B matrix(continuous input matrix) is calculated through a {@link - * edu.wpi.first.wpilibj.system.NumericalJacobian}. In this case f has to be control-affine (of the + * edu.wpi.first.math.system.NumericalJacobian}. In this case f has to be control-affine (of the * form f(x) + Bu). * *

    The feedforward is calculated as u_ff = B+ (rDot - f(x)), where diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/ElevatorFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/controller/ElevatorFeedforward.java rename to wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java index ebab615e6b..248015f134 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/ElevatorFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; /** * A helper class that computes feedforward outputs for a simple elevator (modeled as a motor acting diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/LinearPlantInversionFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforward.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/controller/LinearPlantInversionFeedforward.java rename to wpimath/src/main/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforward.java index 00d041f471..8610c58c64 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/LinearPlantInversionFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforward.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.LinearSystem; import org.ejml.simple.SimpleMatrix; /** diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/LinearQuadraticRegulator.java b/wpimath/src/main/java/edu/wpi/first/math/controller/LinearQuadraticRegulator.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/controller/LinearQuadraticRegulator.java rename to wpimath/src/main/java/edu/wpi/first/math/controller/LinearQuadraticRegulator.java index 0d6eca348f..5aa19e92ec 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/LinearQuadraticRegulator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/LinearQuadraticRegulator.java @@ -2,17 +2,17 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; import edu.wpi.first.math.Drake; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.Vector; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.Vector; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.LinearSystem; import org.ejml.simple.SimpleMatrix; /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/RamseteController.java b/wpimath/src/main/java/edu/wpi/first/math/controller/RamseteController.java similarity index 96% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/RamseteController.java rename to wpimath/src/main/java/edu/wpi/first/math/controller/RamseteController.java index 7f875874b3..086f8206a9 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/controller/RamseteController.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/RamseteController.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.trajectory.Trajectory; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.trajectory.Trajectory; /** * Ramsete is a nonlinear time-varying feedback controller for unicycle models that drives the model diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/SimpleMotorFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/controller/SimpleMotorFeedforward.java rename to wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java index 5c28f68fad..85bdcf32a2 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/controller/SimpleMotorFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; /** A helper class that computes feedforward outputs for a simple permanent-magnet DC motor. */ @SuppressWarnings("MemberName") diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/AngleStatistics.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/AngleStatistics.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/AngleStatistics.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/AngleStatistics.java index c7077108bf..ce28dd48dc 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/AngleStatistics.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/AngleStatistics.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; -import edu.wpi.first.wpiutil.math.MathUtil; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.numbers.N1; import java.util.function.BiFunction; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/DifferentialDrivePoseEstimator.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimator.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/DifferentialDrivePoseEstimator.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimator.java index 66873dec41..d78d254e12 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/DifferentialDrivePoseEstimator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimator.java @@ -2,29 +2,29 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; +import edu.wpi.first.math.MatBuilder; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N3; +import edu.wpi.first.math.numbers.N5; import edu.wpi.first.wpiutil.WPIUtilJNI; -import edu.wpi.first.wpiutil.math.MatBuilder; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N3; -import edu.wpi.first.wpiutil.math.numbers.N5; import java.util.function.BiConsumer; /** - * This class wraps an {@link edu.wpi.first.wpilibj.estimator.UnscentedKalmanFilter Unscented Kalman + * This class wraps an {@link edu.wpi.first.math.estimator.UnscentedKalmanFilter Unscented Kalman * Filter} to fuse latency-compensated vision measurements with differential drive encoder * measurements. It will correct for noisy vision measurements and encoder drift. It is intended to - * be an easy drop-in for {@link edu.wpi.first.wpilibj.kinematics.DifferentialDriveOdometry}; in - * fact, if you never call {@link DifferentialDrivePoseEstimator#addVisionMeasurement} and only call + * be an easy drop-in for {@link edu.wpi.first.math.kinematics.DifferentialDriveOdometry}; in fact, + * if you never call {@link DifferentialDrivePoseEstimator#addVisionMeasurement} and only call * {@link DifferentialDrivePoseEstimator#update} then this will behave exactly the same as * DifferentialDriveOdometry. * diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/ExtendedKalmanFilter.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/ExtendedKalmanFilter.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/ExtendedKalmanFilter.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/ExtendedKalmanFilter.java index 2f3343c982..325159ec20 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/ExtendedKalmanFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/ExtendedKalmanFilter.java @@ -2,17 +2,17 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import edu.wpi.first.math.Drake; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.system.NumericalIntegration; -import edu.wpi.first.wpilibj.system.NumericalJacobian; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.NumericalIntegration; +import edu.wpi.first.math.system.NumericalJacobian; import java.util.function.BiFunction; /** diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/KalmanFilter.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilter.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/KalmanFilter.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilter.java index f98d40c47c..197bb9367e 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/KalmanFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilter.java @@ -2,17 +2,17 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import edu.wpi.first.math.Drake; import edu.wpi.first.math.MathSharedStore; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.LinearSystem; /** * A Kalman filter combines predictions from a model and measurements to give an estimate of the diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/KalmanFilterLatencyCompensator.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilterLatencyCompensator.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/KalmanFilterLatencyCompensator.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilterLatencyCompensator.java index 29685d33e6..52ebb5c063 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/KalmanFilterLatencyCompensator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanFilterLatencyCompensator.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.numbers.N1; import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/KalmanTypeFilter.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanTypeFilter.java similarity index 81% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/KalmanTypeFilter.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanTypeFilter.java index 25de57a317..3fd3957d71 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/KalmanTypeFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/KalmanTypeFilter.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.numbers.N1; @SuppressWarnings({"ParameterName", "InterfaceTypeParameterName"}) interface KalmanTypeFilter { diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/MecanumDrivePoseEstimator.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimator.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/MecanumDrivePoseEstimator.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimator.java index afca17dae9..79dcccefb0 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/MecanumDrivePoseEstimator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimator.java @@ -2,28 +2,28 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveWheelSpeeds; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.MecanumDriveKinematics; +import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N3; import edu.wpi.first.wpiutil.WPIUtilJNI; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N3; import java.util.function.BiConsumer; /** * This class wraps an {@link UnscentedKalmanFilter Unscented Kalman Filter} to fuse * latency-compensated vision measurements with mecanum drive encoder velocity measurements. It will * correct for noisy measurements and encoder drift. It is intended to be an easy but more accurate - * drop-in for {@link edu.wpi.first.wpilibj.kinematics.MecanumDriveOdometry}. + * drop-in for {@link edu.wpi.first.math.kinematics.MecanumDriveOdometry}. * *

    {@link MecanumDrivePoseEstimator#update} should be called every robot loop. If your loops are * faster or slower than the default of 0.02s, then you should change the nominal delta time using diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/MerweScaledSigmaPoints.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/MerweScaledSigmaPoints.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/MerweScaledSigmaPoints.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/MerweScaledSigmaPoints.java index 95fcb71681..daaadb457c 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/MerweScaledSigmaPoints.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/MerweScaledSigmaPoints.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.numbers.N1; import org.ejml.simple.SimpleMatrix; /** diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/SwerveDrivePoseEstimator.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimator.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/SwerveDrivePoseEstimator.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimator.java index 958e8357e7..40afdadb5d 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/SwerveDrivePoseEstimator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimator.java @@ -2,28 +2,28 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.SwerveModuleState; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.kinematics.SwerveModuleState; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N3; import edu.wpi.first.wpiutil.WPIUtilJNI; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N3; import java.util.function.BiConsumer; /** * This class wraps an {@link UnscentedKalmanFilter Unscented Kalman Filter} to fuse * latency-compensated vision measurements with swerve drive encoder velocity measurements. It will * correct for noisy measurements and encoder drift. It is intended to be an easy but more accurate - * drop-in for {@link edu.wpi.first.wpilibj.kinematics.SwerveDriveOdometry}. + * drop-in for {@link edu.wpi.first.math.kinematics.SwerveDriveOdometry}. * *

    {@link SwerveDrivePoseEstimator#update} should be called every robot loop. If your loops are * faster or slower than the default of 0.02s, then you should change the nominal delta time using diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/UnscentedKalmanFilter.java b/wpimath/src/main/java/edu/wpi/first/math/estimator/UnscentedKalmanFilter.java similarity index 97% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/UnscentedKalmanFilter.java rename to wpimath/src/main/java/edu/wpi/first/math/estimator/UnscentedKalmanFilter.java index 146fbbe64e..c242e05ee6 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/estimator/UnscentedKalmanFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/estimator/UnscentedKalmanFilter.java @@ -2,17 +2,17 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.system.NumericalIntegration; -import edu.wpi.first.wpilibj.system.NumericalJacobian; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.Pair; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.Pair; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.NumericalIntegration; +import edu.wpi.first.math.system.NumericalJacobian; import java.util.function.BiFunction; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/LinearFilter.java b/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/LinearFilter.java rename to wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java index 1f782d5281..ffb9178cc3 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/LinearFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.math.filter; import edu.wpi.first.math.MathSharedStore; import edu.wpi.first.math.MathUsageId; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/MedianFilter.java b/wpimath/src/main/java/edu/wpi/first/math/filter/MedianFilter.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/MedianFilter.java rename to wpimath/src/main/java/edu/wpi/first/math/filter/MedianFilter.java index 7c285834a9..b9c4198191 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/MedianFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/filter/MedianFilter.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.math.filter; import edu.wpi.first.wpiutil.CircularBuffer; import java.util.ArrayList; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Pose2d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Pose2d.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Pose2d.java rename to wpimath/src/main/java/edu/wpi/first/math/geometry/Pose2d.java index 8f5687607e..6033b898f1 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Pose2d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Pose2d.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Rotation2d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation2d.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Rotation2d.java rename to wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation2d.java index c4c83a811c..74ef228919 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Rotation2d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation2d.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Transform2d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Transform2d.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Transform2d.java rename to wpimath/src/main/java/edu/wpi/first/math/geometry/Transform2d.java index 19dd4d6056..2eb69dab60 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Transform2d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Transform2d.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import java.util.Objects; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Translation2d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Translation2d.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Translation2d.java rename to wpimath/src/main/java/edu/wpi/first/math/geometry/Translation2d.java index 23723a7216..251c078671 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Translation2d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Translation2d.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Twist2d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Twist2d.java similarity index 97% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Twist2d.java rename to wpimath/src/main/java/edu/wpi/first/math/geometry/Twist2d.java index 2d2a56ebf0..c73d23629a 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/geometry/Twist2d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Twist2d.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import java.util.Objects; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/ChassisSpeeds.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java similarity index 97% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/ChassisSpeeds.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java index 5723ca3369..451c008006 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/ChassisSpeeds.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; -import edu.wpi.first.wpilibj.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Rotation2d; /** * Represents the speed of a robot chassis. Although this struct contains similar members compared diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveKinematics.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/DifferentialDriveKinematics.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveKinematics.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/DifferentialDriveKinematics.java index 29d6f14925..7984e396c9 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveKinematics.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/DifferentialDriveKinematics.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import edu.wpi.first.math.MathSharedStore; import edu.wpi.first.math.MathUsageId; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveOdometry.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/DifferentialDriveOdometry.java similarity index 95% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveOdometry.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/DifferentialDriveOdometry.java index fe0af3c285..01395735a6 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveOdometry.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/DifferentialDriveOdometry.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import edu.wpi.first.math.MathSharedStore; import edu.wpi.first.math.MathUsageId; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Twist2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Twist2d; /** * Class for differential drive odometry. Odometry allows you to track the robot's position on the diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveWheelSpeeds.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/DifferentialDriveWheelSpeeds.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveWheelSpeeds.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/DifferentialDriveWheelSpeeds.java index 82ab4eb600..b84eeba3ad 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveWheelSpeeds.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/DifferentialDriveWheelSpeeds.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; /** Represents the wheel speeds for a differential drive drivetrain. */ @SuppressWarnings("MemberName") diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveKinematics.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveKinematics.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveKinematics.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveKinematics.java index eea3f2e280..d613135fbb 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveKinematics.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveKinematics.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import edu.wpi.first.math.MathSharedStore; import edu.wpi.first.math.MathUsageId; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Translation2d; import org.ejml.simple.SimpleMatrix; /** diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveMotorVoltages.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveMotorVoltages.java similarity index 97% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveMotorVoltages.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveMotorVoltages.java index 5696c96935..b504acc71d 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveMotorVoltages.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveMotorVoltages.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; /** Represents the motor voltages for a mecanum drive drivetrain. */ @SuppressWarnings("MemberName") diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveOdometry.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveOdometry.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveOdometry.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveOdometry.java index b2dcc8649e..7bf9b5b7f0 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveOdometry.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveOdometry.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import edu.wpi.first.math.MathSharedStore; import edu.wpi.first.math.MathUsageId; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Twist2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Twist2d; import edu.wpi.first.wpiutil.WPIUtilJNI; /** diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveWheelSpeeds.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveWheelSpeeds.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveWheelSpeeds.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveWheelSpeeds.java index b9f753ea25..7a159fe661 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveWheelSpeeds.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/MecanumDriveWheelSpeeds.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import java.util.stream.DoubleStream; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveKinematics.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveKinematics.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java index fdaf2ec782..5acb6eebbf 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveKinematics.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import edu.wpi.first.math.MathSharedStore; import edu.wpi.first.math.MathUsageId; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; import java.util.Arrays; import java.util.Collections; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveOdometry.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveOdometry.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveOdometry.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveOdometry.java index 0dd4a0098f..df5c0e115a 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveOdometry.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveOdometry.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import edu.wpi.first.math.MathSharedStore; import edu.wpi.first.math.MathUsageId; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Twist2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Twist2d; import edu.wpi.first.wpiutil.WPIUtilJNI; /** diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveModuleState.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveModuleState.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveModuleState.java rename to wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveModuleState.java index 2c800376d4..d005f18866 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/kinematics/SwerveModuleState.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveModuleState.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; -import edu.wpi.first.wpilibj.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Rotation2d; /** Represents the state of one swerve module. */ @SuppressWarnings("MemberName") diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/math/Discretization.java b/wpimath/src/main/java/edu/wpi/first/math/math/Discretization.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/math/Discretization.java rename to wpimath/src/main/java/edu/wpi/first/math/math/Discretization.java index b32548730b..25c85eb372 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/math/Discretization.java +++ b/wpimath/src/main/java/edu/wpi/first/math/math/Discretization.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.math; +package edu.wpi.first.math.math; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.Pair; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.Pair; import org.ejml.simple.SimpleMatrix; @SuppressWarnings({"ParameterName", "MethodTypeParameterName"}) diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/math/StateSpaceUtil.java b/wpimath/src/main/java/edu/wpi/first/math/math/StateSpaceUtil.java similarity index 93% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/math/StateSpaceUtil.java rename to wpimath/src/main/java/edu/wpi/first/math/math/StateSpaceUtil.java index 827927a598..3739482d9a 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/math/StateSpaceUtil.java +++ b/wpimath/src/main/java/edu/wpi/first/math/math/StateSpaceUtil.java @@ -2,18 +2,18 @@ // 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 edu.wpi.first.wpilibj.math; +package edu.wpi.first.math.math; +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.VecBuilder; import edu.wpi.first.math.WPIMathJNI; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpiutil.math.MathUtil; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N3; -import edu.wpi.first.wpiutil.math.numbers.N4; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N3; +import edu.wpi.first.math.numbers.N4; import java.util.Random; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/CubicHermiteSpline.java b/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/spline/CubicHermiteSpline.java rename to wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java index 44b549723e..9bbeaf6032 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/CubicHermiteSpline.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/CubicHermiteSpline.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.spline; +package edu.wpi.first.math.spline; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/PoseWithCurvature.java b/wpimath/src/main/java/edu/wpi/first/math/spline/PoseWithCurvature.java similarity index 91% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/spline/PoseWithCurvature.java rename to wpimath/src/main/java/edu/wpi/first/math/spline/PoseWithCurvature.java index 1a1ce62be3..8bad7b159b 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/PoseWithCurvature.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/PoseWithCurvature.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpilibj.spline; +package edu.wpi.first.math.spline; -import edu.wpi.first.wpilibj.geometry.Pose2d; +import edu.wpi.first.math.geometry.Pose2d; /** Represents a pair of a pose and a curvature. */ @SuppressWarnings("MemberName") diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/QuinticHermiteSpline.java b/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/spline/QuinticHermiteSpline.java rename to wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java index d189a4fdf4..40170443f6 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/QuinticHermiteSpline.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/QuinticHermiteSpline.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.spline; +package edu.wpi.first.math.spline; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/Spline.java b/wpimath/src/main/java/edu/wpi/first/math/spline/Spline.java similarity index 95% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/spline/Spline.java rename to wpimath/src/main/java/edu/wpi/first/math/spline/Spline.java index 495d463781..5451eea46b 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/Spline.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/Spline.java @@ -2,10 +2,10 @@ // 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 edu.wpi.first.wpilibj.spline; +package edu.wpi.first.math.spline; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; import java.util.Arrays; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/SplineHelper.java b/wpimath/src/main/java/edu/wpi/first/math/spline/SplineHelper.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/spline/SplineHelper.java rename to wpimath/src/main/java/edu/wpi/first/math/spline/SplineHelper.java index af9ee84ee3..ed023cc181 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/SplineHelper.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/SplineHelper.java @@ -2,10 +2,10 @@ // 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 edu.wpi.first.wpilibj.spline; +package edu.wpi.first.math.spline; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Translation2d; import java.util.Arrays; import java.util.List; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/SplineParameterizer.java b/wpimath/src/main/java/edu/wpi/first/math/spline/SplineParameterizer.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/spline/SplineParameterizer.java rename to wpimath/src/main/java/edu/wpi/first/math/spline/SplineParameterizer.java index 23675bcb08..171f0c4486 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/spline/SplineParameterizer.java +++ b/wpimath/src/main/java/edu/wpi/first/math/spline/SplineParameterizer.java @@ -26,7 +26,7 @@ * SOFTWARE. */ -package edu.wpi.first.wpilibj.spline; +package edu.wpi.first.math.spline; import java.util.ArrayDeque; import java.util.ArrayList; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/LinearSystem.java b/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystem.java similarity index 95% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/system/LinearSystem.java rename to wpimath/src/main/java/edu/wpi/first/math/system/LinearSystem.java index bd20199b85..395f2bb53a 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/LinearSystem.java +++ b/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystem.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.system; +package edu.wpi.first.math.system; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.numbers.N1; @SuppressWarnings("ClassTypeParameterName") public class LinearSystem { diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/LinearSystemLoop.java b/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystemLoop.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/system/LinearSystemLoop.java rename to wpimath/src/main/java/edu/wpi/first/math/system/LinearSystemLoop.java index a40a63f4e4..ea67468cbb 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/LinearSystemLoop.java +++ b/wpimath/src/main/java/edu/wpi/first/math/system/LinearSystemLoop.java @@ -2,15 +2,15 @@ // 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 edu.wpi.first.wpilibj.system; +package edu.wpi.first.math.system; -import edu.wpi.first.wpilibj.controller.LinearPlantInversionFeedforward; -import edu.wpi.first.wpilibj.controller.LinearQuadraticRegulator; -import edu.wpi.first.wpilibj.estimator.KalmanFilter; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.controller.LinearPlantInversionFeedforward; +import edu.wpi.first.math.controller.LinearQuadraticRegulator; +import edu.wpi.first.math.estimator.KalmanFilter; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; import java.util.function.Function; import org.ejml.MatrixDimensionException; import org.ejml.simple.SimpleMatrix; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/NumericalIntegration.java b/wpimath/src/main/java/edu/wpi/first/math/system/NumericalIntegration.java similarity index 97% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/system/NumericalIntegration.java rename to wpimath/src/main/java/edu/wpi/first/math/system/NumericalIntegration.java index 5b52ee47fb..608c2f6e22 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/NumericalIntegration.java +++ b/wpimath/src/main/java/edu/wpi/first/math/system/NumericalIntegration.java @@ -2,15 +2,15 @@ // 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 edu.wpi.first.wpilibj.system; +package edu.wpi.first.math.system; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.Pair; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N5; -import edu.wpi.first.wpiutil.math.numbers.N6; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.Pair; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N5; +import edu.wpi.first.math.numbers.N6; import java.util.function.BiFunction; import java.util.function.DoubleFunction; import java.util.function.Function; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/NumericalJacobian.java b/wpimath/src/main/java/edu/wpi/first/math/system/NumericalJacobian.java similarity index 95% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/system/NumericalJacobian.java rename to wpimath/src/main/java/edu/wpi/first/math/system/NumericalJacobian.java index 97ef58ba09..6c2c896edb 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/NumericalJacobian.java +++ b/wpimath/src/main/java/edu/wpi/first/math/system/NumericalJacobian.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.system; +package edu.wpi.first.math.system; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.Num; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.Num; +import edu.wpi.first.math.numbers.N1; import java.util.function.BiFunction; import java.util.function.Function; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/plant/DCMotor.java b/wpimath/src/main/java/edu/wpi/first/math/system/plant/DCMotor.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/system/plant/DCMotor.java rename to wpimath/src/main/java/edu/wpi/first/math/system/plant/DCMotor.java index c4683a1c52..579a4ad566 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/plant/DCMotor.java +++ b/wpimath/src/main/java/edu/wpi/first/math/system/plant/DCMotor.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpilibj.system.plant; +package edu.wpi.first.math.system.plant; -import edu.wpi.first.wpilibj.util.Units; +import edu.wpi.first.math.util.Units; /** Holds the constants for a DC motor. */ public class DCMotor { diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/plant/LinearSystemId.java b/wpimath/src/main/java/edu/wpi/first/math/system/plant/LinearSystemId.java similarity index 95% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/system/plant/LinearSystemId.java rename to wpimath/src/main/java/edu/wpi/first/math/system/plant/LinearSystemId.java index 01a5bf4ec9..fc517f4928 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/system/plant/LinearSystemId.java +++ b/wpimath/src/main/java/edu/wpi/first/math/system/plant/LinearSystemId.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj.system.plant; +package edu.wpi.first.math.system.plant; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; public final class LinearSystemId { private LinearSystemId() { @@ -137,7 +137,7 @@ public final class LinearSystemId { * inputs are [voltage], and outputs are [velocity]. * *

    The distance unit you choose MUST be an SI unit (i.e. meters or radians). You can use the - * {@link edu.wpi.first.wpilibj.util.Units} class for converting between unit types. + * {@link edu.wpi.first.math.util.Units} class for converting between unit types. * * @param kV The velocity gain, in volts per (units per second) * @param kA The acceleration gain, in volts per (units per second squared) @@ -160,7 +160,7 @@ public final class LinearSystemId { * velocity]^T, inputs are [voltage], and outputs are [position]. * *

    The distance unit you choose MUST be an SI unit (i.e. meters or radians). You can use the - * {@link edu.wpi.first.wpilibj.util.Units} class for converting between unit types. + * {@link edu.wpi.first.math.util.Units} class for converting between unit types. * * @param kV The velocity gain, in volts per (units per second) * @param kA The acceleration gain, in volts per (units per second squared) diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/Trajectory.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/Trajectory.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/Trajectory.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/Trajectory.java index 15b4119aa5..5c1f67663b 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/Trajectory.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/Trajectory.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import com.fasterxml.jackson.annotation.JsonProperty; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Transform2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Transform2d; import java.util.ArrayList; import java.util.List; import java.util.Objects; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryConfig.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryConfig.java similarity index 90% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryConfig.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryConfig.java index 9cf359a2e9..fbf734fd31 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryConfig.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryConfig.java @@ -2,15 +2,15 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; -import edu.wpi.first.wpilibj.trajectory.constraint.DifferentialDriveKinematicsConstraint; -import edu.wpi.first.wpilibj.trajectory.constraint.MecanumDriveKinematicsConstraint; -import edu.wpi.first.wpilibj.trajectory.constraint.SwerveDriveKinematicsConstraint; -import edu.wpi.first.wpilibj.trajectory.constraint.TrajectoryConstraint; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.kinematics.MecanumDriveKinematics; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.trajectory.constraint.DifferentialDriveKinematicsConstraint; +import edu.wpi.first.math.trajectory.constraint.MecanumDriveKinematicsConstraint; +import edu.wpi.first.math.trajectory.constraint.SwerveDriveKinematicsConstraint; +import edu.wpi.first.math.trajectory.constraint.TrajectoryConstraint; import java.util.ArrayList; import java.util.List; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGenerator.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryGenerator.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGenerator.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryGenerator.java index b20b866676..e50c0020f6 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGenerator.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryGenerator.java @@ -2,18 +2,18 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import edu.wpi.first.math.MathSharedStore; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Transform2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.spline.PoseWithCurvature; -import edu.wpi.first.wpilibj.spline.Spline; -import edu.wpi.first.wpilibj.spline.SplineHelper; -import edu.wpi.first.wpilibj.spline.SplineParameterizer; -import edu.wpi.first.wpilibj.spline.SplineParameterizer.MalformedSplineException; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Transform2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.spline.PoseWithCurvature; +import edu.wpi.first.math.spline.Spline; +import edu.wpi.first.math.spline.SplineHelper; +import edu.wpi.first.math.spline.SplineParameterizer; +import edu.wpi.first.math.spline.SplineParameterizer.MalformedSplineException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryParameterizer.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryParameterizer.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryParameterizer.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryParameterizer.java index cfad464295..eb1a645ea4 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryParameterizer.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryParameterizer.java @@ -26,10 +26,10 @@ * SOFTWARE. */ -package edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; -import edu.wpi.first.wpilibj.spline.PoseWithCurvature; -import edu.wpi.first.wpilibj.trajectory.constraint.TrajectoryConstraint; +import edu.wpi.first.math.spline.PoseWithCurvature; +import edu.wpi.first.math.trajectory.constraint.TrajectoryConstraint; import java.util.ArrayList; import java.util.List; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryUtil.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryUtil.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryUtil.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryUtil.java index b9b14fd826..953245aecc 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryUtil.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryUtil.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import edu.wpi.first.math.WPIMathJNI; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfile.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrapezoidProfile.java similarity index 99% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfile.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/TrapezoidProfile.java index f9ddb8a765..e0e464a215 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfile.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrapezoidProfile.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import edu.wpi.first.math.MathSharedStore; import edu.wpi.first.math.MathUsageId; diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/CentripetalAccelerationConstraint.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/CentripetalAccelerationConstraint.java similarity index 96% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/CentripetalAccelerationConstraint.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/CentripetalAccelerationConstraint.java index 7b1ae798b3..13138e84ce 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/CentripetalAccelerationConstraint.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/CentripetalAccelerationConstraint.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpilibj.trajectory.constraint; +package edu.wpi.first.math.trajectory.constraint; -import edu.wpi.first.wpilibj.geometry.Pose2d; +import edu.wpi.first.math.geometry.Pose2d; /** * A constraint on the maximum absolute centripetal acceleration allowed when traversing a diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/DifferentialDriveKinematicsConstraint.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/DifferentialDriveKinematicsConstraint.java similarity index 92% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/DifferentialDriveKinematicsConstraint.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/DifferentialDriveKinematicsConstraint.java index 11c99ce07b..37d8d68bbe 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/DifferentialDriveKinematicsConstraint.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/DifferentialDriveKinematicsConstraint.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj.trajectory.constraint; +package edu.wpi.first.math.trajectory.constraint; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; /** * A class that enforces constraints on the differential drive kinematics. This can be used to diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/DifferentialDriveVoltageConstraint.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/DifferentialDriveVoltageConstraint.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/DifferentialDriveVoltageConstraint.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/DifferentialDriveVoltageConstraint.java index afc7cd4e1f..0cfaf9631d 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/DifferentialDriveVoltageConstraint.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/DifferentialDriveVoltageConstraint.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj.trajectory.constraint; +package edu.wpi.first.math.trajectory.constraint; import static edu.wpi.first.wpiutil.ErrorMessages.requireNonNullParam; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; /** * A class that enforces constraints on differential drive voltage expenditure based on the motor diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/EllipticalRegionConstraint.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/EllipticalRegionConstraint.java similarity index 93% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/EllipticalRegionConstraint.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/EllipticalRegionConstraint.java index 7ec8cee6ba..c3bd226c2f 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/EllipticalRegionConstraint.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/EllipticalRegionConstraint.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj.trajectory.constraint; +package edu.wpi.first.math.trajectory.constraint; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; /** Enforces a particular constraint only within an elliptical region. */ public class EllipticalRegionConstraint implements TrajectoryConstraint { diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/MaxVelocityConstraint.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/MaxVelocityConstraint.java similarity index 92% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/MaxVelocityConstraint.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/MaxVelocityConstraint.java index c755aead34..d672295c6d 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/MaxVelocityConstraint.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/MaxVelocityConstraint.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpilibj.trajectory.constraint; +package edu.wpi.first.math.trajectory.constraint; -import edu.wpi.first.wpilibj.geometry.Pose2d; +import edu.wpi.first.math.geometry.Pose2d; /** * Represents a constraint that enforces a max velocity. This can be composed with the {@link diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/MecanumDriveKinematicsConstraint.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/MecanumDriveKinematicsConstraint.java similarity index 93% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/MecanumDriveKinematicsConstraint.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/MecanumDriveKinematicsConstraint.java index 80f5c732ee..9cb980a9aa 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/MecanumDriveKinematicsConstraint.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/MecanumDriveKinematicsConstraint.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj.trajectory.constraint; +package edu.wpi.first.math.trajectory.constraint; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.MecanumDriveKinematics; /** * A class that enforces constraints on the mecanum drive kinematics. This can be used to ensure diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/RectangularRegionConstraint.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/RectangularRegionConstraint.java similarity index 94% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/RectangularRegionConstraint.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/RectangularRegionConstraint.java index 0827d991da..b29df5e9ae 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/RectangularRegionConstraint.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/RectangularRegionConstraint.java @@ -2,10 +2,10 @@ // 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 edu.wpi.first.wpilibj.trajectory.constraint; +package edu.wpi.first.math.trajectory.constraint; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Translation2d; /** Enforces a particular constraint only within a rectangular region. */ public class RectangularRegionConstraint implements TrajectoryConstraint { diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/SwerveDriveKinematicsConstraint.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/SwerveDriveKinematicsConstraint.java similarity index 93% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/SwerveDriveKinematicsConstraint.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/SwerveDriveKinematicsConstraint.java index af61a44c7e..d87e3252cb 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/SwerveDriveKinematicsConstraint.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/SwerveDriveKinematicsConstraint.java @@ -2,11 +2,11 @@ // 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 edu.wpi.first.wpilibj.trajectory.constraint; +package edu.wpi.first.math.trajectory.constraint; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; /** * A class that enforces constraints on the swerve drive kinematics. This can be used to ensure that diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/TrajectoryConstraint.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/TrajectoryConstraint.java similarity index 95% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/TrajectoryConstraint.java rename to wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/TrajectoryConstraint.java index 56275578d2..ed03a3185a 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/trajectory/constraint/TrajectoryConstraint.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/constraint/TrajectoryConstraint.java @@ -2,9 +2,9 @@ // 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 edu.wpi.first.wpilibj.trajectory.constraint; +package edu.wpi.first.math.trajectory.constraint; -import edu.wpi.first.wpilibj.geometry.Pose2d; +import edu.wpi.first.math.geometry.Pose2d; /** * An interface for defining user-defined velocity and acceleration constraints while generating diff --git a/wpimath/src/main/java/edu/wpi/first/wpilibj/util/Units.java b/wpimath/src/main/java/edu/wpi/first/math/util/Units.java similarity index 98% rename from wpimath/src/main/java/edu/wpi/first/wpilibj/util/Units.java rename to wpimath/src/main/java/edu/wpi/first/math/util/Units.java index 28774efa36..204a95a570 100644 --- a/wpimath/src/main/java/edu/wpi/first/wpilibj/util/Units.java +++ b/wpimath/src/main/java/edu/wpi/first/math/util/Units.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.util; +package edu.wpi.first.math.util; /** Utility class that converts between commonly used units in FRC. */ public final class Units { diff --git a/wpimath/src/main/native/cpp/geometry/Pose2d.cpp b/wpimath/src/main/native/cpp/geometry/Pose2d.cpp index 887b43f4f5..d7e57c039d 100644 --- a/wpimath/src/main/native/cpp/geometry/Pose2d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Pose2d.cpp @@ -20,12 +20,6 @@ Pose2d Pose2d::operator+(const Transform2d& other) const { return TransformBy(other); } -Pose2d& Pose2d::operator+=(const Transform2d& other) { - m_translation += other.Translation().RotateBy(m_rotation); - m_rotation += other.Rotation(); - return *this; -} - Transform2d Pose2d::operator-(const Pose2d& other) const { const auto pose = this->RelativeTo(other); return Transform2d(pose.Translation(), pose.Rotation()); diff --git a/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp b/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp index efcc520e4f..37b86f2dc6 100644 --- a/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Rotation2d.cpp @@ -38,24 +38,10 @@ Rotation2d Rotation2d::operator+(const Rotation2d& other) const { return RotateBy(other); } -Rotation2d& Rotation2d::operator+=(const Rotation2d& other) { - double cos = Cos() * other.Cos() - Sin() * other.Sin(); - double sin = Cos() * other.Sin() + Sin() * other.Cos(); - m_cos = cos; - m_sin = sin; - m_value = units::radian_t(std::atan2(m_sin, m_cos)); - return *this; -} - Rotation2d Rotation2d::operator-(const Rotation2d& other) const { return *this + -other; } -Rotation2d& Rotation2d::operator-=(const Rotation2d& other) { - *this += -other; - return *this; -} - Rotation2d Rotation2d::operator-() const { return Rotation2d(-m_value); } diff --git a/wpimath/src/main/native/cpp/geometry/Translation2d.cpp b/wpimath/src/main/native/cpp/geometry/Translation2d.cpp index 6323b60746..5e066bb40b 100644 --- a/wpimath/src/main/native/cpp/geometry/Translation2d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Translation2d.cpp @@ -33,21 +33,10 @@ Translation2d Translation2d::operator+(const Translation2d& other) const { return {X() + other.X(), Y() + other.Y()}; } -Translation2d& Translation2d::operator+=(const Translation2d& other) { - m_x += other.m_x; - m_y += other.m_y; - return *this; -} - Translation2d Translation2d::operator-(const Translation2d& other) const { return *this + -other; } -Translation2d& Translation2d::operator-=(const Translation2d& other) { - *this += -other; - return *this; -} - Translation2d Translation2d::operator-() const { return {-m_x, -m_y}; } @@ -56,12 +45,6 @@ Translation2d Translation2d::operator*(double scalar) const { return {scalar * m_x, scalar * m_y}; } -Translation2d& Translation2d::operator*=(double scalar) { - m_x *= scalar; - m_y *= scalar; - return *this; -} - Translation2d Translation2d::operator/(double scalar) const { return *this * (1.0 / scalar); } @@ -75,11 +58,6 @@ bool Translation2d::operator!=(const Translation2d& other) const { return !operator==(other); } -Translation2d& Translation2d::operator/=(double scalar) { - *this *= (1.0 / scalar); - return *this; -} - void frc::to_json(wpi::json& json, const Translation2d& translation) { json = wpi::json{{"x", translation.X().to()}, {"y", translation.Y().to()}}; diff --git a/wpimath/src/main/native/cpp/trajectory/TrajectoryGenerator.cpp b/wpimath/src/main/native/cpp/trajectory/TrajectoryGenerator.cpp index 475c7c4257..73d23dcb9d 100644 --- a/wpimath/src/main/native/cpp/trajectory/TrajectoryGenerator.cpp +++ b/wpimath/src/main/native/cpp/trajectory/TrajectoryGenerator.cpp @@ -115,7 +115,7 @@ Trajectory TrajectoryGenerator::GenerateTrajectory( const Transform2d flip{Translation2d(), Rotation2d(180_deg)}; if (config.IsReversed()) { for (auto& waypoint : newWaypoints) { - waypoint += flip; + waypoint = waypoint + flip; } } diff --git a/wpimath/src/main/native/include/frc/geometry/Pose2d.h b/wpimath/src/main/native/include/frc/geometry/Pose2d.h index 357b29e991..310fd8116e 100644 --- a/wpimath/src/main/native/include/frc/geometry/Pose2d.h +++ b/wpimath/src/main/native/include/frc/geometry/Pose2d.h @@ -57,18 +57,6 @@ class Pose2d { */ Pose2d operator+(const Transform2d& other) const; - /** - * Transforms the current pose by the transformation. - * - * This is similar to the + operator, except that it mutates the current - * object. - * - * @param other The transform to transform the pose by. - * - * @return Reference to the new mutated object. - */ - Pose2d& operator+=(const Transform2d& other); - /** * Returns the Transform2d that maps the one pose to another. * diff --git a/wpimath/src/main/native/include/frc/geometry/Rotation2d.h b/wpimath/src/main/native/include/frc/geometry/Rotation2d.h index 1748e60d9a..9f6d1b02a1 100644 --- a/wpimath/src/main/native/include/frc/geometry/Rotation2d.h +++ b/wpimath/src/main/native/include/frc/geometry/Rotation2d.h @@ -59,18 +59,6 @@ class Rotation2d { */ Rotation2d operator+(const Rotation2d& other) const; - /** - * Adds a rotation to the current rotation. - * - * This is similar to the + operator except that it mutates the current - * object. - * - * @param other The rotation to add. - * - * @return The reference to the new mutated object. - */ - Rotation2d& operator+=(const Rotation2d& other); - /** * Subtracts the new rotation from the current rotation and returns the new * rotation. @@ -84,18 +72,6 @@ class Rotation2d { */ Rotation2d operator-(const Rotation2d& other) const; - /** - * Subtracts the new rotation from the current rotation. - * - * This is similar to the - operator except that it mutates the current - * object. - * - * @param other The rotation to subtract. - * - * @return The reference to the new mutated object. - */ - Rotation2d& operator-=(const Rotation2d& other); - /** * Takes the inverse of the current rotation. This is simply the negative of * the current angular value. diff --git a/wpimath/src/main/native/include/frc/geometry/Translation2d.h b/wpimath/src/main/native/include/frc/geometry/Translation2d.h index 57532d2687..f49cd6385a 100644 --- a/wpimath/src/main/native/include/frc/geometry/Translation2d.h +++ b/wpimath/src/main/native/include/frc/geometry/Translation2d.h @@ -110,18 +110,6 @@ class Translation2d { */ Translation2d operator+(const Translation2d& other) const; - /** - * Adds the new translation to the current translation. - * - * This is similar to the + operator, except that the current object is - * mutated. - * - * @param other The translation to add. - * - * @return The reference to the new mutated object. - */ - Translation2d& operator+=(const Translation2d& other); - /** * Subtracts the other translation from the other translation and returns the * difference. @@ -135,18 +123,6 @@ class Translation2d { */ Translation2d operator-(const Translation2d& other) const; - /** - * Subtracts the new translation from the current translation. - * - * This is similar to the - operator, except that the current object is - * mutated. - * - * @param other The translation to subtract. - * - * @return The reference to the new mutated object. - */ - Translation2d& operator-=(const Translation2d& other); - /** * Returns the inverse of the current translation. This is equivalent to * rotating by 180 degrees, flipping the point over both axes, or simply @@ -167,17 +143,6 @@ class Translation2d { */ Translation2d operator*(double scalar) const; - /** - * Multiplies the current translation by a scalar. - * - * This is similar to the * operator, except that current object is mutated. - * - * @param scalar The scalar to multiply by. - * - * @return The reference to the new mutated object. - */ - Translation2d& operator*=(double scalar); - /** * Divides the translation by a scalar and returns the new translation. * @@ -205,17 +170,6 @@ class Translation2d { */ bool operator!=(const Translation2d& other) const; - /* - * Divides the current translation by a scalar. - * - * This is similar to the / operator, except that current object is mutated. - * - * @param scalar The scalar to divide by. - * - * @return The reference to the new mutated object. - */ - Translation2d& operator/=(double scalar); - private: units::meter_t m_x = 0_m; units::meter_t m_y = 0_m; diff --git a/wpimath/src/test/java/edu/wpi/first/wpiutil/math/MathUtilTest.java b/wpimath/src/test/java/edu/wpi/first/math/MathUtilTest.java similarity index 98% rename from wpimath/src/test/java/edu/wpi/first/wpiutil/math/MathUtilTest.java rename to wpimath/src/test/java/edu/wpi/first/math/MathUtilTest.java index 6808b45fbb..af48bad955 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpiutil/math/MathUtilTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/MathUtilTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpimath/src/test/java/edu/wpi/first/wpiutil/math/MatrixTest.java b/wpimath/src/test/java/edu/wpi/first/math/MatrixTest.java similarity index 94% rename from wpimath/src/test/java/edu/wpi/first/wpiutil/math/MatrixTest.java rename to wpimath/src/test/java/edu/wpi/first/math/MatrixTest.java index bfe382541d..45df8fe929 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpiutil/math/MatrixTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/MatrixTest.java @@ -2,16 +2,16 @@ // 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 edu.wpi.first.wpiutil.math; +package edu.wpi.first.math; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; -import edu.wpi.first.wpiutil.math.numbers.N3; -import edu.wpi.first.wpiutil.math.numbers.N4; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.numbers.N3; +import edu.wpi.first.math.numbers.N4; import org.ejml.data.SingularMatrixException; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/controller/ControlAffinePlantInversionFeedforwardTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforwardTest.java similarity index 86% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/controller/ControlAffinePlantInversionFeedforwardTest.java rename to wpimath/src/test/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforwardTest.java index 7eeae12b45..350ef18c11 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/controller/ControlAffinePlantInversionFeedforwardTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforwardTest.java @@ -2,15 +2,15 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; import org.junit.jupiter.api.Test; class ControlAffinePlantInversionFeedforwardTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/controller/LinearPlantInversionFeedforwardTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforwardTest.java similarity index 75% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/controller/LinearPlantInversionFeedforwardTest.java rename to wpimath/src/test/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforwardTest.java index 8695bbce70..98b0e6c661 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/controller/LinearPlantInversionFeedforwardTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforwardTest.java @@ -2,15 +2,15 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; import org.junit.jupiter.api.Test; class LinearPlantInversionFeedforwardTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/controller/LinearQuadraticRegulatorTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearQuadraticRegulatorTest.java similarity index 89% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/controller/LinearQuadraticRegulatorTest.java rename to wpimath/src/test/java/edu/wpi/first/math/controller/LinearQuadraticRegulatorTest.java index 8c81fc717e..5658709382 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/controller/LinearQuadraticRegulatorTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearQuadraticRegulatorTest.java @@ -2,16 +2,16 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; import org.junit.jupiter.api.Test; public class LinearQuadraticRegulatorTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/controller/LinearSystemLoopTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearSystemLoopTest.java similarity index 89% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/controller/LinearSystemLoopTest.java rename to wpimath/src/test/java/edu/wpi/first/math/controller/LinearSystemLoopTest.java index 8f9668f355..e0d8c14be6 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/controller/LinearSystemLoopTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/LinearSystemLoopTest.java @@ -2,22 +2,22 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.estimator.KalmanFilter; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.LinearSystemLoop; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.estimator.KalmanFilter; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.LinearSystemLoop; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.trajectory.TrapezoidProfile; import java.util.ArrayList; import java.util.List; import java.util.Random; diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/RamseteControllerTest.java b/wpimath/src/test/java/edu/wpi/first/math/controller/RamseteControllerTest.java similarity index 86% rename from wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/RamseteControllerTest.java rename to wpimath/src/test/java/edu/wpi/first/math/controller/RamseteControllerTest.java index 5800fdc0c1..58e7eb4c0b 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/controller/RamseteControllerTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/controller/RamseteControllerTest.java @@ -2,17 +2,17 @@ // 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 edu.wpi.first.wpilibj.controller; +package edu.wpi.first.math.controller; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Twist2d; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpiutil.math.MathUtil; +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Twist2d; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import java.util.ArrayList; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/AngleStatisticsTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/AngleStatisticsTest.java similarity index 89% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/AngleStatisticsTest.java rename to wpimath/src/test/java/edu/wpi/first/math/estimator/AngleStatisticsTest.java index 0503ac865d..9fcf5e31c4 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/AngleStatisticsTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/AngleStatisticsTest.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; import org.junit.jupiter.api.Test; public class AngleStatisticsTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/DifferentialDrivePoseEstimatorTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimatorTest.java similarity index 85% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/DifferentialDrivePoseEstimatorTest.java rename to wpimath/src/test/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimatorTest.java index c800b65211..552ce788e4 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/DifferentialDrivePoseEstimatorTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/DifferentialDrivePoseEstimatorTest.java @@ -2,21 +2,21 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds; -import edu.wpi.first.wpilibj.trajectory.Trajectory; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpiutil.math.MatBuilder; -import edu.wpi.first.wpiutil.math.Nat; +import edu.wpi.first.math.MatBuilder; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds; +import edu.wpi.first.math.trajectory.Trajectory; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import java.util.List; import java.util.Random; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/ExtendedKalmanFilterTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/ExtendedKalmanFilterTest.java similarity index 91% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/ExtendedKalmanFilterTest.java rename to wpimath/src/test/java/edu/wpi/first/math/estimator/ExtendedKalmanFilterTest.java index 79810c8bff..f389c2fe5b 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/ExtendedKalmanFilterTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/ExtendedKalmanFilterTest.java @@ -2,26 +2,26 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.system.NumericalIntegration; -import edu.wpi.first.wpilibj.system.NumericalJacobian; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; -import edu.wpi.first.wpiutil.math.numbers.N3; -import edu.wpi.first.wpiutil.math.numbers.N5; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.numbers.N3; +import edu.wpi.first.math.numbers.N5; +import edu.wpi.first.math.system.NumericalIntegration; +import edu.wpi.first.math.system.NumericalJacobian; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/KalmanFilterTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/KalmanFilterTest.java similarity index 91% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/KalmanFilterTest.java rename to wpimath/src/test/java/edu/wpi/first/math/estimator/KalmanFilterTest.java index f497150455..7415e513bc 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/KalmanFilterTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/KalmanFilterTest.java @@ -2,25 +2,25 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.system.LinearSystem; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; -import edu.wpi.first.wpiutil.math.numbers.N3; -import edu.wpi.first.wpiutil.math.numbers.N6; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.numbers.N3; +import edu.wpi.first.math.numbers.N6; +import edu.wpi.first.math.system.LinearSystem; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import java.util.ArrayList; import java.util.List; import java.util.Random; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/MecanumDrivePoseEstimatorTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimatorTest.java similarity index 88% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/MecanumDrivePoseEstimatorTest.java rename to wpimath/src/test/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimatorTest.java index c59844dace..82845d7be0 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/MecanumDrivePoseEstimatorTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/MecanumDrivePoseEstimatorTest.java @@ -2,18 +2,18 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.MecanumDriveKinematics; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.MecanumDriveKinematics; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import java.util.List; import java.util.Random; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/MerweScaledSigmaPointsTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/MerweScaledSigmaPointsTest.java similarity index 88% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/MerweScaledSigmaPointsTest.java rename to wpimath/src/test/java/edu/wpi/first/math/estimator/MerweScaledSigmaPointsTest.java index 4462b7dc01..b6e32fc56b 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/MerweScaledSigmaPointsTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/MerweScaledSigmaPointsTest.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; import org.junit.jupiter.api.Test; public class MerweScaledSigmaPointsTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/SwerveDrivePoseEstimatorTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimatorTest.java similarity index 88% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/SwerveDrivePoseEstimatorTest.java rename to wpimath/src/test/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimatorTest.java index 8ed50c4e5c..52752bc849 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/SwerveDrivePoseEstimatorTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/SwerveDrivePoseEstimatorTest.java @@ -2,18 +2,18 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.SwerveDriveKinematics; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.SwerveDriveKinematics; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import java.util.List; import java.util.Random; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/UnscentedKalmanFilterTest.java b/wpimath/src/test/java/edu/wpi/first/math/estimator/UnscentedKalmanFilterTest.java similarity index 94% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/UnscentedKalmanFilterTest.java rename to wpimath/src/test/java/edu/wpi/first/math/estimator/UnscentedKalmanFilterTest.java index 2a68283960..96b137aef6 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/estimator/UnscentedKalmanFilterTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/estimator/UnscentedKalmanFilterTest.java @@ -2,29 +2,29 @@ // 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 edu.wpi.first.wpilibj.estimator; +package edu.wpi.first.math.estimator; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.math.Discretization; -import edu.wpi.first.wpilibj.math.StateSpaceUtil; -import edu.wpi.first.wpilibj.system.NumericalIntegration; -import edu.wpi.first.wpilibj.system.NumericalJacobian; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig; -import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; -import edu.wpi.first.wpiutil.math.numbers.N4; -import edu.wpi.first.wpiutil.math.numbers.N6; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.math.Discretization; +import edu.wpi.first.math.math.StateSpaceUtil; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.numbers.N4; +import edu.wpi.first.math.numbers.N6; +import edu.wpi.first.math.system.NumericalIntegration; +import edu.wpi.first.math.system.NumericalJacobian; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; +import edu.wpi.first.math.trajectory.TrajectoryConfig; +import edu.wpi.first.math.trajectory.TrajectoryGenerator; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/LinearFilterTest.java b/wpimath/src/test/java/edu/wpi/first/math/filter/LinearFilterTest.java similarity index 99% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/LinearFilterTest.java rename to wpimath/src/test/java/edu/wpi/first/math/filter/LinearFilterTest.java index 9405bf1ffc..41be6f62c4 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/LinearFilterTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/filter/LinearFilterTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.math.filter; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/MedianFilterTest.java b/wpimath/src/test/java/edu/wpi/first/math/filter/MedianFilterTest.java similarity index 97% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/MedianFilterTest.java rename to wpimath/src/test/java/edu/wpi/first/math/filter/MedianFilterTest.java index ff2b77ef5b..06b3d019f0 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/MedianFilterTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/filter/MedianFilterTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj; +package edu.wpi.first.math.filter; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Pose2dTest.java b/wpimath/src/test/java/edu/wpi/first/math/geometry/Pose2dTest.java similarity index 98% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Pose2dTest.java rename to wpimath/src/test/java/edu/wpi/first/math/geometry/Pose2dTest.java index effdb2abb8..b6e66af400 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Pose2dTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/geometry/Pose2dTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Rotation2dTest.java b/wpimath/src/test/java/edu/wpi/first/math/geometry/Rotation2dTest.java similarity index 98% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Rotation2dTest.java rename to wpimath/src/test/java/edu/wpi/first/math/geometry/Rotation2dTest.java index 468d2a2042..cb3f0f3dfd 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Rotation2dTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/geometry/Rotation2dTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Transform2dTest.java b/wpimath/src/test/java/edu/wpi/first/math/geometry/Transform2dTest.java similarity index 96% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Transform2dTest.java rename to wpimath/src/test/java/edu/wpi/first/math/geometry/Transform2dTest.java index 40dd7a36a4..1a2f8e795d 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Transform2dTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/geometry/Transform2dTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Translation2dTest.java b/wpimath/src/test/java/edu/wpi/first/math/geometry/Translation2dTest.java similarity index 98% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Translation2dTest.java rename to wpimath/src/test/java/edu/wpi/first/math/geometry/Translation2dTest.java index d2f58ea68c..2d8eeaabe7 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Translation2dTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/geometry/Translation2dTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Twist2dTest.java b/wpimath/src/test/java/edu/wpi/first/math/geometry/Twist2dTest.java similarity index 98% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Twist2dTest.java rename to wpimath/src/test/java/edu/wpi/first/math/geometry/Twist2dTest.java index 45d8e2c420..c13bb09709 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/geometry/Twist2dTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/geometry/Twist2dTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.geometry; +package edu.wpi.first.math.geometry; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/ChassisSpeedsTest.java b/wpimath/src/test/java/edu/wpi/first/math/kinematics/ChassisSpeedsTest.java similarity index 90% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/ChassisSpeedsTest.java rename to wpimath/src/test/java/edu/wpi/first/math/kinematics/ChassisSpeedsTest.java index 45311bf4c2..b9c3785caa 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/ChassisSpeedsTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/kinematics/ChassisSpeedsTest.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Rotation2d; import org.junit.jupiter.api.Test; class ChassisSpeedsTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveKinematicsTest.java b/wpimath/src/test/java/edu/wpi/first/math/kinematics/DifferentialDriveKinematicsTest.java similarity index 98% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveKinematicsTest.java rename to wpimath/src/test/java/edu/wpi/first/math/kinematics/DifferentialDriveKinematicsTest.java index e2c5b1d2be..adee41fabc 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveKinematicsTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/kinematics/DifferentialDriveKinematicsTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveOdometryTest.java b/wpimath/src/test/java/edu/wpi/first/math/kinematics/DifferentialDriveOdometryTest.java similarity index 87% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveOdometryTest.java rename to wpimath/src/test/java/edu/wpi/first/math/kinematics/DifferentialDriveOdometryTest.java index 136b45528a..f85e8fbf2b 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/DifferentialDriveOdometryTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/kinematics/DifferentialDriveOdometryTest.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; import org.junit.jupiter.api.Test; class DifferentialDriveOdometryTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveKinematicsTest.java b/wpimath/src/test/java/edu/wpi/first/math/kinematics/MecanumDriveKinematicsTest.java similarity index 98% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveKinematicsTest.java rename to wpimath/src/test/java/edu/wpi/first/math/kinematics/MecanumDriveKinematicsTest.java index 64667f0204..9345bf8515 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveKinematicsTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/kinematics/MecanumDriveKinematicsTest.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Translation2d; import org.junit.jupiter.api.Test; class MecanumDriveKinematicsTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveOdometryTest.java b/wpimath/src/test/java/edu/wpi/first/math/kinematics/MecanumDriveOdometryTest.java similarity index 94% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveOdometryTest.java rename to wpimath/src/test/java/edu/wpi/first/math/kinematics/MecanumDriveOdometryTest.java index 483223fce1..3f431093f3 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/MecanumDriveOdometryTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/kinematics/MecanumDriveOdometryTest.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; import org.junit.jupiter.api.Test; class MecanumDriveOdometryTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveKinematicsTest.java b/wpimath/src/test/java/edu/wpi/first/math/kinematics/SwerveDriveKinematicsTest.java similarity index 98% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveKinematicsTest.java rename to wpimath/src/test/java/edu/wpi/first/math/kinematics/SwerveDriveKinematicsTest.java index dc40fe3106..fb81b6da44 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveKinematicsTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/kinematics/SwerveDriveKinematicsTest.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; import org.junit.jupiter.api.Test; class SwerveDriveKinematicsTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveOdometryTest.java b/wpimath/src/test/java/edu/wpi/first/math/kinematics/SwerveDriveOdometryTest.java similarity index 94% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveOdometryTest.java rename to wpimath/src/test/java/edu/wpi/first/math/kinematics/SwerveDriveOdometryTest.java index 64e1aa587b..cb6dfdfdb0 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/SwerveDriveOdometryTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/kinematics/SwerveDriveOdometryTest.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; import org.junit.jupiter.api.Test; class SwerveDriveOdometryTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/SwerveModuleStateTest.java b/wpimath/src/test/java/edu/wpi/first/math/kinematics/SwerveModuleStateTest.java similarity index 95% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/SwerveModuleStateTest.java rename to wpimath/src/test/java/edu/wpi/first/math/kinematics/SwerveModuleStateTest.java index 49ca2f642e..01815be00d 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/kinematics/SwerveModuleStateTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/kinematics/SwerveModuleStateTest.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.kinematics; +package edu.wpi.first.math.kinematics; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Rotation2d; import org.junit.jupiter.api.Test; class SwerveModuleStateTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/math/StateSpaceUtilTest.java b/wpimath/src/test/java/edu/wpi/first/math/math/StateSpaceUtilTest.java similarity index 94% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/math/StateSpaceUtilTest.java rename to wpimath/src/test/java/edu/wpi/first/math/math/StateSpaceUtilTest.java index af810af69f..3c0dd01fb2 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/math/StateSpaceUtilTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/math/StateSpaceUtilTest.java @@ -2,20 +2,20 @@ // 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 edu.wpi.first.wpilibj.math; +package edu.wpi.first.math.math; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.SimpleMatrixUtils; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; -import edu.wpi.first.wpiutil.math.numbers.N2; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.SimpleMatrixUtils; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; import java.util.ArrayList; import java.util.List; import org.ejml.dense.row.MatrixFeatures_DDRM; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/spline/CubicHermiteSplineTest.java b/wpimath/src/test/java/edu/wpi/first/math/spline/CubicHermiteSplineTest.java similarity index 95% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/spline/CubicHermiteSplineTest.java rename to wpimath/src/test/java/edu/wpi/first/math/spline/CubicHermiteSplineTest.java index 8d4d101bf9..b92bb6a319 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/spline/CubicHermiteSplineTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/spline/CubicHermiteSplineTest.java @@ -2,17 +2,17 @@ // 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 edu.wpi.first.wpilibj.spline; +package edu.wpi.first.math.spline; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.spline.SplineParameterizer.MalformedSplineException; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.spline.SplineParameterizer.MalformedSplineException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/spline/QuinticHermiteSplineTest.java b/wpimath/src/test/java/edu/wpi/first/math/spline/QuinticHermiteSplineTest.java similarity index 94% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/spline/QuinticHermiteSplineTest.java rename to wpimath/src/test/java/edu/wpi/first/math/spline/QuinticHermiteSplineTest.java index f00ab9a1cf..d5fd071a23 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/spline/QuinticHermiteSplineTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/spline/QuinticHermiteSplineTest.java @@ -2,16 +2,16 @@ // 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 edu.wpi.first.wpilibj.spline; +package edu.wpi.first.math.spline; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.spline.SplineParameterizer.MalformedSplineException; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.spline.SplineParameterizer.MalformedSplineException; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/system/LinearSystemIDTest.java b/wpimath/src/test/java/edu/wpi/first/math/system/LinearSystemIDTest.java similarity index 91% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/system/LinearSystemIDTest.java rename to wpimath/src/test/java/edu/wpi/first/math/system/LinearSystemIDTest.java index 8015a2f6a3..353d066b20 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/system/LinearSystemIDTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/system/LinearSystemIDTest.java @@ -2,16 +2,16 @@ // 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 edu.wpi.first.wpilibj.system; +package edu.wpi.first.math.system; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.system.plant.DCMotor; -import edu.wpi.first.wpilibj.system.plant.LinearSystemId; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.system.plant.DCMotor; +import edu.wpi.first.math.system.plant.LinearSystemId; import org.junit.jupiter.api.Test; class LinearSystemIDTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/system/NumericalIntegrationTest.java b/wpimath/src/test/java/edu/wpi/first/math/system/NumericalIntegrationTest.java similarity index 87% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/system/NumericalIntegrationTest.java rename to wpimath/src/test/java/edu/wpi/first/math/system/NumericalIntegrationTest.java index 1f67e26cab..3dc9b49619 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/system/NumericalIntegrationTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/system/NumericalIntegrationTest.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj.system; +package edu.wpi.first.math.system; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpiutil.math.Matrix; -import edu.wpi.first.wpiutil.math.Nat; -import edu.wpi.first.wpiutil.math.VecBuilder; -import edu.wpi.first.wpiutil.math.numbers.N1; +import edu.wpi.first.math.Matrix; +import edu.wpi.first.math.Nat; +import edu.wpi.first.math.VecBuilder; +import edu.wpi.first.math.numbers.N1; import org.junit.jupiter.api.Test; public class NumericalIntegrationTest { diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/CentripetalAccelerationConstraintTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/CentripetalAccelerationConstraintTest.java similarity index 87% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/CentripetalAccelerationConstraintTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/CentripetalAccelerationConstraintTest.java index 3aab65c5f9..1805589c9e 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/CentripetalAccelerationConstraintTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/CentripetalAccelerationConstraintTest.java @@ -2,12 +2,12 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.trajectory.constraint.CentripetalAccelerationConstraint; -import edu.wpi.first.wpilibj.util.Units; +import edu.wpi.first.math.trajectory.constraint.CentripetalAccelerationConstraint; +import edu.wpi.first.math.util.Units; import java.util.Collections; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/DifferentialDriveKinematicsConstraintTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveKinematicsConstraintTest.java similarity index 84% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/DifferentialDriveKinematicsConstraintTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveKinematicsConstraintTest.java index b206d42ced..7614a83e12 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/DifferentialDriveKinematicsConstraintTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveKinematicsConstraintTest.java @@ -2,15 +2,15 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.trajectory.constraint.DifferentialDriveKinematicsConstraint; -import edu.wpi.first.wpilibj.util.Units; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.trajectory.constraint.DifferentialDriveKinematicsConstraint; +import edu.wpi.first.math.util.Units; import java.util.Collections; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/DifferentialDriveVoltageConstraintTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveVoltageConstraintTest.java similarity index 88% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/DifferentialDriveVoltageConstraintTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveVoltageConstraintTest.java index 6ad7bad819..34e0a594f7 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/DifferentialDriveVoltageConstraintTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/DifferentialDriveVoltageConstraintTest.java @@ -2,19 +2,19 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.kinematics.ChassisSpeeds; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.trajectory.constraint.DifferentialDriveVoltageConstraint; +import edu.wpi.first.math.controller.SimpleMotorFeedforward; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.kinematics.ChassisSpeeds; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.trajectory.constraint.DifferentialDriveVoltageConstraint; import java.util.ArrayList; import java.util.Collections; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/EllipticalRegionConstraintTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/EllipticalRegionConstraintTest.java similarity index 87% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/EllipticalRegionConstraintTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/EllipticalRegionConstraintTest.java index 948b270757..f9e3c1821f 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/EllipticalRegionConstraintTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/EllipticalRegionConstraintTest.java @@ -2,17 +2,17 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.trajectory.constraint.EllipticalRegionConstraint; -import edu.wpi.first.wpilibj.trajectory.constraint.MaxVelocityConstraint; -import edu.wpi.first.wpilibj.util.Units; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.trajectory.constraint.EllipticalRegionConstraint; +import edu.wpi.first.math.trajectory.constraint.MaxVelocityConstraint; +import edu.wpi.first.math.util.Units; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/RectangularRegionConstraintTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/RectangularRegionConstraintTest.java similarity index 84% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/RectangularRegionConstraintTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/RectangularRegionConstraintTest.java index 7ad58c4e62..1ab826edea 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/RectangularRegionConstraintTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/RectangularRegionConstraintTest.java @@ -2,17 +2,17 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.trajectory.constraint.MaxVelocityConstraint; -import edu.wpi.first.wpilibj.trajectory.constraint.RectangularRegionConstraint; -import edu.wpi.first.wpilibj.util.Units; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.trajectory.constraint.MaxVelocityConstraint; +import edu.wpi.first.math.trajectory.constraint.RectangularRegionConstraint; +import edu.wpi.first.math.util.Units; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryConcatenateTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryConcatenateTest.java similarity index 91% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryConcatenateTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryConcatenateTest.java index d8ff29f400..2e80d7b2ef 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryConcatenateTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryConcatenateTest.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGeneratorTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryGeneratorTest.java similarity index 87% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGeneratorTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryGeneratorTest.java index fd580b3eb9..97c1858bd1 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGeneratorTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryGeneratorTest.java @@ -2,18 +2,18 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; -import static edu.wpi.first.wpilibj.util.Units.feetToMeters; +import static edu.wpi.first.math.util.Units.feetToMeters; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Transform2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; -import edu.wpi.first.wpilibj.trajectory.constraint.TrajectoryConstraint; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Transform2d; +import edu.wpi.first.math.geometry.Translation2d; +import edu.wpi.first.math.trajectory.constraint.TrajectoryConstraint; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryJsonTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryJsonTest.java similarity index 81% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryJsonTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryJsonTest.java index 9dfb0ca6a1..bb7260110d 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryJsonTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryJsonTest.java @@ -2,13 +2,13 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.kinematics.DifferentialDriveKinematics; -import edu.wpi.first.wpilibj.trajectory.constraint.DifferentialDriveKinematicsConstraint; +import edu.wpi.first.math.kinematics.DifferentialDriveKinematics; +import edu.wpi.first.math.trajectory.constraint.DifferentialDriveKinematicsConstraint; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryTransformTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryTransformTest.java similarity index 89% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryTransformTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryTransformTest.java index ad691d26fe..6268768d84 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrajectoryTransformTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrajectoryTransformTest.java @@ -2,14 +2,14 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import static org.junit.jupiter.api.Assertions.assertEquals; -import edu.wpi.first.wpilibj.geometry.Pose2d; -import edu.wpi.first.wpilibj.geometry.Rotation2d; -import edu.wpi.first.wpilibj.geometry.Transform2d; -import edu.wpi.first.wpilibj.geometry.Translation2d; +import edu.wpi.first.math.geometry.Pose2d; +import edu.wpi.first.math.geometry.Rotation2d; +import edu.wpi.first.math.geometry.Transform2d; +import edu.wpi.first.math.geometry.Translation2d; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfileTest.java b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrapezoidProfileTest.java similarity index 99% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfileTest.java rename to wpimath/src/test/java/edu/wpi/first/math/trajectory/TrapezoidProfileTest.java index ca6f8b8fbf..de01bf791f 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/trajectory/TrapezoidProfileTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/trajectory/TrapezoidProfileTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.trajectory; +package edu.wpi.first.math.trajectory; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; diff --git a/wpimath/src/test/java/edu/wpi/first/wpilibj/util/UnitsTest.java b/wpimath/src/test/java/edu/wpi/first/math/util/UnitsTest.java similarity index 97% rename from wpimath/src/test/java/edu/wpi/first/wpilibj/util/UnitsTest.java rename to wpimath/src/test/java/edu/wpi/first/math/util/UnitsTest.java index 788aa1015a..89484039a2 100644 --- a/wpimath/src/test/java/edu/wpi/first/wpilibj/util/UnitsTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/util/UnitsTest.java @@ -2,7 +2,7 @@ // 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 edu.wpi.first.wpilibj.util; +package edu.wpi.first.math.util; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpimath/src/test/native/cpp/geometry/Rotation2dTest.cpp b/wpimath/src/test/native/cpp/geometry/Rotation2dTest.cpp index 15d683310f..0597cd3218 100644 --- a/wpimath/src/test/native/cpp/geometry/Rotation2dTest.cpp +++ b/wpimath/src/test/native/cpp/geometry/Rotation2dTest.cpp @@ -39,7 +39,7 @@ TEST(Rotation2dTest, RotateByFromZero) { TEST(Rotation2dTest, RotateByNonZero) { auto rot = Rotation2d(90.0_deg); - rot += Rotation2d(30.0_deg); + rot = rot + Rotation2d(30.0_deg); EXPECT_NEAR(rot.Degrees().to(), 120.0, kEpsilon); } diff --git a/wpiutil/src/main/native/include/wpi/jni_util.h b/wpiutil/src/main/native/include/wpi/jni_util.h index df3075c390..11e8f542c2 100644 --- a/wpiutil/src/main/native/include/wpi/jni_util.h +++ b/wpiutil/src/main/native/include/wpi/jni_util.h @@ -593,6 +593,81 @@ class JSingletonCallbackManager : public JCallbackManager { } }; +inline std::string GetJavaStackTrace(JNIEnv* env, StringRef skipPrefix) { + // create a throwable + static JClass throwableCls(env, "java/lang/Throwable"); + if (!throwableCls) { + return ""; + } + static jmethodID constructorId = nullptr; + if (!constructorId) { + constructorId = env->GetMethodID(throwableCls, "", "()V"); + } + JLocal throwable(env, env->NewObject(throwableCls, constructorId)); + + // retrieve information from the exception. + // get method id + // getStackTrace returns an array of StackTraceElement + static jmethodID getStackTraceId = nullptr; + if (!getStackTraceId) { + getStackTraceId = env->GetMethodID(throwableCls, "getStackTrace", + "()[Ljava/lang/StackTraceElement;"); + } + + // call getStackTrace + JLocal stackTrace( + env, static_cast( + env->CallObjectMethod(throwable, getStackTraceId))); + + if (!stackTrace) { + return ""; + } + + // get length of the array + jsize stackTraceLength = env->GetArrayLength(stackTrace); + + // get toString methodId of StackTraceElement class + static JClass stackTraceElementCls(env, "java/lang/StackTraceElement"); + if (!stackTraceElementCls) { + return ""; + } + static jmethodID toStringId = nullptr; + if (!toStringId) { + toStringId = env->GetMethodID(stackTraceElementCls, "toString", + "()Ljava/lang/String;"); + } + + bool foundFirst = false; + std::string buf; + raw_string_ostream oss(buf); + for (jsize i = 0; i < stackTraceLength; i++) { + // add the result of toString method of each element in the result + JLocal curStackTraceElement( + env, env->GetObjectArrayElement(stackTrace, i)); + + // call to string on the object + JLocal stackElementString( + env, static_cast( + env->CallObjectMethod(curStackTraceElement, toStringId))); + + if (!stackElementString) { + return ""; + } + + // add a line to res + JStringRef elem(env, stackElementString); + if (!foundFirst) { + if (elem.str().startswith(skipPrefix)) { + continue; + } + foundFirst = true; + } + oss << "\tat " << elem << '\n'; + } + + return oss.str(); +} + inline std::string GetJavaStackTrace(JNIEnv* env, std::string* func, StringRef excludeFuncPrefix) { // create a throwable