[wpimath] Refactor WheelVoltages inner class to a separate file (#4203)

This commit is contained in:
Tyler Veness
2022-05-01 11:01:20 -07:00
committed by GitHub
parent 87bf70fa8e
commit ce1a7d698a
8 changed files with 63 additions and 70 deletions

View File

@@ -21,20 +21,6 @@ public class DifferentialDriveAccelerationLimiter {
private final double m_maxLinearAccel;
private final double m_maxAngularAccel;
/** Motor voltages for a differential drive. */
@SuppressWarnings("MemberName")
public static class WheelVoltages {
public double left;
public double right;
private WheelVoltages() {}
public WheelVoltages(double left, double right) {
this.left = left;
this.right = right;
}
}
/**
* Constructs a DifferentialDriveAccelerationLimiter.
*
@@ -64,7 +50,7 @@ public class DifferentialDriveAccelerationLimiter {
* @return The constrained wheel voltages.
*/
@SuppressWarnings("LocalVariableName")
public WheelVoltages calculate(
public DifferentialDriveWheelVoltages calculate(
double leftVelocity, double rightVelocity, double leftVoltage, double rightVoltage) {
var u = new MatBuilder<>(Nat.N2(), Nat.N1()).fill(leftVoltage, rightVoltage);
@@ -99,6 +85,6 @@ public class DifferentialDriveAccelerationLimiter {
// u = B⁻¹(dx/dt - Ax)
u = m_system.getB().solve(dxdt.minus(m_system.getA().times(x)));
return new WheelVoltages(u.get(0, 0), u.get(1, 0));
return new DifferentialDriveWheelVoltages(u.get(0, 0), u.get(1, 0));
}
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.math.controller;
/** Motor voltages for a differential drive. */
@SuppressWarnings("MemberName")
public class DifferentialDriveWheelVoltages {
public double left;
public double right;
public DifferentialDriveWheelVoltages() {}
public DifferentialDriveWheelVoltages(double left, double right) {
this.left = left;
this.right = right;
}
}

View File

@@ -37,20 +37,6 @@ public class LTVDifferentialDriveController {
private Matrix<N5, N1> m_error = new Matrix<>(Nat.N5(), Nat.N1());
private Matrix<N5, N1> m_tolerance = new Matrix<>(Nat.N5(), Nat.N1());
/** Motor voltages for a differential drive. */
@SuppressWarnings("MemberName")
public static class WheelVoltages {
public double left;
public double right;
public WheelVoltages() {}
public WheelVoltages(double left, double right) {
this.left = left;
this.right = right;
}
}
/** States of the drivetrain system. */
enum State {
kX(0),
@@ -204,7 +190,7 @@ public class LTVDifferentialDriveController {
* @return Left and right output voltages of the LTV controller.
*/
@SuppressWarnings("LocalVariableName")
public WheelVoltages calculate(
public DifferentialDriveWheelVoltages calculate(
Pose2d currentPose,
double leftVelocity,
double rightVelocity,
@@ -245,7 +231,7 @@ public class LTVDifferentialDriveController {
var u = K.times(inRobotFrame).times(m_error);
return new WheelVoltages(u.get(0, 0), u.get(1, 0));
return new DifferentialDriveWheelVoltages(u.get(0, 0), u.get(1, 0));
}
/**
@@ -260,7 +246,7 @@ public class LTVDifferentialDriveController {
* @param desiredState The desired pose, linear velocity, and angular velocity from a trajectory.
* @return The left and right output voltages of the LTV controller.
*/
public WheelVoltages calculate(
public DifferentialDriveWheelVoltages calculate(
Pose2d currentPose,
double leftVelocity,
double rightVelocity,