Skip to content

Commit

Permalink
[wpimath] Add setters to Feedforward gains
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Turner <[email protected]>
  • Loading branch information
spacey-sooty committed Feb 14, 2025
1 parent e648b9c commit 6a05985
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
*/
public class ArmFeedforward implements ProtobufSerializable, StructSerializable {
/** The static gain, in volts. */
private final double ks;
private double ks;

/** The gravity gain, in volts. */
private final double kg;
private double kg;

/** The velocity gain, in V/(rad/s). */
private final double kv;
private double kv;

/** The acceleration gain, in V/(rad/s²). */
private final double ka;
private double ka;

/** The period, in seconds. */
private final double m_dt;
Expand Down Expand Up @@ -95,6 +95,15 @@ public double getKs() {
return ks;
}

/**
* Sets the static gain.
*
* @param ks The static gain in volts.
*/
public void setKs(double ks) {
this.ks = ks;
}

/**
* Returns the gravity gain in volts.
*
Expand All @@ -104,6 +113,15 @@ public double getKg() {
return kg;
}

/**
* Sets the gravity gain.
*
* @param kg The gravity gain in volts.
*/
public void setKg(double kg) {
this.kg = kg;
}

/**
* Returns the velocity gain in V/(rad/s).
*
Expand All @@ -113,6 +131,15 @@ public double getKv() {
return kv;
}

/**
* Sets the velocity gain.
*
* @param kv The velocity gain in V/(rad/s).
*/
public void setKv(double kv) {
this.kv = kv;
}

/**
* Returns the acceleration gain in V/(rad/s²).
*
Expand All @@ -122,6 +149,15 @@ public double getKa() {
return ka;
}

/**
* Sets the acceleration gain.
*
* @param ka The acceleration gain in V/(rad/2²).
*/
public void setKa(double ka) {
this.ka = ka;
}

/**
* Returns the period in seconds.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/
public class ElevatorFeedforward implements ProtobufSerializable, StructSerializable {
/** The static gain, in volts. */
private final double ks;
private double ks;

/** The gravity gain, in volts. */
private final double kg;
private double kg;

/** The velocity gain, in V/(m/s). */
private final double kv;
private double kv;

/** The acceleration gain, in V/(m/s²). */
private final double ka;
private double ka;

/** The period, in seconds. */
private final double m_dt;
Expand Down Expand Up @@ -95,6 +95,15 @@ public double getKs() {
return ks;
}

/**
* Sets the static gain.
*
* @param ks The static gain in volts.
*/
public void setKs(double ks) {
this.ks = ks;
}

/**
* Returns the gravity gain in volts.
*
Expand All @@ -104,6 +113,15 @@ public double getKg() {
return kg;
}

/**
* Sets the gravity gain.
*
* @param kg The gravity gain in volts.
*/
public void setKg(double kg) {
this.kg = kg;
}

/**
* Returns the velocity gain in V/(m/s).
*
Expand All @@ -113,6 +131,15 @@ public double getKv() {
return kv;
}

/**
* Sets the velocity gain.
*
* @param kv The velocity gain in V/(rad/s).
*/
public void setKv(double kv) {
this.kv = kv;
}

/**
* Returns the acceleration gain in V/(m/s²).
*
Expand All @@ -122,6 +149,15 @@ public double getKa() {
return ka;
}

/**
* Sets the acceleration gain.
*
* @param ka The acceleration gain in V/(rad/2²).
*/
public void setKa(double ka) {
this.ka = ka;
}

/**
* Returns the period in seconds.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
/** A helper class that computes feedforward outputs for a simple permanent-magnet DC motor. */
public class SimpleMotorFeedforward implements ProtobufSerializable, StructSerializable {
/** The static gain, in volts. */
private final double ks;
private double ks;

/** The velocity gain, in V/(units/s). */
private final double kv;
private double kv;

/** The acceleration gain, in V/(units/s²). */
private final double ka;
private double ka;

/** The period, in seconds. */
private final double m_dt;
Expand Down Expand Up @@ -92,6 +92,15 @@ public double getKs() {
return ks;
}

/**
* Sets the static gain.
*
* @param ks The static gain in volts.
*/
public void setKs(double ks) {
this.ks = ks;
}

/**
* Returns the velocity gain in V/(units/s).
*
Expand All @@ -103,6 +112,15 @@ public double getKv() {
return kv;
}

/**
* Sets the velocity gain.
*
* @param kv The velocity gain in V/(rad/s).
*/
public void setKv(double kv) {
this.kv = kv;
}

/**
* Returns the acceleration gain in V/(units/s²).
*
Expand All @@ -114,6 +132,15 @@ public double getKa() {
return ka;
}

/**
* Sets the acceleration gain.
*
* @param ka The acceleration gain in V/(rad/2²).
*/
public void setKa(double ka) {
this.ka = ka;
}

/**
* Returns the period in seconds.
*
Expand Down
31 changes: 30 additions & 1 deletion wpimath/src/main/native/include/frc/controller/ArmFeedforward.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <wpi/MathExtras.h>
#include <wpi/SymbolExports.h>
#include <cstdlib>

#include "units/angle.h"
#include "units/angular_velocity.h"
Expand Down Expand Up @@ -249,12 +250,26 @@ class WPILIB_DLLEXPORT ArmFeedforward {
*/
constexpr units::volt_t GetKs() const { return kS; }

/**
* Returns the static gain.
*
* @param kS The static gain.
*/
constexpr void SetKs(units::volt_t kS) { this->kS = kS; }

/**
* Returns the gravity gain.
*
* @return The gravity gain.
*/
constexpr units::volt_t GetKg() const { return kG; }
constexpr units::volt_t GetKg() { return kG; }

/**
* Returns the gravity gain.
*
* @param kG The gravity gain.
*/
constexpr void SetKg(units::volt_t kG) { this->kG = kG; }

/**
* Returns the velocity gain.
Expand All @@ -263,13 +278,27 @@ class WPILIB_DLLEXPORT ArmFeedforward {
*/
constexpr units::unit_t<kv_unit> GetKv() const { return kV; }

/**
* Returns the velocity gain.
*
* @param kV The velocity gain.
*/
constexpr void SetKv(units::unit_t<kv_unit> kV) { this->kV = units::unit_t<kv_unit>{kV}; }

/**
* Returns the acceleration gain.
*
* @return The acceleration gain.
*/
constexpr units::unit_t<ka_unit> GetKa() const { return kA; }

/**
* Returns the acceleration gain.
*
* @param kA The acceleration gain.
*/
constexpr void SetKa(units::unit_t<ka_unit> kA) { this->kA = units::unit_t<ka_unit>{kA}; }

private:
/// The static gain, in volts.
units::volt_t kS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,55 @@ class ElevatorFeedforward {
*/
constexpr units::volt_t GetKs() const { return kS; }

/**
* Returns the static gain.
*
* @param kS The static gain.
*/
constexpr void SetKs(units::volt_t kS) { this->kS = kS; }

/**
* Returns the gravity gain.
*
* @return The gravity gain.
*/
constexpr units::volt_t GetKg() const { return kG; }

/**
* Returns the gravity gain.
*
* @param kG The gravity gain.
*/
constexpr void SetKg(units::volt_t kG) { this->kG = kG; }

/**
* Returns the velocity gain.
*
* @return The velocity gain.
*/
constexpr units::unit_t<kv_unit> GetKv() const { return kV; }

/**
* Returns the velocity gain.
*
* @param kV The velocity gain.
*/
constexpr void SetKv(units::unit_t<kv_unit> kV) { this->kV = kV; }

/**
* Returns the acceleration gain.
*
* @return The acceleration gain.
*/
constexpr units::unit_t<ka_unit> GetKa() const { return kA; }

/**
* Returns the acceleration gain.
*
* @param kA The acceleration gain.
*/
constexpr void SetKa(units::unit_t<ka_unit> kA) { this->kA = kA; }

private:
/// The static gain.
units::volt_t kS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,41 @@ class SimpleMotorFeedforward {
*/
constexpr units::volt_t GetKs() const { return kS; }

/**
* Returns the static gain.
*
* @param kS The static gain.
*/
constexpr void SetKs(units::volt_t kS) { this->kS = kS; }

/**
* Returns the velocity gain.
*
* @return The velocity gain.
*/
constexpr units::unit_t<kv_unit> GetKv() const { return kV; }

/**
* Returns the velocity gain.
*
* @param kV The velocity gain.
*/
constexpr void SetKv(units::unit_t<kv_unit> kV) { this->kV = kV; }

/**
* Returns the acceleration gain.
*
* @return The acceleration gain.
*/
constexpr units::unit_t<ka_unit> GetKa() const { return kA; }

/**
* Returns the acceleration gain.
*
* @param kA The acceleration gain.
*/
constexpr void SetKa(units::unit_t<ka_unit> kA) { this->kA = kA; }

/**
* Returns the period.
*
Expand Down

0 comments on commit 6a05985

Please sign in to comment.