[wpimath] Make public final values in feedforwards private and add getters (#6851)

This commit is contained in:
Joseph Eng
2024-07-20 07:01:56 -07:00
committed by GitHub
parent d827c84c5e
commit b4d42d8980
22 changed files with 288 additions and 94 deletions

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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;
/// The velocity gain, in V/(rad/s)volt seconds per radian.
units::unit_t<kv_unit> kV;
/// The acceleration gain, in volt seconds² per radian.
const units::unit_t<ka_unit> kA;
/// The acceleration gain, in V/(rad/s²).
units::unit_t<ka_unit> kA;
};
} // namespace frc

View File

@@ -182,17 +182,46 @@ class ElevatorFeedforward {
return MaxAchievableAcceleration(-maxVoltage, 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.
const units::volt_t kS;
units::volt_t kS;
/// The gravity gain.
const units::volt_t kG;
units::volt_t kG;
/// The velocity gain.
const units::unit_t<kv_unit> kV;
units::unit_t<kv_unit> kV;
/// The acceleration gain.
const units::unit_t<ka_unit> kA;
units::unit_t<ka_unit> kA;
};
} // namespace frc

View File

@@ -245,16 +245,44 @@ class SimpleMotorFeedforward {
return MaxAchievableAcceleration(-maxVoltage, velocity);
}
/** The static gain. */
const units::volt_t kS;
/**
* Returns the static gain.
*
* @return The static gain.
*/
units::volt_t GetKs() const { return kS; }
/** The velocity gain. */
const units::unit_t<kv_unit> kV;
/**
* Returns the velocity gain.
*
* @return The velocity gain.
*/
units::unit_t<kv_unit> GetKv() const { return kV; }
/** The acceleration gain. */
const units::unit_t<ka_unit> kA;
/**
* Returns the acceleration gain.
*
* @return The acceleration gain.
*/
units::unit_t<ka_unit> GetKa() const { return kA; }
/**
* Returns the period.
*
* @return The period.
*/
units::second_t GetDt() const { return m_dt; }
private:
/** The static gain. */
units::volt_t kS;
/** The velocity gain. */
units::unit_t<kv_unit> kV;
/** The acceleration gain. */
units::unit_t<ka_unit> kA;
/** The period. */
units::second_t m_dt;
};