From 1cec28f05d2231a6fcda50d0d2a1fbf990f390cd Mon Sep 17 00:00:00 2001 From: LoadingPleaseWait Date: Sun, 20 Mar 2016 23:31:24 -0500 Subject: [PATCH] Improve accuracy of simulated Victor SPs --- .../FRCNetworkCommunicationsLibrary.java | 41 ++++++++++++++++++- .../edu/wpi/first/wpilibj/hal/PWMJNI.java | 14 ++++++- .../loader/simulation/SimulationData.java | 5 +++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/patches/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java b/patches/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java index 0c18ad1..fea362a 100644 --- a/patches/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java +++ b/patches/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java @@ -10,13 +10,20 @@ import java.nio.IntBuffer; import java.nio.ShortBuffer; +/** + * JNI Wrapper for library FRC_NetworkCommunications
+ */ public class FRCNetworkCommunicationsLibrary extends JNIWrapper { + + /** Module type from LoadOut.h */ public static interface tModuleType { public static final int kModuleType_Unknown = 0x00; public static final int kModuleType_Analog = 0x01; public static final int kModuleType_Digital = 0x02; public static final int kModuleType_Solenoid = 0x03; }; + + /** Target class from LoadOut.h */ public static interface tTargetClass { public static final int kTargetClass_Unknown = 0x00; public static final int kTargetClass_FRC1 = 0x10; @@ -27,6 +34,8 @@ public static interface tTargetClass { public static final int kTargetClass_FamilyMask = 0xF0; public static final int kTargetClass_ModuleMask = 0x0F; }; + + /** Resource types from UsageReporting.h */ public static interface tResourceType { public static final int kResourceType_Controller = 0; public static final int kResourceType_Module = 1; @@ -77,7 +86,18 @@ public static interface tResourceType { public static final int kResourceType_HiTechnicAccel = 46; public static final int kResourceType_HiTechnicCompass = 47; public static final int kResourceType_SRF08 = 48; + public static final int kResourceType_AnalogOutput = 49; + public static final int kResourceType_VictorSP = 50; + public static final int kResourceType_TalonSRX = 51; + public static final int kResourceType_CANTalonSRX = 52; + public static final int kResourceType_ADXL362 = 53; + public static final int kResourceType_ADXRS450 = 54; + public static final int kResourceType_RevSPARK = 55; + public static final int kResourceType_MindsensorsSD540 = 56; + public static final int kResourceType_DigitalFilter = 57; }; + + /** Instances from UsageReporting.h */ public static interface tInstances { public static final int kLanguage_LabVIEW = 1; public static final int kLanguage_CPlusPlus = 2; @@ -112,6 +132,7 @@ public static interface tInstances { public static final int kCommand_Scheduler = 1; public static final int kSmartDashboard_Instance = 1; }; + public static final int kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input = 17; public static final int kFRC_NetworkCommunication_DynamicType_Kinect_Vertices1 = 21; public static final int SYS_STATUS_DATA_SIZE = 44; @@ -134,8 +155,26 @@ public static int report(int resource, byte instanceNumber, byte context, String public static void setNewDataSem(long mutexId) {} + /** + * Report the usage of a resource of interest.
+ * + *
+ *$ + * @param resource one of the values in the tResourceType above (max value + * 51).
+ * @param instanceNumber an index that identifies the resource instance.
+ * @param context an optional additional context number for some cases (such + * as module number). Set to 0 to omit.
+ * @param feature a string to be included describing features in use on a + * specific resource. Setting the same resource more than once allows + * you to change the feature string.
+ * Original signature : + * uint32_t report(tResourceType, uint8_t, uint8_t, const char*) + */ public static int FRCNetworkCommunicationUsageReportingReport(byte resource, byte instanceNumber, byte context, String feature) { - //TODO: Report + // keep track of what motor controllers are initialized where + if (resource == tResourceType.kResourceType_VictorSP) + SimulationData.motorControllers[instanceNumber] = resource; return 0; } diff --git a/patches/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java b/patches/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java index 0a89cd6..96560ee 100644 --- a/patches/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java +++ b/patches/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java @@ -1,5 +1,6 @@ package edu.wpi.first.wpilibj.hal; +import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary; import jaci.openrio.toast.core.loader.simulation.SimulationData; public class PWMJNI extends DIOJNI { @@ -13,7 +14,18 @@ public static void freePWMChannel(long digital_port_pointer) { public static void setPWM(long digital_port_pointer, short value) { byte port = (byte)digital_port_pointer; - SimulationData.setPWM(port, (double) (value - 1012) / 255); + double output = (double) (value - 1012) / 255; + // let's figure out what motor controller is being used + switch (SimulationData.motorControllers[port]){ + case FRCNetworkCommunicationsLibrary.tResourceType.kResourceType_VictorSP: + if (output > 0.6) + output += 0.01; + else if (output < -0.8) + output -= 0.01; + output += 0.05; + break; + } + SimulationData.setPWM(port, output); } public static short getPWM(long digital_port_pointer) { diff --git a/src/main/java/jaci/openrio/toast/core/loader/simulation/SimulationData.java b/src/main/java/jaci/openrio/toast/core/loader/simulation/SimulationData.java index 527a7d6..24a4cb0 100644 --- a/src/main/java/jaci/openrio/toast/core/loader/simulation/SimulationData.java +++ b/src/main/java/jaci/openrio/toast/core/loader/simulation/SimulationData.java @@ -64,6 +64,11 @@ public static void setPWM(byte port, double val) { if (SimulationGUI.INSTANCE != null) SimulationGUI.INSTANCE.pwmSpinners[port].setValue(val); } + + /** + * USAGE REPORTING * + */ + public static byte[] motorControllers = new byte[10]; /** * POWER DISTRIBUTION PANEL *