Skip to content

Commit

Permalink
Make public final values in feedforwards private and add getters
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Jul 18, 2024
1 parent 7663211 commit 1f7c768
Show file tree
Hide file tree
Showing 22 changed files with 282 additions and 88 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. */
public final double ks;
private final double ks;

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

/** The velocity gain, in volt seconds per radian. */
public final double kv;
private final double kv;

/** The acceleration gain, in volt seconds² per radian. */
public final double ka;
private final double ka;

/** Arm feedforward protobuf for serialization. */
public static final ArmFeedforwardProto proto = new ArmFeedforwardProto();
Expand Down Expand Up @@ -69,6 +69,42 @@ public ArmFeedforward(double ks, double kg, double kv) {
this(ks, kg, kv, 0);
}

/**
* Returns the static gain.
*
* @return The static gain, in volts.
*/
public double getKs() {
return ks;
}

/**
* Returns the gravity gain.
*
* @return The gravity gain, in volts.
*/
public double getKg() {
return kg;
}

/**
* Returns the velocity gain.
*
* @return The velocity gain, in volt seconds per radian.
*/
public double getKv() {
return kv;
}

/**
* Returns the acceleration gain.
*
* @return The acceleration gain, in volts seconds² per radian.
*/
public double getKa() {
return ka;
}

