diff --git a/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp b/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp index f4330f4121..8224887ff1 100644 --- a/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/DifferentialDrivetrainSim.cpp @@ -90,7 +90,7 @@ Pose2d DifferentialDrivetrainSim::GetPose() const { units::meter_t(GetOutput(State::kY)), GetHeading()); } -units::ampere_t DifferentialDrivetrainSim::GetCurrentDraw() const { +units::ampere_t DifferentialDrivetrainSim::GetLeftCurrentDraw() const { auto loadIleft = m_motor.Current(units::radians_per_second_t(m_x(State::kLeftVelocity) * m_currentGearing / @@ -98,6 +98,10 @@ units::ampere_t DifferentialDrivetrainSim::GetCurrentDraw() const { units::volt_t(m_u(0))) * wpi::sgn(m_u(0)); + return loadIleft; +} + +units::ampere_t DifferentialDrivetrainSim::GetRightCurrentDraw() const { auto loadIRight = m_motor.Current(units::radians_per_second_t(m_x(State::kRightVelocity) * m_currentGearing / @@ -105,7 +109,10 @@ units::ampere_t DifferentialDrivetrainSim::GetCurrentDraw() const { units::volt_t(m_u(1))) * wpi::sgn(m_u(1)); - return loadIleft + loadIRight; + return loadIRight; +} +units::ampere_t DifferentialDrivetrainSim::GetCurrentDraw() const { + return GetLeftCurrentDraw() + GetRightCurrentDraw(); } void DifferentialDrivetrainSim::SetState( diff --git a/wpilibc/src/main/native/include/frc/simulation/DifferentialDrivetrainSim.h b/wpilibc/src/main/native/include/frc/simulation/DifferentialDrivetrainSim.h index e67445d08a..1d47726b29 100644 --- a/wpilibc/src/main/native/include/frc/simulation/DifferentialDrivetrainSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/DifferentialDrivetrainSim.h @@ -158,6 +158,16 @@ class DifferentialDrivetrainSim { return units::meters_per_second_t{GetOutput(State::kLeftVelocity)}; } + /** + * Returns the currently drawn current for the right side. + */ + units::ampere_t GetRightCurrentDraw() const; + + /** + * Returns the currently drawn current for the left side. + */ + units::ampere_t GetLeftCurrentDraw() const; + /** * Returns the currently drawn current. */ diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java index b823ffc127..c88b435eb9 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java @@ -201,18 +201,26 @@ public class DifferentialDrivetrainSim { return getOutput(State.kLeftVelocity); } - public double getCurrentDrawAmps() { + public double getLeftCurrentDrawAmps() { var loadIleft = m_motor.getCurrent( getState(State.kLeftVelocity) * m_currentGearing / m_wheelRadiusMeters, m_u.get(0, 0)) * Math.signum(m_u.get(0, 0)); + return loadIleft; + } + public double getRightCurrentDrawAmps() { var loadIright = m_motor.getCurrent( getState(State.kRightVelocity) * m_currentGearing / m_wheelRadiusMeters, m_u.get(1, 0)) * Math.signum(m_u.get(1, 0)); - return loadIleft + loadIright; + return loadIright; } + public double getCurrentDrawAmps() { + return getLeftCurrentDrawAmps() + getRightCurrentDrawAmps(); + } + + public double getCurrentGearing() { return m_currentGearing; }