Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
viggy96 committed Nov 7, 2023
1 parent 7d704e0 commit 02f9f60
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 139 deletions.
10 changes: 4 additions & 6 deletions src/main/java/org/lasarobotics/battery/BatteryScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ class BatteryScanner {
private static final int BATTERY_ID_LENGTH = 10;

// Scanner
private static final byte[] SCAN_COMMNAND =
new byte[] {0x7e, 0x00, 0x08, 0x01, 0x00, 0x02, 0x01, (byte) 0xab, (byte) 0xcd};
private static final byte[] RESPONSE_PREFIX =
new byte[] {0x02, 0x00, 0x00, 0x01, 0x00, 0x33, 0x31};
private static final byte[] SCAN_COMMAND = new byte[] { 0x7e, 0x00, 0x08, 0x01, 0x00, 0x02, 0x01, (byte) 0xab, (byte) 0xcd };
private static final byte[] RESPONSE_PREFIX = new byte[] { 0x02, 0x00, 0x00, 0x01, 0x00, 0x33, 0x31 };
private static final int RESPONSE_LENGTH = RESPONSE_PREFIX.length + BATTERY_ID_LENGTH;
private static final int BAUD_RATE = 9600;
private static final double TIMEOUT = 1.5;
Expand All @@ -28,9 +26,9 @@ String scanBattery() {

try (SerialPort port = new SerialPort(BAUD_RATE, SerialPort.Port.kUSB)) {
port.setTimeout(TIMEOUT);
port.setWriteBufferSize(SCAN_COMMNAND.length);
port.setWriteBufferSize(SCAN_COMMAND.length);
port.setReadBufferSize(RESPONSE_LENGTH);
port.write(SCAN_COMMNAND, SCAN_COMMNAND.length);
port.write(SCAN_COMMAND, SCAN_COMMAND.length);
byte[] response = port.read(RESPONSE_LENGTH);

// Ensure response is correct length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ public void setFieldCentric(boolean isFieldCentric) {
m_isFieldCentric = (isFieldCentric) ? 1 : 0;
}

public int isFieldCentric() {
return m_isFieldCentric;
/**
* Get if kinematics are using field centric controls
* @return True if field centric
*/
public boolean isFieldCentric() {
return (m_isFieldCentric == 1) ? true : false;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/lasarobotics/hardware/Analog.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public static class AnalogInputs {
private ID m_id;
private AnalogInputsAutoLogged m_inputs;

/**
* Create an Analog object
* @param id Analog ID
*/
public Analog(Analog.ID id) {
this.m_id = id;
this.m_analogInput = new AnalogInput(id.port);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/lasarobotics/hardware/Servo.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Servo(Servo.ID id, double conversionFactor) {

/**
* Create a servo object with built-in logging
* @param id
* @param id Servo ID
*/
public Servo(Servo.ID id) {
this(id, 1.0);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/lasarobotics/led/LEDStrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static enum Section {
MIDDLE,
END;

public static final Section FULL[] = { START, MIDDLE, END };
public static final Section[] FULL = { START, MIDDLE, END };

private static final int SMALL_SECTION_LENGTH = 10;

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/lasarobotics/drive/ThrottleMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class ThrottleMapTest {
private final double DELTA = 1e-5;
private final double ALT_DELTA = 0.15;
private final double CONTROLLER_DEADBAND = 0.10;
private final double DRIVE_THROTTLE_INPUT_CURVE_X[] = { 0.0, 0.100, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900, 1.000 };
private final double DRIVE_THROTTLE_INPUT_CURVE_Y[] = { 0.0, 0.200, 0.400, 0.600, 0.800, 1.000, 1.200, 1.400, 1.600, 1.800, 2.000 };
private final double[] DRIVE_THROTTLE_INPUT_CURVE_X = { 0.0, 0.100, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900, 1.000 };
private final double[] DRIVE_THROTTLE_INPUT_CURVE_Y = { 0.0, 0.200, 0.400, 0.600, 0.800, 1.000, 1.200, 1.400, 1.600, 1.800, 2.000 };
private final SplineInterpolator SPLINE_INTERPOLATOR = new SplineInterpolator();
private final PolynomialSplineFunction DRIVE_THROTTLE_INPUT_CURVE = SPLINE_INTERPOLATOR.interpolate(DRIVE_THROTTLE_INPUT_CURVE_X, DRIVE_THROTTLE_INPUT_CURVE_Y);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class TurnPIDControllerTest {
private final double DELTA = 1e-5;

private static final double CONTROLLER_DEADBAND = 0.10;
private static final double DRIVE_TURN_INPUT_CURVE_X[] = { 0.0, 0.100, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900, 1.0 };
private static final double DRIVE_TURN_INPUT_CURVE_Y[] = { 0.0, 0.008, 0.032, 0.072, 0.128, 0.200, 0.288, 0.392, 0.512, 0.768, 1.0 };
private static final double[] DRIVE_TURN_INPUT_CURVE_X = { 0.0, 0.100, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900, 1.0 };
private static final double[] DRIVE_TURN_INPUT_CURVE_Y = { 0.0, 0.008, 0.032, 0.072, 0.128, 0.200, 0.288, 0.392, 0.512, 0.768, 1.0 };
private static final PolynomialSplineFunction DRIVE_TURN_INPUT_CURVE = new SplineInterpolator().interpolate(DRIVE_TURN_INPUT_CURVE_X, DRIVE_TURN_INPUT_CURVE_Y);
private static final PIDConstants DRIVE_TURN_PID = new PIDConstants(30.0, 0.0, 0.3, 0.0, GlobalConstants.ROBOT_LOOP_PERIOD);
private static final double DRIVE_TURN_SCALAR = 30.0;
Expand Down
151 changes: 151 additions & 0 deletions vendordeps/Phoenix5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"fileName": "Phoenix5.json",
"name": "CTRE-Phoenix (v5)",
"version": "5.32.0-beta-1",
"frcYear": 2024,
"uuid": "ab676553-b602-441f-a38d-f1296eff6537",
"mavenUrls": [
"https://maven.ctr-electronics.com/release/"
],
"jsonUrl": "https://maven.ctr-electronics.com/release/com/ctre/phoenix/Phoenix5-frc2024-beta-latest.json",
"requires": [
{
"uuid": "e995de00-2c64-4df5-8831-c1441420ff19",
"errorMessage": "Phoenix 5 requires low-level libraries from Phoenix 6. Please add the Phoenix 6 vendordep before adding Phoenix 5.",
"offlineFileName": "Phoenix6.json",
"onlineUrl": "https://maven.ctr-electronics.com/release/com/ctre/phoenix6/latest/Phoenix6-frc2024-beta-latest.json"
}
],
"javaDependencies": [
{
"groupId": "com.ctre.phoenix",
"artifactId": "api-java",
"version": "5.32.0-beta-1"
},
{
"groupId": "com.ctre.phoenix",
"artifactId": "wpiapi-java",
"version": "5.32.0-beta-1"
}
],
"jniDependencies": [
{
"groupId": "com.ctre.phoenix",
"artifactId": "cci",
"version": "5.32.0-beta-1",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
"windowsx86-64",
"linuxx86-64",
"linuxathena"
],
"simMode": "hwsim"
},
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "cci-sim",
"version": "5.32.0-beta-1",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
"windowsx86-64",
"linuxx86-64",
"osxuniversal"
],
"simMode": "swsim"
}
],
"cppDependencies": [
{
"groupId": "com.ctre.phoenix",
"artifactId": "wpiapi-cpp",
"version": "5.32.0-beta-1",
"libName": "CTRE_Phoenix_WPI",
"headerClassifier": "headers",
"sharedLibrary": true,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"linuxx86-64",
"linuxathena"
],
"simMode": "hwsim"
},
{
"groupId": "com.ctre.phoenix",
"artifactId": "api-cpp",
"version": "5.32.0-beta-1",
"libName": "CTRE_Phoenix",
"headerClassifier": "headers",
"sharedLibrary": true,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"linuxx86-64",
"linuxathena"
],
"simMode": "hwsim"
},
{
"groupId": "com.ctre.phoenix",
"artifactId": "cci",
"version": "5.32.0-beta-1",
"libName": "CTRE_PhoenixCCI",
"headerClassifier": "headers",
"sharedLibrary": true,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"linuxx86-64",
"linuxathena"
],
"simMode": "hwsim"
},
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "wpiapi-cpp-sim",
"version": "5.32.0-beta-1",
"libName": "CTRE_Phoenix_WPISim",
"headerClassifier": "headers",
"sharedLibrary": true,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"linuxx86-64",
"osxuniversal"
],
"simMode": "swsim"
},
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "api-cpp-sim",
"version": "5.32.0-beta-1",
"libName": "CTRE_PhoenixSim",
"headerClassifier": "headers",
"sharedLibrary": true,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"linuxx86-64",
"osxuniversal"
],
"simMode": "swsim"
},
{
"groupId": "com.ctre.phoenix.sim",
"artifactId": "cci-sim",
"version": "5.32.0-beta-1",
"libName": "CTRE_PhoenixCCISim",
"headerClassifier": "headers",
"sharedLibrary": true,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"windowsx86-64",
"linuxx86-64",
"osxuniversal"
],
"simMode": "swsim"
}
]
}
Loading

0 comments on commit 02f9f60

Please sign in to comment.