/**
* Calculates the feedforward from the gains and setpoints.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
*/
public class ElevatorFeedforward implements ProtobufSerializable, StructSerializable {
/** The static gain. */
public final double ks;
private final double ks;

/** The gravity gain. */
public final double kg;
private final double kg;

/** The velocity gain. */
public final double kv;
private final double kv;

/** The acceleration gain. */
public final double ka;
private final double ka;

/** ElevatorFeedforward protobuf for serialization. */
public static final ElevatorFeedforwardProto proto = new ElevatorFeedforwardProto();
Expand Down Expand Up @@ -71,6 +71,42 @@ public ElevatorFeedforward(double ks, double kg, double kv) {
this(ks, kg, kv, 0);
}

/**
* Returns the static gain.
*
* @return The static gain.
*/
public double getKs() {
return ks;
}

/**
* Returns the gravity gain.
*
* @return The gravity gain.
*/
public double getKg() {
return kg;
}

/**
* Returns the velocity gain.
*
* @return The velocity gain.
*/
public double getKv() {
return kv;
}

/**
* Returns the acceleration gain.
*
* @return The acceleration gain.
*/
public double getKa() {
return ka;
}

/**
* Calculates the feedforward from the gains and setpoints.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
/** A helper class that computes feedforward outputs for a simple permanent-magnet DC motor. */
public class SimpleMotorFeedforward {
/** The static gain. */
public final double ks;
private final double ks;

/** The velocity gain. */
public final double kv;
private final double kv;

/** The acceleration gain. */
public final double ka;
private final double ka;

/** The period. */
private double m_dt;
private final double m_dt;

/**
* Creates a new SimpleMotorFeedforward with the specified gains and period. Units of the gain
Expand Down Expand Up @@ -80,6 +80,42 @@ public SimpleMotorFeedforward(double ks, double kv) {
this(ks, kv, 0, 0.020);
}

/**
* Returns the static gain.
*
* @return The static gain.
*/
public double getKs() {
return ks;
}

/**
* Returns the velocity gain.
*
* @return The velocity gain.
*/
public double getKv() {
return kv;
}

/**
* Returns the acceleration gain.
*
* @return The acceleration gain.
*/
public double getKa() {
return ka;
}

/**
* Returns the period.
*
* @return The period in seconds.
*/
public double getDt() {
return m_dt;
}

/**
* Calculates the feedforward from the gains and setpoints.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public ArmFeedforward unpack(ProtobufArmFeedforward msg) {

@Override
public void pack(ProtobufArmFeedforward msg, ArmFeedforward value) {
msg.setKs(value.ks);
msg.setKg(value.kg);
msg.setKv(value.kv);
msg.setKa(value.ka);
msg.setKs(value.getKs());
msg.setKg(value.getKg());
msg.setKv(value.getKv());
msg.setKa(value.getKa());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public ElevatorFeedforward unpack(ProtobufElevatorFeedforward msg) {

@Override
public void pack(ProtobufElevatorFeedforward msg, ElevatorFeedforward value) {
msg.setKs(value.ks);
msg.setKg(value.kg);
msg.setKv(value.kv);
msg.setKa(value.ka);
msg.setKs(value.getKs());
msg.setKg(value.getKg());
msg.setKv(value.getKv());
msg.setKa(value.getKa());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public ArmFeedforward unpack(ByteBuffer bb) {

@Override
public void pack(ByteBuffer bb, ArmFeedforward value) {
bb.putDouble(value.ks);
bb.putDouble(value.kg);
bb.putDouble(value.kv);
bb.putDouble(value.ka);
bb.putDouble(value.getKs());
bb.putDouble(value.getKg());
bb.putDouble(value.getKv());
bb.putDouble(value.getKa());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public ElevatorFeedforward unpack(ByteBuffer bb) {

@Override
public void pack(ByteBuffer bb, ElevatorFeedforward value) {
bb.putDouble(value.ks);
bb.putDouble(value.kg);
bb.putDouble(value.kv);
bb.putDouble(value.ka);
bb.putDouble(value.getKs());
bb.putDouble(value.getKg());
bb.putDouble(value.getKv());
bb.putDouble(value.getKa());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ frc::ArmFeedforward wpi::Protobuf<frc::ArmFeedforward>::Unpack(
void wpi::Protobuf<frc::ArmFeedforward>::Pack(
google::protobuf::Message* msg, const frc::ArmFeedforward& value) {
auto m = static_cast<wpi::proto::ProtobufArmFeedforward*>(msg);
m->set_ks(value.kS.value());
m->set_kg(value.kG.value());
m->set_kv(value.kV.value());
m->set_ka(value.kA.value());
m->set_ks(value.getKs().value());
m->set_kg(value.getKg().value());
m->set_kv(value.getKv().value());
m->set_ka(value.getKa().value());
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ frc::ElevatorFeedforward wpi::Protobuf<frc::ElevatorFeedforward>::Unpack(
void wpi::Protobuf<frc::ElevatorFeedforward>::Pack(
google::protobuf::Message* msg, const frc::ElevatorFeedforward& value) {
auto m = static_cast<wpi::proto::ProtobufElevatorFeedforward*>(msg);
m->set_ks(value.kS());
m->set_kg(value.kG());
m->set_kv(value.kV());
m->set_ka(value.kA());
m->set_ks(value.getKs().value());
m->set_kg(value.getKg().value());
m->set_kv(value.getKv().value());
m->set_ka(value.getKa().value());
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ frc::ArmFeedforward StructType::Unpack(std::span<const uint8_t> data) {

void StructType::Pack(std::span<uint8_t> data,
const frc::ArmFeedforward& value) {
wpi::PackStruct<kKsOff>(data, value.kS());
wpi::PackStruct<kKgOff>(data, value.kG());
wpi::PackStruct<kKvOff>(data, value.kV());
wpi::PackStruct<kKaOff>(data, value.kA());
wpi::PackStruct<kKsOff>(data, value.getKs().value());
wpi::PackStruct<kKgOff>(data, value.getKg().value());
wpi::PackStruct<kKvOff>(data, value.getKv().value());
wpi::PackStruct<kKaOff>(data, value.getKa().value());
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ frc::ElevatorFeedforward StructType::Unpack(std::span<const uint8_t> data) {

void StructType::Pack(std::span<uint8_t> data,
const frc::ElevatorFeedforward& value) {
wpi::PackStruct<kKsOff>(data, value.kS());
wpi::PackStruct<kKgOff>(data, value.kG());
wpi::PackStruct<kKvOff>(data, value.kV());
wpi::PackStruct<kKaOff>(data, value.kA());
wpi::PackStruct<kKsOff>(data, value.getKs().value());
wpi::PackStruct<kKgOff>(data, value.getKg().value());
wpi::PackStruct<kKvOff>(data, value.getKv().value());
wpi::PackStruct<kKaOff>(data, value.getKa().value());
}
37 changes: 33 additions & 4 deletions wpimath/src/main/native/include/frc/controller/ArmFeedforward.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,46 @@ class WPILIB_DLLEXPORT ArmFeedforward {
return MaxAchievableAcceleration(-maxVoltage, angle, velocity);
}

/**
* Returns the static gain.
*
* @return The static gain.
*/
units::volt_t getKs() const { return kS; }

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

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

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

private:
/// The static gain, in volts.
const units::volt_t kS;
units::volt_t kS;

/// The gravity gain, in volts.
const units::volt_t kG;
units::volt_t kG;

/// The velocity gain, in volt seconds per radian.
const units::unit_t<kv_unit> kV;
units::unit_t<kv_unit> kV;

/// The acceleration gain, in volt seconds² per radian.
const units::unit_t<ka_unit> kA;
units::unit_t<ka_unit> kA;
};
} // namespace frc

Expand Down
Loading

0 comments on commit 1f7c768

Please sign in to comment.