mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
[examples] Armbot: rename kCos to kG (#3975)
This commit is contained in:
@@ -15,7 +15,7 @@ ArmSubsystem::ArmSubsystem()
|
||||
kP, 0, 0, {kMaxVelocity, kMaxAcceleration})),
|
||||
m_motor(kMotorPort),
|
||||
m_encoder(kEncoderPorts[0], kEncoderPorts[1]),
|
||||
m_feedforward(kS, kCos, kV, kA) {
|
||||
m_feedforward(kS, kG, kV, kA) {
|
||||
m_encoder.SetDistancePerPulse(kEncoderDistancePerPulse.value());
|
||||
// Start arm in neutral position
|
||||
SetGoal(State{kArmOffset, 0_rad_per_s});
|
||||
|
||||
@@ -46,7 +46,7 @@ constexpr double kP = 1;
|
||||
// These are fake gains; in actuality these must be determined individually for
|
||||
// each robot
|
||||
constexpr auto kS = 1_V;
|
||||
constexpr auto kCos = 1_V;
|
||||
constexpr auto kG = 1_V;
|
||||
constexpr auto kV = 0.5_V * 1_s / 1_rad;
|
||||
constexpr auto kA = 0.1_V * 1_s * 1_s / 1_rad;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ ArmSubsystem::ArmSubsystem()
|
||||
: frc2::TrapezoidProfileSubsystem<units::radians>(
|
||||
{kMaxVelocity, kMaxAcceleration}, kArmOffset),
|
||||
m_motor(kMotorPort),
|
||||
m_feedforward(kS, kCos, kV, kA) {
|
||||
m_feedforward(kS, kG, kV, kA) {
|
||||
m_motor.SetPID(kP, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ constexpr double kP = 1;
|
||||
// These are fake gains; in actuality these must be determined individually for
|
||||
// each robot
|
||||
constexpr auto kS = 1_V;
|
||||
constexpr auto kCos = 1_V;
|
||||
constexpr auto kG = 1_V;
|
||||
constexpr auto kV = 0.5_V * 1_s / 1_rad;
|
||||
constexpr auto kA = 0.1_V * 1_s * 1_s / 1_rad;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class Constants {
|
||||
|
||||
// These are fake gains; in actuality these must be determined individually for each robot
|
||||
public static final double kSVolts = 1;
|
||||
public static final double kCosVolts = 1;
|
||||
public static final double kGVolts = 1;
|
||||
public static final double kVVoltSecondPerRad = 0.5;
|
||||
public static final double kAVoltSecondSquaredPerRad = 0.1;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ArmSubsystem extends ProfiledPIDSubsystem {
|
||||
new Encoder(ArmConstants.kEncoderPorts[0], ArmConstants.kEncoderPorts[1]);
|
||||
private final ArmFeedforward m_feedforward =
|
||||
new ArmFeedforward(
|
||||
ArmConstants.kSVolts, ArmConstants.kCosVolts,
|
||||
ArmConstants.kSVolts, ArmConstants.kGVolts,
|
||||
ArmConstants.kVVoltSecondPerRad, ArmConstants.kAVoltSecondSquaredPerRad);
|
||||
|
||||
/** Create a new ArmSubsystem. */
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class Constants {
|
||||
|
||||
// These are fake gains; in actuality these must be determined individually for each robot
|
||||
public static final double kSVolts = 1;
|
||||
public static final double kCosVolts = 1;
|
||||
public static final double kGVolts = 1;
|
||||
public static final double kVVoltSecondPerRad = 0.5;
|
||||
public static final double kAVoltSecondSquaredPerRad = 0.1;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ArmSubsystem extends TrapezoidProfileSubsystem {
|
||||
new ExampleSmartMotorController(ArmConstants.kMotorPort);
|
||||
private final ArmFeedforward m_feedforward =
|
||||
new ArmFeedforward(
|
||||
ArmConstants.kSVolts, ArmConstants.kCosVolts,
|
||||
ArmConstants.kSVolts, ArmConstants.kGVolts,
|
||||
ArmConstants.kVVoltSecondPerRad, ArmConstants.kAVoltSecondSquaredPerRad);
|
||||
|
||||
/** Create a new ArmSubsystem. */
|
||||
|
||||
@@ -35,14 +35,14 @@ class WPILIB_DLLEXPORT ArmFeedforward {
|
||||
* Creates a new ArmFeedforward with the specified gains.
|
||||
*
|
||||
* @param kS The static gain, in volts.
|
||||
* @param kCos The gravity gain, in volts.
|
||||
* @param kG The gravity gain, in volts.
|
||||
* @param kV The velocity gain, in volt seconds per radian.
|
||||
* @param kA The acceleration gain, in volt seconds^2 per radian.
|
||||
*/
|
||||
constexpr ArmFeedforward(
|
||||
units::volt_t kS, units::volt_t kCos, units::unit_t<kv_unit> kV,
|
||||
units::volt_t kS, units::volt_t kG, units::unit_t<kv_unit> kV,
|
||||
units::unit_t<ka_unit> kA = units::unit_t<ka_unit>(0))
|
||||
: kS(kS), kCos(kCos), kV(kV), kA(kA) {}
|
||||
: kS(kS), kG(kG), kV(kV), kA(kA) {}
|
||||
|
||||
/**
|
||||
* Calculates the feedforward from the gains and setpoints.
|
||||
@@ -56,7 +56,7 @@ class WPILIB_DLLEXPORT ArmFeedforward {
|
||||
units::unit_t<Velocity> velocity,
|
||||
units::unit_t<Acceleration> acceleration =
|
||||
units::unit_t<Acceleration>(0)) const {
|
||||
return kS * wpi::sgn(velocity) + kCos * units::math::cos(angle) +
|
||||
return kS * wpi::sgn(velocity) + kG * units::math::cos(angle) +
|
||||
kV * velocity + kA * acceleration;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class WPILIB_DLLEXPORT ArmFeedforward {
|
||||
units::volt_t maxVoltage, units::unit_t<Angle> angle,
|
||||
units::unit_t<Acceleration> acceleration) {
|
||||
// Assume max velocity is positive
|
||||
return (maxVoltage - kS - kCos * units::math::cos(angle) -
|
||||
return (maxVoltage - kS - kG * units::math::cos(angle) -
|
||||
kA * acceleration) /
|
||||
kV;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class WPILIB_DLLEXPORT ArmFeedforward {
|
||||
units::volt_t maxVoltage, units::unit_t<Angle> angle,
|
||||
units::unit_t<Acceleration> acceleration) {
|
||||
// Assume min velocity is negative, ks flips sign
|
||||
return (-maxVoltage + kS - kCos * units::math::cos(angle) -
|
||||
return (-maxVoltage + kS - kG * units::math::cos(angle) -
|
||||
kA * acceleration) /
|
||||
kV;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ class WPILIB_DLLEXPORT ArmFeedforward {
|
||||
units::volt_t maxVoltage, units::unit_t<Angle> angle,
|
||||
units::unit_t<Velocity> velocity) {
|
||||
return (maxVoltage - kS * wpi::sgn(velocity) -
|
||||
kCos * units::math::cos(angle) - kV * velocity) /
|
||||
kG * units::math::cos(angle) - kV * velocity) /
|
||||
kA;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ class WPILIB_DLLEXPORT ArmFeedforward {
|
||||
}
|
||||
|
||||
units::volt_t kS{0};
|
||||
units::volt_t kCos{0};
|
||||
units::volt_t kG{0};
|
||||
units::unit_t<kv_unit> kV{0};
|
||||
units::unit_t<ka_unit> kA{0};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user