From 26d101caf9ccbf5a9e123398b2c783db7af58ba8 Mon Sep 17 00:00:00 2001 From: Alex Henning Date: Wed, 23 Jul 2014 14:04:33 -0400 Subject: [PATCH] Restructure WPILibJ to share code. wpilibJavaDevices now contains RoboRIO specific code and wpilibJava has shared high level information. The restructuring was mostly just copy and paste. The three big exceptions are Timer, RobotState and HLUsageReporting. Those require some dependencies injection since that appears to be the cleanest way to share the code. Change-Id: Ie7011e32bc95953a87801a9905b3bfec7f8de285 --- wpilibj/pom.xml | 1 + wpilibj/wpilibJava/pom.xml | 96 +- .../wpilibj/DriverStationEnhancedIO.java | 1293 ----------------- .../wpi/first/wpilibj/HLUsageReporting.java | 31 + .../java/edu/wpi/first/wpilibj/Kinect.java | 456 ------ .../edu/wpi/first/wpilibj/KinectStick.java | 260 ---- .../wpi/first/wpilibj/MotorSafetyHelper.java | 5 +- .../edu/wpi/first/wpilibj/PIDController.java | 23 +- .../edu/wpi/first/wpilibj/RobotState.java | 57 + .../java/edu/wpi/first/wpilibj/Skeleton.java | 227 --- .../java/edu/wpi/first/wpilibj/Timer.java | 172 ++- .../first/wpilibj/buttons/AnalogIOButton.java | 35 - .../wpilibj/buttons/DigitalIOButton.java | 33 - .../wpi/first/wpilibj/command/Command.java | 4 +- .../wpi/first/wpilibj/command/Scheduler.java | 6 +- .../wpilibj/command/WaitUntilCommand.java | 4 +- .../.gitignore | 0 wpilibj/wpilibJavaDevices/pom.xml | 91 ++ .../edu/wpi/first/wpilibj/ADXL345_I2C.java | 0 .../edu/wpi/first/wpilibj/ADXL345_SPI.java | 0 .../wpi/first/wpilibj/AccumulatorResult.java | 0 .../first/wpilibj/AnalogAccelerometer.java | 0 .../edu/wpi/first/wpilibj/AnalogInput.java | 1 - .../edu/wpi/first/wpilibj/AnalogOutput.java | 0 .../first/wpilibj/AnalogPotentiometer.java | 0 .../edu/wpi/first/wpilibj/AnalogTrigger.java | 0 .../first/wpilibj/AnalogTriggerOutput.java | 0 .../first/wpilibj/BuiltInAccelerometer.java | 0 .../java/edu/wpi/first/wpilibj/CANJaguar.java | 1 + .../edu/wpi/first/wpilibj/Compressor.java | 0 .../java/edu/wpi/first/wpilibj/Counter.java | 0 .../edu/wpi/first/wpilibj/CounterBase.java | 0 .../java/edu/wpi/first/wpilibj/Dashboard.java | 0 .../edu/wpi/first/wpilibj/DigitalInput.java | 0 .../edu/wpi/first/wpilibj/DigitalOutput.java | 0 .../edu/wpi/first/wpilibj/DigitalSource.java | 0 .../edu/wpi/first/wpilibj/DoubleSolenoid.java | 0 .../edu/wpi/first/wpilibj/DriverStation.java | 17 +- .../wpi/first/wpilibj/DriverStationLCD.java | 0 .../java/edu/wpi/first/wpilibj/Encoder.java | 0 .../java/edu/wpi/first/wpilibj/GearTooth.java | 0 .../main/java/edu/wpi/first/wpilibj/Gyro.java | 1 + .../main/java/edu/wpi/first/wpilibj/I2C.java | 0 .../edu/wpi/first/wpilibj/IDashboard.java | 0 .../wpilibj/InterruptableSensorBase.java | 0 .../edu/wpi/first/wpilibj/IterativeRobot.java | 1 + .../java/edu/wpi/first/wpilibj/Jaguar.java | 0 .../java/edu/wpi/first/wpilibj/Joystick.java | 0 .../main/java/edu/wpi/first/wpilibj/PWM.java | 0 .../first/wpilibj/PowerDistributionPanel.java | 0 .../edu/wpi/first/wpilibj/Preferences.java | 0 .../java/edu/wpi/first/wpilibj/Relay.java | 0 .../java/edu/wpi/first/wpilibj/Resource.java | 0 .../java/edu/wpi/first/wpilibj/RobotBase.java | 102 +- .../edu/wpi/first/wpilibj/RobotDrive.java | 0 .../main/java/edu/wpi/first/wpilibj/SPI.java | 0 .../java/edu/wpi/first/wpilibj/SafePWM.java | 0 .../edu/wpi/first/wpilibj/SensorBase.java | 0 .../edu/wpi/first/wpilibj/SerialPort.java | 0 .../java/edu/wpi/first/wpilibj/Servo.java | 0 .../edu/wpi/first/wpilibj/SimpleRobot.java | 1 + .../java/edu/wpi/first/wpilibj/Solenoid.java | 0 .../edu/wpi/first/wpilibj/SolenoidBase.java | 0 .../wpi/first/wpilibj/SpeedController.java | 0 .../java/edu/wpi/first/wpilibj/Talon.java | 0 .../edu/wpi/first/wpilibj/Ultrasonic.java | 1 + .../java/edu/wpi/first/wpilibj/Utility.java | 7 - .../java/edu/wpi/first/wpilibj/Victor.java | 0 .../wpi/first/wpilibj/camera/AxisCamera.java | 0 .../wpilibj/camera/AxisCameraException.java | 0 .../edu/wpi/first/wpilibj/camera/package.html | 0 .../wpilibj/can/CANExceptionFactory.java | 0 .../can/CANInvalidBufferException.java | 0 .../edu/wpi/first/wpilibj/can/CANJNI.java | 0 .../can/CANJaguarVersionException.java | 0 .../can/CANMessageNotAllowedException.java | 0 .../can/CANMessageNotFoundException.java | 0 .../can/CANNotInitializedException.java | 0 .../communication/FRCCommonControlData.java | 0 .../communication/FRCCommonControlMasks.java | 1 - .../FRCNetworkCommunicationsLibrary.java | 0 .../wpilibj/communication/NIRioStatus.java | 0 .../wpilibj/communication/UsageReporting.java | 0 .../first/wpilibj/hal/AccelerometerJNI.java | 0 .../edu/wpi/first/wpilibj/hal/AnalogJNI.java | 0 .../wpi/first/wpilibj/hal/CompressorJNI.java | 0 .../edu/wpi/first/wpilibj/hal/CounterJNI.java | 0 .../edu/wpi/first/wpilibj/hal/DIOJNI.java | 0 .../edu/wpi/first/wpilibj/hal/EncoderJNI.java | 0 .../edu/wpi/first/wpilibj/hal/HALLibrary.java | 0 .../edu/wpi/first/wpilibj/hal/HALUtil.java | 0 .../edu/wpi/first/wpilibj/hal/I2CJNI.java | 0 .../wpi/first/wpilibj/hal/InterruptJNI.java | 0 .../edu/wpi/first/wpilibj/hal/JNIWrapper.java | 0 .../edu/wpi/first/wpilibj/hal/PDPJNI.java | 0 .../edu/wpi/first/wpilibj/hal/PWMJNI.java | 0 .../edu/wpi/first/wpilibj/hal/RelayJNI.java | 0 .../edu/wpi/first/wpilibj/hal/SPIJNI.java | 0 .../wpi/first/wpilibj/hal/SolenoidJNI.java | 0 .../wpi/first/wpilibj/image/BinaryImage.java | 0 .../wpi/first/wpilibj/image/ColorImage.java | 0 .../wpilibj/image/CriteriaCollection.java | 0 .../wpi/first/wpilibj/image/CurveOptions.java | 0 .../wpilibj/image/EllipseDescriptor.java | 0 .../wpi/first/wpilibj/image/EllipseMatch.java | 0 .../edu/wpi/first/wpilibj/image/HSLImage.java | 0 .../edu/wpi/first/wpilibj/image/Image.java | 0 .../first/wpilibj/image/LinearAverages.java | 0 .../wpi/first/wpilibj/image/MonoImage.java | 0 .../edu/wpi/first/wpilibj/image/NIVision.java | 0 .../wpilibj/image/NIVisionException.java | 0 .../wpilibj/image/ParticleAnalysisReport.java | 0 .../edu/wpi/first/wpilibj/image/RGBImage.java | 0 .../first/wpilibj/image/RegionOfInterest.java | 0 .../wpilibj/image/ShapeDetectionOptions.java | 0 .../edu/wpi/first/wpilibj/image/package.html | 0 .../internal/HardwareHLUsageReporting.java | 18 + .../first/wpilibj/internal/HardwareTimer.java | 125 ++ .../java/edu/wpi/first/wpilibj/package.html | 0 .../java/edu/wpi/first/wpilibj/visa/Visa.java | 0 .../wpi/first/wpilibj/visa/VisaException.java | 0 .../edu/wpi/first/wpilibj/visa/package.html | 0 .../edu/wpi/first/wpilibj/ExampleTest.java | 0 .../edu/wpi/first/wpilibj/ResourceTest.java | 0 wpilibj/wpilibJavaFinal/pom.xml | 232 ++- wpilibj/wpilibJavaJNI/pom.xml | 2 +- wpilibj/wpilibJavaSim/pom.xml | 5 + .../edu/wpi/first/wpilibj/Controller.java | 25 - .../edu/wpi/first/wpilibj/DriverStation.java | 2 +- .../edu/wpi/first/wpilibj/GenericHID.java | 155 -- .../edu/wpi/first/wpilibj/IterativeRobot.java | 1 + .../edu/wpi/first/wpilibj/MotorSafety.java | 23 - .../wpi/first/wpilibj/MotorSafetyHelper.java | 124 -- .../edu/wpi/first/wpilibj/NamedSendable.java | 14 - .../edu/wpi/first/wpilibj/PIDController.java | 578 -------- .../java/edu/wpi/first/wpilibj/PIDOutput.java | 21 - .../java/edu/wpi/first/wpilibj/PIDSource.java | 39 - .../java/edu/wpi/first/wpilibj/RobotBase.java | 5 + .../java/edu/wpi/first/wpilibj/Sendable.java | 26 - .../edu/wpi/first/wpilibj/SimpleRobot.java | 1 + .../edu/wpi/first/wpilibj/buttons/Button.java | 70 - .../first/wpilibj/buttons/InternalButton.java | 48 - .../first/wpilibj/buttons/JoystickButton.java | 38 - .../first/wpilibj/buttons/NetworkButton.java | 33 - .../wpi/first/wpilibj/buttons/Trigger.java | 200 --- .../wpi/first/wpilibj/command/Command.java | 523 ------- .../first/wpilibj/command/CommandGroup.java | 398 ----- .../command/IllegalUseOfCommandException.java | 38 - .../wpilibj/command/LinkedListElement.java | 66 - .../wpi/first/wpilibj/command/PIDCommand.java | 191 --- .../first/wpilibj/command/PIDSubsystem.java | 260 ---- .../first/wpilibj/command/PrintCommand.java | 46 - .../edu/wpi/first/wpilibj/command/Set.java | 42 - .../first/wpilibj/command/StartCommand.java | 47 - .../wpi/first/wpilibj/command/Subsystem.java | 197 --- .../first/wpilibj/command/WaitCommand.java | 50 - .../wpilibj/command/WaitForChildren.java | 36 - .../wpilibj/interfaces/Potentiometer.java | 17 - .../{Timer.java => internal/SimTimer.java} | 154 +- .../first/wpilibj/livewindow/LiveWindow.java | 219 --- .../livewindow/LiveWindowSendable.java | 32 - .../wpi/first/wpilibj/parsing/IDevice.java | 15 - .../wpilibj/parsing/IDeviceController.java | 15 - .../first/wpilibj/parsing/IInputOutput.java | 16 - .../wpi/first/wpilibj/parsing/IMechanism.java | 17 - .../wpi/first/wpilibj/parsing/ISensor.java | 17 - .../wpi/first/wpilibj/parsing/IUtility.java | 17 - .../smartdashboard/SendableChooser.java | 146 -- .../smartdashboard/SmartDashboard.java | 297 ---- .../wpilibj/util/AllocationException.java | 23 - .../first/wpilibj/util/BoundaryException.java | 62 - .../util/CheckedAllocationException.java | 24 - .../wpi/first/wpilibj/util/SortedVector.java | 75 - .../wpilibj/util/UncleanStatusException.java | 58 - 174 files changed, 637 insertions(+), 7173 deletions(-) delete mode 100644 wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DriverStationEnhancedIO.java create mode 100644 wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java delete mode 100644 wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Kinect.java delete mode 100644 wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/KinectStick.java create mode 100644 wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/RobotState.java delete mode 100644 wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Skeleton.java delete mode 100644 wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/buttons/AnalogIOButton.java delete mode 100644 wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/buttons/DigitalIOButton.java rename wpilibj/{wpilibJava => wpilibJavaDevices}/.gitignore (100%) create mode 100644 wpilibj/wpilibJavaDevices/pom.xml rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/ADXL345_I2C.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/ADXL345_SPI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/AccumulatorResult.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java (99%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/BuiltInAccelerometer.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java (99%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Compressor.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Counter.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/CounterBase.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Dashboard.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/DriverStation.java (97%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/DriverStationLCD.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Encoder.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/GearTooth.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Gyro.java (99%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/I2C.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/IDashboard.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java (99%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Jaguar.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Joystick.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/PWM.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Preferences.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Relay.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Resource.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/RobotBase.java (61%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/SPI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/SafePWM.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/SensorBase.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/SerialPort.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Servo.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java (99%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Solenoid.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/SolenoidBase.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/SpeedController.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Talon.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java (99%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Utility.java (94%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/Victor.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/camera/AxisCamera.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/camera/AxisCameraException.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/camera/package.html (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/can/CANInvalidBufferException.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/can/CANJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/can/CANJaguarVersionException.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotAllowedException.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotFoundException.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/can/CANNotInitializedException.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlData.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlMasks.java (86%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/communication/NIRioStatus.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/communication/UsageReporting.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/AccelerometerJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/AnalogJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/CounterJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/EncoderJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/HALLibrary.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/I2CJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/InterruptJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/RelayJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/SPIJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/hal/SolenoidJNI.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/BinaryImage.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/ColorImage.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/CriteriaCollection.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/CurveOptions.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/EllipseDescriptor.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/EllipseMatch.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/HSLImage.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/Image.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/LinearAverages.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/MonoImage.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/NIVision.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/NIVisionException.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/ParticleAnalysisReport.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/RGBImage.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/RegionOfInterest.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/ShapeDetectionOptions.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/image/package.html (100%) create mode 100644 wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java create mode 100644 wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/package.html (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/visa/Visa.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/visa/VisaException.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/main/java/edu/wpi/first/wpilibj/visa/package.html (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/test/java/edu/wpi/first/wpilibj/ExampleTest.java (100%) rename wpilibj/{wpilibJava => wpilibJavaDevices}/src/test/java/edu/wpi/first/wpilibj/ResourceTest.java (100%) delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Controller.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/GenericHID.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/MotorSafety.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/MotorSafetyHelper.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/NamedSendable.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDController.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDSource.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Sendable.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/Button.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Command.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/IllegalUseOfCommandException.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/LinkedListElement.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Set.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/WaitCommand.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/interfaces/Potentiometer.java rename wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/{Timer.java => internal/SimTimer.java} (50%) delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindowSendable.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IDevice.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IDeviceController.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IInputOutput.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IMechanism.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/ISensor.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IUtility.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/AllocationException.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/BoundaryException.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/CheckedAllocationException.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java delete mode 100644 wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/UncleanStatusException.java diff --git a/wpilibj/pom.xml b/wpilibj/pom.xml index e9c076f6d7..4217c0c552 100644 --- a/wpilibj/pom.xml +++ b/wpilibj/pom.xml @@ -9,6 +9,7 @@ wpilibJava + wpilibJavaDevices wpilibJavaSim wpilibJavaJNI wpilibJavaFinal diff --git a/wpilibj/wpilibJava/pom.xml b/wpilibj/wpilibJava/pom.xml index f4f3f0e387..3699499472 100644 --- a/wpilibj/wpilibJava/pom.xml +++ b/wpilibj/wpilibJava/pom.xml @@ -1,6 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 edu.wpi.first.wpilibj wpilibJava @@ -18,11 +18,11 @@ docline-java8-disable - [1.8, + [1.8, - + org.apache.maven.plugins maven-javadoc-plugin @@ -30,47 +30,21 @@ -Xdoclint:none - + - - - - - - - - - - edu.wpi.first.wpilib.networktables.java NetworkTables 0.1.0-SNAPSHOT - junit - junit - 4.11 + junit + junit + 4.11 @@ -83,68 +57,12 @@ 1.7 1.7 - - edu/wpi/first/wpilibj/image/ - edu/wpi/first/wpilibj/camera/ - edu/wpi/first/wpilibj/visa/ - edu/wpi/first/wpilibj/SerialPort.java - edu/wpi/first/wpilibj/Kinect.java - edu/wpi/first/wpilibj/KinectStick.java - edu/wpi/first/wpilibj/DriverStationEnhancedIO.java - edu/wpi/first/wpilibj/buttons/DigitalIOButton.java - edu/wpi/first/wpilibj/buttons/AnalogIOButton.java - - org.apache.maven.plugins maven-source-plugin - - org.apache.maven.plugins - maven-javadoc-plugin - - - edu/wpi/first/wpilibj/image/ - edu/wpi/first/wpilibj/camera/ - edu/wpi/first/wpilibj/visa/ - edu/wpi/first/wpilibj/SerialPort.java - edu/wpi/first/wpilibj/Kinect.java - edu/wpi/first/wpilibj/KinectStick.java - edu/wpi/first/wpilibj/DriverStationEnhancedIO.java - edu/wpi/first/wpilibj/buttons/DigitalIOButton.java - edu/wpi/first/wpilibj/buttons/AnalogIOButton.java - - - diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DriverStationEnhancedIO.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DriverStationEnhancedIO.java deleted file mode 100644 index 71b605dbb6..0000000000 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DriverStationEnhancedIO.java +++ /dev/null @@ -1,1293 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ -package edu.wpi.first.wpilibj; - -import java.util.Arrays; -import java.util.List; - -import org.omg.CosNaming.NamingContextExtPackage.AddressHelper; - -import com.sun.jna.Pointer; -import com.sun.jna.PointerUtils; -import com.sun.jna.Structure; - -import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary; -import edu.wpi.first.wpilibj.parsing.IInputOutput; -import edu.wpi.first.wpilibj.util.BoundaryException; - -/** - * - * @author dtjones - */ -public class DriverStationEnhancedIO implements IInputOutput { - - /** - * Reads the specified shorts from memory into the given array of shorts. - * - * @param pointer - * The memory location to copy from - * @param offset - * The offset in memory to start copying at - * @param shorts - * The array to store the shorts in - * @param low - * The offset in the array to start storing at - * @param number - * The number of shorts to read from memory - */ - private static void getShorts(Pointer pointer, long offset, short[] shorts, - int low, int number) { - for (int i = 0; i < number; i++) { - shorts[low + i] = pointer.getShort(offset + i); - } - } - - /** - * Reads the specified bytes from memory into the given array of bytes. - * - * @param pointer - * The memory location to copy from - * @param offset - * The offset in memory to start copying at - * @param shorts - * The array to store the bytes in - * @param low - * The offset in the array to start storing at - * @param number - * The number of bytes to read from memory - */ - private static void getBytes(Pointer pointer, long offset, byte[] bytes, - int low, int number) { - for (int i = 0; i < number; i++) { - bytes[low + i] = pointer.getByte(offset + i); - } - } - - /** - * Writes the given array of shorts into memory, with the given offset, - * starting at the given low and writing the number of shorts specified. - * - * @param pointer - * The memory pointer to write to - * @param offset - * The memory offset to start writing to - * @param shorts - * The list of shorts to write - * @param low - * The array number in the list to start at - * @param number - * The number of shorts to write, starting at low - */ - private static void setShorts(Pointer pointer, long offset, short[] shorts, - int low, int number) { - for (int i = 0; i + low < number; i++) { - pointer.setShort(offset + i, shorts[i + low]); - } - } - - /** - * Writes the given array of bytes into memory, with the given offset, - * starting at the given low and writing the number of bytes specified. - * - * @param pointer - * The memory pointer to write to - * @param offset - * The memory offset to start writing to - * @param bytes - * The list of bytes to write - * @param low - * The array number in the list to start at - * @param number - * The number of bytes to write, starting at low - */ - private static void setBytes(Pointer pointer, long offset, byte[] bytes, - int low, int number) { - for (int i = 0; i + low < number; i++) { - pointer.setByte(offset + i, bytes[i + low]); - } - } - - /** - * Copies bytes from the source pointer to the destination. - * - * @param src - * The source pointer - * @param srcOffset - * The offset to start copying memory at - * @param dst - * The destination pointer - * @param dstOffset - * The offset to copy to - * @param len - * The number of bytes to copy - */ - private static void copyBytes(Pointer src, int srcOffset, Pointer dst, - int dstOffset, int len) { - for (int i = 0; i < len; i++) { - dst.setByte(dstOffset + i, src.getByte(srcOffset + i)); - } - } - - static class output_t extends Structure { - - short digital = 0; - short digital_oe = 0; - short digital_pe = 0; - short[] pwm_compare = new short[4]; - short[] pwm_period = new short[2]; - byte[] dac = new byte[2]; - byte leds = 0; - private byte enables = 0; - byte pwm_enable = 0; // :4 - byte comparator_enable = 0; // :2 - byte quad_index_enable = 0; // :2 - // union - // { - // struct - // { - // // Bits are inverted from cypress fw because of big-endian! - // UINT8 pwm_enable : 4; - // UINT8 comparator_enable : 2; - // UINT8 quad_index_enable : 2; - // }; - // UINT8 enables; - // }; - byte fixed_digital_out = 0; - - final static int size = 23; - - output_t(Pointer backingMemory) { - useMemory(backingMemory); - } - - public void setEnables(byte enablesByte) { - enables = enablesByte; - pwm_enable = (byte) ((enablesByte & (byte) 0xF0) >> 4); - comparator_enable = (byte) ((enablesByte & (byte) 0x0C) >> 2); - quad_index_enable = (byte) ((enablesByte & (byte) 0x03)); - } - - public byte getEnables() { - enables = (byte) (((pwm_enable << 4) & (byte) 0xF0) - | ((comparator_enable << 2) & (byte) 0x0C) | ((quad_index_enable) & (byte) 0x03)); - return enables; - } - - public void read() { - digital = getPointer().getShort(0); - digital_oe = getPointer().getShort(2); - digital_pe = getPointer().getShort(4); - getShorts(getPointer(), 6, pwm_compare, 0, pwm_compare.length); - getShorts(getPointer(), 14, pwm_period, 0, pwm_period.length); - getBytes(getPointer(), 18, dac, 0, dac.length); - leds = getPointer().getByte(20); - setEnables(getPointer().getByte(21)); - fixed_digital_out = getPointer().getByte(22); - } - - public void write() { - getPointer().setShort(0, digital); - getPointer().setShort(2, digital_oe); - getPointer().setShort(4, digital_pe); - setShorts(getPointer(), 6, pwm_compare, 0, pwm_compare.length); - setShorts(getPointer(), 14, pwm_period, 0, pwm_period.length); - setBytes(getPointer(), 18, dac, 0, dac.length); - getPointer().setByte(20, leds); - getPointer().setByte(21, getEnables()); - getPointer().setByte(22, fixed_digital_out); - } - - public int size() { - return size; - } - - @Override - protected List getFieldOrder() { - // XXX: I'm just returning the order from the class declaration, - // don't know if this is correct - return Arrays.asList(new String[] { "digital", "digital_oe", - "digital_pe", "pwm_compare", "pwm_period", "dac", "leds", - "enables", "pwm_enable", "comparator_enable", - "quad_index_enable" }); - - } - } // data to IO (23 bytes) - - // Dynamic block definitions - // END: Definitions from the Cypress firmware - static class input_t extends Structure { - - byte api_version; - byte fw_version; - short[] analog = new short[8]; - short digital; - short[] accel = new short[3]; - short[] quad = new short[2]; - byte buttons; - byte capsense_slider; - byte capsense_proximity; - - final static int size = 33; - - input_t(Pointer backingMemory) { - useMemory(backingMemory); - } - - public void read() { - api_version = getPointer().getByte(0); - fw_version = getPointer().getByte(1); - getShorts(getPointer(), 2, analog, 0, analog.length); - digital = getPointer().getShort(18); - getShorts(getPointer(), 20, accel, 0, accel.length); - getShorts(getPointer(), 26, quad, 0, quad.length); - buttons = getPointer().getByte(30); - capsense_slider = getPointer().getByte(31); - capsense_proximity = getPointer().getByte(32); - } - - public void write() { - getPointer().setByte(0, api_version); - getPointer().setByte(1, fw_version); - setShorts(getPointer(), 2, analog, 0, analog.length); - getPointer().setShort(18, digital); - setShorts(getPointer(), 20, accel, 0, accel.length); - setShorts(getPointer(), 26, quad, 0, quad.length); - getPointer().setByte(30, buttons); - getPointer().setByte(31, capsense_slider); - getPointer().setByte(32, capsense_proximity); - } - - public int size() { - return size; - } - - protected List getFieldOrder() { - // XXX: I'm just returning the order from the class declaration, - // don't know if this is correct - return Arrays.asList(new String[] { "api_version", "fw_version", - "analog", "digital", "accel", "quad", "buttons", - "capsense_slider", "capsense_proximity" }); - - } - } // data from IO (33 bytes) - - class status_block_t extends Structure { - - byte size = 25; // Must be 25 (size remaining in the block not counting - // the size variable) - byte id = kOutputBlockID; // Must be 18 - output_t data; - byte flags; - - { - allocateMemory(); - // XXX: Need to determine if this is actually enough, or if we need to find a way to specifiy size as well - data = new output_t(new Pointer(PointerUtils.getAddress(getPointer()) + 2)); -// data = new output_t(new Pointer(getPointer().address().toUWord() -// .toPrimitive() + 2, output_t.size)); - } - - public void read() { - - size = getPointer().getByte(0); - id = getPointer().getByte(1); - data.read(); - flags = getPointer().getByte(25); - } - - public void write() { - getPointer().setByte(0, size); - getPointer().setByte(1, id); - data.write(); - getPointer().setByte(25, flags); - } - - public int size() { - return 26; - } - - public void copy(status_block_t dest) { - write(); - copyBytes(getPointer(), 0, dest.getPointer(), 0, size()); - dest.read(); - } - - protected List getFieldOrder() { - // XXX: I'm just returning the order from the class declaration, - // don't know if this is correct - return Arrays - .asList(new String[] { "size", "id", "data", "flags" }); - } - } - - class control_block_t extends Structure { - - byte size = 34; // Must be 34 - byte id = kInputBlockID; // Must be 17 - input_t data; - - { - allocateMemory(); - // XXX: Need to determine if this is actually enough, or if we need to find a way to specifiy size as well - data = new input_t(new Pointer(PointerUtils.getAddress(getPointer()) + 2)); -// data = new input_t(new Pointer(getPointer().address().toUWord() -// .toPrimitive() + 2, input_t.size)); - } - - public void read() { - size = getPointer().getByte(0); - id = getPointer().getByte(1); - data.read(); - } - - public void write() { - getPointer().setByte(0, size); - getPointer().setByte(1, id); - data.write(); - } - - public int size() { - return 35; - } - - public void copy(control_block_t dest) { - write(); - copyBytes(getPointer(), 0, dest.getPointer(), 0, size()); - dest.read(); - } - - protected List getFieldOrder() { - // XXX: I'm just returning the order from the class declaration, - // don't know if this is correct - return Arrays.asList(new String[] { "size", "id", "data" }); - } - } - - public static class EnhancedIOException extends Exception { - - public EnhancedIOException(String msg) { - super(msg); - } - } - - public static final double kAnalogInputResolution = ((double) ((1 << 14) - 1)); - public static final double kAnalogInputReference = 3.3; - public static final double kAnalogOutputResolution = ((double) ((1 << 8) - 1)); - public static final double kAnalogOutputReference = 4.0; - public static final double kAccelOffset = 8300; - public static final double kAccelScale = 3300.0; - public static final int kSupportedAPIVersion = 1; - control_block_t m_inputData; - status_block_t m_outputData; - final Object m_inputDataSemaphore; - final Object m_outputDataSemaphore; - boolean m_inputValid; - boolean m_outputValid; - boolean m_configChanged; - boolean m_requestEnhancedEnable; - short[] m_encoderOffsets = new short[2]; - - /** - * Digital configuration for enhanced IO - */ - public static class tDigitalConfig { - - /** - * The integer value representing this enumeration - */ - public final int value; - static final int kUnknown_val = 0; - static final int kInputFloating_val = 1; - static final int kInputPullUp_val = 2; - static final int kInputPullDown_val = 3; - static final int kOutput_val = 4; - static final int kPWM_val = 5; - static final int kAnalogComparator_val = 6; - public static final tDigitalConfig kUnknown = new tDigitalConfig( - kUnknown_val); - public static final tDigitalConfig kInputFloating = new tDigitalConfig( - kInputFloating_val); - public static final tDigitalConfig kInputPullUp = new tDigitalConfig( - kInputPullUp_val); - public static final tDigitalConfig kInputPullDown = new tDigitalConfig( - kInputPullDown_val); - public static final tDigitalConfig kOutput = new tDigitalConfig( - (kOutput_val)); - public static final tDigitalConfig kPWM = new tDigitalConfig((kPWM_val)); - public static final tDigitalConfig kAnalogComparator = new tDigitalConfig( - (kAnalogComparator_val)); - - private tDigitalConfig(int value) { - this.value = value; - } - } - - /** - * Accelerometer channel for enhanced IO - */ - public static class tAccelChannel { - - /** - * The integer value representing this enumeration - */ - public final int value; - static final int kAccelX_val = 0; - static final int kAccelY_val = 1; - static final int kAccelZ_val = 2; - public static final tAccelChannel kAccelX = new tAccelChannel( - kAccelX_val); - public static final tAccelChannel kAccelY = new tAccelChannel( - kAccelY_val); - public static final tAccelChannel kAccelZ = new tAccelChannel( - kAccelZ_val); - - private tAccelChannel(int value) { - this.value = value; - } - } - - /** - * PWM period channels for enhanced IO - */ - public static class tPWMPeriodChannels { - - /** - * The integer value representing this enumeration - */ - public final int value; - static final int kPWMChannels1and2_val = 0; - static final int kPWMChannels3and4_val = 1; - public static final tPWMPeriodChannels kPWMChannels1and2 = new tPWMPeriodChannels( - kPWMChannels1and2_val); - public static final tPWMPeriodChannels kPWMChannels3and4 = new tPWMPeriodChannels( - kPWMChannels3and4_val); - - private tPWMPeriodChannels(int value) { - this.value = value; - } - } - - static final byte kInputBlockID = 17, kOutputBlockID = 18; - static final int kStatusValid = 0x01, kStatusConfigChanged = 0x02, - kForceEnhancedMode = 0x04; - - /** - * DriverStationEnhancedIO constructor. - * - * This is only called once when the DriverStation constructor is called. - */ - DriverStationEnhancedIO() { - m_inputValid = false; - m_outputValid = false; - m_configChanged = false; - m_requestEnhancedEnable = false; - m_inputData = new control_block_t(); - m_outputData = new status_block_t(); - m_outputData.size = (byte) (m_outputData.size() - 1); - m_outputData.id = kOutputBlockID; - // Expected to be active low, so initialize inactive. - m_outputData.data.fixed_digital_out = 0x3; - m_inputDataSemaphore = new Object(); - m_outputDataSemaphore = new Object(); - m_encoderOffsets[0] = 0; - m_encoderOffsets[1] = 0; - } - - status_block_t tempOutputData = new status_block_t(); - control_block_t tempInputData = new control_block_t(); - - /** - * Called by the DriverStation class when data is available. This function - * will set any modified configuration / output, then read the input and - * configuration from the IO. - */ - void updateData() { - int retVal; - synchronized (m_outputDataSemaphore) { - if (m_outputValid || m_configChanged || m_requestEnhancedEnable) { - m_outputData.flags = kStatusValid; - if (m_requestEnhancedEnable) { - // Someone called one of the get config APIs, but we are not - // in enhanced mode. - m_outputData.flags |= kForceEnhancedMode; - } - if (m_configChanged) { - if (!m_outputValid) { - // Someone called one of the set config APIs, but we are - // not in enhanced mode. - m_outputData.flags |= kForceEnhancedMode; - } - m_outputData.flags |= kStatusConfigChanged; - } - // XXX: Needs Heavy testing - FRC_NetworkCommunicationsLibrary.overrideIOConfig(m_outputData - .getPointer().getString(0), 5); - } - // XXX: Needs heavy testing - retVal = FRC_NetworkCommunicationsLibrary.getDynamicControlData( - kOutputBlockID, - tempOutputData.getPointer().getByteBuffer(0, - tempOutputData.size()), tempOutputData.size(), 5); - if (retVal == 0) { - if (m_outputValid) { - if (m_configChanged) { - // If our config change made the round trip then clear - // the flag. - if (isConfigEqual(tempOutputData, m_outputData)) { - m_configChanged = false; - } - } else { - // TODO: This won't work until artf1128 is fixed - // if (tempOutputData.flags & kStatusConfigChanged) - { - // Configuration was updated on the DS, so update - // our local cache. - mergeConfigIntoOutput(tempOutputData, m_outputData); - } - } - } else { - // Initialize the local cache. - mergeConfigIntoOutput(tempOutputData, m_outputData); - } - m_requestEnhancedEnable = false; - m_outputValid = true; - } else { - m_outputValid = false; - m_inputValid = false; - } - } - - synchronized (m_inputDataSemaphore) { - // XXX: Needs heavy testing - retVal = FRC_NetworkCommunicationsLibrary.getDynamicControlData( - kInputBlockID, - tempInputData.getPointer().getByteBuffer(0, - tempInputData.size()), tempInputData.size(), 5); - if (retVal == 0 - && tempInputData.data.api_version == kSupportedAPIVersion) { - tempInputData.copy(m_inputData); - m_inputValid = true; - } else { - m_outputValid = false; - m_inputValid = false; - } - } - } - - /** - * Merge the config portion of the DS output block into the local cache. - */ - void mergeConfigIntoOutput(status_block_t dsOutputBlock, - status_block_t localCache) { - localCache.data.digital = (short) ((localCache.data.digital & dsOutputBlock.data.digital_oe) | (dsOutputBlock.data.digital & ~dsOutputBlock.data.digital_oe)); - localCache.data.digital_oe = dsOutputBlock.data.digital_oe; - localCache.data.digital_pe = dsOutputBlock.data.digital_pe; - localCache.data.pwm_period[0] = dsOutputBlock.data.pwm_period[0]; - localCache.data.pwm_period[1] = dsOutputBlock.data.pwm_period[1]; - localCache.data.setEnables(dsOutputBlock.data.getEnables()); - } - - /** - * Compare the config portion of the output blocks. - */ - boolean isConfigEqual(status_block_t dsOutputBlock, - status_block_t localCache) { - if (localCache.data.digital_oe != dsOutputBlock.data.digital_oe) { - return false; - } - if ((localCache.data.digital & ~dsOutputBlock.data.digital) != (dsOutputBlock.data.digital & ~dsOutputBlock.data.digital)) { - return false; - } - if (localCache.data.digital_pe != dsOutputBlock.data.digital_pe) { - return false; - } - if (localCache.data.pwm_period[0] != dsOutputBlock.data.pwm_period[0]) { - return false; - } - if (localCache.data.pwm_period[1] != dsOutputBlock.data.pwm_period[1]) { - return false; - } - if (localCache.data.getEnables() != dsOutputBlock.data.getEnables()) { - return false; - } - return true; - } - - /** - * Query an accelerometer channel on the DS IO. - * - * @param channel - * The channel number to read. - * @return The current acceleration on the channel in Gs. - */ - public double getAcceleration(tAccelChannel channel) - throws EnhancedIOException { - if (!m_inputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_inputDataSemaphore) { - return (m_inputData.data.accel[channel.value] - kAccelOffset) - / kAccelScale; - } - } - - /** - * Query an analog input channel on the DS IO. - * - * @param channel - * The channel number to read. [1,8] - * @return The analog input voltage for the channel. - */ - public double getAnalogIn(int channel) throws EnhancedIOException { - // 3.3V is the analog reference voltage - return getAnalogInRatio(channel) * kAnalogInputReference; - } - - /** - * Query an analog input channel on the DS IO in ratiometric form. - * - * @param channel - * The channel number to read. [1,8] - * @return The analog input percentage for the channel. - */ - public double getAnalogInRatio(int channel) throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 8); - if (!m_inputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_inputDataSemaphore) { - return m_inputData.data.analog[channel - 1] - / kAnalogInputResolution; - } - } - - /** - * Query the voltage currently being output. - * - * AO1 is pin 11 on the top connector (P2). AO2 is pin 12 on the top - * connector (P2). - * - * @param channel - * The analog output channel on the DS IO. [1,2] - * @return The voltage being output on the channel. - */ - public double getAnalogOut(int channel) throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 2); - if (!m_outputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - - synchronized (m_outputDataSemaphore) { - int tempData = m_outputData.data.dac[channel - 1]; - tempData = tempData < 0 ? tempData + 256 : tempData; - return tempData * kAnalogOutputReference / kAnalogOutputResolution; - } - } - - /** - * Set the analog output voltage. - * - * AO1 is pin 11 on the top connector (P2). AO2 is pin 12 on the top - * connector (P2). AO1 is the reference voltage for the 2 analog comparators - * on DIO15 and DIO16. - * - * The output range is 0V to 4V, however due to the supply voltage don't - * expect more than about 3V. Current supply capability is only 100uA. - * - * @param channel - * The analog output channel on the DS IO. [1,2] - * @param value - * The voltage to output on the channel. - */ - public void setAnalogOut(int channel, double value) - throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 2); - if (!m_outputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - if (value < 0.0) { - value = 0.0; - } - if (value > kAnalogOutputReference) { - value = kAnalogOutputReference; - } - if (value > kAnalogOutputReference) { - value = kAnalogOutputReference; - } - - synchronized (m_outputDataSemaphore) { - m_outputData.data.dac[channel - 1] = (byte) (value - / kAnalogOutputReference * kAnalogOutputResolution); - } - } - - /** - * Get the state of a button on the IO board. - * - * Button1 is the physical button "S1". Button2 is pin 4 on the top - * connector (P2). Button3 is pin 6 on the top connector (P2). Button4 is - * pin 8 on the top connector (P2). Button5 is pin 10 on the top connector - * (P2). Button6 is pin 7 on the top connector (P2). - * - * Button2 through Button6 are Capacitive Sense buttons. - * - * @param channel - * The button channel to read. [1,6] - * @return The state of the selected button. - */ - public boolean getButton(int channel) throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 6); - return ((getButtons() >> (channel - 1)) & 1) != 0; - } - - /** - * Get the state of all the button channels. - * - * @return The state of the 6 button channels in the 6 lsb of the returned - * byte. - */ - public byte getButtons() throws EnhancedIOException { - if (!m_inputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_inputDataSemaphore) { - return m_inputData.data.buttons; - } - } - - /** - * Set the state of an LED on the IO board. - * - * @param channel - * The LED channel to set. [1,8] - * @param value - * True to turn the LED on. - */ - public void setLED(int channel, boolean value) throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 8); - if (!m_outputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - byte leds; - synchronized (m_outputDataSemaphore) { - leds = m_outputData.data.leds; - - leds &= ~(1 << (channel - 1)); - if (value) { - leds |= 1 << (channel - 1); - } - - m_outputData.data.leds = leds; - } - } - - /** - * Set the state of all 8 LEDs on the IO board. - * - * @param value - * The state of each LED. LED1 is lsb and LED8 is msb. - */ - public void setLEDs(byte value) throws EnhancedIOException { - if (!m_outputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_outputDataSemaphore) { - m_outputData.data.leds = value; - } - } - - /** - * Get the current state of a DIO channel regardless of mode. - * - * @param channel - * The DIO channel to read. [1,16] - * @return The state of the selected digital line. - */ - public boolean getDigital(int channel) throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 16); - return ((getDigitals() >> (channel - 1)) & 1) != 0; - } - - /** - * Get the state of all 16 DIO lines regardless of mode. - * - * @return The state of all DIO lines. DIO1 is lsb and DIO16 is msb. - */ - public short getDigitals() throws EnhancedIOException { - if (!m_inputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_inputDataSemaphore) { - return m_inputData.data.digital; - } - } - - /** - * Set the state of a DIO line that is configured for digital output. - * - * @param channel - * The DIO channel to set. [1,16] - * @param value - * The state to set the selected channel to. - */ - public void setDigitalOutput(int channel, boolean value) - throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 16); - if (!m_outputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - short digital; - synchronized (m_outputDataSemaphore) { - - if ((m_outputData.data.digital_oe & (1 << (channel - 1))) != 0) { - digital = m_outputData.data.digital; - - digital &= ~(1 << (channel - 1)); - if (value) { - digital |= 1 << (channel - 1); - } - - m_outputData.data.digital = digital; - } else { - System.err.println("Line not configured for output"); - } - } - } - - /** - * Get the current configuration for a DIO line. - * - * This has the side effect of forcing the Driver Station to switch to - * Enhanced mode if it's not when called. If Enhanced mode is not enabled - * when this is called, it will return kUnknown. - * - * @param channel - * The DIO channel config to get. [1,16] - * @return The configured mode for the DIO line. - */ - public tDigitalConfig getDigitalConfig(int channel) - throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 16); - if (!m_outputValid) { - m_requestEnhancedEnable = true; - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_outputDataSemaphore) { - if ((channel >= 1) && (channel <= 4)) { - if ((m_outputData.data.pwm_enable & (1 << (channel - 1))) != 0) { - return tDigitalConfig.kPWM; - } - } - if ((channel >= 15) && (channel <= 16)) { - if ((m_outputData.data.comparator_enable & (1 << (channel - 15))) != 0) { - return tDigitalConfig.kAnalogComparator; - } - } - if ((m_outputData.data.digital_oe & (1 << (channel - 1))) != 0) { - return tDigitalConfig.kOutput; - } - if ((m_outputData.data.digital_pe & (1 << (channel - 1))) == 0) { - return tDigitalConfig.kInputFloating; - } - if ((m_outputData.data.digital & (1 << (channel - 1))) != 0) { - return tDigitalConfig.kInputPullUp; - } else { - return tDigitalConfig.kInputPullDown; - } - } - } - - /** - * Override the DS's configuration of a DIO line. - * - * If configured to kInputFloating, the selected DIO line will be tri-stated - * with no internal pull resistor. - * - * If configured to kInputPullUp, the selected DIO line will be tri-stated - * with a 5k-Ohm internal pull-up resistor enabled. - * - * If configured to kInputPullDown, the selected DIO line will be tri-stated - * with a 5k-Ohm internal pull-down resistor enabled. - * - * If configured to kOutput, the selected DIO line will actively drive to 0V - * or Vddio (specified by J1 and J4). DIO1 through DIO12, DIO15, and DIO16 - * can source 4mA and can sink 8mA. DIO12 and DIO13 can source 4mA and can - * sink 25mA. - * - * In addition to the common configurations, DIO1 through DIO4 can be - * configured to kPWM to enable PWM output. - * - * In addition to the common configurations, DIO15 and DIO16 can be - * configured to kAnalogComparator to enable analog comparators on those 2 - * DIO lines. When enabled, the lines are tri-stated and will accept analog - * voltages between 0V and 3.3V. If the input voltage is greater than the - * voltage output by AO1, the DIO will read as true, if less then false. - * - * @param channel - * The DIO line to configure. [1,16] - * @param config - * The mode to put the DIO line in. - */ - public void setDigitalConfig(int channel, tDigitalConfig config) - throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 16); - if (config == tDigitalConfig.kPWM && ((channel > 4) || (channel < 1))) { - throw new EnhancedIOException( - "PWM channels must be between 1 and 4"); - } - if (config == tDigitalConfig.kAnalogComparator - && ((channel < 15) || (channel > 16))) { - throw new EnhancedIOException( - "Analog comparator channels must be between 15 and 16"); - } - - synchronized (m_outputDataSemaphore) { - m_configChanged = true; - - if ((channel >= 1) && (channel <= 4)) { - if (config == tDigitalConfig.kPWM) { - m_outputData.data.pwm_enable |= 1 << (channel - 1); - m_outputData.data.digital &= ~(1 << (channel - 1)); - m_outputData.data.digital_oe |= 1 << (channel - 1); - m_outputData.data.digital_pe &= ~(1 << (channel - 1)); - return; - } else { - m_outputData.data.pwm_enable &= ~(1 << (channel - 1)); - } - } else if ((channel >= 15) && (channel <= 16)) { - if (config == tDigitalConfig.kAnalogComparator) { - m_outputData.data.comparator_enable |= 1 << (channel - 15); - m_outputData.data.digital &= ~(1 << (channel - 1)); - m_outputData.data.digital_oe &= ~(1 << (channel - 1)); - m_outputData.data.digital_pe &= ~(1 << (channel - 1)); - return; - } else { - m_outputData.data.comparator_enable &= ~(1 << (channel - 15)); - } - } - if (config == tDigitalConfig.kInputFloating) { - m_outputData.data.digital &= ~(1 << (channel - 1)); - m_outputData.data.digital_oe &= ~(1 << (channel - 1)); - m_outputData.data.digital_pe &= ~(1 << (channel - 1)); - } else if (config == tDigitalConfig.kInputPullUp) { - m_outputData.data.digital |= 1 << (channel - 1); - m_outputData.data.digital_oe &= ~(1 << (channel - 1)); - m_outputData.data.digital_pe |= 1 << (channel - 1); - } else if (config == tDigitalConfig.kInputPullDown) { - m_outputData.data.digital &= ~(1 << (channel - 1)); - m_outputData.data.digital_oe &= ~(1 << (channel - 1)); - m_outputData.data.digital_pe |= 1 << (channel - 1); - } else if (config == tDigitalConfig.kOutput) { - m_outputData.data.digital_oe |= 1 << (channel - 1); - m_outputData.data.digital_pe &= ~(1 << (channel - 1)); - } else { - // Something went wrong. - } - } - } - - /** - * Get the period of a PWM generator. - * - * This has the side effect of forcing the Driver Station to switch to - * Enhanced mode if it's not when called. If Enhanced mode is not enabled - * when this is called, it will return 0. - * - * @param channels - * Select the generator by specifying the two channels to which - * it is connected. - * @return The period of the PWM generator in seconds. - */ - public double getPWMPeriod(tPWMPeriodChannels channels) - throws EnhancedIOException { - if (!m_outputValid) { - m_requestEnhancedEnable = true; - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_outputDataSemaphore) { - int tempData = m_outputData.data.pwm_period[channels.value] & 0xFFFF; - return tempData / 24000000.0; - } - } - - /** - * Set the period of a PWM generator. - * - * There are 2 PWM generators on the IO board. One can generate PWM signals - * on DIO1 and DIO2, the other on DIO3 and DIO4. Each generator has one - * counter and two compare registers. As such, each pair of PWM outputs - * share the output period but have independent duty cycles. - * - * @param channels - * Select the generator by specifying the two channels to which - * it is connected. - * @param period - * The period of the PWM generator in seconds. [0.0,0.002731] - */ - public void setPWMPeriod(tPWMPeriodChannels channels, double period) - throws EnhancedIOException { - // Convert to ticks based on the IO board's 24MHz clock - double ticks = period * 24000000.0; - // Limit the range of the ticks... warn if too big. - if (ticks > 65534.0) { - ticks = 65534.0; - throw new EnhancedIOException("Enhanced IO PWM Period Out of Range"); - } else if (ticks < 0.0) { - ticks = 0.0; - } - // Preserve the duty cycles. - double[] dutyCycles = new double[2]; - dutyCycles[0] = getPWMOutput((channels.value << 1) + 1); - dutyCycles[1] = getPWMOutput((channels.value << 1) + 2); - synchronized (m_outputDataSemaphore) { - // Update the period - m_outputData.data.pwm_period[channels.value] = (short) ticks; - m_configChanged = true; - } - // Restore the duty cycles - setPWMOutput((channels.value << 1) + 1, dutyCycles[0]); - setPWMOutput((channels.value << 1) + 2, dutyCycles[1]); - } - - /** - * Get the state being output on a fixed digital output. - * - * @param channel - * The FixedDO line to get. [1,2] - * @return The state of the FixedDO line. - */ - public boolean getFixedDigitalOutput(int channel) - throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 2); - if (!m_outputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_outputDataSemaphore) { - return ((m_outputData.data.fixed_digital_out >> (channel - 1)) & 1) != 0; - } - } - - /** - * Set the state to output on a Fixed High Current Digital Output line. - * - * FixedDO1 is pin 5 on the top connector (P2). FixedDO2 is pin 3 on the top - * connector (P2). - * - * The FixedDO lines always output 0V and 3.3V regardless of J1 and J4. They - * can source 4mA and can sink 25mA. Because of this, they are expected to - * be used in an active low configuration, such as connecting to the cathode - * of a bright LED. Because they are expected to be active low, they default - * to true. - * - * @param channel - * The FixedDO channel to set. - * @param value - * The state to set the FixedDO. - */ - public void setFixedDigitalOutput(int channel, boolean value) - throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 2); - if (!m_outputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - byte digital; - synchronized (m_outputDataSemaphore) { - digital = m_outputData.data.fixed_digital_out; - - digital &= ~(1 << (channel - 1)); - if (value) { - digital |= 1 << (channel - 1); - } - - m_outputData.data.fixed_digital_out = digital; - } - } - - /** - * Get the position of a quadrature encoder. - * - * There are two signed 16-bit 4X quadrature decoders on the IO board. These - * decoders are always monitoring the state of the lines assigned to them, - * but these lines do not have to be used for encoders. - * - * Encoder1 uses DIO4 for "A", DIO6 for "B", and DIO8 for "Index". Encoder2 - * uses DIO5 for "A", DIO7 for "B", and DIO9 for "Index". - * - * The index functionality can be enabled or disabled using - * SetEncoderIndexEnable(). - * - * @param encoderNumber - * The quadrature encoder to access. [1,2] - * @return The current position of the quadrature encoder. - */ - public short getEncoder(int encoderNumber) throws EnhancedIOException { - BoundaryException.assertWithinBounds(encoderNumber, 1, 2); - if (!m_inputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_inputDataSemaphore) { - return (short) (m_inputData.data.quad[encoderNumber - 1] - m_encoderOffsets[encoderNumber - 1]); - } - } - - /** - * Reset the position of an encoder to 0. - * - * This simply stores an offset locally. It does not reset the hardware - * counter on the IO board. If you use this method with Index enabled, you - * may get unexpected results. - * - * @param encoderNumber - * The quadrature encoder to reset. [1,2] - */ - public void resetEncoder(int encoderNumber) throws EnhancedIOException { - BoundaryException.assertWithinBounds(encoderNumber, 1, 2); - if (!m_inputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_inputDataSemaphore) { - m_encoderOffsets[encoderNumber - 1] = m_inputData.data.quad[encoderNumber - 1]; - } - } - - /** - * Get the current configuration of a quadrature encoder index channel. - * - * This has the side effect of forcing the Driver Station to switch to - * Enhanced mode if it's not when called. If Enhanced mode is not enabled - * when this is called, it will return false. - * - * @param encoderNumber - * The quadrature encoder. [1,2] - * @return Is the index channel of the encoder enabled. - */ - public boolean getEncoderIndexEnable(int encoderNumber) - throws EnhancedIOException { - BoundaryException.assertWithinBounds(encoderNumber, 1, 2); - if (!m_outputValid) { - m_requestEnhancedEnable = true; - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_outputDataSemaphore) { - return ((m_outputData.data.quad_index_enable >> (encoderNumber - 1)) & 1) != 0; - } - } - - /** - * Enable or disable the index channel of a quadrature encoder. - * - * The quadrature decoders on the IO board support an active-low index - * input. - * - * Encoder1 uses DIO8 for "Index". Encoder2 uses DIO9 for "Index". - * - * When enabled, the decoder's counter will be reset to 0 when A, B, and - * Index are all low. - * - * @param encoderNumber - * The quadrature encoder. [1,2] - * @param enable - * If true, reset the encoder in an index condition. - */ - public void setEncoderIndexEnable(int encoderNumber, boolean enable) { - BoundaryException.assertWithinBounds(encoderNumber, 1, 2); - synchronized (m_outputDataSemaphore) { - m_outputData.data.quad_index_enable &= ~(1 << (encoderNumber - 1)); - if (enable) { - m_outputData.data.quad_index_enable |= 1 << (encoderNumber - 1); - } - m_configChanged = true; - } - } - - /** - * Get the value of the Capacitive Sense touch slider. - * - * @return Value between 0.0 (toward center of board) and 1.0 (toward edge - * of board). -1.0 means no touch detected. - */ - public double getTouchSlider() throws EnhancedIOException { - if (!m_inputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_inputDataSemaphore) { - byte rawValue = m_inputData.data.capsense_slider; - int value = rawValue < 0 ? rawValue + 256 : rawValue; - return value == 255 ? -1.0 : value / 254.0; - } - } - - /** - * Get the percent duty-cycle that the PWM generator channel is configured - * to output. - * - * @param channel - * The DIO line's PWM generator to get the duty-cycle from. [1,4] - * @return The percent duty-cycle being output (if the DIO line is - * configured for PWM). [0.0,1.0] - */ - public double getPWMOutput(int channel) throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 4); - if (!m_outputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_outputDataSemaphore) { - int tempCompare = m_outputData.data.pwm_compare[channel - 1] & 0xFFFF; - int tempPeriod = m_outputData.data.pwm_period[(channel - 1) >> 1] & 0xFFFF; - return (double) tempCompare / (double) tempPeriod; - } - } - - /** - * Set the percent duty-cycle to output on a PWM enabled DIO line. - * - * DIO1 through DIO4 have the ability to output a PWM signal. The period of - * the signal can be configured in pairs using SetPWMPeriod(). - * - * @param channel - * The DIO line's PWM generator to set. [1,4] - * @param value - * The percent duty-cycle to output from the PWM generator. - * [0.0,1.0] - */ - public void setPWMOutput(int channel, double value) - throws EnhancedIOException { - BoundaryException.assertWithinBounds(channel, 1, 4); - if (!m_outputValid) { - throw new EnhancedIOException("Enhanced IO Missing"); - } - if (value > 1.0) { - value = 1.0; - } else if (value < 0.0) { - value = 0.0; - } - synchronized (m_outputDataSemaphore) { - m_outputData.data.pwm_compare[channel - 1] = (short) (value * (double) m_outputData.data.pwm_period[(channel - 1) >> 1]); - } - } - - /** - * Get the firmware version running on the IO board. - * - * This also has the side effect of forcing the driver station to switch to - * Enhanced mode if it is not. If you plan to switch between Driver Stations - * with unknown IO configurations, you can call this until it returns a - * non-0 version to ensure that this API is accessible before proceeding. - * - * @return The version of the firmware running on the IO board. 0 if the - * board is not attached or not in Enhanced mode. - */ - public byte getFirmwareVersion() throws EnhancedIOException { - if (!m_inputValid) { - m_requestEnhancedEnable = true; - throw new EnhancedIOException("Enhanced IO Missing"); - } - synchronized (m_inputDataSemaphore) { - return m_inputData.data.fw_version; - } - } -} diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java new file mode 100644 index 0000000000..74b1e23836 --- /dev/null +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java @@ -0,0 +1,31 @@ +package edu.wpi.first.wpilibj; + +/** + * Support for high level usage reporting. + * + * @author alex + */ +public class HLUsageReporting { + private static Interface impl; + + public static void SetImplementation(Interface i) { + impl = i; + } + + public static void reportScheduler() { + if (impl != null) { + impl.reportScheduler(); + } + } + + public static void reportPIDController(int num) { + if (impl != null) { + impl.reportPIDController(num); + } + } + + public interface Interface { + void reportScheduler(); + void reportPIDController(int num); + } +} diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Kinect.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Kinect.java deleted file mode 100644 index 951e8d4728..0000000000 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Kinect.java +++ /dev/null @@ -1,456 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -import com.sun.jna.Pointer; -import com.sun.jna.Structure; -import edu.wpi.first.wpilibj.communication.FRCControl; -import edu.wpi.first.wpilibj.communication.UsageReporting; - -/** - * @author bradmiller - * Handles raw data input from the FRC Kinect Server - * when used with a Kinect device connected to the Driver Station. - * Each time a value is requested the most recent value is returned. - * See Getting Started with Microsoft Kinect for FRC and the Kinect - * for Windows SDK API reference for more information - * - */ -public class Kinect { - - private static Kinect m_instance; - - /** - * Gets an instance of the Kinect device - * - * @return The Kinect. - */ - public static synchronized Kinect getInstance() { - if(m_instance == null) - m_instance = new Kinect(); - return m_instance; - } - - /** - * A set of 4 coordinates (x,y,z,w) bundled into one object - */ - public class Point4 { - public float x, y, z, w; - - public float getX() { - return x; - } - public float getY() { - return y; - } - public float getZ() { - return z; - } - public float getW() { - return w; - } - - public int size() { - return 16; - } - } - - static class header_t extends Structure { - - byte[] version = new byte[11]; - byte players; - int flags; - float[] floorClipPlane = new float[4]; - float[] gravityNormalVector = new float[3]; - - final static int size = 44; - - header_t(Pointer backingMemory) { - useMemory(backingMemory); - } - - public void read() { - backingNativeMemory.getBytes(0, version, 0, version.length); - players = backingNativeMemory.getByte(11); - flags = backingNativeMemory.getInt(12); - backingNativeMemory.getFloats(16, floorClipPlane, 0, floorClipPlane.length); - backingNativeMemory.getFloats(32, gravityNormalVector, 0, gravityNormalVector.length); - } - - public void write() { - backingNativeMemory.setBytes(0, version, 0, version.length); - backingNativeMemory.setByte(11, players); - backingNativeMemory.setInt(12, flags); - backingNativeMemory.setFloats(16, floorClipPlane, 0, floorClipPlane.length); - backingNativeMemory.setFloats(32, gravityNormalVector, 0, gravityNormalVector.length); - } - - public int size() { - return size; - } - } - - static class skeletonExtra_t extends Structure { - byte[] trackingState = new byte[20]; - float[] position = new float[3]; - int quality; - int trackState; - - final static int size = 40; - - skeletonExtra_t(Pointer backingMemory) { - useMemory(backingMemory); - } - - public void read() { - backingNativeMemory.getBytes(0, trackingState, 0, trackingState.length); - backingNativeMemory.getFloats(20, position, 0, position.length); - quality = backingNativeMemory.getInt(32); - trackState = backingNativeMemory.getInt(36); - } - - public void write() { - backingNativeMemory.setBytes(0, trackingState, 0, trackingState.length); - backingNativeMemory.setFloats(20, position, 0, position.length); - backingNativeMemory.setInt(32, quality); - backingNativeMemory.setInt(36, trackState); - } - - public int size() { - return size; - } - } - - static class skeleton_t extends Structure { - float[] vertices = new float[60]; - - final static int size = 240; - - skeleton_t(Pointer backingMemory) { - useMemory(backingMemory); - } - - public void read() { - backingNativeMemory.getFloats(0, vertices, 0, vertices.length); - } - - public void write() { - backingNativeMemory.setFloats(0, vertices, 0, vertices.length); - } - - public int size() { - return size; - } - } - - class header_block_t extends FRCControl.DynamicControlData { - byte size = 45; - byte id = kHeaderBlockID; - header_t data; - - { - allocateMemory(); - data = new header_t( - new Pointer(backingNativeMemory.address().toUWord().toPrimitive() + 2, - header_t.size)); - } - - public void read() { - - size = backingNativeMemory.getByte(0); - id = backingNativeMemory.getByte(1); - data.read(); - } - - public void write() { - backingNativeMemory.setByte(0, size); - backingNativeMemory.setByte(1, id); - data.write(); - } - - public int size() { - return 46; - } - - public void copy(header_block_t dest) { - write(); - Pointer.copyBytes(backingNativeMemory, 0, dest.backingNativeMemory, 0, size()); - dest.read(); - } - } - - class skeletonExtra_block_t extends FRCControl.DynamicControlData { - byte size = 41; - byte id = kSkeletonExtraBlockID; - skeletonExtra_t data; - - { - allocateMemory(); - data = new skeletonExtra_t( - new Pointer(backingNativeMemory.address().toUWord().toPrimitive() + 2, - skeletonExtra_t.size)); - } - - public void read() { - - size = backingNativeMemory.getByte(0); - id = backingNativeMemory.getByte(1); - data.read(); - } - - public void write() { - backingNativeMemory.setByte(0, size); - backingNativeMemory.setByte(1, id); - data.write(); - } - - public int size() { - return 42; - } - - public void copy(skeletonExtra_block_t dest) { - write(); - Pointer.copyBytes(backingNativeMemory, 0, dest.backingNativeMemory, 0, size()); - dest.read(); - } - } - - class skeleton_block_t extends FRCControl.DynamicControlData { - byte size = -15; //temporary hack for 241 - byte id = kSkeletonBlockID; - skeleton_t data; - - { - allocateMemory(); - data = new skeleton_t( - new Pointer(backingNativeMemory.address().toUWord().toPrimitive() + 2, - skeleton_t.size)); - } - - public void read() { - size = backingNativeMemory.getByte(0); - id = backingNativeMemory.getByte(1); - data.read(); - } - - public void write() { - backingNativeMemory.setByte(0, size); - backingNativeMemory.setByte(1, id); - data.write(); - } - - public int size() { - return 242; - } - - public void copy(skeleton_block_t dest) { - write(); - Pointer.copyBytes(backingNativeMemory, 0, dest.backingNativeMemory, 0, size()); - dest.read(); - } - } - - static final byte kHeaderBlockID = 19; - static final byte kSkeletonExtraBlockID = 20; - static final byte kSkeletonBlockID = 21; - - header_block_t m_headerData; - skeletonExtra_block_t m_skeletonExtraData; - skeleton_block_t m_skeletonData; - boolean m_headerValid = false; - boolean m_skeletonExtraValid = false; - boolean m_skeletonValid = false; - final Object m_headerDataSemaphore; - final Object m_skeletonExtraDataSemaphore; - final Object m_skeletonDataSemaphore; - int m_recentPacketNumber = 0; - - /** - * Kinect constructor. - * - * This is only called once on the first call of getInstance() - */ - Kinect() { - m_headerData = new header_block_t(); - m_skeletonExtraData = new skeletonExtra_block_t(); - m_skeletonData = new skeleton_block_t(); - m_headerDataSemaphore = new Object(); - m_skeletonExtraDataSemaphore = new Object(); - m_skeletonDataSemaphore = new Object(); - - UsageReporting.report(UsageReporting.kResourceType_Kinect, 0); - } - header_block_t tempHeaderData = new header_block_t(); - skeletonExtra_block_t tempSkeletonExtraData = new skeletonExtra_block_t(); - skeleton_block_t tempSkeletonData = new skeleton_block_t(); - - - /** - * Called by the other Kinect functions to check for the latest data - * This function will update the internal data structures - * with the most recent Kinect input - */ - void updateData() { - int retVal; - - if (m_recentPacketNumber != DriverStation.getInstance().getPacketNumber()) { - m_recentPacketNumber = DriverStation.getInstance().getPacketNumber(); - synchronized (m_headerDataSemaphore) { - retVal = FRCControl.getDynamicControlData(kHeaderBlockID, tempHeaderData, tempHeaderData.size(), 5); - if (retVal == 0) { - tempHeaderData.copy(m_headerData); - m_headerValid = true; - } else { - m_headerValid = false; - } - } - - synchronized (m_skeletonExtraDataSemaphore) { - retVal = FRCControl.getDynamicControlData(kSkeletonExtraBlockID, tempSkeletonExtraData, tempSkeletonExtraData.size(), 5); - if (retVal == 0) { - tempSkeletonExtraData.copy(m_skeletonExtraData); - m_skeletonExtraValid = true; - } else { - m_skeletonExtraValid = false; - } - } - - synchronized (m_skeletonDataSemaphore) { - retVal = FRCControl.getDynamicControlData(kSkeletonBlockID, tempSkeletonData, tempSkeletonData.size(), 5); - if (retVal == 0) { - tempSkeletonData.copy(m_skeletonData); - m_skeletonValid = true; - } else { - m_skeletonValid = false; - } - } - } - } - - /** - * Query the number of players detected by the Kinect - * - * @return The current number of players - */ - public int getNumberOfPlayers() { - updateData(); - if (!m_headerValid) { - return 0; - } - synchronized (m_headerDataSemaphore) { - return (int)m_headerData.data.players; - } - } - - /** - * Retrieve the FloorClipPlane from the Kinect device - * - * @return The FloorClipPlane - */ - public Point4 getFloorClipPlane() { - updateData(); - Point4 tempClipPlane = new Point4(); - - if (!m_headerValid) { - return tempClipPlane; - } - - synchronized(m_headerDataSemaphore) { - tempClipPlane.x = m_headerData.data.floorClipPlane[0]; - tempClipPlane.y = m_headerData.data.floorClipPlane[1]; - tempClipPlane.z = m_headerData.data.floorClipPlane[2]; - tempClipPlane.w = m_headerData.data.floorClipPlane[3]; - } - return tempClipPlane; - } - - /** - * Retrieve the GravityNormal vector from the Kinect device - * The w value returned from this method is always 0 - * @return The GravityNormal vector - */ - public Point4 getGravityNormal() { - updateData(); - Point4 tempGravityNormal = new Point4(); - - if (!m_headerValid) { - return tempGravityNormal; - } - - synchronized(m_headerDataSemaphore) { - tempGravityNormal.x = m_headerData.data.gravityNormalVector[0]; - tempGravityNormal.y = m_headerData.data.gravityNormalVector[1]; - tempGravityNormal.z = m_headerData.data.gravityNormalVector[2]; - tempGravityNormal.w = 0; - } - return tempGravityNormal; - } - - /** - * Query the position of the detected skeleton - * The w value returned from this method is always 1 - * @return The position of the skeleton - */ - public Point4 getPosition() { - updateData(); - Point4 tempPosition = new Point4(); - - if (!m_skeletonExtraValid) { - return tempPosition; - } - - synchronized(m_headerDataSemaphore) { - tempPosition.x = m_skeletonExtraData.data.position[0]; - tempPosition.y = m_skeletonExtraData.data.position[1]; - tempPosition.z = m_skeletonExtraData.data.position[2]; - tempPosition.w = 1; - } - return tempPosition; - } - - /** - * Retrieve the detected skeleton from the Kinect device - * - * @return The skeleton - */ - public Skeleton getSkeleton() { - updateData(); - Skeleton tempSkeleton = new Skeleton(); - - if (!m_skeletonValid) { - return tempSkeleton; - } - - synchronized (m_skeletonDataSemaphore) { - for(int i=0; i<20; i++) { - tempSkeleton.skeleton[i].x = m_skeletonData.data.vertices[i*3]; - tempSkeleton.skeleton[i].y = m_skeletonData.data.vertices[i*3+1]; - tempSkeleton.skeleton[i].z = m_skeletonData.data.vertices[i*3+2]; - } - } - - synchronized (m_skeletonExtraDataSemaphore) { - for(int i=0; i<20; i++) { - tempSkeleton.skeleton[i].trackingState = m_skeletonExtraData.data.trackingState[i]; - } - switch(m_skeletonExtraData.data.trackState) { - case 0: - tempSkeleton.trackState = Skeleton.tTrackState.kNotTracked; - break; - case 1: - tempSkeleton.trackState = Skeleton.tTrackState.kPositionOnly; - break; - case 2: - tempSkeleton.trackState = Skeleton.tTrackState.kTracked; - break; - } - - } - return tempSkeleton; - } -} diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/KinectStick.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/KinectStick.java deleted file mode 100644 index 8f962f251b..0000000000 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/KinectStick.java +++ /dev/null @@ -1,260 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ -package edu.wpi.first.wpilibj; - -import com.sun.jna.Pointer; -import com.sun.jna.Structure; -import edu.wpi.first.wpilibj.communication.FRCControl; -import edu.wpi.first.wpilibj.communication.UsageReporting; - -/** - * @author bradmiller - * Handles input from the Joystick data sent by the FRC Kinect Server - * when used with a Kinect device connected to the Driver Station. - * Each time a value is requested the most recent value is returned. - * Default gestures embedded in the FRC Kinect Server are described - * in the document Getting Started with Microsoft Kinect for FRC. - */ -public class KinectStick extends GenericHID { - - private final static byte kJoystickDataID = 24; - private final static byte kJoystickDataSize = 18; - private int m_recentPacketNumber; - - private int m_id; - - static class JoystickDataBlock extends Structure { - - byte joystick1[] = new byte[6]; - short button1; - byte joystick2[] = new byte[6]; - short button2; - - public static final int size = kJoystickDataSize - 2; - - JoystickDataBlock(Pointer backingMemory) { - useMemory(backingMemory); - } - - public void read() { - backingNativeMemory.getBytes(0, joystick1, 0, 6); - button1 = backingNativeMemory.getShort(6); - backingNativeMemory.getBytes(8, joystick2, 0, 6); - button2 = backingNativeMemory.getShort(14); - } - - public void write() { - backingNativeMemory.setBytes(0, joystick1, 0, 6); - backingNativeMemory.setShort(6, button1); - backingNativeMemory.setBytes(8, joystick2, 0, 6); - backingNativeMemory.setShort(14, button2); - } - - public int size() { - return size; - } - } - - class JoystickData extends FRCControl.DynamicControlData { - - JoystickDataBlock data; - - { - allocateMemory(); - data = new JoystickDataBlock( - new Pointer(backingNativeMemory.address().toUWord().toPrimitive() + 2, - JoystickDataBlock.size)); - } - - public void read() { - data.read(); - } - - public void write() { - data.write(); - } - - public int size() { - return kJoystickDataSize; - } - - public void copy(JoystickData dest) { - write(); - Pointer.copyBytes(backingNativeMemory, 0, dest.backingNativeMemory, 0, size()); - dest.read(); - } - } - JoystickData tempOutputData = new JoystickData(); - - /** - * Construct an instance of a KinectStick. - * @param id which KinectStick to read, in the default gestures - * an id of 1 corresponds to the left arm and 2 to the right arm. - */ - public KinectStick(int id) { - m_id = id; - - UsageReporting.report(UsageReporting.kResourceType_KinectStick, id); - } - - /** - * Update the data in this class with the latest data from the - * Driver Station. - */ - private void getData() { - if (m_recentPacketNumber != DriverStation.getInstance().getPacketNumber()) { - m_recentPacketNumber = DriverStation.getInstance().getPacketNumber(); - int retVal = FRCControl.getDynamicControlData(kJoystickDataID, tempOutputData, tempOutputData.size(), 5); - if (retVal != 0) { - System.err.println("Bad retval: " + retVal); - } - } - } - - /** - * Convert a value from a byte to a double in the - * -1 to 1 range - * @param rawValue the value to convert - * @return the normalized value - */ - private double normalize(byte rawValue) { - if(rawValue >= 0) - return rawValue / 127.0; - else - return rawValue / 128.0; - } - - /** - * Get the X value of the KinectStick. This axis - * is unimplemented in the default gestures but can - * be populated by teams editing the Kinect Server. - * See (@link Joystick for axis number mapping) - * @param hand Unused - * @return The X value of the KinectStick - */ - public double getX(Hand hand) { - getData(); - return getRawAxis(Joystick.kDefaultXAxis); - } - - /** - * Get the Y value of the KinectStick. This axis - * represents arm angle in the default gestures - * See (@link Joystick for axis number mapping) - * @param hand Unused - * @return The Y value of the KinectStick - */ - public double getY(Hand hand) { - getData(); - return getRawAxis(Joystick.kDefaultYAxis); - } - - /** - * Get the Z value of the KinectStick. This axis - * is unimplemented in the default gestures but can - * be populated by teams editing the Kinect Server. - * See (@link Joystick for axis number mapping) - * @param hand Unused - * @return The Z value of the KinectStick - */ - public double getZ(Hand hand) { - getData(); - return getRawAxis(Joystick.kDefaultZAxis); - } - - /** - * Get the Twist value of the KinectStick. This axis - * is unimplemented in the default gestures but can - * be populated by teams editing the Kinect Server. - * See (@link Joystick for axis number mapping) - * @return The Twist value of the KinectStick - */ - public double getTwist() { - getData(); - return getRawAxis(Joystick.kDefaultTwistAxis); - } - - /** - * Get the Throttle value of the KinectStick. This axis - * is unimplemented in the default gestures but can - * be populated by teams editing the Kinect Server. - * See (@link Joystick for axis number mapping) - * @return The Throttle value of the KinectStick - */ - public double getThrottle() { - getData(); - return getRawAxis(Joystick.kDefaultThrottleAxis); - } - - /** - * Get the value of the KinectStick axis. - * - * @param axis The axis to read [1-6]. - * @return The value of the axis - */ - public double getRawAxis(int axis) { - if (axis < 1 || axis > DriverStation.kJoystickAxes) - return 0.0; - - getData(); - if (m_id == 1) { - return normalize(tempOutputData.data.joystick1[axis-1]); - } else { - return normalize(tempOutputData.data.joystick2[axis-1]); - } - } - - /** - * Get the button value for the button set as the default trigger in - * (@link Joystick) - * - * @param hand Unused - * @return The state of the button. - */ - public boolean getTrigger(Hand hand) { - getData(); - return (tempOutputData.data.button1 & (short) Joystick.kDefaultTriggerButton) != 0; - } - - /** - * Get the button value for the button set as the default top in - * (@link Joystick) - * - * @param hand Unused - * @return The state of the button. - */ - public boolean getTop(Hand hand) { - getData(); - return (tempOutputData.data.button1 & (short) Joystick.kDefaultTopButton) != 0; - } - - /** - * Get the button value for the button set as the default bumper in - * (@link Joystick) - * - * @param hand Unused - * @return The state of the button. - */ - public boolean getBumper(Hand hand) { - getData(); - return (tempOutputData.data.button1 & (short) 4) != 0; - } - - /** - * Get the button value for buttons 1 through 12. The default gestures - * implement only 9 buttons. - * - * The appropriate button is returned as a boolean value. - * - * @param button The button number to be read. - * @return The state of the button. - */ - public boolean getRawButton(int button) { - getData(); - return (tempOutputData.data.button1 & (short) (1 << (button - 1))) != 0; - } -} diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/MotorSafetyHelper.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/MotorSafetyHelper.java index 2a06ef3e22..5fb7c95f1b 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/MotorSafetyHelper.java +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/MotorSafetyHelper.java @@ -7,6 +7,8 @@ package edu.wpi.first.wpilibj; +import edu.wpi.first.wpilibj.Timer; + /** * The MotorSafetyHelper object is constructed for every object that wants to implement the Motor * Safety protocol. The helper object has the code to actually do the timing and call the @@ -82,8 +84,7 @@ public class MotorSafetyHelper { * updated again. */ public void check() { - DriverStation ds = DriverStation.getInstance(); - if (!m_enabled || ds.isDisabled() || ds.isTest()) + if (!m_enabled || RobotState.isDisabled() || RobotState.isTest()) return; if (m_stopTime < Timer.getFPGATimestamp()) { System.err.println(m_safeObject.getDescription() + "... Output not updated often enough."); diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/PIDController.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/PIDController.java index 15a774c906..02b1f58e2b 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/PIDController.java +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/PIDController.java @@ -6,10 +6,7 @@ /*----------------------------------------------------------------------------*/ package edu.wpi.first.wpilibj; -import java.util.TimerTask; - -import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; -import edu.wpi.first.wpilibj.communication.UsageReporting; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.parsing.IUtility; import edu.wpi.first.wpilibj.tables.ITable; @@ -46,7 +43,6 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller { private double m_period = kDefaultPeriod; PIDSource m_pidInput; PIDOutput m_pidOutput; - java.util.Timer m_controlLoop; private boolean m_freed = false; private boolean m_usingPercentTolerance; @@ -91,8 +87,7 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller { } } - private class PIDTask extends TimerTask { - + private class PIDTask implements Runnable { private PIDController m_controller; public PIDTask(PIDController controller) { @@ -103,10 +98,9 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller { } public void run() { - if(!m_freed){ + while (!m_controller.m_freed) { m_controller.calculate(); - } else { - cancel(); + Timer.delay(m_controller.m_period); } } } @@ -133,9 +127,6 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller { throw new NullPointerException("Null PIDOutput was given"); } - m_controlLoop = new java.util.Timer(); - - m_P = Kp; m_I = Ki; m_D = Kd; @@ -145,10 +136,10 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller { m_pidOutput = output; m_period = period; - m_controlLoop.schedule(new PIDTask(this), 0L, (long) (m_period * 1000)); + new Thread(new PIDTask(this)).start(); instances++; - UsageReporting.report(tResourceType.kResourceType_PIDController, instances); + HLUsageReporting.reportPIDController(instances); m_tolerance = new NullTolerance(); } @@ -199,10 +190,8 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller { public void free() { m_freed = true; if(this.table!=null) table.removeTableListener(listener); - m_controlLoop.cancel(); m_pidInput = null; m_pidOutput = null; - m_controlLoop = null; } /** diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/RobotState.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/RobotState.java new file mode 100644 index 0000000000..f7ccc55595 --- /dev/null +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/RobotState.java @@ -0,0 +1,57 @@ +package edu.wpi.first.wpilibj; + +public class RobotState { + private static Interface impl; + + public static void SetImplementation(Interface i) { + impl = i; + } + + public static boolean isDisabled() { + if (impl != null) { + return impl.isDisabled(); + } else { + return true; + } + } + + public static boolean isEnabled() { + if (impl != null) { + return impl.isEnabled(); + } else { + return false; + } + } + + public static boolean isOperatorControl() { + if (impl != null) { + return impl.isOperatorControl(); + } else { + return true; + } + } + + public static boolean isAutonomous() { + if (impl != null) { + return impl.isAutonomous(); + } else { + return false; + } + } + + public static boolean isTest() { + if (impl != null) { + return impl.isTest(); + } else { + return false; + } + } + + interface Interface { + boolean isDisabled(); + boolean isEnabled(); + boolean isOperatorControl(); + boolean isAutonomous(); + boolean isTest(); + } +} diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Skeleton.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Skeleton.java deleted file mode 100644 index d78d2c202a..0000000000 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Skeleton.java +++ /dev/null @@ -1,227 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -/** - * A Skeleton object to be used with Kinect data from the - * FRC Kinect server on the DriverStation - * @author koconnor - */ -public class Skeleton { - - /** - * The TrackState of the skeleton - */ - public static class tTrackState { - - /** The integer value representing this enumeration. */ - public final int value; - - protected static final int kNotTracked_val = 0; - protected static final int kPositionOnly_val = 1; - protected static final int kTracked_val = 2; - - /** TrackState: Not Tracked */ - public static final tTrackState kNotTracked = new tTrackState(kNotTracked_val); - /** TrackState: Position Only */ - public static final tTrackState kPositionOnly = new tTrackState(kPositionOnly_val); - /** TrackState: Tracked */ - public static final tTrackState kTracked = new tTrackState(kTracked_val); - - private tTrackState(int value) { - this.value = value; - } - } - - /** - * The Joint TrackingState - */ - public static class tJointTrackingState { - /** The integer value representing this enumeration. */ - public final int value; - - protected static final int kNotTracked_val = 0; - protected static final int kInferred_val = 1; - protected static final int kTracked_val = 2; - - /** Joint TrackingState: Not Tracked */ - public static final tJointTrackingState kNotTracked = new tJointTrackingState(kNotTracked_val); - /** Joint TrackingState: Inferred */ - public static final tJointTrackingState kInferred = new tJointTrackingState(kInferred_val); - /** Joint TrackingState: Tracked */ - public static final tJointTrackingState kTracked = new tJointTrackingState(kTracked_val); - - private tJointTrackingState(int value) { - this.value = value; - } - } - - /** - * An individual Joint from Kinect data - */ - public class Joint { - protected float x, y, z; - protected byte trackingState; - - Joint() { - x = y = z = 0; - } - - public float getX() { - return x; - } - public float getY() { - return y; - } - public float getZ() { - return z; - } - public tJointTrackingState getTrackingState() { - switch(trackingState) { - case 1: - return tJointTrackingState.kInferred; - case 2: - return tJointTrackingState.kTracked; - default: - return tJointTrackingState.kNotTracked; - } - } - } - - /** - * Helper class used to index the joints in a (@link Skeleton) - */ - public static class tJointTypes { - public final int value; - - protected static final int kHipCenter_val = 0; - protected static final int kSpine_val = 1; - protected static final int kShoulderCenter_val = 2; - protected static final int kHead_val = 3; - protected static final int kShoulderLeft_val = 4; - protected static final int kElbowLeft_val = 5; - protected static final int kWristLeft_val = 6; - protected static final int kHandLeft_val = 7; - protected static final int kShoulderRight_val = 8; - protected static final int kElbowRight_val = 9; - protected static final int kWristRight_val = 10; - protected static final int kHandRight_val = 11; - protected static final int kHipLeft_val = 12; - protected static final int kKneeLeft_val = 13; - protected static final int kAnkleLeft_val = 14; - protected static final int kFootLeft_val = 15; - protected static final int kHipRight_val = 16; - protected static final int kKneeRight_val = 17; - protected static final int kAnkleRight_val = 18; - protected static final int kFootRight_val = 19; - protected static final int kCount_val = 20; - - public static final tJointTypes kHipCenter = new tJointTypes(kHipCenter_val); - public static final tJointTypes kSpine = new tJointTypes(kSpine_val); - public static final tJointTypes kShoulderCenter = new tJointTypes(kShoulderCenter_val); - public static final tJointTypes kHead = new tJointTypes(kHead_val); - public static final tJointTypes kShoulderLeft = new tJointTypes(kShoulderLeft_val); - public static final tJointTypes kElbowLeft = new tJointTypes(kElbowLeft_val); - public static final tJointTypes kWristLeft = new tJointTypes(kWristLeft_val); - public static final tJointTypes kHandLeft = new tJointTypes(kHandLeft_val); - public static final tJointTypes kShoulderRight = new tJointTypes(kShoulderRight_val); - public static final tJointTypes kElbowRight = new tJointTypes(kElbowRight_val); - public static final tJointTypes kWristRight = new tJointTypes(kWristRight_val); - public static final tJointTypes kHandRight = new tJointTypes(kHandRight_val); - public static final tJointTypes kHipLeft = new tJointTypes(kHipLeft_val); - public static final tJointTypes kKneeLeft = new tJointTypes(kKneeLeft_val); - public static final tJointTypes kAnkleLeft = new tJointTypes(kAnkleLeft_val); - public static final tJointTypes kFootLeft = new tJointTypes(kFootLeft_val); - public static final tJointTypes kHipRight = new tJointTypes(kHipRight_val); - public static final tJointTypes kKneeRight = new tJointTypes(kKneeRight_val); - public static final tJointTypes kAnkleRight = new tJointTypes(kAnkleRight_val); - public static final tJointTypes kFootRight = new tJointTypes(kFootRight_val); - public static final tJointTypes kCount = new tJointTypes(kCount_val); - - private tJointTypes(int value) { - this.value = value; - } - } - - public Joint GetHandRight() { - return skeleton[tJointTypes.kHandRight.value]; - } - public Joint GetHandLeft() { - return skeleton[tJointTypes.kHandLeft.value]; - } - public Joint GetWristRight() { - return skeleton[tJointTypes.kWristRight.value]; - } - public Joint GetWristLeft() { - return skeleton[tJointTypes.kWristLeft.value]; - } - public Joint GetElbowLeft() { - return skeleton[tJointTypes.kElbowLeft.value]; - } - public Joint GetElbowRight() { - return skeleton[tJointTypes.kElbowRight.value]; - } - public Joint GetShoulderLeft() { - return skeleton[tJointTypes.kShoulderLeft.value]; - } - public Joint GetShoulderRight() { - return skeleton[tJointTypes.kShoulderRight.value]; - } - public Joint GetShoulderCenter() { - return skeleton[tJointTypes.kShoulderCenter.value]; - } - public Joint GetHead() { - return skeleton[tJointTypes.kHead.value]; - } - public Joint GetSpine() { - return skeleton[tJointTypes.kSpine.value]; - } - public Joint GetHipCenter() { - return skeleton[tJointTypes.kHipCenter.value]; - } - public Joint GetHipRight() { - return skeleton[tJointTypes.kHipRight.value]; - } - public Joint GetHipLeft() { - return skeleton[tJointTypes.kHipLeft.value]; - } - public Joint GetKneeLeft() { - return skeleton[tJointTypes.kKneeLeft.value]; - } - public Joint GetKneeRight() { - return skeleton[tJointTypes.kKneeRight.value]; - } - public Joint GetAnkleLeft() { - return skeleton[tJointTypes.kAnkleLeft.value]; - } - public Joint GetAnkleRight() { - return skeleton[tJointTypes.kAnkleRight.value]; - } - public Joint GetFootLeft() { - return skeleton[tJointTypes.kFootLeft.value]; - } - public Joint GetFootRight() { - return skeleton[tJointTypes.kFootRight.value]; - } - public Joint GetJoint(tJointTypes index) { - return skeleton[index.value]; - } - - public tTrackState GetTrackState() { - return trackState; - } - - Skeleton() { - for(int i=0; i<20; i++) { - skeleton[i] = new Joint(); - } - } - - protected Joint[] skeleton = new Joint[20]; - protected tTrackState trackState; -} diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Timer.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Timer.java index 72eb1b7e51..3111ca3346 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Timer.java +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Timer.java @@ -1,27 +1,44 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - package edu.wpi.first.wpilibj; -import edu.wpi.first.wpilibj.parsing.IUtility; - -/** - * Timer objects measure accumulated time in milliseconds. - * The timer object functions like a stopwatch. It can be started, stopped, and cleared. When the - * timer is running its value counts up in milliseconds. When stopped, the timer holds the current - * value. The implementation simply records the time when started and subtracts the current time - * whenever the value is requested. - */ -public class Timer implements IUtility { - - private long m_startTime; - private double m_accumulatedTime; - private boolean m_running; +public class Timer { + private static StaticInterface impl; + public static void SetImplementation(StaticInterface ti) { + impl = ti; + } + + /** + * Return the system clock time in seconds. Return the time from the + * FPGA hardware clock in seconds since the FPGA started. + * + * @return Robot running time in seconds. + */ + public static double getFPGATimestamp() { + if (impl != null) { + return impl.getFPGATimestamp(); + } else { + return 0; // TODO: Handle error + } + } + + /** + * Return the approximate match time + * The FMS does not currently send the official match time to the robots + * This returns the time since the enable signal sent from the Driver Station + * At the beginning of autonomous, the time is reset to 0.0 seconds + * At the beginning of teleop, the time is reset to +15.0 seconds + * If the robot is disabled, this returns 0.0 seconds + * Warning: This is not an official time (so it cannot be used to argue with referees) + * @return Match time in seconds since the beginning of autonomous + */ + public static double getMatchTime() { + if (impl != null) { + return impl.getMatchTime(); + } else { + return 0; // TODO: Handle error + } + } + /** * Pause the thread for a specified time. Pause the execution of the * thread for a specified period of time given in seconds. Motors will @@ -32,51 +49,24 @@ public class Timer implements IUtility { * @param seconds Length of time to pause */ public static void delay(final double seconds) { - try { - Thread.sleep((long) (seconds * 1e3)); - } catch (final InterruptedException e) { - } + if (impl != null) { + impl.delay(seconds); + } else { + // TODO: Handle error + } } - - /** - * Return the system clock time in microseconds. Return the time from the - * FPGA hardware clock in microseconds since the FPGA started. - * - * @deprecated Use getFPGATimestamp instead. - * @return Robot running time in microseconds. - */ - public static long getUsClock() { - return Utility.getFPGATime(); + + public interface StaticInterface { + double getFPGATimestamp(); + double getMatchTime(); + void delay(final double seconds); + Interface newTimer(); } - - /** - * Return the system clock time in milliseconds. Return the time from the - * FPGA hardware clock in milliseconds since the FPGA started. - * - * @deprecated Use getFPGATimestamp instead. - * @return Robot running time in milliseconds. - */ - static long getMsClock() { - return getUsClock() / 1000; - } - - /** - * Return the system clock time in seconds. Return the time from the - * FPGA hardware clock in seconds since the FPGA started. - * - * @return Robot running time in seconds. - */ - public static double getFPGATimestamp() { - return Utility.getFPGATime() / 1000000.0; - } - - /** - * Create a new timer object. - * Create a new timer object and reset the time to zero. The timer is initially not running and - * must be started. - */ + + private Interface timer; + public Timer() { - reset(); + timer = impl.newTimer(); } /** @@ -86,21 +76,16 @@ public class Timer implements IUtility { * * @return Current time value for this timer in seconds */ - public synchronized double get() { - if (m_running) { - return ((double) ((getMsClock() - m_startTime) + m_accumulatedTime)) / 1000.0; - } else { - return m_accumulatedTime; - } + public double get() { + return timer.get(); } /** * Reset the timer by setting the time to 0. * Make the timer startTime the current time so new requests will be relative now */ - public synchronized void reset() { - m_accumulatedTime = 0; - m_startTime = getMsClock(); + public void reset() { + timer.reset(); } /** @@ -108,9 +93,8 @@ public class Timer implements IUtility { * Just set the running flag to true indicating that all time requests should be * relative to the system clock. */ - public synchronized void start() { - m_startTime = getMsClock(); - m_running = true; + public void start() { + timer.start(); } /** @@ -119,9 +103,39 @@ public class Timer implements IUtility { * subsequent time requests to be read from the accumulated time rather than * looking at the system clock. */ - public synchronized void stop() { - final double temp = get(); - m_accumulatedTime = temp; - m_running = false; + public void stop() { + timer.stop(); + } + + public interface Interface { + /** + * Get the current time from the timer. If the clock is running it is derived from + * the current system clock the start time stored in the timer class. If the clock + * is not running, then return the time when it was last stopped. + * + * @return Current time value for this timer in seconds + */ + public double get(); + + /** + * Reset the timer by setting the time to 0. + * Make the timer startTime the current time so new requests will be relative now + */ + public void reset(); + + /** + * Start the timer running. + * Just set the running flag to true indicating that all time requests should be + * relative to the system clock. + */ + public void start(); + + /** + * Stop the timer. + * This computes the time as of now and clears the running flag, causing all + * subsequent time requests to be read from the accumulated time rather than + * looking at the system clock. + */ + public void stop(); } } diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/buttons/AnalogIOButton.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/buttons/AnalogIOButton.java deleted file mode 100644 index b1f1c948dc..0000000000 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/buttons/AnalogIOButton.java +++ /dev/null @@ -1,35 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.buttons; - -import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj.DriverStationEnhancedIO.EnhancedIOException; - -/** - * - * @author Greg - */ -public class AnalogIOButton extends Trigger { - - public static double THRESHOLD = 0.5; - - int port; - - public AnalogIOButton(int port) { - this.port = port; - } - - public boolean get() { - try { - return DriverStation.getInstance().getEnhancedIO().getAnalogIn(port) < THRESHOLD; - } catch (EnhancedIOException ex) { - return false; - } - } - -} diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/buttons/DigitalIOButton.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/buttons/DigitalIOButton.java deleted file mode 100644 index 824259afcd..0000000000 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/buttons/DigitalIOButton.java +++ /dev/null @@ -1,33 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.buttons; - -import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj.DriverStationEnhancedIO.EnhancedIOException; - -/** - * - * @author Greg - */ -public class DigitalIOButton extends Button { - public final static boolean ACTIVE_STATE = false; - - int port; - - public DigitalIOButton(int port) { - this.port = port; - } - - public boolean get() { - try { - return DriverStation.getInstance().getEnhancedIO().getDigital(port) == ACTIVE_STATE; - } catch (EnhancedIOException ex) { - return false; - } - } -} diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/Command.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/Command.java index 3cda95b65a..b25757ac82 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/Command.java +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/Command.java @@ -7,8 +7,8 @@ package edu.wpi.first.wpilibj.command; -import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.NamedSendable; +import edu.wpi.first.wpilibj.RobotState; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.tables.ITable; import edu.wpi.first.wpilibj.tables.ITableListener; @@ -201,7 +201,7 @@ public abstract class Command implements NamedSendable { * @return whether or not the command should stay within the {@link Scheduler}. */ synchronized boolean run() { - if (!m_runWhenDisabled && m_parent == null && DriverStation.getInstance().isDisabled()) { + if (!m_runWhenDisabled && m_parent == null && RobotState.isDisabled()) { cancel(); } if (isCanceled()) { diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java index ed576dbd8c..dd998cf8f2 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/Scheduler.java @@ -10,11 +10,9 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; +import edu.wpi.first.wpilibj.HLUsageReporting; import edu.wpi.first.wpilibj.NamedSendable; import edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler; -import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances; -import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; -import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.networktables2.type.NumberArray; import edu.wpi.first.wpilibj.networktables2.type.StringArray; import edu.wpi.first.wpilibj.tables.ITable; @@ -91,7 +89,7 @@ public class Scheduler implements NamedSendable { * Instantiates a {@link Scheduler}. */ private Scheduler() { - UsageReporting.report(tResourceType.kResourceType_Command, tInstances.kCommand_Scheduler); + HLUsageReporting.reportScheduler(); } /** diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java index ff93417d1e..ff15d4a66d 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/command/WaitUntilCommand.java @@ -7,7 +7,7 @@ package edu.wpi.first.wpilibj.command; -import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.Timer; /** * WaitUntilCommand - waits until an absolute game time. @@ -34,7 +34,7 @@ public class WaitUntilCommand extends Command { * Check if we've reached the actual finish time. */ public boolean isFinished() { - return DriverStation.getInstance().getMatchTime() >= m_time; + return Timer.getMatchTime() >= m_time; } public void end() { diff --git a/wpilibj/wpilibJava/.gitignore b/wpilibj/wpilibJavaDevices/.gitignore similarity index 100% rename from wpilibj/wpilibJava/.gitignore rename to wpilibj/wpilibJavaDevices/.gitignore diff --git a/wpilibj/wpilibJavaDevices/pom.xml b/wpilibj/wpilibJavaDevices/pom.xml new file mode 100644 index 0000000000..0cc5c20f73 --- /dev/null +++ b/wpilibj/wpilibJavaDevices/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + edu.wpi.first.wpilibj + wpilibJavaDevices + jar + 0.1.0-SNAPSHOT + + + edu.wpi.first.wpilib.templates.athena + library-jar + 0.1.0-SNAPSHOT + ../../maven-utilities/athena/library-jar + + + + + docline-java8-disable + + [1.8, + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + -Xdoclint:none + + + + + + + + + + edu.wpi.first.wpilibj + wpilibJava + 0.1.0-SNAPSHOT + + + edu.wpi.first.wpilib.networktables.java + NetworkTables + 0.1.0-SNAPSHOT + + + junit + junit + 4.11 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + edu/wpi/first/wpilibj/image/ + edu/wpi/first/wpilibj/camera/ + edu/wpi/first/wpilibj/visa/ + edu/wpi/first/wpilibj/SerialPort.java + + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + edu/wpi/first/wpilibj/image/ + edu/wpi/first/wpilibj/camera/ + edu/wpi/first/wpilibj/visa/ + edu/wpi/first/wpilibj/SerialPort.java + + + + + + diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/ADXL345_I2C.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/ADXL345_I2C.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/ADXL345_I2C.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/ADXL345_I2C.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/ADXL345_SPI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/ADXL345_SPI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/ADXL345_SPI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/ADXL345_SPI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AccumulatorResult.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AccumulatorResult.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AccumulatorResult.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AccumulatorResult.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java similarity index 99% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java index f0b6bde7e4..b2bb2c16ce 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java @@ -73,7 +73,6 @@ public class AnalogInput extends SensorBase implements PIDSource, ByteBuffer status = ByteBuffer.allocateDirect(4); // set the byte order status.order(ByteOrder.LITTLE_ENDIAN); - // XXX: Uncomment when Analog has been fixed m_port = AnalogJNI.initializeAnalogInputPort(port_pointer, status.asIntBuffer()); HALUtil.checkStatus(status.asIntBuffer()); diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/BuiltInAccelerometer.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/BuiltInAccelerometer.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/BuiltInAccelerometer.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/BuiltInAccelerometer.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java similarity index 99% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java index d905cba1f0..0dc0f276d0 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java @@ -13,6 +13,7 @@ import java.nio.ByteOrder; import edu.wpi.first.wpilibj.can.CANExceptionFactory; import edu.wpi.first.wpilibj.can.CANJNI; import edu.wpi.first.wpilibj.can.CANMessageNotFoundException; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.tables.ITable; import edu.wpi.first.wpilibj.tables.ITableListener; diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Compressor.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Compressor.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Compressor.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Compressor.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Counter.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Counter.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/CounterBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CounterBase.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/CounterBase.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CounterBase.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Dashboard.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Dashboard.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Dashboard.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Dashboard.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java similarity index 97% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DriverStation.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index 34d7464329..a1488d4f23 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -13,12 +13,13 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary; import edu.wpi.first.wpilibj.communication.FRCCommonControlData; import edu.wpi.first.wpilibj.communication.FRCCommonControlMasks; import edu.wpi.first.wpilibj.hal.HALUtil; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.parsing.IInputOutput; /** * Provide access to the network communication data to / from the Driver Station. */ -public class DriverStation implements IInputOutput { +public class DriverStation implements IInputOutput, RobotState.Interface { /** * The size of the user status data @@ -104,8 +105,6 @@ public class DriverStation implements IInputOutput { private boolean m_userInTest = false; private boolean m_newControlData; private final ByteBuffer m_packetDataAvailableSem; - // XXX: Add DriverStationEnhancedIO back - // private DriverStationEnhancedIO m_enhancedIO = new DriverStationEnhancedIO(); /** * Gets an instance of the DriverStation @@ -164,8 +163,6 @@ public class DriverStation implements IInputOutput { HALUtil.takeMutex(m_packetDataAvailableSem); synchronized (this) { getData(); - // XXX: Add DriverStationEnhancedIO back - // m_enhancedIO.updateData(); setData(); } synchronized (m_dataSem) { @@ -597,16 +594,6 @@ public class DriverStation implements IInputOutput { return (m_controlData.control & FRCCommonControlMasks.FMS_ATTATCHED) > 0; } - /** - * Get the interface to the enhanced IO of the new driver station. - * @return An enhanced IO object for the advanced features of the driver - * station. - */ - // XXX: Add DriverStationEnhancedIO back - // public DriverStationEnhancedIO getEnhancedIO() { - // return m_enhancedIO; - // } - /** * Return the approximate match time * The FMS does not currently send the official match time to the robots diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DriverStationLCD.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStationLCD.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/DriverStationLCD.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStationLCD.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Encoder.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Encoder.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Encoder.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Encoder.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/GearTooth.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/GearTooth.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/GearTooth.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/GearTooth.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Gyro.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Gyro.java similarity index 99% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Gyro.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Gyro.java index 8d9bd81d0a..63bf87d0b5 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Gyro.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Gyro.java @@ -8,6 +8,7 @@ package edu.wpi.first.wpilibj; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.parsing.ISensor; diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/I2C.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/I2C.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/I2C.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/I2C.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/IDashboard.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/IDashboard.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/IDashboard.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/IDashboard.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java similarity index 99% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java index 96c751d8cd..36fb122ab8 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java @@ -10,6 +10,7 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.livewindow.LiveWindow; /** diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Jaguar.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Jaguar.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Jaguar.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Jaguar.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Joystick.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Joystick.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Joystick.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Joystick.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/PWM.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PWM.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/PWM.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PWM.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Preferences.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Preferences.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Preferences.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Preferences.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Relay.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Relay.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Relay.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Relay.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Resource.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Resource.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Resource.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Resource.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java similarity index 61% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/RobotBase.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index f209cadcdf..94567c9252 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -19,6 +19,9 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInst import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary; import edu.wpi.first.wpilibj.communication.UsageReporting; +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj.internal.HardwareHLUsageReporting; +import edu.wpi.first.wpilibj.internal.HardwareTimer; import edu.wpi.first.wpilibj.networktables.NetworkTable; /** @@ -156,102 +159,13 @@ public abstract class RobotBase { * the robot. * @throws javax.microedition.midlet.MIDletStateChangeException */ - public static void main(String args[]) { // TODO: expose main to teams? + public static void main(String args[]) { boolean errorOnExit = false; - // /* JNI Testing */ - // boolean booleanTest = true; - // byte byteTest = (byte)0xa5; - // char charTest = 'X'; - // short shortTest = 12346; - // int intTest = 2987654; - // long longTest = 897678665; - // float floatTest = 45.123456f; - // double doubleTest = 234E16; - - // FRCNetworkCommunicationsLibrary.JNIValueParameterTest(booleanTest, byteTest, charTest, shortTest, - // intTest, longTest, floatTest, doubleTest); - - // boolean booleanReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnBooleanTest(booleanTest); - // System.out.println("Boolean Return: " + booleanReturn ); - - // byte byteReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnByteTest(byteTest); - // System.out.println("Byte Return: " + byteReturn ); - - // char charReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnCharTest(charTest); - // System.out.println("Char Return: " + charReturn ); - - // short shortReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnShortTest(shortTest); - // System.out.println("Short Return: " + shortReturn ); - - // int intReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnIntTest(intTest); - // System.out.println("Int Return: " + intReturn ); - - // long longReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnLongTest(longTest); - // System.out.println("Long Return: " + longReturn ); - - // float floatReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnFloatTest(floatTest); - // System.out.println("Float Return: " + floatReturn ); - - // double doubleReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnDoubleTest(doubleTest); - // System.out.println("Double Return: " + doubleReturn ); - - - - // String testValue = "This is a test string"; - - // String returnValue = FRCNetworkCommunicationsLibrary.JNIObjectReturnStringTest(testValue); - - // System.out.println("String Return:" + returnValue); - - // ByteBuffer directBuffer = ByteBuffer.allocateDirect(4); - - // directBuffer.put(0, (byte)0xFA); - // directBuffer.put(1, (byte)0xAB); - // directBuffer.put(2, (byte)0xB4); - // directBuffer.put(3, (byte)0xCD); - - // ByteBuffer returnBuffer1 = FRCNetworkCommunicationsLibrary.JNIObjectReturnByteBufferTest(directBuffer); - - // System.out.println("Return Buffer Capacity: " + returnBuffer1.capacity()); - // System.out.println("ByteBuffer1 Return0: " + returnBuffer1.get(0) ); - // System.out.println("ByteBuffer1 Return1: " + returnBuffer1.get(1) ); - // System.out.println("ByteBuffer1 Return2: " + returnBuffer1.get(2) ); - // System.out.println("ByteBuffer1 Return3: " + returnBuffer1.get(3) ); - - - // ByteBuffer directByteBuffer = ByteBuffer.allocateDirect(4); - //set to little endian for C++ - // directByteBuffer.order(ByteOrder.LITTLE_ENDIAN); - - // directByteBuffer.putInt(0,2874933); - - // System.out.println("Param In: " + directByteBuffer.getInt(0)); - // System.out.println("Param In Byte0: " + directByteBuffer.get(0) ); - // System.out.println("Param In Byte1: " + directByteBuffer.get(1) ); - // System.out.println("Param In Byte2: " + directByteBuffer.get(2) ); - // System.out.println("Param In Byte3: " + directByteBuffer.get(3) ); - - - // ByteBuffer returnBuffer2 = FRCNetworkCommunicationsLibrary.JNIObjectAndParamReturnIntBufferTest(directByteBuffer.asIntBuffer()); - - // System.out.println("Param Out: " + directByteBuffer.getInt(0)); - - - - // System.out.println("Return Buffer Capacity: " + returnBuffer2.capacity()); - // System.out.println("ByteBuffer2 Return0: " + returnBuffer2.get(0) ); - // System.out.println("ByteBuffer2 Return1: " + returnBuffer2.get(1) ); - // System.out.println("ByteBuffer2 Return2: " + returnBuffer2.get(2) ); - // System.out.println("ByteBuffer2 Return3: " + returnBuffer2.get(3) ); - - // System.out.println("Byte Order from C++" + returnBuffer2.order().toString()); - // System.out.println("ByteBuffer2 as Int" + returnBuffer2.getInt(0)); - //change to little endian - // returnBuffer2.order(ByteOrder.LITTLE_ENDIAN); - // System.out.println("ByteBuffer2 as Int" + returnBuffer2.getInt(0)); - - /* End JNI Testing */ + // Set some implementations so that the static methods work properly + Timer.SetImplementation(new HardwareTimer()); + HLUsageReporting.SetImplementation(new HardwareHLUsageReporting()); + RobotState.SetImplementation(DriverStation.getInstance()); FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationReserve(); FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting(); diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotDrive.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SPI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SPI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SPI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SPI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SafePWM.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SafePWM.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SafePWM.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SafePWM.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SensorBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SensorBase.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SensorBase.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SensorBase.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SerialPort.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SerialPort.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Servo.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Servo.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Servo.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Servo.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java similarity index 99% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java index 21d00f5c87..265c0641e1 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java @@ -10,6 +10,7 @@ package edu.wpi.first.wpilibj; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.livewindow.LiveWindow; /** diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Solenoid.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Solenoid.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Solenoid.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Solenoid.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SolenoidBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SolenoidBase.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SolenoidBase.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SolenoidBase.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SpeedController.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SpeedController.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/SpeedController.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SpeedController.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Talon.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Talon.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Talon.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Talon.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java similarity index 99% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java index d5d66d911e..07331926f7 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Ultrasonic.java @@ -9,6 +9,7 @@ package edu.wpi.first.wpilibj; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.parsing.ISensor; diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Utility.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Utility.java similarity index 94% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Utility.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Utility.java index e84cd92180..5205269f79 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Utility.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Utility.java @@ -80,13 +80,6 @@ public class Utility implements IUtility { final String url = "dserror:edu.wpi.first.wpilibj.Utility"; // the path // is just a // comment. - /* XXX: Code Review! - Isolate isolate = VM.getCurrentIsolate(); - if (enabled) { - isolate.addErr(url); - } else { - isolate.removeErr(url); - } */ } } diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Victor.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Victor.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/Victor.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Victor.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/camera/AxisCamera.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/camera/AxisCamera.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/camera/AxisCamera.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/camera/AxisCamera.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/camera/AxisCameraException.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/camera/AxisCameraException.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/camera/AxisCameraException.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/camera/AxisCameraException.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/camera/package.html b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/camera/package.html similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/camera/package.html rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/camera/package.html diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANInvalidBufferException.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANInvalidBufferException.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANInvalidBufferException.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANInvalidBufferException.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANJaguarVersionException.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANJaguarVersionException.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANJaguarVersionException.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANJaguarVersionException.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotAllowedException.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotAllowedException.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotAllowedException.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotAllowedException.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotFoundException.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotFoundException.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotFoundException.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANMessageNotFoundException.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANNotInitializedException.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANNotInitializedException.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/can/CANNotInitializedException.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANNotInitializedException.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlData.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlData.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlData.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlData.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlMasks.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlMasks.java similarity index 86% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlMasks.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlMasks.java index 41101152ac..d0b73bf4d2 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlMasks.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCCommonControlMasks.java @@ -1,7 +1,6 @@ package edu.wpi.first.wpilibj.communication; public class FRCCommonControlMasks { - // XXX: Verify these are right in FRCCommonControlData.field1 public static byte CHECK_VERSIONS = 1 << 0; public static byte TEST = 1 << 1; public static byte RESYNC = 1 << 2; diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/NIRioStatus.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/NIRioStatus.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/NIRioStatus.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/NIRioStatus.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/UsageReporting.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/UsageReporting.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/communication/UsageReporting.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/UsageReporting.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/AccelerometerJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/AccelerometerJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/AccelerometerJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/AccelerometerJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/AnalogJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/AnalogJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/AnalogJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/AnalogJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/CounterJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CounterJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/CounterJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CounterJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/EncoderJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/EncoderJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/EncoderJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/EncoderJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/HALLibrary.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALLibrary.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/HALLibrary.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALLibrary.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/I2CJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/I2CJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/I2CJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/I2CJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/InterruptJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/InterruptJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/InterruptJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/InterruptJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/RelayJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/RelayJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/RelayJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/RelayJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/SPIJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SPIJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/SPIJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SPIJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/SolenoidJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SolenoidJNI.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/hal/SolenoidJNI.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SolenoidJNI.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/BinaryImage.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/BinaryImage.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/BinaryImage.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/BinaryImage.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/ColorImage.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/ColorImage.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/ColorImage.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/ColorImage.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/CriteriaCollection.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/CriteriaCollection.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/CriteriaCollection.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/CriteriaCollection.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/CurveOptions.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/CurveOptions.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/CurveOptions.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/CurveOptions.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/EllipseDescriptor.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/EllipseDescriptor.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/EllipseDescriptor.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/EllipseDescriptor.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/EllipseMatch.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/EllipseMatch.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/EllipseMatch.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/EllipseMatch.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/HSLImage.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/HSLImage.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/HSLImage.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/HSLImage.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/Image.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/Image.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/Image.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/Image.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/LinearAverages.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/LinearAverages.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/LinearAverages.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/LinearAverages.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/MonoImage.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/MonoImage.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/MonoImage.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/MonoImage.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/NIVision.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/NIVision.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/NIVision.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/NIVision.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/NIVisionException.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/NIVisionException.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/NIVisionException.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/NIVisionException.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/ParticleAnalysisReport.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/ParticleAnalysisReport.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/ParticleAnalysisReport.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/ParticleAnalysisReport.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/RGBImage.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/RGBImage.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/RGBImage.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/RGBImage.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/RegionOfInterest.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/RegionOfInterest.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/RegionOfInterest.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/RegionOfInterest.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/ShapeDetectionOptions.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/ShapeDetectionOptions.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/ShapeDetectionOptions.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/ShapeDetectionOptions.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/package.html b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/package.html similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/image/package.html rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/image/package.html diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java new file mode 100644 index 0000000000..09b70000a5 --- /dev/null +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java @@ -0,0 +1,18 @@ +package edu.wpi.first.wpilibj.internal; + +import edu.wpi.first.wpilibj.HLUsageReporting; +import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances; +import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; +import edu.wpi.first.wpilibj.communication.UsageReporting; + +public class HardwareHLUsageReporting implements HLUsageReporting.Interface { + @Override + public void reportScheduler() { + UsageReporting.report(tResourceType.kResourceType_Command, tInstances.kCommand_Scheduler); + } + + @Override + public void reportPIDController(int num) { + UsageReporting.report(tResourceType.kResourceType_PIDController, num); + } +} diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java new file mode 100644 index 0000000000..f86ea1379c --- /dev/null +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareTimer.java @@ -0,0 +1,125 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.internal; + +import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj.Utility; +import edu.wpi.first.wpilibj.parsing.IUtility; + +/** + * Timer objects measure accumulated time in milliseconds. + * The timer object functions like a stopwatch. It can be started, stopped, and cleared. When the + * timer is running its value counts up in milliseconds. When stopped, the timer holds the current + * value. The implementation simply records the time when started and subtracts the current time + * whenever the value is requested. + */ +public class HardwareTimer implements IUtility, Timer.StaticInterface { + /** + * Pause the thread for a specified time. Pause the execution of the + * thread for a specified period of time given in seconds. Motors will + * continue to run at their last assigned values, and sensors will continue + * to update. Only the task containing the wait will pause until the wait + * time is expired. + * + * @param seconds Length of time to pause + */ + @Override + public void delay(final double seconds) { + try { + Thread.sleep((long) (seconds * 1e3)); + } catch (final InterruptedException e) { + } + } + + /** + * Return the system clock time in seconds. Return the time from the + * FPGA hardware clock in seconds since the FPGA started. + * + * @return Robot running time in seconds. + */ + @Override + public double getFPGATimestamp() { + return Utility.getFPGATime() / 1000000.0; + } + + @Override + public double getMatchTime() { + return DriverStation.getInstance().getMatchTime(); + } + + @Override + public Timer.Interface newTimer() { + return new TimerImpl(); + } + + class TimerImpl implements Timer.Interface { + private long m_startTime; + private double m_accumulatedTime; + private boolean m_running; + + /** + * Create a new timer object. + * Create a new timer object and reset the time to zero. The timer is initially not running and + * must be started. + */ + public TimerImpl() { + reset(); + } + + private long getMsClock() { + return Utility.getFPGATime() / 1000; + } + + /** + * Get the current time from the timer. If the clock is running it is derived from + * the current system clock the start time stored in the timer class. If the clock + * is not running, then return the time when it was last stopped. + * + * @return Current time value for this timer in seconds + */ + public synchronized double get() { + if (m_running) { + return ((double) ((getMsClock() - m_startTime) + m_accumulatedTime)) / 1000.0; + } else { + return m_accumulatedTime; + } + } + + /** + * Reset the timer by setting the time to 0. + * Make the timer startTime the current time so new requests will be relative now + */ + public synchronized void reset() { + m_accumulatedTime = 0; + m_startTime = getMsClock(); + } + + /** + * Start the timer running. + * Just set the running flag to true indicating that all time requests should be + * relative to the system clock. + */ + public synchronized void start() { + m_startTime = getMsClock(); + m_running = true; + } + + /** + * Stop the timer. + * This computes the time as of now and clears the running flag, causing all + * subsequent time requests to be read from the accumulated time rather than + * looking at the system clock. + */ + public synchronized void stop() { + final double temp = get(); + m_accumulatedTime = temp; + m_running = false; + } + } +} diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/package.html b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/package.html similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/package.html rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/package.html diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/visa/Visa.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/visa/Visa.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/visa/Visa.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/visa/Visa.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/visa/VisaException.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/visa/VisaException.java similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/visa/VisaException.java rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/visa/VisaException.java diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/visa/package.html b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/visa/package.html similarity index 100% rename from wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/visa/package.html rename to wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/visa/package.html diff --git a/wpilibj/wpilibJava/src/test/java/edu/wpi/first/wpilibj/ExampleTest.java b/wpilibj/wpilibJavaDevices/src/test/java/edu/wpi/first/wpilibj/ExampleTest.java similarity index 100% rename from wpilibj/wpilibJava/src/test/java/edu/wpi/first/wpilibj/ExampleTest.java rename to wpilibj/wpilibJavaDevices/src/test/java/edu/wpi/first/wpilibj/ExampleTest.java diff --git a/wpilibj/wpilibJava/src/test/java/edu/wpi/first/wpilibj/ResourceTest.java b/wpilibj/wpilibJavaDevices/src/test/java/edu/wpi/first/wpilibj/ResourceTest.java similarity index 100% rename from wpilibj/wpilibJava/src/test/java/edu/wpi/first/wpilibj/ResourceTest.java rename to wpilibj/wpilibJavaDevices/src/test/java/edu/wpi/first/wpilibj/ResourceTest.java diff --git a/wpilibj/wpilibJavaFinal/pom.xml b/wpilibj/wpilibJavaFinal/pom.xml index eb2af4eb52..df2d974653 100644 --- a/wpilibj/wpilibJavaFinal/pom.xml +++ b/wpilibj/wpilibJavaFinal/pom.xml @@ -13,37 +13,29 @@ 0.1.0-SNAPSHOT ../../maven-utilities/athena/library-jar/pom.xml - - - - - - - edu.wpi.first.wpilibj - wpilibJava - 0.1.0-SNAPSHOT + edu.wpi.first.wpilibj + wpilibJava + 0.1.0-SNAPSHOT - edu.wpi.first.wpilibj - wpilibJavaJNI - 0.1.0-SNAPSHOT - so + edu.wpi.first.wpilibj + wpilibJavaDevices + 0.1.0-SNAPSHOT + + edu.wpi.first.wpilibj + wpilibJavaJNI + 0.1.0-SNAPSHOT + so + - + org.apache.maven.plugins maven-antrun-plugin 1.7 @@ -57,7 +49,7 @@ + classpathref="maven.plugin.classpath" /> @@ -70,7 +62,23 @@ - + + + + + + + + + + + + + + + + + @@ -86,144 +94,88 @@ generate-sources - + - - - ant-contrib - ant-contrib - 1.0b3 - - - ant - ant - - - + ant-contrib + ant-contrib + 1.0b3 + + + ant + ant + + + - org.apache.maven.plugins maven-install-plugin 2.5.1 - install-jar - install - - install - + install-jar + install + + install + - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-dependency-plugin - - [2.8,) - - copy - - - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - [2.8,) - - unpack - - - - - - - - - - - + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-dependency-plugin + + [2.8,) + + copy + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + [2.8,) + + unpack + + + + + + + + + + + diff --git a/wpilibj/wpilibJavaJNI/pom.xml b/wpilibj/wpilibJavaJNI/pom.xml index edb4450a79..3ef82d2a4d 100644 --- a/wpilibj/wpilibJavaJNI/pom.xml +++ b/wpilibj/wpilibJavaJNI/pom.xml @@ -14,7 +14,7 @@ edu.wpi.first.wpilibj - wpilibJava + wpilibJavaDevices 0.1.0-SNAPSHOT jar diff --git a/wpilibj/wpilibJavaSim/pom.xml b/wpilibj/wpilibJavaSim/pom.xml index a1d86d2dd5..943bfc2fc2 100644 --- a/wpilibj/wpilibJavaSim/pom.xml +++ b/wpilibj/wpilibJavaSim/pom.xml @@ -29,6 +29,11 @@ + + edu.wpi.first.wpilibj + wpilibJava + 0.1.0-SNAPSHOT + edu.wpi.first.wpilib.networktables.java NetworkTables diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Controller.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Controller.java deleted file mode 100644 index d03c926aad..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Controller.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package edu.wpi.first.wpilibj; - -/** - * An interface for controllers. Controllers run control loops, the most command - * are PID controllers and there variants, but this includes anything that is - * controlling an actuator in a separate thread. - * - * @author alex - */ -interface Controller { - /** - * Allows the control loop to run. - */ - public void enable(); - - /** - * Stops the control loop from running until explicitly re-enabled by calling - * {@link enable()}. - */ - public void disable(); -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index ba75d5a810..8e59460c50 100644 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -17,7 +17,7 @@ import edu.wpi.first.wpilibj.parsing.IInputOutput; /** * Provide access to the network communication data to / from the Driver Station. */ -public class DriverStation implements IInputOutput { +public class DriverStation implements IInputOutput, RobotState.Interface { /** * Slot for the analog module to read the battery */ diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/GenericHID.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/GenericHID.java deleted file mode 100644 index a5f8e7ccac..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/GenericHID.java +++ /dev/null @@ -1,155 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -/** - * GenericHID Interface - */ -public abstract class GenericHID { - - /** - * Which hand the Human Interface Device is associated with. - */ - public static class Hand { - - /** - * The integer value representing this enumeration - */ - public final int value; - static final int kLeft_val = 0; - static final int kRight_val = 1; - /** - * hand: left - */ - public static final Hand kLeft = new Hand(kLeft_val); - /** - * hand: right - */ - public static final Hand kRight = new Hand(kRight_val); - - private Hand(int value) { - this.value = value; - } - } - - /** - * Get the x position of the HID - * @return the x position of the HID - */ - public final double getX() { - return getX(Hand.kRight); - } - - /** - * Get the x position of HID - * @param hand which hand, left or right - * @return the x position - */ - public abstract double getX(Hand hand); - - /** - * Get the y position of the HID - * @return the y position - */ - public final double getY() { - return getY(Hand.kRight); - } - - /** - * Get the y position of the HID - * @param hand which hand, left or right - * @return the y position - */ - public abstract double getY(Hand hand); - - /** - * Get the z position of the HID - * @return the z position - */ - public final double getZ() { - return getZ(Hand.kRight); - } - - /** - * Get the z position of the HID - * @param hand which hand, left or right - * @return the z position - */ - public abstract double getZ(Hand hand); - - /** - * Get the twist value - * @return the twist value - */ - public abstract double getTwist(); - - /** - * Get the throttle - * @return the throttle value - */ - public abstract double getThrottle(); - - /** - * Get the raw axis - * @param which index of the axis - * @return the raw value of the selected axis - */ - public abstract double getRawAxis(int which); - - /** - * Is the trigger pressed - * @return true if pressed - */ - public final boolean getTrigger() { - return getTrigger(Hand.kRight); - } - - /** - * Is the trigger pressed - * @param hand which hand - * @return true if the trigger for the given hand is pressed - */ - public abstract boolean getTrigger(Hand hand); - - /** - * Is the top button pressed - * @return true if the top button is pressed - */ - public final boolean getTop() { - return getTop(Hand.kRight); - } - - /** - * Is the top button pressed - * @param hand which hand - * @return true if hte top button for the given hand is pressed - */ - public abstract boolean getTop(Hand hand); - - /** - * Is the bumper pressed - * @return true if the bumper is pressed - */ - public final boolean getBumper() { - return getBumper(Hand.kRight); - } - - /** - * Is the bumper pressed - * @param hand which hand - * @return true if hte bumper is pressed - */ - public abstract boolean getBumper(Hand hand); - - /** - * Is the given button pressed - * @param button which button number - * @return true if the button is pressed - */ - public abstract boolean getRawButton(int button); -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java index 1438838247..c5307329cd 100644 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/IterativeRobot.java @@ -6,6 +6,7 @@ /*----------------------------------------------------------------------------*/ package edu.wpi.first.wpilibj; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.livewindow.LiveWindow; /** diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/MotorSafety.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/MotorSafety.java deleted file mode 100644 index f566f14867..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/MotorSafety.java +++ /dev/null @@ -1,23 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -/** - * - * @author brad - */ -public interface MotorSafety { - public static final double DEFAULT_SAFETY_EXPIRATION = 0.1; - void setExpiration(double timeout); - double getExpiration(); - boolean isAlive(); - void stopMotor(); - void setSafetyEnabled(boolean enabled); - boolean isSafetyEnabled(); - String getDescription(); -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/MotorSafetyHelper.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/MotorSafetyHelper.java deleted file mode 100644 index 2a06ef3e22..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/MotorSafetyHelper.java +++ /dev/null @@ -1,124 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -/** - * The MotorSafetyHelper object is constructed for every object that wants to implement the Motor - * Safety protocol. The helper object has the code to actually do the timing and call the - * motors Stop() method when the timeout expires. The motor object is expected to call the - * Feed() method whenever the motors value is updated. - * - * @author brad - */ -public class MotorSafetyHelper { - - double m_expiration; - boolean m_enabled; - double m_stopTime; - MotorSafety m_safeObject; - MotorSafetyHelper m_nextHelper; - static MotorSafetyHelper m_headHelper = null; - - /** - * The constructor for a MotorSafetyHelper object. - * The helper object is constructed for every object that wants to implement the Motor - * Safety protocol. The helper object has the code to actually do the timing and call the - * motors Stop() method when the timeout expires. The motor object is expected to call the - * Feed() method whenever the motors value is updated. - * - * @param safeObject a pointer to the motor object implementing MotorSafety. This is used - * to call the Stop() method on the motor. - */ - public MotorSafetyHelper(MotorSafety safeObject) { - m_safeObject = safeObject; - m_enabled = false; - m_expiration = MotorSafety.DEFAULT_SAFETY_EXPIRATION; - m_stopTime = Timer.getFPGATimestamp(); - m_nextHelper = m_headHelper; - m_headHelper = this; - } - - /** - * Feed the motor safety object. - * Resets the timer on this object that is used to do the timeouts. - */ - public void feed() { - m_stopTime = Timer.getFPGATimestamp() + m_expiration; - } - - /** - * Set the expiration time for the corresponding motor safety object. - * @param expirationTime The timeout value in seconds. - */ - public void setExpiration(double expirationTime) { - m_expiration = expirationTime; - } - - /** - * Retrieve the timeout value for the corresponding motor safety object. - * @return the timeout value in seconds. - */ - public double getExpiration() { - return m_expiration; - } - - /** - * Determine of the motor is still operating or has timed out. - * @return a true value if the motor is still operating normally and hasn't timed out. - */ - public boolean isAlive() { - return !m_enabled || m_stopTime > Timer.getFPGATimestamp(); - } - - /** - * Check if this motor has exceeded its timeout. - * This method is called periodically to determine if this motor has exceeded its timeout - * value. If it has, the stop method is called, and the motor is shut down until its value is - * updated again. - */ - public void check() { - DriverStation ds = DriverStation.getInstance(); - if (!m_enabled || ds.isDisabled() || ds.isTest()) - return; - if (m_stopTime < Timer.getFPGATimestamp()) { - System.err.println(m_safeObject.getDescription() + "... Output not updated often enough."); - - m_safeObject.stopMotor(); - } - } - - /** - * Enable/disable motor safety for this device - * Turn on and off the motor safety option for this PWM object. - * @param enabled True if motor safety is enforced for this object - */ - public void setSafetyEnabled(boolean enabled) { - m_enabled = enabled; - } - - /** - * Return the state of the motor safety enabled flag - * Return if the motor safety is currently enabled for this devicce. - * @return True if motor safety is enforced for this device - */ - public boolean isSafetyEnabled() { - return m_enabled; - } - - /** - * Check the motors to see if any have timed out. - * This static method is called periodically to poll all the motors and stop any that have - * timed out. - */ - //TODO: these should be synchronized with the setting methods in case it's called from a different thread - public static void checkMotors() { - for (MotorSafetyHelper msh = m_headHelper; msh != null; msh = msh.m_nextHelper) { - msh.check(); - } - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/NamedSendable.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/NamedSendable.java deleted file mode 100644 index e0b8ae9636..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/NamedSendable.java +++ /dev/null @@ -1,14 +0,0 @@ -package edu.wpi.first.wpilibj; - - -/** - * The interface for sendable objects that gives the sendable a default name in the Smart Dashboard - * - */ -public interface NamedSendable extends Sendable { - - /** - * @return the name of the subtable of SmartDashboard that the Sendable object will use - */ - public String getName(); -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDController.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDController.java deleted file mode 100644 index 5be1ed657a..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDController.java +++ /dev/null @@ -1,578 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ -package edu.wpi.first.wpilibj; - -import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; -import edu.wpi.first.wpilibj.parsing.IUtility; -import edu.wpi.first.wpilibj.tables.ITable; -import edu.wpi.first.wpilibj.tables.ITableListener; -import edu.wpi.first.wpilibj.util.BoundaryException; - -/** - * Class implements a PID Control Loop. - * - * Creates a separate thread which reads the given PIDSource and takes - * care of the integral calculations, as well as writing the given - * PIDOutput - */ -public class PIDController implements IUtility, LiveWindowSendable, Controller { - - public static final double kDefaultPeriod = .05; - private static int instances = 0; - private double m_P; // factor for "proportional" control - private double m_I; // factor for "integral" control - private double m_D; // factor for "derivative" control - private double m_F; // factor for feedforward term - private double m_maximumOutput = 1.0; // |maximum output| - private double m_minimumOutput = -1.0; // |minimum output| - private double m_maximumInput = 0.0; // maximum input - limit setpoint to this - private double m_minimumInput = 0.0; // minimum input - limit setpoint to this - private boolean m_continuous = false; // do the endpoints wrap around? eg. Absolute encoder - private boolean m_enabled = false; //is the pid controller enabled - private double m_prevError = 0.0; // the prior sensor input (used to compute velocity) - private double m_totalError = 0.0; //the sum of the errors for use in the integral calc - private Tolerance m_tolerance; //the tolerance object used to check if on target - private double m_setpoint = 0.0; - private double m_error = 0.0; - private double m_result = 0.0; - private double m_period = kDefaultPeriod; - PIDSource m_pidInput; - PIDOutput m_pidOutput; - private boolean m_freed = false; - private boolean m_usingPercentTolerance; - - /** - * Tolerance is the type of tolerance used to specify if the PID controller is on target. - * The various implementations of this class such as PercentageTolerance and AbsoluteTolerance - * specify types of tolerance specifications to use. - */ - public interface Tolerance { - public boolean onTarget(); - } - - public class PercentageTolerance implements Tolerance { - double percentage; - - PercentageTolerance(double value) { - percentage = value; - } - - public boolean onTarget() { - return (Math.abs(getError()) < percentage / 100 - * (m_maximumInput - m_minimumInput)); - } - } - - public class AbsoluteTolerance implements Tolerance { - double value; - - AbsoluteTolerance(double value) { - this.value = value; - } - - public boolean onTarget() { - return Math.abs(getError()) < value; - } - } - - public class NullTolerance implements Tolerance { - - public boolean onTarget() { - throw new RuntimeException("No tolerance value set when using PIDController.onTarget()"); - } - } - - private class PIDTask implements Runnable { - private PIDController m_controller; - - public PIDTask(PIDController controller) { - if (controller == null) { - throw new NullPointerException("Given PIDController was null"); - } - m_controller = controller; - } - - public void run() { - while (!m_controller.m_freed) { - m_controller.calculate(); - Timer.delay(m_controller.m_period); - } - } - } - - /** - * Allocate a PID object with the given constants for P, I, D, and F - * @param Kp the proportional coefficient - * @param Ki the integral coefficient - * @param Kd the derivative coefficient - * @param Kf the feed forward term - * @param source The PIDSource object that is used to get values - * @param output The PIDOutput object that is set to the output percentage - * @param period the loop time for doing calculations. This particularly effects calculations of the - * integral and differential terms. The default is 50ms. - */ - public PIDController(double Kp, double Ki, double Kd, double Kf, - PIDSource source, PIDOutput output, - double period) { - - if (source == null) { - throw new NullPointerException("Null PIDSource was given"); - } - if (output == null) { - throw new NullPointerException("Null PIDOutput was given"); - } - - m_P = Kp; - m_I = Ki; - m_D = Kd; - m_F = Kf; - - m_pidInput = source; - m_pidOutput = output; - m_period = period; - - new Thread(new PIDTask(this)).start(); - - instances++; - m_tolerance = new NullTolerance(); - } - - /** - * Allocate a PID object with the given constants for P, I, D and period - * @param Kp - * @param Ki - * @param Kd - * @param source - * @param output - * @param period - */ - public PIDController(double Kp, double Ki, double Kd, - PIDSource source, PIDOutput output, - double period) { - this(Kp, Ki, Kd, 0.0, source, output, period); - } - - /** - * Allocate a PID object with the given constants for P, I, D, using a 50ms period. - * @param Kp the proportional coefficient - * @param Ki the integral coefficient - * @param Kd the derivative coefficient - * @param source The PIDSource object that is used to get values - * @param output The PIDOutput object that is set to the output percentage - */ - public PIDController(double Kp, double Ki, double Kd, - PIDSource source, PIDOutput output) { - this(Kp, Ki, Kd, source, output, kDefaultPeriod); - } - - /** - * Allocate a PID object with the given constants for P, I, D, using a 50ms period. - * @param Kp the proportional coefficient - * @param Ki the integral coefficient - * @param Kd the derivative coefficient - * @param source The PIDSource object that is used to get values - * @param output The PIDOutput object that is set to the output percentage - */ - public PIDController(double Kp, double Ki, double Kd, double Kf, - PIDSource source, PIDOutput output) { - this(Kp, Ki, Kd, Kf, source, output, kDefaultPeriod); - } - - /** - * Free the PID object - */ - public void free() { - m_freed = true; - if(this.table!=null) table.removeTableListener(listener); - m_pidInput = null; - m_pidOutput = null; - } - - /** - * Read the input, calculate the output accordingly, and write to the output. - * This should only be called by the PIDTask - * and is created during initialization. - */ - private void calculate() { - boolean enabled; - PIDSource pidInput; - - synchronized (this) { - if (m_pidInput == null) { - return; - } - if (m_pidOutput == null) { - return; - } - enabled = m_enabled; // take snapshot of these values... - pidInput = m_pidInput; - } - - if (enabled) { - double input; - double result; - PIDOutput pidOutput = null; - synchronized (this){ - input = pidInput.pidGet(); - } - synchronized (this) { - m_error = m_setpoint - input; - if (m_continuous) { - if (Math.abs(m_error) - > (m_maximumInput - m_minimumInput) / 2) { - if (m_error > 0) { - m_error = m_error - m_maximumInput + m_minimumInput; - } else { - m_error = m_error - + m_maximumInput - m_minimumInput; - } - } - } - - if (m_I != 0) { - double potentialIGain = (m_totalError + m_error) * m_I; - if (potentialIGain < m_maximumOutput) { - if (potentialIGain > m_minimumOutput) { - m_totalError += m_error; - } else { - m_totalError = m_minimumOutput / m_I; - } - } else { - m_totalError = m_maximumOutput / m_I; - } - } - - m_result = m_P * m_error + m_I * m_totalError + m_D * (m_error - m_prevError) + m_setpoint * m_F; - m_prevError = m_error; - - if (m_result > m_maximumOutput) { - m_result = m_maximumOutput; - } else if (m_result < m_minimumOutput) { - m_result = m_minimumOutput; - } - pidOutput = m_pidOutput; - result = m_result; - } - - pidOutput.pidWrite(result); - } - } - - /** - * Set the PID Controller gain parameters. - * Set the proportional, integral, and differential coefficients. - * @param p Proportional coefficient - * @param i Integral coefficient - * @param d Differential coefficient - */ - public synchronized void setPID(double p, double i, double d) { - m_P = p; - m_I = i; - m_D = d; - - if (table != null) { - table.putNumber("p", p); - table.putNumber("i", i); - table.putNumber("d", d); - } - } - - /** - * Set the PID Controller gain parameters. - * Set the proportional, integral, and differential coefficients. - * @param p Proportional coefficient - * @param i Integral coefficient - * @param d Differential coefficient - * @param f Feed forward coefficient - */ - public synchronized void setPID(double p, double i, double d, double f) { - m_P = p; - m_I = i; - m_D = d; - m_F = f; - - if (table != null) { - table.putNumber("p", p); - table.putNumber("i", i); - table.putNumber("d", d); - table.putNumber("f", f); - } - } - - /** - * Get the Proportional coefficient - * @return proportional coefficient - */ - public double getP() { - return m_P; - } - - /** - * Get the Integral coefficient - * @return integral coefficient - */ - public double getI() { - return m_I; - } - - /** - * Get the Differential coefficient - * @return differential coefficient - */ - public synchronized double getD() { - return m_D; - } - - /** - * Get the Feed forward coefficient - * @return feed forward coefficient - */ - public synchronized double getF() { - return m_F; - } - - /** - * Return the current PID result - * This is always centered on zero and constrained the the max and min outs - * @return the latest calculated output - */ - public synchronized double get() { - return m_result; - } - - /** - * Set the PID controller to consider the input to be continuous, - * Rather then using the max and min in as constraints, it considers them to - * be the same point and automatically calculates the shortest route to - * the setpoint. - * @param continuous Set to true turns on continuous, false turns off continuous - */ - public synchronized void setContinuous(boolean continuous) { - m_continuous = continuous; - } - - /** - * Set the PID controller to consider the input to be continuous, - * Rather then using the max and min in as constraints, it considers them to - * be the same point and automatically calculates the shortest route to - * the setpoint. - */ - public synchronized void setContinuous() { - this.setContinuous(true); - } - - /** - * Sets the maximum and minimum values expected from the input. - * - * @param minimumInput the minimum percentage expected from the input - * @param maximumInput the maximum percentage expected from the output - */ - public synchronized void setInputRange(double minimumInput, double maximumInput) { - if (minimumInput > maximumInput) { - throw new BoundaryException("Lower bound is greater than upper bound"); - } - m_minimumInput = minimumInput; - m_maximumInput = maximumInput; - setSetpoint(m_setpoint); - } - - /** - * Sets the minimum and maximum values to write. - * - * @param minimumOutput the minimum percentage to write to the output - * @param maximumOutput the maximum percentage to write to the output - */ - public synchronized void setOutputRange(double minimumOutput, double maximumOutput) { - if (minimumOutput > maximumOutput) { - throw new BoundaryException("Lower bound is greater than upper bound"); - } - m_minimumOutput = minimumOutput; - m_maximumOutput = maximumOutput; - } - - /** - * Set the setpoint for the PIDController - * @param setpoint the desired setpoint - */ - public synchronized void setSetpoint(double setpoint) { - if (m_maximumInput > m_minimumInput) { - if (setpoint > m_maximumInput) { - m_setpoint = m_maximumInput; - } else if (setpoint < m_minimumInput) { - m_setpoint = m_minimumInput; - } else { - m_setpoint = setpoint; - } - } else { - m_setpoint = setpoint; - } - - if (table != null) - table.putNumber("setpoint", m_setpoint); - } - - /** - * Returns the current setpoint of the PIDController - * @return the current setpoint - */ - public synchronized double getSetpoint() { - return m_setpoint; - } - - /** - * Returns the current difference of the input from the setpoint - * @return the current error - */ - public synchronized double getError() { - //return m_error; - return getSetpoint() - m_pidInput.pidGet(); - } - - /** - * Set the percentage error which is considered tolerable for use with - * OnTarget. (Input of 15.0 = 15 percent) - * @param percent error which is tolerable - * @deprecated Use {@link #setPercentTolerance(double) or {@link #setAbsoluteTolerance(double)} instead. - */ - public synchronized void setTolerance(double percent) { - m_tolerance = new PercentageTolerance(percent); - } - - /** - * Set the absolute error which is considered tolerable for use with - * OnTarget. - * @param absvalue absolute error which is tolerable in the units of the input object - */ - public synchronized void setAbsoluteTolerance(double absvalue) { - m_tolerance = new AbsoluteTolerance(absvalue); - } - - /** - * Set the percentage error which is considered tolerable for use with - * OnTarget. (Input of 15.0 = 15 percent) - * @param percentage percent error which is tolerable - */ - public synchronized void setPercentTolerance(double percentage) { - m_tolerance = new PercentageTolerance(percentage); - } - - /** - * Return true if the error is within the percentage of the total input range, - * determined by setTolerance. This assumes that the maximum and minimum input - * were set using setInput. - * @return true if the error is less than the tolerance - */ - public synchronized boolean onTarget() { - return m_tolerance.onTarget(); - } - - /** - * Begin running the PIDController - */ - public synchronized void enable() { - m_enabled = true; - - if (table != null) { - table.putBoolean("enabled", true); - } - } - - /** - * Stop running the PIDController, this sets the output to zero before stopping. - */ - public synchronized void disable() { - m_pidOutput.pidWrite(0); - m_enabled = false; - - if (table != null) { - table.putBoolean("enabled", false); - } - } - - /** - * Return true if PIDController is enabled. - */ - public synchronized boolean isEnable() { - return m_enabled; - } - - /** - * Reset the previous error,, the integral term, and disable the controller. - */ - public synchronized void reset() { - disable(); - m_prevError = 0; - m_totalError = 0; - m_result = 0; - } - - public String getSmartDashboardType() { - return "PIDController"; - } - - private ITableListener listener = new ITableListener() { - public void valueChanged(ITable table, String key, Object value, boolean isNew) { - if (key.equals("p") || key.equals("i") || key.equals("d") || key.equals("f")) { - if (m_P != table.getNumber("p", 0.0) || m_I != table.getNumber("i", 0.0) || - m_D != table.getNumber("d", 0.0) || m_F != table.getNumber("f", 0.0)) - setPID(table.getNumber("p", 0.0), table.getNumber("i", 0.0), table.getNumber("d", 0.0), table.getNumber("f", 0.0)); - } else if (key.equals("setpoint")) { - if (m_setpoint != ((Double) value).doubleValue()) - setSetpoint(((Double) value).doubleValue()); - } else if (key.equals("enabled")) { - if (m_enabled != ((Boolean) value).booleanValue()) { - if (((Boolean) value).booleanValue()) { - enable(); - } else { - disable(); - } - } - } - } - }; - private ITable table; - public void initTable(ITable table) { - if(this.table!=null) - this.table.removeTableListener(listener); - this.table = table; - if(table!=null) { - table.putNumber("p", getP()); - table.putNumber("i", getI()); - table.putNumber("d", getD()); - table.putNumber("f", getF()); - table.putNumber("setpoint", getSetpoint()); - table.putBoolean("enabled", isEnable()); - table.addTableListener(listener, false); - } - } - - /** - * {@inheritDoc} - */ - public ITable getTable() { - return table; - } - - /** - * {@inheritDoc} - */ - public void updateTable() { - } - - /** - * {@inheritDoc} - */ - public void startLiveWindowMode() { - disable(); - } - - /** - * {@inheritDoc} - */ - public void stopLiveWindowMode() { - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java deleted file mode 100644 index 668eca2a1e..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDOutput.java +++ /dev/null @@ -1,21 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -/** - * This interface allows PIDController to write it's results to its output. - * @author dtjones - */ -public interface PIDOutput { - - /** - * Set the output to the value calculated by PIDController - * @param output the value calculated by PIDController - */ - public void pidWrite(double output); -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDSource.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDSource.java deleted file mode 100644 index 73e83d73fe..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/PIDSource.java +++ /dev/null @@ -1,39 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj; - -/** - * This interface allows for PIDController to automatically read from this - * object - * @author dtjones - */ -public interface PIDSource { - - /** - * A description for the type of output value to provide to a PIDController - */ - public static class PIDSourceParameter { - public final int value; - static final int kDistance_val = 0; - static final int kRate_val = 1; - static final int kAngle_val = 2; - public static final PIDSourceParameter kDistance = new PIDSourceParameter(kDistance_val); - public static final PIDSourceParameter kRate = new PIDSourceParameter(kRate_val); - public static final PIDSourceParameter kAngle = new PIDSourceParameter(kAngle_val); - - private PIDSourceParameter(int value) { - this.value = value; - } - } - - /** - * Get the result to use in PIDController - * @return the result to use in PIDController - */ - public double pidGet(); -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index 751aa71b6b..43738d0b17 100644 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -13,6 +13,7 @@ import java.util.Enumeration; import java.util.jar.Manifest; import edu.wpi.first.wpilibj.simulation.MainNode; +import edu.wpi.first.wpilibj.internal.SimTimer; import edu.wpi.first.wpilibj.networktables.NetworkTable; /** @@ -152,6 +153,10 @@ public abstract class RobotBase { */ public static void main(String args[]) { // TODO: expose main to teams? boolean errorOnExit = false; + + // Set some implementations so that the static methods work properly + Timer.SetImplementation(new SimTimer()); + RobotState.SetImplementation(DriverStation.getInstance()); try { MainNode.openGazeboConnection(); diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Sendable.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Sendable.java deleted file mode 100644 index 978b4a7851..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Sendable.java +++ /dev/null @@ -1,26 +0,0 @@ -package edu.wpi.first.wpilibj; - -import edu.wpi.first.wpilibj.tables.ITable; - - -/** - * The base interface for objects that can be sent over the network - * through network tables. - */ -public interface Sendable { - /** - * Initializes a table for this sendable object. - * @param subtable The table to put the values in. - */ - public void initTable(ITable subtable); - - /** - * @return the table that is currently associated with the sendable - */ - public ITable getTable(); - - /** - * @return the string representation of the named data type that will be used by the smart dashboard for this sendable - */ - public String getSmartDashboardType(); -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java index 4535240d84..6fafbdd32f 100644 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java +++ b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/SimpleRobot.java @@ -7,6 +7,7 @@ package edu.wpi.first.wpilibj; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.livewindow.LiveWindow; /** diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/Button.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/Button.java deleted file mode 100644 index 54cefba333..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/Button.java +++ /dev/null @@ -1,70 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.buttons; - -import edu.wpi.first.wpilibj.command.Command; - -/** - * This class provides an easy way to link commands to OI inputs. - * - * It is very easy to link a button to a command. For instance, you could - * link the trigger button of a joystick to a "score" command. - * - * This class represents a subclass of Trigger that is specifically aimed at - * buttons on an operator interface as a common use case of the more generalized - * Trigger objects. This is a simple wrapper around Trigger with the method names - * renamed to fit the Button object use. - * - * @author brad - */ -public abstract class Button extends Trigger { - - /** - * Starts the given command whenever the button is newly pressed. - * @param command the command to start - */ - public void whenPressed(final Command command) { - whenActive(command); - } - - /** - * Constantly starts the given command while the button is held. - * - * {@link Command#start()} will be called repeatedly while the button is held, - * and will be canceled when the button is released. - * - * @param command the command to start - */ - public void whileHeld(final Command command) { - whileActive(command); - } - - /** - * Starts the command when the button is released - * @param command the command to start - */ - public void whenReleased(final Command command) { - whenInactive(command); - } - - /** - * Toggles the command whenever the button is pressed (on then off then on) - * @param command - */ - public void toggleWhenPressed(final Command command) { - toggleWhenActive(command); - } - - /** - * Cancel the command when the button is pressed - * @param command - */ - public void cancelWhenPressed(final Command command) { - cancelWhenActive(command); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java deleted file mode 100644 index 8757c271c7..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/InternalButton.java +++ /dev/null @@ -1,48 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.buttons; - -/** - * This class is intended to be used within a program. The programmer can manually set its value. - * Also includes a setting for whether or not it should invert its value. - * - * @author Joe - */ -public class InternalButton extends Button { - - boolean pressed; - boolean inverted; - - /** - * Creates an InternalButton that is not inverted. - */ - public InternalButton() { - this(false); - } - - /** - * Creates an InternalButton which is inverted depending on the input. - * - * @param inverted if false, then this button is pressed when set to true, otherwise it is pressed when set to false. - */ - public InternalButton(boolean inverted) { - this.pressed = this.inverted = inverted; - } - - public void setInverted(boolean inverted) { - this.inverted = inverted; - } - - public void setPressed(boolean pressed) { - this.pressed = pressed; - } - - public boolean get() { - return pressed ^ inverted; - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java deleted file mode 100644 index 5beff0d7ec..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/JoystickButton.java +++ /dev/null @@ -1,38 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.buttons; - -import edu.wpi.first.wpilibj.GenericHID; - -/** - * - * @author bradmiller - */ -public class JoystickButton extends Button { - - GenericHID m_joystick; - int m_buttonNumber; - - /** - * Create a joystick button for triggering commands - * @param joystick The GenericHID object that has the button (e.g. Joystick, KinectStick, etc) - * @param buttonNumber The button number (see {@link GenericHID#getRawButton(int) } - */ - public JoystickButton(GenericHID joystick, int buttonNumber) { - m_joystick = joystick; - m_buttonNumber = buttonNumber; - } - - /** - * Gets the value of the joystick button - * @return The value of the joystick button - */ - public boolean get() { - return m_joystick.getRawButton(m_buttonNumber); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java deleted file mode 100644 index fd0a23149c..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/NetworkButton.java +++ /dev/null @@ -1,33 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.buttons; - -import edu.wpi.first.wpilibj.networktables.NetworkTable; - -/** - * - * @author Joe - */ -public class NetworkButton extends Button { - - NetworkTable table; - String field; - - public NetworkButton(String table, String field) { - this(NetworkTable.getTable(table), field); - } - - public NetworkButton(NetworkTable table, String field) { - this.table = table; - this.field = field; - } - - public boolean get() { - return table.isConnected() && table.getBoolean(field, false); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java deleted file mode 100644 index 4e6ca903ec..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/buttons/Trigger.java +++ /dev/null @@ -1,200 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.buttons; - -import edu.wpi.first.wpilibj.Sendable; -import edu.wpi.first.wpilibj.command.Command; -import edu.wpi.first.wpilibj.command.Scheduler; -import edu.wpi.first.wpilibj.tables.ITable; - -/** - * This class provides an easy way to link commands to inputs. - * - * It is very easy to link a button to a command. For instance, you could - * link the trigger button of a joystick to a "score" command. - * - * It is encouraged that teams write a subclass of Trigger if they want to have - * something unusual (for instance, if they want to react to the user holding - * a button while the robot is reading a certain sensor input). For this, they - * only have to write the {@link Trigger#get()} method to get the full functionality - * of the Trigger class. - * - * @author Joe Grinstead - */ -public abstract class Trigger implements Sendable { - - /** - * Returns whether or not the trigger is active - * - * This method will be called repeatedly a command is linked to the Trigger. - * - * @return whether or not the trigger condition is active. - */ - public abstract boolean get(); - - /** - * Returns whether get() return true or the internal table for SmartDashboard use is pressed. - * @return whether get() return true or the internal table for SmartDashboard use is pressed - */ - private boolean grab() { - return get() || (table != null /*&& table.isConnected()*/ && table.getBoolean("pressed", false));//FIXME make is connected work? - } - - /** - * Starts the given command whenever the trigger just becomes active. - * @param command the command to start - */ - public void whenActive(final Command command) { - new ButtonScheduler() { - - boolean pressedLast = grab(); - - public void execute() { - if (grab()) { - if (!pressedLast) { - pressedLast = true; - command.start(); - } - } else { - pressedLast = false; - } - } - } .start(); - } - - /** - * Constantly starts the given command while the button is held. - * - * {@link Command#start()} will be called repeatedly while the trigger is active, - * and will be canceled when the trigger becomes inactive. - * - * @param command the command to start - */ - public void whileActive(final Command command) { - new ButtonScheduler() { - - boolean pressedLast = grab(); - - public void execute() { - if (grab()) { - pressedLast = true; - command.start(); - } else { - if (pressedLast) { - pressedLast = false; - command.cancel(); - } - } - } - } .start(); - } - - /** - * Starts the command when the trigger becomes inactive - * @param command the command to start - */ - public void whenInactive(final Command command) { - new ButtonScheduler() { - - boolean pressedLast = grab(); - - public void execute() { - if (grab()) { - pressedLast = true; - } else { - if (pressedLast) { - pressedLast = false; - command.start(); - } - } - } - } .start(); - } - - /** - * Toggles a command when the trigger becomes active - * @param command the command to toggle - */ - public void toggleWhenActive(final Command command) { - new ButtonScheduler() { - - boolean pressedLast = grab(); - - public void execute() { - if (grab()) { - if (!pressedLast) { - pressedLast = true; - if (command.isRunning()) { - command.cancel(); - } else { - command.start(); - } - } - } else { - pressedLast = false; - } - } - } .start(); - } - - /** - * Cancels a command when the trigger becomes active - * @param command the command to cancel - */ - public void cancelWhenActive(final Command command) { - new ButtonScheduler() { - - boolean pressedLast = grab(); - - public void execute() { - if (grab()) { - if (!pressedLast) { - pressedLast = true; - command.cancel(); - } - } else { - pressedLast = false; - } - } - } .start(); - } - - /** - * An internal class of {@link Trigger}. The user should ignore this, it is - * only public to interface between packages. - */ - public abstract class ButtonScheduler { - public abstract void execute(); - - protected void start() { - Scheduler.getInstance().addButton(this); - } - } - - /** - * These methods continue to return the "Button" SmartDashboard type until we decided - * to create a Trigger widget type for the dashboard. - */ - public String getSmartDashboardType() { - return "Button"; - } - private ITable table; - public void initTable(ITable table) { - this.table = table; - if(table!=null) { - table.putBoolean("pressed", get()); - } - } - - /** - * {@inheritDoc} - */ - public ITable getTable() { - return table; - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Command.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Command.java deleted file mode 100644 index 3cda95b65a..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Command.java +++ /dev/null @@ -1,523 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj.NamedSendable; -import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj.tables.ITable; -import edu.wpi.first.wpilibj.tables.ITableListener; -import java.util.Enumeration; -import java.util.NoSuchElementException; - -/** - * The Command class is at the very core of the entire command framework. - * Every command can be started with a call to {@link Command#start() start()}. - * Once a command is started it will call {@link Command#initialize() initialize()}, and then - * will repeatedly call {@link Command#execute() execute()} until the {@link Command#isFinished() isFinished()} - * returns true. Once it does, {@link Command#end() end()} will be called. - * - *

However, if at any point while it is running {@link Command#cancel() cancel()} is called, then - * the command will be stopped and {@link Command#interrupted() interrupted()} will be called.

- * - *

If a command uses a {@link Subsystem}, then it should specify that it does so by - * calling the {@link Command#requires(Subsystem) requires(...)} method - * in its constructor. Note that a Command may have multiple requirements, and - * {@link Command#requires(Subsystem) requires(...)} should be - * called for each one.

- * - *

If a command is running and a new command with shared requirements is started, - * then one of two things will happen. If the active command is interruptible, - * then {@link Command#cancel() cancel()} will be called and the command will be removed - * to make way for the new one. If the active command is not interruptible, the - * other one will not even be started, and the active one will continue functioning.

- * - * @author Brad Miller - * @author Joe Grinstead - * @see Subsystem - * @see CommandGroup - * @see IllegalUseOfCommandException - */ -public abstract class Command implements NamedSendable { - - /** The name of this command */ - private String m_name; - /** The time since this command was initialized */ - private double m_startTime = -1; - /** The time (in seconds) before this command "times out" (or -1 if no timeout) */ - private double m_timeout = -1; - /** Whether or not this command has been initialized */ - private boolean m_initialized = false; - /** The requirements (or null if no requirements) */ - private Set m_requirements; - /** Whether or not it is running */ - private boolean m_running = false; - /** Whether or not it is interruptible*/ - private boolean m_interruptible = true; - /** Whether or not it has been canceled */ - private boolean m_canceled = false; - /** Whether or not it has been locked */ - private boolean m_locked = false; - /** Whether this command should run when the robot is disabled */ - private boolean m_runWhenDisabled = false; - /** The {@link CommandGroup} this is in */ - private CommandGroup m_parent; - - /** - * Creates a new command. - * The name of this command will be set to its class name. - */ - public Command() { - m_name = getClass().getName(); - m_name = m_name.substring(m_name.lastIndexOf('.') + 1); - } - - /** - * Creates a new command with the given name. - * @param name the name for this command - * @throws IllegalArgumentException if name is null - */ - public Command(String name) { - if (name == null) { - throw new IllegalArgumentException("Name must not be null."); - } - m_name = name; - } - - /** - * Creates a new command with the given timeout and a default name. - * The default name is the name of the class. - * @param timeout the time (in seconds) before this command "times out" - * @throws IllegalArgumentException if given a negative timeout - * @see Command#isTimedOut() isTimedOut() - */ - public Command(double timeout) { - this(); - if (timeout < 0) { - throw new IllegalArgumentException("Timeout must not be negative. Given:" + timeout); - } - m_timeout = timeout; - } - - /** - * Creates a new command with the given name and timeout. - * @param name the name of the command - * @param timeout the time (in seconds) before this command "times out" - * @throws IllegalArgumentException if given a negative timeout or name was null. - * @see Command#isTimedOut() isTimedOut() - */ - public Command(String name, double timeout) { - this(name); - if (timeout < 0) { - throw new IllegalArgumentException("Timeout must not be negative. Given:" + timeout); - } - m_timeout = timeout; - } - - /** - * Returns the name of this command. - * If no name was specified in the constructor, - * then the default is the name of the class. - * @return the name of this command - */ - public String getName() { - return m_name; - } - - /** - * Sets the timeout of this command. - * @param seconds the timeout (in seconds) - * @throws IllegalArgumentException if seconds is negative - * @see Command#isTimedOut() isTimedOut() - */ - protected synchronized final void setTimeout(double seconds) { - if (seconds < 0) { - throw new IllegalArgumentException("Seconds must be positive. Given:" + seconds); - } - m_timeout = seconds; - } - - /** - * Returns the time since this command was initialized (in seconds). - * This function will work even if there is no specified timeout. - * @return the time since this command was initialized (in seconds). - */ - public synchronized final double timeSinceInitialized() { - return m_startTime < 0 ? 0 : Timer.getFPGATimestamp() - m_startTime; - } - - /** - * This method specifies that the given {@link Subsystem} is used by this command. - * This method is crucial to the functioning of the Command System in general. - * - *

Note that the recommended way to call this method is in the constructor.

- * - * @param subsystem the {@link Subsystem} required - * @throws IllegalArgumentException if subsystem is null - * @throws IllegalUseOfCommandException if this command has started before or if it has been given to a {@link CommandGroup} - * @see Subsystem - */ - protected synchronized void requires(Subsystem subsystem) { - validate("Can not add new requirement to command"); - if (subsystem != null) { - if (m_requirements == null) { - m_requirements = new Set(); - } - m_requirements.add(subsystem); - } else { - throw new IllegalArgumentException("Subsystem must not be null."); - } - } - - /** - * Called when the command has been removed. - * This will call {@link Command#interrupted() interrupted()} or {@link Command#end() end()}. - */ - synchronized void removed() { - if (m_initialized) { - if (isCanceled()) { - interrupted(); - _interrupted(); - } else { - end(); - _end(); - } - } - m_initialized = false; - m_canceled = false; - m_running = false; - if (table != null) { - table.putBoolean("running", false); - } - } - - /** - * The run method is used internally to actually run the commands. - * @return whether or not the command should stay within the {@link Scheduler}. - */ - synchronized boolean run() { - if (!m_runWhenDisabled && m_parent == null && DriverStation.getInstance().isDisabled()) { - cancel(); - } - if (isCanceled()) { - return false; - } - if (!m_initialized) { - m_initialized = true; - startTiming(); - _initialize(); - initialize(); - } - _execute(); - execute(); - return !isFinished(); - } - - /** - * The initialize method is called the first time this Command is run after - * being started. - */ - protected abstract void initialize(); - - /** A shadow method called before {@link Command#initialize() initialize()} */ - void _initialize() { - } - - /** - * The execute method is called repeatedly until this Command either finishes - * or is canceled. - */ - protected abstract void execute(); - - /** A shadow method called before {@link Command#execute() execute()} */ - void _execute() { - } - - /** - * Returns whether this command is finished. - * If it is, then the command will be removed - * and {@link Command#end() end()} will be called. - * - *

It may be useful for a team to reference the {@link Command#isTimedOut() isTimedOut()} method - * for time-sensitive commands.

- * @return whether this command is finished. - * @see Command#isTimedOut() isTimedOut() - */ - protected abstract boolean isFinished(); - - /** - * Called when the command ended peacefully. This is where you may want - * to wrap up loose ends, like shutting off a motor that was being used - * in the command. - */ - protected abstract void end(); - - /** A shadow method called after {@link Command#end() end()}. */ - void _end() { - } - - /** - * Called when the command ends because somebody called {@link Command#cancel() cancel()} - * or another command shared the same requirements as this one, and booted - * it out. - * - *

This is where you may want - * to wrap up loose ends, like shutting off a motor that was being used - * in the command.

- * - *

Generally, it is useful to simply call the {@link Command#end() end()} method - * within this method

- */ - protected abstract void interrupted(); - - /** A shadow method called after {@link Command#interrupted() interrupted()}. */ - void _interrupted() { - } - - /** - * Called to indicate that the timer should start. - * This is called right before {@link Command#initialize() initialize()} is, inside the - * {@link Command#run() run()} method. - */ - private void startTiming() { - m_startTime = Timer.getFPGATimestamp(); - } - - /** - * Returns whether or not the {@link Command#timeSinceInitialized() timeSinceInitialized()} - * method returns a number which is greater than or equal to the timeout for the command. - * If there is no timeout, this will always return false. - * @return whether the time has expired - */ - protected synchronized boolean isTimedOut() { - return m_timeout != -1 && timeSinceInitialized() >= m_timeout; - } - - /** - * Returns the requirements (as an {@link Enumeration Enumeration} of {@link Subsystem Subsystems}) of this command - * @return the requirements (as an {@link Enumeration Enumeration} of {@link Subsystem Subsystems}) of this command - */ - synchronized Enumeration getRequirements() { - return m_requirements == null ? emptyEnumeration : m_requirements.getElements(); - } - - /** - * Prevents further changes from being made - */ - synchronized void lockChanges() { - m_locked = true; - } - - /** - * If changes are locked, then this will throw an {@link IllegalUseOfCommandException}. - * @param message the message to say (it is appended by a default message) - */ - synchronized void validate(String message) { - if (m_locked) { - throw new IllegalUseOfCommandException(message + " after being started or being added to a command group"); - } - } - - /** - * Sets the parent of this command. No actual change is made to the group. - * @param parent the parent - * @throws IllegalUseOfCommandException if this {@link Command} already is already in a group - */ - synchronized void setParent(CommandGroup parent) { - if (this.m_parent != null) { - throw new IllegalUseOfCommandException("Can not give command to a command group after already being put in a command group"); - } - lockChanges(); - this.m_parent = parent; - if (table != null) { - table.putBoolean("isParented", true); - } - } - - /** - * Starts up the command. Gets the command ready to start. - *

Note that the command will eventually start, however it will not necessarily - * do so immediately, and may in fact be canceled before initialize is even called.

- * @throws IllegalUseOfCommandException if the command is a part of a CommandGroup - */ - public synchronized void start() { - lockChanges(); - if (m_parent != null) { - throw new IllegalUseOfCommandException("Can not start a command that is a part of a command group"); - } - Scheduler.getInstance().add(this); - } - - /** - * This is used internally to mark that the command has been started. - * The lifecycle of a command is: - * - * startRunning() is called. - * run() is called (multiple times potentially) - * removed() is called - * - * It is very important that startRunning and removed be called in order or some assumptions - * of the code will be broken. - */ - synchronized void startRunning() { - m_running = true; - m_startTime = -1; - if (table != null) { - table.putBoolean("running", true); - } - } - - /** - * Returns whether or not the command is running. - * This may return true even if the command has just been canceled, as it may - * not have yet called {@link Command#interrupted()}. - * @return whether or not the command is running - */ - public synchronized boolean isRunning() { - return m_running; - } - - /** - * This will cancel the current command. - *

This will cancel the current command eventually. It can be called multiple times. - * And it can be called when the command is not running. If the command is running though, - * then the command will be marked as canceled and eventually removed.

- *

A command can not be canceled - * if it is a part of a command group, you must cancel the command group instead.

- * @throws IllegalUseOfCommandException if this command is a part of a command group - */ - public synchronized void cancel() { - if (m_parent != null) { - throw new IllegalUseOfCommandException("Can not manually cancel a command in a command group"); - } - _cancel(); - } - - /** - * This works like cancel(), except that it doesn't throw an exception if it is a part - * of a command group. Should only be called by the parent command group. - */ - synchronized void _cancel() { - if (isRunning()) { - m_canceled = true; - } - } - - /** - * Returns whether or not this has been canceled. - * @return whether or not this has been canceled - */ - public synchronized boolean isCanceled() { - return m_canceled; - } - - /** - * Returns whether or not this command can be interrupted. - * @return whether or not this command can be interrupted - */ - public synchronized boolean isInterruptible() { - return m_interruptible; - } - - /** - * Sets whether or not this command can be interrupted. - * @param interruptible whether or not this command can be interrupted - */ - protected synchronized void setInterruptible(boolean interruptible) { - this.m_interruptible = interruptible; - } - - /** - * Checks if the command requires the given {@link Subsystem}. - * @param system the system - * @return whether or not the subsystem is required, or false if given null - */ - public synchronized boolean doesRequire(Subsystem system) { - return m_requirements != null && m_requirements.contains(system); - } - - /** - * Returns the {@link CommandGroup} that this command is a part of. - * Will return null if this {@link Command} is not in a group. - * @return the {@link CommandGroup} that this command is a part of (or null if not in group) - */ - public synchronized CommandGroup getGroup() { - return m_parent; - } - - /** - * Sets whether or not this {@link Command} should run when the robot is disabled. - * - *

By default a command will not run when the robot is disabled, and will in fact be canceled.

- * @param run whether or not this command should run when the robot is disabled - */ - public void setRunWhenDisabled(boolean run) { - m_runWhenDisabled = run; - } - - /** - * Returns whether or not this {@link Command} will run when the robot is disabled, or if it will cancel itself. - * @return whether or not this {@link Command} will run when the robot is disabled, or if it will cancel itself - */ - public boolean willRunWhenDisabled() { - return m_runWhenDisabled; - } - /** An empty enumeration given whenever there are no requirements */ - private static Enumeration emptyEnumeration = new Enumeration() { - - public boolean hasMoreElements() { - return false; - } - - public Object nextElement() { - throw new NoSuchElementException(); - } - }; - - /** - * The string representation for a {@link Command} is by default its name. - * @return the string representation of this object - */ - public String toString() { - return getName(); - } - - - public String getSmartDashboardType() { - return "Command"; - } - private ITableListener listener = new ITableListener() { - public void valueChanged(ITable table, String key, Object value, boolean isNew) { - if (((Boolean) value).booleanValue()) { - start(); - } else { - cancel(); - } - } - }; - private ITable table; - public void initTable(ITable table) { - if(this.table!=null) - this.table.removeTableListener(listener); - this.table = table; - if(table!=null) { - table.putString("name", getName()); - table.putBoolean("running", isRunning()); - table.putBoolean("isParented", m_parent != null); - table.addTableListener("running", listener, false); - } - } - - /** - * {@inheritDoc} - */ - public ITable getTable() { - return table; - } - -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java deleted file mode 100644 index 55a2203e92..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/CommandGroup.java +++ /dev/null @@ -1,398 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -import java.util.Enumeration; -import java.util.Vector; - -/** - * A {@link CommandGroup} is a list of commands which are executed in sequence. - * - *

Commands in a {@link CommandGroup} are added using the {@link CommandGroup#addSequential(Command) addSequential(...)} method - * and are called sequentially. - * {@link CommandGroup CommandGroups} are themselves {@link Command commands} - * and can be given to other {@link CommandGroup CommandGroups}.

- * - *

{@link CommandGroup CommandGroups} will carry all of the requirements of their {@link Command subcommands}. Additional - * requirements can be specified by calling {@link CommandGroup#requires(Subsystem) requires(...)} - * normally in the constructor.

- * - *

CommandGroups can also execute commands in parallel, simply by adding them - * using {@link CommandGroup#addParallel(Command) addParallel(...)}.

- * - * @author Brad Miller - * @author Joe Grinstead - * @see Command - * @see Subsystem - * @see IllegalUseOfCommandException - */ -public class CommandGroup extends Command { - - /** The commands in this group (stored in entries) */ - private Vector m_commands = new Vector(); - /** The active children in this group (stored in entries) */ - Vector m_children = new Vector(); - /** The current command, -1 signifies that none have been run */ - private int m_currentCommandIndex = -1; - - /** - * Creates a new {@link CommandGroup CommandGroup}. - * The name of this command will be set to its class name. - */ - public CommandGroup() { - } - - /** - * Creates a new {@link CommandGroup CommandGroup} with the given name. - * @param name the name for this command group - * @throws IllegalArgumentException if name is null - */ - public CommandGroup(String name) { - super(name); - } - - /** - * Adds a new {@link Command Command} to the group. The {@link Command Command} will be started after - * all the previously added {@link Command Commands}. - * - *

Note that any requirements the given {@link Command Command} has will be added to the - * group. For this reason, a {@link Command Command's} requirements can not be changed after - * being added to a group.

- * - *

It is recommended that this method be called in the constructor.

- * - * @param command The {@link Command Command} to be added - * @throws IllegalUseOfCommandException if the group has been started before or been given to another group - * @throws IllegalArgumentException if command is null - */ - public synchronized final void addSequential(Command command) { - validate("Can not add new command to command group"); - if (command == null) { - throw new IllegalArgumentException("Given null command"); - } - - command.setParent(this); - - m_commands.addElement(new Entry(command, Entry.IN_SEQUENCE)); - for (Enumeration e = command.getRequirements(); e.hasMoreElements();) { - requires((Subsystem) e.nextElement()); - } - } - - /** - * Adds a new {@link Command Command} to the group with a given timeout. - * The {@link Command Command} will be started after all the previously added commands. - * - *

Once the {@link Command Command} is started, it will be run until it finishes or the time - * expires, whichever is sooner. Note that the given {@link Command Command} will have no - * knowledge that it is on a timer.

- * - *

Note that any requirements the given {@link Command Command} has will be added to the - * group. For this reason, a {@link Command Command's} requirements can not be changed after - * being added to a group.

- * - *

It is recommended that this method be called in the constructor.

- * - * @param command The {@link Command Command} to be added - * @param timeout The timeout (in seconds) - * @throws IllegalUseOfCommandException if the group has been started before or been given to another group or - * if the {@link Command Command} has been started before or been given to another group - * @throws IllegalArgumentException if command is null or timeout is negative - */ - public synchronized final void addSequential(Command command, double timeout) { - validate("Can not add new command to command group"); - if (command == null) { - throw new IllegalArgumentException("Given null command"); - } - if (timeout < 0) { - throw new IllegalArgumentException("Can not be given a negative timeout"); - } - - command.setParent(this); - - m_commands.addElement(new Entry(command, Entry.IN_SEQUENCE, timeout)); - for (Enumeration e = command.getRequirements(); e.hasMoreElements();) { - requires((Subsystem) e.nextElement()); - } - } - - /** - * Adds a new child {@link Command} to the group. The {@link Command} will be started after - * all the previously added {@link Command Commands}. - * - *

Instead of waiting for the child to finish, a {@link CommandGroup} will have it - * run at the same time as the subsequent {@link Command Commands}. The child will run until either - * it finishes, a new child with conflicting requirements is started, or - * the main sequence runs a {@link Command} with conflicting requirements. In the latter - * two cases, the child will be canceled even if it says it can't be - * interrupted.

- * - *

Note that any requirements the given {@link Command Command} has will be added to the - * group. For this reason, a {@link Command Command's} requirements can not be changed after - * being added to a group.

- * - *

It is recommended that this method be called in the constructor.

- * - * @param command The command to be added - * @throws IllegalUseOfCommandException if the group has been started before or been given to another command group - * @throws IllegalArgumentException if command is null - */ - public synchronized final void addParallel(Command command) { - validate("Can not add new command to command group"); - if (command == null) { - throw new NullPointerException("Given null command"); - } - - command.setParent(this); - - m_commands.addElement(new Entry(command, Entry.BRANCH_CHILD)); - for (Enumeration e = command.getRequirements(); e.hasMoreElements();) { - requires((Subsystem) e.nextElement()); - } - } - - /** - * Adds a new child {@link Command} to the group with the given timeout. The {@link Command} will be started after - * all the previously added {@link Command Commands}. - * - *

Once the {@link Command Command} is started, it will run until it finishes, is interrupted, - * or the time expires, whichever is sooner. Note that the given {@link Command Command} will have no - * knowledge that it is on a timer.

- * - *

Instead of waiting for the child to finish, a {@link CommandGroup} will have it - * run at the same time as the subsequent {@link Command Commands}. The child will run until either - * it finishes, the timeout expires, a new child with conflicting requirements is started, or - * the main sequence runs a {@link Command} with conflicting requirements. In the latter - * two cases, the child will be canceled even if it says it can't be - * interrupted.

- * - *

Note that any requirements the given {@link Command Command} has will be added to the - * group. For this reason, a {@link Command Command's} requirements can not be changed after - * being added to a group.

- * - *

It is recommended that this method be called in the constructor.

- * - * @param command The command to be added - * @param timeout The timeout (in seconds) - * @throws IllegalUseOfCommandException if the group has been started before or been given to another command group - * @throws IllegalArgumentException if command is null - */ - public synchronized final void addParallel(Command command, double timeout) { - validate("Can not add new command to command group"); - if (command == null) { - throw new NullPointerException("Given null command"); - } - if (timeout < 0) { - throw new IllegalArgumentException("Can not be given a negative timeout"); - } - - command.setParent(this); - - m_commands.addElement(new Entry(command, Entry.BRANCH_CHILD, timeout)); - for (Enumeration e = command.getRequirements(); e.hasMoreElements();) { - requires((Subsystem) e.nextElement()); - } - } - - void _initialize() { - m_currentCommandIndex = -1; - } - - void _execute() { - Entry entry = null; - Command cmd = null; - boolean firstRun = false; - if (m_currentCommandIndex == -1) { - firstRun = true; - m_currentCommandIndex = 0; - } - - while (m_currentCommandIndex < m_commands.size()) { - - if (cmd != null) { - if (entry.isTimedOut()) { - cmd._cancel(); - } - if (cmd.run()) { - break; - } else { - cmd.removed(); - m_currentCommandIndex++; - firstRun = true; - cmd = null; - continue; - } - } - - entry = (Entry) m_commands.elementAt(m_currentCommandIndex); - cmd = null; - - switch (entry.state) { - case Entry.IN_SEQUENCE: - cmd = entry.command; - if (firstRun) { - cmd.startRunning(); - cancelConflicts(cmd); - } - firstRun = false; - break; - case Entry.BRANCH_PEER: - m_currentCommandIndex++; - entry.command.start(); - break; - case Entry.BRANCH_CHILD: - m_currentCommandIndex++; - cancelConflicts(entry.command); - entry.command.startRunning(); - m_children.addElement(entry); - break; - } - } - - // Run Children - for (int i = 0; i < m_children.size(); i++) { - entry = (Entry) m_children.elementAt(i); - Command child = entry.command; - if (entry.isTimedOut()) { - child._cancel(); - } - if (!child.run()) { - child.removed(); - m_children.removeElementAt(i--); - } - } - } - - void _end() { - // Theoretically, we don't have to check this, but we do if teams override the isFinished method - if (m_currentCommandIndex != -1 && m_currentCommandIndex < m_commands.size()) { - Command cmd = ((Entry) m_commands.elementAt(m_currentCommandIndex)).command; - cmd._cancel(); - cmd.removed(); - } - - Enumeration children = m_children.elements(); - while (children.hasMoreElements()) { - Command cmd = ((Entry) children.nextElement()).command; - cmd._cancel(); - cmd.removed(); - } - m_children.removeAllElements(); - } - - void _interrupted() { - _end(); - } - - /** - * Returns true if all the {@link Command Commands} in this group - * have been started and have finished. - * - *

Teams may override this method, although they should probably - * reference super.isFinished() if they do.

- * - * @return whether this {@link CommandGroup} is finished - */ - protected boolean isFinished() { - return m_currentCommandIndex >= m_commands.size() && m_children.isEmpty(); - } - - // Can be overwritten by teams - protected void initialize() { - } - - // Can be overwritten by teams - protected void execute() { - } - - // Can be overwritten by teams - protected void end() { - } - - // Can be overwritten by teams - protected void interrupted() { - } - - /** - * Returns whether or not this group is interruptible. - * A command group will be uninterruptible if {@link CommandGroup#setInterruptible(boolean) setInterruptable(false)} - * was called or if it is currently running an uninterruptible command - * or child. - * - * @return whether or not this {@link CommandGroup} is interruptible. - */ - public synchronized boolean isInterruptible() { - if (!super.isInterruptible()) { - return false; - } - - if (m_currentCommandIndex != -1 && m_currentCommandIndex < m_commands.size()) { - Command cmd = ((Entry) m_commands.elementAt(m_currentCommandIndex)).command; - if (!cmd.isInterruptible()) { - return false; - } - } - - for (int i = 0; i < m_children.size(); i++) { - if (!((Entry) m_children.elementAt(i)).command.isInterruptible()) { - return false; - } - } - - return true; - } - - private void cancelConflicts(Command command) { - for (int i = 0; i < m_children.size(); i++) { - Command child = ((Entry) m_children.elementAt(i)).command; - - Enumeration requirements = command.getRequirements(); - - while (requirements.hasMoreElements()) { - Object requirement = requirements.nextElement(); - if (child.doesRequire((Subsystem) requirement)) { - child._cancel(); - child.removed(); - m_children.removeElementAt(i--); - break; - } - } - } - } - - private static class Entry { - - private static final int IN_SEQUENCE = 0; - private static final int BRANCH_PEER = 1; - private static final int BRANCH_CHILD = 2; - Command command; - int state; - double timeout; - - Entry(Command command, int state) { - this.command = command; - this.state = state; - this.timeout = -1; - } - - Entry(Command command, int state, double timeout) { - this.command = command; - this.state = state; - this.timeout = timeout; - } - - boolean isTimedOut() { - if (timeout == -1) { - return false; - } else { - double time = command.timeSinceInitialized(); - return time == 0 ? false : time >= timeout; - } - } - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/IllegalUseOfCommandException.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/IllegalUseOfCommandException.java deleted file mode 100644 index ae13045782..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/IllegalUseOfCommandException.java +++ /dev/null @@ -1,38 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -/** - * This exception will be thrown if a command is used illegally. There are - * several ways for this to happen. - * - *

Basically, a command becomes "locked" after it is first started or added - * to a command group.

- * - *

This exception should be thrown if (after a command has been locked) its requirements - * change, it is put into multiple command groups, - * it is started from outside its command group, or it adds a new child.

- * - * @author Joe Grinstead - */ -public class IllegalUseOfCommandException extends RuntimeException { - - /** - * Instantiates an {@link IllegalUseOfCommandException}. - */ - public IllegalUseOfCommandException() { - } - - /** - * Instantiates an {@link IllegalUseOfCommandException} with the given message. - * @param message the message - */ - public IllegalUseOfCommandException(String message) { - super(message); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/LinkedListElement.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/LinkedListElement.java deleted file mode 100644 index 1d2dcc6f81..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/LinkedListElement.java +++ /dev/null @@ -1,66 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -/** - * - * @author Greg - */ -class LinkedListElement { - private LinkedListElement next; - private LinkedListElement previous; - private Command data; - - public LinkedListElement() { - } - - public void setData(Command newData) { - data = newData; - } - - public Command getData() { - return data; - } - - public LinkedListElement getNext() { - return next; - } - - public LinkedListElement getPrevious() { - return previous; - } - - public void add(LinkedListElement l) { - if(next == null) { - next = l; - next.previous = this; - } else { - next.previous = l; - l.next = next; - l.previous = this; - next = l; - } - } - - public LinkedListElement remove() { - if(previous == null && next == null) { - - } else if(next == null) { - previous.next = null; - } else if(previous == null) { - next.previous = null; - } else { - next.previous = previous; - previous.next = next; - } - LinkedListElement n = next; - next = null; - previous = null; - return n; - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java deleted file mode 100644 index 158fd58961..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PIDCommand.java +++ /dev/null @@ -1,191 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -import edu.wpi.first.wpilibj.PIDController; -import edu.wpi.first.wpilibj.PIDOutput; -import edu.wpi.first.wpilibj.PIDSource; -import edu.wpi.first.wpilibj.Sendable; -import edu.wpi.first.wpilibj.tables.ITable; - -/** - * This class defines a {@link Command} which interacts heavily with a PID loop. - * - *

It provides some convenience methods to run an internal {@link PIDController}. - * It will also start and stop said {@link PIDController} when the {@link PIDCommand} is - * first initialized and ended/interrupted.

- * - * @author Joe Grinstead - */ -public abstract class PIDCommand extends Command implements Sendable { - - /** The internal {@link PIDController} */ - private PIDController controller; - /** An output which calls {@link PIDCommand#usePIDOutput(double)} */ - private PIDOutput output = new PIDOutput() { - - public void pidWrite(double output) { - usePIDOutput(output); - } - }; - /** A source which calls {@link PIDCommand#returnPIDInput()} */ - private PIDSource source = new PIDSource() { - - public double pidGet() { - return returnPIDInput(); - } - }; - - /** - * Instantiates a {@link PIDCommand} that will use the given p, i and d values. - * @param name the name of the command - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - */ - public PIDCommand(String name, double p, double i, double d) { - super(name); - controller = new PIDController(p, i, d, source, output); - } - - /** - * Instantiates a {@link PIDCommand} that will use the given p, i and d values. It will also space the time - * between PID loop calculations to be equal to the given period. - * @param name the name - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param period the time (in seconds) between calculations - */ - public PIDCommand(String name, double p, double i, double d, double period) { - super(name); - controller = new PIDController(p, i, d, source, output, period); - } - - /** - * Instantiates a {@link PIDCommand} that will use the given p, i and d values. - * It will use the class name as its name. - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - */ - public PIDCommand(double p, double i, double d) { - controller = new PIDController(p, i, d, source, output); - } - - /** - * Instantiates a {@link PIDCommand} that will use the given p, i and d values. - * It will use the class name as its name.. - * It will also space the time - * between PID loop calculations to be equal to the given period. - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param period the time (in seconds) between calculations - */ - public PIDCommand(double p, double i, double d, double period) { - controller = new PIDController(p, i, d, source, output, period); - } - - /** - * Returns the {@link PIDController} used by this {@link PIDCommand}. - * Use this if you would like to fine tune the pid loop. - * - *

Notice that calling {@link PIDController#setSetpoint(double) setSetpoint(...)} on the controller - * will not result in the setpoint being trimmed to be in - * the range defined by {@link PIDCommand#setSetpointRange(double, double) setSetpointRange(...)}.

- * - * @return the {@link PIDController} used by this {@link PIDCommand} - */ - protected PIDController getPIDController() { - return controller; - } - - void _initialize() { - controller.enable(); - } - - void _end() { - controller.disable(); - } - - void _interrupted() { - _end(); - } - - /** - * Adds the given value to the setpoint. - * If {@link PIDCommand#setRange(double, double) setRange(...)} was used, - * then the bounds will still be honored by this method. - * @param deltaSetpoint the change in the setpoint - */ - public void setSetpointRelative(double deltaSetpoint) { - setSetpoint(getSetpoint() + deltaSetpoint); - } - - /** - * Sets the setpoint to the given value. If {@link PIDCommand#setRange(double, double) setRange(...)} - * was called, - * then the given setpoint - * will be trimmed to fit within the range. - * @param setpoint the new setpoint - */ - protected void setSetpoint(double setpoint) { - controller.setSetpoint(setpoint); - } - - /** - * Returns the setpoint. - * @return the setpoint - */ - protected double getSetpoint() { - return controller.getSetpoint(); - } - - /** - * Returns the current position - * @return the current position - */ - protected double getPosition() { - return returnPIDInput(); - } - - /** - * Returns the input for the pid loop. - * - *

It returns the input for the pid loop, so if this command was based - * off of a gyro, then it should return the angle of the gyro

- * - *

All subclasses of {@link PIDCommand} must override this method.

- * - *

This method will be called in a different thread then the {@link Scheduler} thread.

- * - * @return the value the pid loop should use as input - */ - protected abstract double returnPIDInput(); - - /** - * Uses the value that the pid loop calculated. The calculated value is the "output" parameter. - * This method is a good time to set motor values, maybe something along the lines of driveline.tankDrive(output, -output) - * - *

All subclasses of {@link PIDCommand} must override this method.

- * - *

This method will be called in a different thread then the {@link Scheduler} thread.

- * - * @param output the value the pid loop calculated - */ - protected abstract void usePIDOutput(double output); - - public String getSmartDashboardType() { - return "PIDCommand"; - } - public void initTable(ITable table) { - controller.initTable(table); - super.initTable(table); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java deleted file mode 100644 index fb0384fb4d..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PIDSubsystem.java +++ /dev/null @@ -1,260 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -import edu.wpi.first.wpilibj.PIDController; -import edu.wpi.first.wpilibj.PIDOutput; -import edu.wpi.first.wpilibj.PIDSource; -import edu.wpi.first.wpilibj.Sendable; -import edu.wpi.first.wpilibj.tables.ITable; - -/** - * This class is designed to handle the case where there is a {@link Subsystem} - * which uses a single {@link PIDController} almost constantly (for instance, - * an elevator which attempts to stay at a constant height). - * - *

It provides some convenience methods to run an internal {@link PIDController}. - * It also allows access to the internal {@link PIDController} in order to give total control - * to the programmer.

- * - * @author Joe Grinstead - */ -public abstract class PIDSubsystem extends Subsystem implements Sendable { - - /** The internal {@link PIDController} */ - private PIDController controller; - /** An output which calls {@link PIDCommand#usePIDOutput(double)} */ - private PIDOutput output = new PIDOutput() { - - public void pidWrite(double output) { - usePIDOutput(output); - } - }; - /** A source which calls {@link PIDCommand#returnPIDInput()} */ - private PIDSource source = new PIDSource() { - - public double pidGet() { - return returnPIDInput(); - } - }; - - /** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * @param name the name - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - */ - public PIDSubsystem(String name, double p, double i, double d) { - super(name); - controller = new PIDController(p, i, d, source, output); - } - - /** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * @param name the name - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param f the feed forward value - */ - public PIDSubsystem(String name, double p, double i, double d, double f) { - super(name); - controller = new PIDController(p, i, d, f, source, output); - } - - /** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. It will also space the time - * between PID loop calculations to be equal to the given period. - * @param name the name - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param period the time (in seconds) between calculations - */ - public PIDSubsystem(String name, double p, double i, double d, double f, double period) { - super(name); - controller = new PIDController(p, i, d, f, source, output, period); - } - - /** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * It will use the class name as its name. - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - */ - public PIDSubsystem(double p, double i, double d) { - controller = new PIDController(p, i, d, source, output); - } - - /** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * It will use the class name as its name. - * It will also space the time - * between PID loop calculations to be equal to the given period. - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param f the feed forward coefficient - * @param period the time (in seconds) between calculations - */ - public PIDSubsystem(double p, double i, double d, double period, double f) { - controller = new PIDController(p, i, d, f, source, output, period); - } - - /** - * Instantiates a {@link PIDSubsystem} that will use the given p, i and d values. - * It will use the class name as its name. - * It will also space the time - * between PID loop calculations to be equal to the given period. - * @param p the proportional value - * @param i the integral value - * @param d the derivative value - * @param period the time (in seconds) between calculations - */ - public PIDSubsystem(double p, double i, double d, double period) { - controller = new PIDController(p, i, d, source, output, period); - } - - /** - * Returns the {@link PIDController} used by this {@link PIDSubsystem}. - * Use this if you would like to fine tune the pid loop. - * - *

Notice that calling {@link PIDController#setSetpoint(double) setSetpoint(...)} on the controller - * will not result in the setpoint being trimmed to be in - * the range defined by {@link PIDSubsystem#setSetpointRange(double, double) setSetpointRange(...)}.

- * - * @return the {@link PIDController} used by this {@link PIDSubsystem} - */ - public PIDController getPIDController() { - return controller; - } - - - /** - * Adds the given value to the setpoint. - * If {@link PIDCommand#setRange(double, double) setRange(...)} was used, - * then the bounds will still be honored by this method. - * @param deltaSetpoint the change in the setpoint - */ - public void setSetpointRelative(double deltaSetpoint) { - setSetpoint(getPosition() + deltaSetpoint); - } - - /** - * Sets the setpoint to the given value. If {@link PIDCommand#setRange(double, double) setRange(...)} - * was called, - * then the given setpoint - * will be trimmed to fit within the range. - * @param setpoint the new setpoint - */ - public void setSetpoint(double setpoint) { - controller.setSetpoint(setpoint); - } - - /** - * Returns the setpoint. - * @return the setpoint - */ - public double getSetpoint() { - return controller.getSetpoint(); - } - - /** - * Returns the current position - * @return the current position - */ - public double getPosition() { - return returnPIDInput(); - } - - /** - * Sets the maximum and minimum values expected from the input. - * - * @param minimumInput the minimum value expected from the input - * @param maximumInput the maximum value expected from the output - */ - public void setInputRange(double minimumInput, double maximumInput) { - controller.setInputRange(minimumInput, maximumInput); - } - - /** - * Set the absolute error which is considered tolerable for use with - * OnTarget. The value is in the same range as the PIDInput values. - * @param t A PIDController.Tolerance object instance that is for example - * AbsoluteTolerance or PercentageTolerance. E.g. setTolerance(new PIDController.AbsoluteTolerance(0.1)) - */ - public void setAbsoluteTolerance(double t) { - controller.setAbsoluteTolerance(t); - } - - /** - * Set the percentage error which is considered tolerable for use with - * OnTarget. (Value of 15.0 == 15 percent) - * @param t A PIDController.Tolerance object instance that is for example - * AbsoluteTolerance or PercentageTolerance. E.g. setTolerance(new PIDController.AbsoluteTolerance(0.1)) - */ - public void setPercentTolerance(double p) { - controller.setPercentTolerance(p); - } - - /** - * Return true if the error is within the percentage of the total input range, - * determined by setTolerance. This assumes that the maximum and minimum input - * were set using setInput. - * @return true if the error is less than the tolerance - */ - public boolean onTarget() { - return controller.onTarget(); - } - - /** - * Returns the input for the pid loop. - * - *

It returns the input for the pid loop, so if this Subsystem was based - * off of a gyro, then it should return the angle of the gyro

- * - *

All subclasses of {@link PIDSubsystem} must override this method.

- * - * @return the value the pid loop should use as input - */ - protected abstract double returnPIDInput(); - - /** - * Uses the value that the pid loop calculated. The calculated value is the "output" parameter. - * This method is a good time to set motor values, maybe something along the lines of driveline.tankDrive(output, -output) - * - *

All subclasses of {@link PIDSubsystem} must override this method.

- * - * @param output the value the pid loop calculated - */ - protected abstract void usePIDOutput(double output); - - /** - * Enables the internal {@link PIDController} - */ - public void enable() { - controller.enable(); - } - - /** - * Disables the internal {@link PIDController} - */ - public void disable() { - controller.disable(); - } - - public String getSmartDashboardType() { - return "PIDSubsystem"; - } - public void initTable(ITable table) { - controller.initTable(table); - super.initTable(table); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java deleted file mode 100644 index 2ca0a514a8..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/PrintCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -/** - * A {@link PrintCommand} is a command which prints out a string when it is initialized, and then immediately finishes. - * It is useful if you want a {@link CommandGroup} to print out a string when it reaches a certain point. - * - * @author Joe Grinstead - */ -public class PrintCommand extends Command { - - /** The message to print out */ - private String message; - - /** - * Instantiates a {@link PrintCommand} which will print the given message when it is run. - * @param message the message to print - */ - public PrintCommand(String message) { - super("Print(\"" + message + "\""); - this.message = message; - } - - protected void initialize() { - System.out.println(message); - } - - protected void execute() { - } - - protected boolean isFinished() { - return true; - } - - protected void end() { - } - - protected void interrupted() { - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Set.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Set.java deleted file mode 100644 index 6da9ec7ba2..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Set.java +++ /dev/null @@ -1,42 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -import java.util.Enumeration; -import java.util.Vector; - -/** - * - * @author Greg - */ -class Set { - Vector set = new Vector(); - - public Set() { - } - - public void add(Object o) { - if(set.contains(o)) return; - set.addElement(o); - } - - public void add(Set s) { - Enumeration stuff = s.getElements(); - for(Enumeration e = stuff; e.hasMoreElements();) { - add(e.nextElement()); - } - } - - public boolean contains(Object o) { - return set.contains(o); - } - - public Enumeration getElements() { - return set.elements(); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java deleted file mode 100644 index f00448aba9..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/StartCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -/** - * A {@link StartCommand} will call the {@link Command#start() start()} method of another command when it is initialized - * and will finish immediately. - * - * @author Joe Grinstead - */ -public class StartCommand extends Command { - - /** The command to fork */ - private Command m_commandToFork; - - /** - * Instantiates a {@link StartCommand} which will start the - * given command whenever its {@link Command#initialize() initialize()} is called. - * @param commandToStart the {@link Command} to start - */ - public StartCommand(Command commandToStart) { - super("Start(" + commandToStart + ")"); - m_commandToFork = commandToStart; - } - - protected void initialize() { - m_commandToFork.start(); - } - - protected void execute() { - } - - protected boolean isFinished() { - return true; - } - - protected void end() { - } - - protected void interrupted() { - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java deleted file mode 100644 index c8ba2904b1..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/Subsystem.java +++ /dev/null @@ -1,197 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -import edu.wpi.first.wpilibj.NamedSendable; -import edu.wpi.first.wpilibj.tables.ITable; -import java.util.Enumeration; -import java.util.Vector; - -/** - * This class defines a major component of the robot. - * - *

A good example of a subsystem is the driveline, or a claw if the robot has one.

- * - *

All motors should be a part of a subsystem. For instance, all the wheel motors should be - * a part of some kind of "Driveline" subsystem.

- * - *

Subsystems are used within the command system as requirements for {@link Command}. - * Only one command which requires a subsystem can run at a time. Also, subsystems - * can have default commands which are started if there is no command running which - * requires this subsystem.

- * - * @author Joe Grinstead - * @see Command - */ -public abstract class Subsystem implements NamedSendable { - - /** Whether or not getDefaultCommand() was called */ - private boolean initializedDefaultCommand = false; - /** The current command */ - private Command currentCommand; - private boolean currentCommandChanged; - - /** The default command */ - private Command defaultCommand; - /** The name */ - private String name; - /** List of all subsystems created */ - private static Vector allSubsystems = new Vector(); - - /** - * Creates a subsystem with the given name - * @param name the name of the subsystem - */ - public Subsystem(String name) { - this.name = name; - Scheduler.getInstance().registerSubsystem(this); - } - - /** - * Creates a subsystem. This will set the name to the name of the class. - */ - public Subsystem() { - this.name = getClass().getName().substring(getClass().getName().lastIndexOf('.') + 1); - Scheduler.getInstance().registerSubsystem(this); - currentCommandChanged = true; - } - - /** - * Initialize the default command for a subsystem - * By default subsystems have no default command, but if they do, the default command is set - * with this method. It is called on all Subsystems by CommandBase in the users program after - * all the Subsystems are created. - */ - protected abstract void initDefaultCommand(); - - /** - * Sets the default command. If this is not called or is called with null, - * then there will be no default command for the subsystem. - * - *

WARNING: This should NOT be called in a constructor if the subsystem is a - * singleton.

- * - * @param command the default command (or null if there should be none) - * @throws IllegalUseOfCommandException if the command does not require the subsystem - */ - protected void setDefaultCommand(Command command) { - if (command == null) { - defaultCommand = null; - } else { - boolean found = false; - Enumeration requirements = command.getRequirements(); - while (requirements.hasMoreElements()) { - if (requirements.nextElement().equals(this)) { - found = true; -// } else { -// throw new IllegalUseOfCommandException("A default command cannot require multiple subsystems"); - } - } - if (!found) { - throw new IllegalUseOfCommandException("A default command must require the subsystem"); - } - defaultCommand = command; - } - if (table != null) { - if (defaultCommand != null) { - table.putBoolean("hasDefault", true); - table.putString("default", defaultCommand.getName()); - } else { - table.putBoolean("hasDefault", false); - } - } - } - - /** - * Returns the default command (or null if there is none). - * @return the default command - */ - protected Command getDefaultCommand() { - if (!initializedDefaultCommand) { - initializedDefaultCommand = true; - initDefaultCommand(); - } - return defaultCommand; - } - - /** - * Sets the current command - * @param command the new current command - */ - void setCurrentCommand(Command command) { - currentCommand = command; - currentCommandChanged = true; - } - - /** - * Call this to alert Subsystem that the current command is actually the command. - * Sometimes, the {@link Subsystem} is told that it has no command while the {@link Scheduler} - * is going through the loop, only to be soon after given a new one. This will avoid that situation. - */ - void confirmCommand() { - if (currentCommandChanged) { - if (table != null) { - if (currentCommand != null) { - table.putBoolean("hasCommand", true); - table.putString("command", currentCommand.getName()); - } else { - table.putBoolean("hasCommand", false); - } - } - currentCommandChanged = false; - } - } - - /** - * Returns the command which currently claims this subsystem. - * @return the command which currently claims this subsystem - */ - public Command getCurrentCommand() { - return currentCommand; - } - - public String toString() { - return getName(); - } - - /** - * Returns the name of this subsystem, which is by default the class name. - * @return the name of this subsystem - */ - public String getName() { - return name; - } - - public String getSmartDashboardType() { - return "Subsystem"; - } - private ITable table; - public void initTable(ITable table) { - this.table = table; - if(table!=null) { - if (defaultCommand != null) { - table.putBoolean("hasDefault", true); - table.putString("default", defaultCommand.getName()); - } else { - table.putBoolean("hasDefault", false); - } - if (currentCommand != null) { - table.putBoolean("hasCommand", true); - table.putString("command", currentCommand.getName()); - } else { - table.putBoolean("hasCommand", false); - } - } - } - /** - * {@inheritDoc} - */ - public ITable getTable() { - return table; - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/WaitCommand.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/WaitCommand.java deleted file mode 100644 index eaf6f19e79..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/WaitCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -/** - * A {@link WaitCommand} will wait for a certain amount of time before finishing. - * It is useful if you want a {@link CommandGroup} to pause for a moment. - * @author Joe Grinstead - * @see CommandGroup - */ -public class WaitCommand extends Command { - - /** - * Instantiates a {@link WaitCommand} with the given timeout. - * @param timeout the time the command takes to run - */ - public WaitCommand(double timeout) { - this("Wait(" + timeout + ")", timeout); - } - - /** - * Instantiates a {@link WaitCommand} with the given timeout. - * @param name the name of the command - * @param timeout the time the command takes to run - */ - public WaitCommand(String name, double timeout) { - super(name, timeout); - } - - protected void initialize() { - } - - protected void execute() { - } - - protected boolean isFinished() { - return isTimedOut(); - } - - protected void end() { - } - - protected void interrupted() { - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java deleted file mode 100644 index 6972a989ca..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/command/WaitForChildren.java +++ /dev/null @@ -1,36 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.command; - -/** - * This command will only finish if whatever {@link CommandGroup} it is in has no active children. - * If it is not a part of a {@link CommandGroup}, then it will finish immediately. If it is itself an - * active child, then the {@link CommandGroup} will never end. - * - *

This class is useful for the situation where you want to allow anything running in parallel to finish, before continuing - * in the main {@link CommandGroup} sequence.

- * @author Joe Grinstead - */ -public class WaitForChildren extends Command { - - protected void initialize() { - } - - protected void execute() { - } - - protected void end() { - } - - protected void interrupted() { - } - - protected boolean isFinished() { - return getGroup() == null || getGroup().m_children.isEmpty(); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/interfaces/Potentiometer.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/interfaces/Potentiometer.java deleted file mode 100644 index b0109a317d..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/interfaces/Potentiometer.java +++ /dev/null @@ -1,17 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ -package edu.wpi.first.wpilibj.interfaces; - -import edu.wpi.first.wpilibj.PIDSource; - -/** - * - * @author alex - */ -public interface Potentiometer extends PIDSource { - double get(); -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Timer.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/internal/SimTimer.java similarity index 50% rename from wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Timer.java rename to wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/internal/SimTimer.java index c6138e751c..c7d0afdfe0 100644 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/Timer.java +++ b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/internal/SimTimer.java @@ -5,11 +5,12 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -package edu.wpi.first.wpilibj; +package edu.wpi.first.wpilibj.internal; import org.gazebosim.transport.Msgs; import org.gazebosim.transport.SubscriberCallback; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.parsing.IUtility; import edu.wpi.first.wpilibj.simulation.MainNode; import gazebo.msgs.GzFloat64.Float64; @@ -21,7 +22,7 @@ import gazebo.msgs.GzFloat64.Float64; * value. The implementation simply records the time when started and subtracts the current time * whenever the value is requested. */ -public class Timer implements IUtility { +public class SimTimer implements IUtility, Timer.StaticInterface { private long m_startTime; private double m_accumulatedTime; @@ -49,7 +50,7 @@ public class Timer implements IUtility { * * @param seconds Length of time to pause */ - public static void delay(final double seconds) { + public void delay(final double seconds) { final double start = simTime; while ((simTime - start) < seconds) { @@ -63,90 +64,91 @@ public class Timer implements IUtility { } } - /** - * Return the system clock time in microseconds. Return the time from the - * FPGA hardware clock in microseconds since the FPGA started. - * - * @deprecated Use getFPGATimestamp instead. - * @return Robot running time in microseconds. - */ - public static long getUsClock() { - return (long) (simTime * 1e6); - } - - /** - * Return the system clock time in milliseconds. Return the time from the - * FPGA hardware clock in milliseconds since the FPGA started. - * - * @deprecated Use getFPGATimestamp instead. - * @return Robot running time in milliseconds. - */ - static long getMsClock() { - return (long) (simTime * 1e3); - } - /** * Return the system clock time in seconds. Return the time from the * FPGA hardware clock in seconds since the FPGA started. * * @return Robot running time in seconds. */ - public static double getFPGATimestamp() { + public double getFPGATimestamp() { return simTime; } - /** - * Create a new timer object. - * Create a new timer object and reset the time to zero. The timer is initially not running and - * must be started. - */ - public Timer() { - reset(); - } + @Override + public double getMatchTime() { + return simTime; + } - /** - * Get the current time from the timer. If the clock is running it is derived from - * the current system clock the start time stored in the timer class. If the clock - * is not running, then return the time when it was last stopped. - * - * @return Current time value for this timer in seconds - */ - public synchronized double get() { - if (m_running) { - return ((double) ((getMsClock() - m_startTime) + m_accumulatedTime)) / 1000.0; - } else { - return m_accumulatedTime; - } - } + @Override + public Timer.Interface newTimer() { + return new TimerImpl(); + } - /** - * Reset the timer by setting the time to 0. - * Make the timer startTime the current time so new requests will be relative now - */ - public synchronized void reset() { - m_accumulatedTime = 0; - m_startTime = getMsClock(); - } + class TimerImpl implements Timer.Interface { + /** + * Create a new timer object. + * Create a new timer object and reset the time to zero. The timer is initially not running and + * must be started. + */ + public TimerImpl() { + reset(); + } - /** - * Start the timer running. - * Just set the running flag to true indicating that all time requests should be - * relative to the system clock. - */ - public synchronized void start() { - m_startTime = getMsClock(); - m_running = true; - } - - /** - * Stop the timer. - * This computes the time as of now and clears the running flag, causing all - * subsequent time requests to be read from the accumulated time rather than - * looking at the system clock. - */ - public synchronized void stop() { - final double temp = get(); - m_accumulatedTime = temp; - m_running = false; + /** + * Return the system clock time in milliseconds. Return the time from the + * FPGA hardware clock in milliseconds since the FPGA started. + * + * @deprecated Use getFPGATimestamp instead. + * @return Robot running time in milliseconds. + */ + private long getMsClock() { + return (long) (simTime * 1e3); + } + + /** + * Get the current time from the timer. If the clock is running it is derived from + * the current system clock the start time stored in the timer class. If the clock + * is not running, then return the time when it was last stopped. + * + * @return Current time value for this timer in seconds + */ + public synchronized double get() { + if (m_running) { + return ((double) ((getMsClock() - m_startTime) + m_accumulatedTime)) / 1000.0; + } else { + return m_accumulatedTime; + } + } + + /** + * Reset the timer by setting the time to 0. + * Make the timer startTime the current time so new requests will be relative now + */ + public synchronized void reset() { + m_accumulatedTime = 0; + m_startTime = getMsClock(); + } + + /** + * Start the timer running. + * Just set the running flag to true indicating that all time requests should be + * relative to the system clock. + */ + public synchronized void start() { + m_startTime = getMsClock(); + m_running = true; + } + + /** + * Stop the timer. + * This computes the time as of now and clears the running flag, causing all + * subsequent time requests to be read from the accumulated time rather than + * looking at the system clock. + */ + public synchronized void stop() { + final double temp = get(); + m_accumulatedTime = temp; + m_running = false; + } } } diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java deleted file mode 100644 index 90ed3a8a14..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindow.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package edu.wpi.first.wpilibj.livewindow; - -import edu.wpi.first.wpilibj.command.Scheduler; -import edu.wpi.first.wpilibj.networktables.NetworkTable; -import edu.wpi.first.wpilibj.tables.ITable; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -/** - * A LiveWindow component is a device (sensor or actuator) that should be added to the - * SmartDashboard in test mode. The components are cached until the first time the robot - * enters Test mode. This allows the components to be inserted, then renamed. - * @author brad - */ -class LiveWindowComponent { - - String m_subsystem; - String m_name; - boolean m_isSensor; - - public LiveWindowComponent(String subsystem, String name, boolean isSensor) { - m_subsystem = subsystem; - m_name = name; - m_isSensor = isSensor; - } - - public String getName() { - return m_name; - } - - public String getSubsystem() { - return m_subsystem; - } - - public boolean isSensor() { - return m_isSensor; - } -} - -/** - * The LiveWindow class is the public interface for putting sensors and - * actuators on the LiveWindow. - * - * @author Alex Henning - */ -public class LiveWindow { - - private static Vector sensors = new Vector(); -// private static Vector actuators = new Vector(); - private static Hashtable components = new Hashtable(); - private static ITable livewindowTable = NetworkTable.getTable("LiveWindow"); - private static ITable statusTable = livewindowTable.getSubTable("~STATUS~"); - private static boolean liveWindowEnabled = false; - private static boolean firstTime = true; - - /** - * Initialize all the LiveWindow elements the first time we enter LiveWindow - * mode. By holding off creating the NetworkTable entries, it allows them to - * be redefined before the first time in LiveWindow mode. This allows - * default sensor and actuator values to be created that are replaced with - * the custom names from users calling addActuator and addSensor. - */ - private static void initializeLiveWindowComponents() { - System.out.println("Initializing the components first time"); - for (Enumeration e = components.keys(); e.hasMoreElements();) { - LiveWindowSendable component = (LiveWindowSendable) e.nextElement(); - LiveWindowComponent c = (LiveWindowComponent) components.get(component); - String subsystem = c.getSubsystem(); - String name = c.getName(); - System.out.println("Initializing table for '" + subsystem + "' '" + name + "'"); - livewindowTable.getSubTable(subsystem).putString("~TYPE~", "LW Subsystem"); - ITable table = livewindowTable.getSubTable(subsystem).getSubTable(name); - table.putString("~TYPE~", component.getSmartDashboardType()); - table.putString("Name", name); - table.putString("Subsystem", subsystem); - component.initTable(table); - if (c.isSensor()) { - sensors.addElement(component); - } - } - } - - /** - * Set the enabled state of LiveWindow. If it's being enabled, turn off the - * scheduler and remove all the commands from the queue and enable all the - * components registered for LiveWindow. If it's being disabled, stop all - * the registered components and reenable the scheduler. TODO: add code to - * disable PID loops when enabling LiveWindow. The commands should reenable - * the PID loops themselves when they get rescheduled. This prevents arms - * from starting to move around, etc. after a period of adjusting them in - * LiveWindow mode. - */ - public static void setEnabled(boolean enabled) { - if (liveWindowEnabled != enabled) { - if (enabled) { - System.out.println("Starting live window mode."); - if (firstTime) { - initializeLiveWindowComponents(); - firstTime = false; - } - Scheduler.getInstance().disable(); - Scheduler.getInstance().removeAll(); - for (Enumeration e = components.keys(); e.hasMoreElements();) { - LiveWindowSendable component = (LiveWindowSendable) e.nextElement(); - component.startLiveWindowMode(); - } - } else { - System.out.println("stopping live window mode."); - for (Enumeration e = components.keys(); e.hasMoreElements();) { - LiveWindowSendable component = (LiveWindowSendable) e.nextElement(); - component.stopLiveWindowMode(); - } - Scheduler.getInstance().enable(); - } - liveWindowEnabled = enabled; - statusTable.putBoolean("LW Enabled", enabled); - } - } - - /** - * The run method is called repeatedly to keep the values refreshed on the screen in - * test mode. - */ - public static void run() { - updateValues(); - } - - /** - * Add a Sensor associated with the subsystem and with call it by the given - * name. - * - * @param subsystem The subsystem this component is part of. - * @param name The name of this component. - * @param component A LiveWindowSendable component that represents a sensor. - */ - public static void addSensor(String subsystem, String name, LiveWindowSendable component) { - components.put(component, new LiveWindowComponent(subsystem, name, true)); - } - - /** - * Add an Actuator associated with the subsystem and with call it by the - * given name. - * - * @param subsystem The subsystem this component is part of. - * @param name The name of this component. - * @param component A LiveWindowSendable component that represents a - * actuator. - */ - public static void addActuator(String subsystem, String name, LiveWindowSendable component) { - components.put(component, new LiveWindowComponent(subsystem, name, false)); - } - - /** - * Puts all sensor values on the live window. - */ - private static void updateValues() { - //TODO: gross - needs to be sped up - for (int i = 0; i < sensors.size(); i++) { - LiveWindowSendable lws = (LiveWindowSendable) sensors.elementAt(i); - lws.updateTable(); - } - // TODO: Add actuators? - // TODO: Add better rate limiting. - } - - /** - * Add Sensor to LiveWindow. The components are shown with the type and - * channel like this: Gyro[1] for a gyro object connected to the first - * analog channel. - * - * @param moduleType A string indicating the type of the module used in the - * naming (above) - * @param channel The channel number the device is connected to - * @param component A reference to the object being added - */ - public static void addSensor(String moduleType, int channel, LiveWindowSendable component) { - addSensor("Ungrouped", moduleType + "[" + channel + "]", component); - if (sensors.contains(component)) { - sensors.removeElement(component); - } - sensors.addElement(component); - } - - /** - * Add Actuator to LiveWindow. The components are shown with the module - * type, slot and channel like this: Servo[1,2] for a servo object connected - * to the first digital module and PWM port 2. - * - * @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 (usually - * PWM) - * @param component The reference to the object being added - */ - public static void addActuator(String moduleType, int channel, LiveWindowSendable component) { - addActuator("Ungrouped", moduleType + "[" + channel + "]", component); - } - - /** - * Add Actuator to LiveWindow. The components are shown with the module - * type, slot and channel like this: Servo[1,2] for a servo object connected - * to the first digital module and PWM port 2. - * - * @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) - * @param component The reference to the object being added - */ - public static void addActuator(String moduleType, int moduleNumber, int channel, LiveWindowSendable component) { - addActuator("Ungrouped", moduleType + "[" + moduleNumber + "," + channel + "]", component); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindowSendable.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindowSendable.java deleted file mode 100644 index 34aa7737ea..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/livewindow/LiveWindowSendable.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package edu.wpi.first.wpilibj.livewindow; - -import edu.wpi.first.wpilibj.Sendable; - -/** - * Live Window Sendable is a special type of object sendable to the live window. - * - * @author Alex Henning - */ -public interface LiveWindowSendable extends Sendable { - /** - * Update the table for this sendable object with the latest - * values. - */ - public void updateTable(); - - /** - * Start having this sendable object automatically respond to - * value changes reflect the value on the table. - */ - public void startLiveWindowMode(); - - /** - * Stop having this sendable object automatically respond to value - * changes. - */ - public void stopLiveWindowMode(); -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IDevice.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IDevice.java deleted file mode 100644 index 706f012c8e..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IDevice.java +++ /dev/null @@ -1,15 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.parsing; - -/** - * An IDevice is any WPILibJ object which can be used in the creation of the - * robot program - * @author Ryan O'Meara - */ -public interface IDevice {} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IDeviceController.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IDeviceController.java deleted file mode 100644 index 8dfd061c1a..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IDeviceController.java +++ /dev/null @@ -1,15 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.parsing; - -/** - * IDeviceController is implemented by control elements in the robot. An - * example of this would be a victor - * @author Ryan O'Meara - */ -public interface IDeviceController extends IDevice {} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IInputOutput.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IInputOutput.java deleted file mode 100644 index 49801a9adc..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IInputOutput.java +++ /dev/null @@ -1,16 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.parsing; - -/** - * IInputOutput is implemented by devices which provide the robot with data and - * allow it to react to its environment. An example of an input/output would be - * a joystick - * @author Ryan O'Meara - */ -public interface IInputOutput extends IDevice {} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IMechanism.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IMechanism.java deleted file mode 100644 index a9411d018b..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IMechanism.java +++ /dev/null @@ -1,17 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.parsing; - -/** - * The IMechanism interface is implemented by any class to be classified as a - * mechanism. These are user-defined, and contain other devices (which implement - * IDevice). They are generally over-arching systems, such as the drive train or - * arm - * @author Ryan O'Meara - */ -public interface IMechanism {} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/ISensor.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/ISensor.java deleted file mode 100644 index 0991fd3b20..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/ISensor.java +++ /dev/null @@ -1,17 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.parsing; - -/** - * ISensor is extended by any WPILibJ class to be categorized as a sensor in the - * java program builder. A sensor is a robot part that provides the robot with - * information about its environment. An example of this is the Ultrasonic - * sensor class - * @author Ryan O'Meara - */ -public interface ISensor extends IDevice {} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IUtility.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IUtility.java deleted file mode 100644 index e7567fd6da..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/parsing/IUtility.java +++ /dev/null @@ -1,17 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.parsing; - -/** - * IUtility is an interface implemented by any WPILibJ class which should appear - * in the utility tree of the java program builder. A utility is generally a - * class which is not a specific device, but more of a software tool. An - * example of this would be the Timer class - * @author Ryan O'Meara - */ -public interface IUtility extends IDevice {} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java deleted file mode 100644 index f2d97ee97a..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java +++ /dev/null @@ -1,146 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ -package edu.wpi.first.wpilibj.smartdashboard; - -import edu.wpi.first.wpilibj.Sendable; -import edu.wpi.first.wpilibj.command.Command; -import edu.wpi.first.wpilibj.networktables2.type.StringArray; -import edu.wpi.first.wpilibj.networktables2.util.List; -import edu.wpi.first.wpilibj.tables.ITable; - -/** - * The {@link SendableChooser} class is a useful tool for presenting a selection - * of options to the {@link SmartDashboard}. - * - *

For instance, you may wish to be able to select between multiple - * autonomous modes. You can do this by putting every possible {@link Command} - * you want to run as an autonomous into a {@link SendableChooser} and then put - * it into the {@link SmartDashboard} to have a list of options appear on the - * laptop. Once autonomous starts, simply ask the {@link SendableChooser} what - * the selected value is.

- * - * @author Joe Grinstead - */ -public class SendableChooser implements Sendable { - - /** - * The key for the default value - */ - private static final String DEFAULT = "default"; - /** - * The key for the selected option - */ - private static final String SELECTED = "selected"; - /** - * The key for the option array - */ - private static final String OPTIONS = "options"; - /** - * A table linking strings to the objects the represent - */ - private StringArray choices = new StringArray(); - private List values = new List(); - private String defaultChoice = null; - private Object defaultValue = null; - - /** - * Instantiates a {@link SendableChooser}. - */ - public SendableChooser() { - } - - /** - * Adds the given object to the list of options. On the - * {@link SmartDashboard} on the desktop, the object will appear as the - * given name. - * - * @param name the name of the option - * @param object the option - */ - public void addObject(String name, Object object) { - //if we don't have a default, set the default automatically - if (defaultChoice == null) { - addDefault(name, object); - return; - } - for (int i = 0; i < choices.size(); ++i) { - if (choices.get(i).equals(name)) { - choices.set(i, name); - values.set(i, object); - return; - } - } - //not found - choices.add(name); - values.add(object); - if (table != null) { - table.putValue(OPTIONS, choices); - } - } - - /** - * Add the given object to the list of options and marks it as the default. - * Functionally, this is very close to - * {@link SendableChooser#addObject(java.lang.String, java.lang.Object) addObject(...)} - * except that it will use this as the default option if none other is - * explicitly selected. - * - * @param name the name of the option - * @param object the option - */ - public void addDefault(String name, Object object) { - if (name == null) { - throw new NullPointerException("Name cannot be null"); - } - defaultChoice = name; - defaultValue = object; - if (table != null) { - table.putString(DEFAULT, defaultChoice); - } - addObject(name, object); - } - - /** - * Returns the selected option. If there is none selected, it will return - * the default. If there is none selected and no default, then it will - * return {@code null}. - * - * @return the option selected - */ - public Object getSelected() { - String selected = table.getString(SELECTED, null); - for (int i = 0; i < values.size(); ++i) { - if (choices.get(i).equals(selected)) { - return values.get(i); - } - } - return defaultValue; - - } - - public String getSmartDashboardType() { - return "String Chooser"; - } - private ITable table; - - public void initTable(ITable table) { - this.table = table; - if (table != null) { - table.putValue(OPTIONS, choices); - if (defaultChoice != null) { - table.putString(DEFAULT, defaultChoice); - } - } - } - - /** - * {@inheritDoc} - */ - public ITable getTable() { - return table; - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java deleted file mode 100644 index 23adfeaad6..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java +++ /dev/null @@ -1,297 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.smartdashboard; - -import edu.wpi.first.wpilibj.NamedSendable; -import edu.wpi.first.wpilibj.Sendable; -import edu.wpi.first.wpilibj.networktables.NetworkTable; -import edu.wpi.first.wpilibj.networktables.NetworkTableKeyNotDefined; -import edu.wpi.first.wpilibj.tables.ITable; -import edu.wpi.first.wpilibj.tables.TableKeyNotDefinedException; -import java.util.Hashtable; -import java.util.NoSuchElementException; - -/** - * The {@link SmartDashboard} class is the bridge between robot programs and the SmartDashboard on the - * laptop. - * - *

When a value is put into the SmartDashboard here, it pops up on the SmartDashboard on the laptop. - * Users can put values into and get values from the SmartDashboard

- * - * @author Joe Grinstead - */ -public class SmartDashboard { - //TODO usage reporting - /** The {@link NetworkTable} used by {@link SmartDashboard} */ - private static final NetworkTable table = NetworkTable.getTable("SmartDashboard"); - /** - * A table linking tables in the SmartDashboard to the {@link SmartDashboardData} objects - * they came from. - */ - private static final Hashtable tablesToData = new Hashtable(); - - /** - * 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 data the value - * @throws IllegalArgumentException if key is null - */ - public static void putData(String key, Sendable data) { - ITable dataTable = table.getSubTable(key); - dataTable.putString("~TYPE~", data.getSmartDashboardType()); - data.initTable(dataTable); - tablesToData.put(data, key); - } - - - //TODO should we reimplement NamedSendable? - /** - * Maps the specified key (where the key is the name of the {@link SmartDashboardNamedData} - * to the specified value in this table. - * The value can be retrieved by calling the get method with a key that is equal to the original key. - * @param value the value - * @throws IllegalArgumentException if key is null - */ - public static void putData(NamedSendable value) { - putData(value.getName(), value); - } - - /** - * Returns the value at the specified key. - * @param key the key - * @return the value - * @throws NetworkTableKeyNotDefined if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not a {@link SmartDashboardData} - * @throws IllegalArgumentException if the key is null - */ -//TODO public static SmartDashboardData getData(String key) { -// NetworkTable subtable = table.getSubTable(key); -// Object data = tablesToData.get(subtable); -// if (data == null) { -// throw new IllegalArgumentException("Value at \"" + key + "\" is not a boolean"); -// } else { -// return (SmartDashboardData) data; -// } -// } - - /** - * 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 - * @throws IllegalArgumentException if key is null - */ - public static void putBoolean(String key, boolean value) { - table.putBoolean(key, value); - } - - /** - * Returns the value at the specified key. - * @param key the key - * @return the value - * @throws NetworkTableKeyNotDefined if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not a boolean - * @throws IllegalArgumentException if the key is null - */ - public static boolean getBoolean(String key) throws TableKeyNotDefinedException { - return table.getBoolean(key); - } - - /** - * Returns the value at the specified key. - * @param key the key - * @param defaultValue returned if the key doesn't exist - * @return the value - * @throws IllegalArgumentException if the value mapped to by the key is not a boolean - * @throws IllegalArgumentException if the key is null - */ - public static boolean getBoolean(String key, boolean defaultValue) { - return table.getBoolean(key, defaultValue); - } - - /** - * 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 - * @throws IllegalArgumentException if key is null - */ - public static void putNumber(String key, double value) { - table.putNumber(key, value); - } - - /** - * Returns the value at the specified key. - * @param key the key - * @return the value - * @throws TableKeyNotDefinedException if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not a double - * @throws IllegalArgumentException if the key is null - */ - public static double getNumber(String key) throws TableKeyNotDefinedException { - return table.getNumber(key); - } - - /** - * 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 NoSuchEleNetworkTableKeyNotDefinedmentException if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not a double - * @throws IllegalArgumentException if the key is null - */ - public static double getNumber(String key, double defaultValue) { - return table.getNumber(key, defaultValue); - } - - /** - * Maps the specified key to the specified value in this table. - * Neither the key nor the value can 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 - * @throws IllegalArgumentException if key or value is null - */ - public static void putString(String key, String value) { - table.putString(key, value); - } - - /** - * Returns the value at the specified key. - * @param key the key - * @return the value - * @throws NetworkTableKeyNotDefined if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not a string - * @throws IllegalArgumentException if the key is null - */ - public static String getString(String key) throws TableKeyNotDefinedException { - return table.getString(key); - } - - /** - * 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 NetworkTableKeyNotDefined if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not a string - * @throws IllegalArgumentException if the key is null - */ - public static String getString(String key, String defaultValue) { - return table.getString(key, defaultValue); - } - - - - - - - - - - /* - * 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. - * - * @deprecated Use {@link #putNumber(java.lang.String, double) putNumber method} instead - * @param key the key - * @param value the value - * @throws IllegalArgumentException if key is null - */ - public static void putInt(String key, int value) { - table.putNumber(key, value); - } - - /** - * Returns the value at the specified key. - * - * @deprecated Use {@link #getNumber(java.lang.String) getNumber} instead - * @param key the key - * @return the value - * @throws TableKeyNotDefinedException if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not an int - * @throws IllegalArgumentException if the key is null - */ - public static int getInt(String key) throws TableKeyNotDefinedException { - return (int) table.getNumber(key); - } - - /** - * Returns the value at the specified key. - * - * @deprecated Use {@link #getNumber(java.lang.String, double) getNumber} instead - * @param key the key - * @param defaultValue the value returned if the key is undefined - * @return the value - * @throws NetworkTableKeyNotDefined if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not an int - * @throws IllegalArgumentException if the key is null - */ - public static int getInt(String key, int defaultValue) throws TableKeyNotDefinedException { - try { - return (int) table.getNumber(key); - } catch (NoSuchElementException ex) { - return defaultValue; - } - } - - /** - * 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. - * - * @deprecated Use{@link #putNumber(java.lang.String, double) putNumber} instead - * @param key the key - * @param value the value - * @throws IllegalArgumentException if key is null - */ - public static void putDouble(String key, double value) { - table.putNumber(key, value); - } - - /** - * Returns the value at the specified key. - * - * @deprecated Use {@link #getNumber(java.lang.String) getNumber} instead - * @param key the key - * @return the value - * @throws NoSuchEleNetworkTableKeyNotDefinedmentException if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not a double - * @throws IllegalArgumentException if the key is null - */ - public static double getDouble(String key) throws TableKeyNotDefinedException { - return table.getNumber(key); - } - - /** - * Returns the value at the specified key. - * - * @deprecated Use {@link #getNumber(java.lang.String, double) getNumber} instead. - * @param key the key - * @param defaultValue the value returned if the key is undefined - * @return the value - * @throws NoSuchEleNetworkTableKeyNotDefinedmentException if there is no value mapped to by the key - * @throws IllegalArgumentException if the value mapped to by the key is not a double - * @throws IllegalArgumentException if the key is null - */ - public static double getDouble(String key, double defaultValue) { - return table.getNumber(key, defaultValue); - } - -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/AllocationException.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/AllocationException.java deleted file mode 100644 index 15d04f464c..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/AllocationException.java +++ /dev/null @@ -1,23 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.util; - -/** - * Exception indicating that the resource is already allocated - * @author dtjones - */ -public class AllocationException extends RuntimeException { - - /** - * Create a new AllocationException - * @param msg the message to attach to the exception - */ - public AllocationException(String msg) { - super(msg); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/BoundaryException.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/BoundaryException.java deleted file mode 100644 index 676687eb58..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/BoundaryException.java +++ /dev/null @@ -1,62 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.util; - -/** - * This exception represents an error in which a lower limit was set as higher - * than an upper limit. - * - * @author dtjones - */ -public class BoundaryException extends RuntimeException { - - /** - * Create a new exception with the given message - * - * @param message - * the message to attach to the exception - */ - public BoundaryException(String message) { - super(message); - } - - /** - * Make sure that the given value is between the upper and lower bounds, and - * throw an exception if they are not. - * - * @param value - * The value to check. - * @param lower - * The minimum acceptable value. - * @param upper - * The maximum acceptable value. - */ - public static void assertWithinBounds(double value, double lower, - double upper) { - if (value < lower || value > upper) - throw new BoundaryException("Value must be between " + lower - + " and " + upper + ", " + value + " given"); - } - - /** - * Returns the message for a boundary exception. Used to keep the message - * consistent across all boundary exceptions. - * - * @param value - * The given value - * @param lower - * The lower limit - * @param upper - * The upper limit - * @return - */ - public static String getMessage(double value, double lower, double upper) { - return "Value must be between " + lower + " and " + upper + ", " - + value + " given"; - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/CheckedAllocationException.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/CheckedAllocationException.java deleted file mode 100644 index 763752666a..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/CheckedAllocationException.java +++ /dev/null @@ -1,24 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.util; - -/** - * Exception indicating that the resource is already allocated - * This is meant to be thrown by the resource class - * @author dtjones - */ -public class CheckedAllocationException extends Exception { - - /** - * Create a new CheckedAllocationException - * @param msg the message to attach to the exception - */ - public CheckedAllocationException(String msg) { - super(msg); - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java deleted file mode 100644 index a3ae959d9d..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java +++ /dev/null @@ -1,75 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ -package edu.wpi.first.wpilibj.util; - -import java.util.Vector; - -/** - * - * @author dtjones - */ -public class SortedVector extends Vector { - - /** - * Interface used to determine the order to place sorted objects. - */ - public static interface Comparator { - - /** - * Compare the given two objects. - * @param object1 First object to compare - * @param object2 Second object to compare - * @return -1, 0, or 1 if the first object is less than, equal to, or - * greater than the second, respectively - */ - public int compare(Object object1, Object object2); - } - Comparator comparator; - - /** - * Create a new sorted vector and use the given comparator to determine order. - * @param comparator The comparator to use to determine what order to place - * the elements in this vector. - */ - public SortedVector(Comparator comparator) { - this.comparator = comparator; - } - - /** - * Adds an element in the Vector, sorted from greatest to least. - * @param element The element to add to the Vector - */ - public void addElement(Object element) { - int highBound = size(); - int lowBound = 0; - while (highBound - lowBound > 0) { - int index = (highBound + lowBound) / 2; - int result = comparator.compare(element, elementAt(index)); - if (result < 0) { - lowBound = index + 1; - } else if (result > 0) { - highBound = index; - } else { - lowBound = index; - highBound = index; - } - } - insertElementAt(element, lowBound); - } - - /** - * Sort the vector. - */ - public void sort() { - Object[] array = new Object[size()]; - copyInto(array); - removeAllElements(); - for (int i = 0; i < array.length; i++) { - addElement(array[i]); - } - } -} diff --git a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/UncleanStatusException.java b/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/UncleanStatusException.java deleted file mode 100644 index 41313f5547..0000000000 --- a/wpilibj/wpilibJavaSim/src/main/java/edu/wpi/first/wpilibj/util/UncleanStatusException.java +++ /dev/null @@ -1,58 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.util; - -/** - * Exception for bad status codes from the chip object - * @author Brian - */ -public final class UncleanStatusException extends IllegalStateException { - - private final int statusCode; - - /** - * Create a new UncleanStatusException - * @param status the status code that caused the exception - * @param message A message describing the exception - */ - public UncleanStatusException(int status, String message) { - super(message); - statusCode = status; - } - - /** - * Create a new UncleanStatusException - * @param status the status code that caused the exception - */ - public UncleanStatusException(int status) { - this(status, "Status code was non-zero"); - } - - /** - * Create a new UncleanStatusException - * @param message a message describing the exception - */ - public UncleanStatusException(String message) { - this(-1, message); - } - - /** - * Create a new UncleanStatusException - */ - public UncleanStatusException() { - this(-1, "Status code was non-zero"); - } - - /** - * Create a new UncleanStatusException - * @return the status code that caused the exception - */ - public int getStatus() { - return statusCode; - } -}