Step 2: Entering the Calculated Constants

Note

In C++, it is important that the feedforward constants be entered as the correct unit type. For more information on C++ units, see The C++ Units Library.

Now that we have our characterization constants, it is time to place them in our code. The recommended place for this is the Constants file of the standard command-based project structure.

The relevant parts of the constants file from the RamseteCommand Example Project (Java, C++) can be seen below.

Feedforward/Feedback Gains

Firstly, we must enter the feedforward and feedback gains which we obtained from the characterization tool.

Note

Feedforward and feedback gains do not, in general, transfer across robots. Do not use the gains from this tutorial for your own robot.

44
45
46
47
48
49
50
51
52
53
    // for *your* robot's drive.
    // The Robot Characterization Toolsuite provides a convenient tool for obtaining these
    // values for your robot.
    public static final double ksVolts = 0.22;
    public static final double kvVoltSecondsPerMeter = 1.98;
    public static final double kaVoltSecondsSquaredPerMeter = 0.2;

    // Example value only - as above, this must be tuned for your drive!
    public static final double kPDriveVel = 8.5;
  }
46
47
48
49
50
51
52
53
54
55
    (kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);

// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
// These characterization values MUST be determined either experimentally or
// theoretically for *your* robot's drive. The Robot Characterization
// Toolsuite provides a convenient tool for obtaining these values for your
// robot.
constexpr auto ks = 0.22_V;
constexpr auto kv = 1.98 * 1_V * 1_s / 1_m;
constexpr auto ka = 0.2 * 1_V * 1_s * 1_s / 1_m;

DifferentialDriveKinematics

Additionally, we must create an instance of the DifferentialDriveKinematics class, which allows us to use the trackwidth (i.e. horizontal distance between the wheels) of the robot to convert from chassis speeds to wheel speeds. As elsewhere, we keep our units in meters.

32
33
34
    public static final double kTrackwidthMeters = 0.69;
    public static final DifferentialDriveKinematics kDriveKinematics =
        new DifferentialDriveKinematics(kTrackwidthMeters);
35
36
constexpr int kRightEncoderPorts[]{2, 3};
constexpr bool kLeftEncoderReversed = false;

Max Trajectory Velocity/Acceleration

We must also decide on a nominal max acceleration and max velocity for the robot during path-following. The maximum velocity value should be set somewhat below the nominal free-speed of the robot. Due to the later use of the DifferentialDriveVoltageConstraint, the maximum acceleration value is not extremely crucial.

62
    // Reasonable baseline values for a RAMSETE follower in units of meters and seconds
60
namespace AutoConstants {

Ramsete Parameters

Finally, we must include a pair of parameters for the RAMSETE controller. The values shown below should work well for most robots, provided distances have been correctly measured in meters - for more information on tuning these values (if it is required), see Constructing the Ramsete Controller Object.

65
66
67
    public static final double kRamseteZeta = 0.7;
  }
}
63
64
65
66
constexpr auto kMaxAcceleration = 3_mps_sq;

// Reasonable baseline values for a RAMSETE follower in units of meters and
// seconds