Étape 2 : Saisie des constantes calculées
Note
En C++, il est important que les constantes de la commande prédictive soient saisies dans le type d’unité approprié. Pour plus d’informations sur les unités C++, voir La librairie d’unités C++.
Maintenant que nous avons nos constantes système, il est temps de les placer dans notre code. L’emplacement recommandé pour cela est le fichier Constants
de la structure de projet basée sur des commandes standard.
The relevant parts of the constants file from the RamseteCommand Example Project (Java, C++) can be seen below.
Gains Prédicitif/Rétroactif
Tout d’abord, nous devons entrer les gains d’anticipation et de rétroaction que nous avons obtenus à partir de l’outil d’identification.
Note
Les gains prédictif et rétroactif ne se transfèrent pas, en général, entre les robots. Aussi, n’utilisez pas les gains de ce tutoriel sur votre propre robot.
39 // These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
40 // These characterization values MUST be determined either experimentally or theoretically
41 // for *your* robot's drive.
42 // The Robot Characterization Toolsuite provides a convenient tool for obtaining these
43 // values for your robot.
44 public static final double ksVolts = 0.22;
45 public static final double kvVoltSecondsPerMeter = 1.98;
46 public static final double kaVoltSecondsSquaredPerMeter = 0.2;
47
48 // Example value only - as above, this must be tuned for your drive!
49 public static final double kPDriveVel = 8.5;
47// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
48// These characterization values MUST be determined either experimentally or
49// theoretically for *your* robot's drive. The Robot Characterization
50// Toolsuite provides a convenient tool for obtaining these values for your
51// robot.
52inline constexpr auto ks = 0.22_V;
53inline constexpr auto kv = 1.98 * 1_V * 1_s / 1_m;
54inline constexpr auto ka = 0.2 * 1_V * 1_s * 1_s / 1_m;
55
56// Example value only - as above, this must be tuned for your drive!
57inline constexpr double kPDriveVel = 8.5;
DifferentialDriveKinematics
En outre, nous devons créer une instance de la classe DifferentialDriveKinematics
, qui nous permet d’utiliser la trackwidth (c’est-à-dire la distance horizontale entre les roues) du robot pour la conversion des vitesses du châssis aux vitesses des roues. Comme partout ailleurs, nous gardons nos unités en mètres.
29 public static final double kTrackwidthMeters = 0.69;
30 public static final DifferentialDriveKinematics kDriveKinematics =
31 new DifferentialDriveKinematics(kTrackwidthMeters);
38inline constexpr auto kTrackwidth = 0.69_m;
39extern const frc::DifferentialDriveKinematics kDriveKinematics;
Vitesse/accélération max sur la trajectoire
Nous devons également décider d’une accélération nominale max et d’une vitesse maximale du robot pendant le suivi de la trajectoire. La valeur maximale de la vitesse doit être choisie légèrement en dessous de la vitesse libre nominale du robot. En raison de l’utilisation ultérieure du DifferentialDriveVoltageConstraint
, la valeur maximale de l’accélération n’est pas extrêmement cruciale.
Avertissement
Max velocity and acceleration, as defined here, are applied only during trajectory generation. They do not limit the RamseteCommand
itself, which may give values to the DriveSubsystem
that can cause the robot to greatly exceed these velocities and accelerations.
57 public static final double kMaxSpeedMetersPerSecond = 3;
58 public static final double kMaxAccelerationMetersPerSecondSquared = 1;
61inline constexpr auto kMaxSpeed = 3_mps;
62inline constexpr auto kMaxAcceleration = 1_mps_sq;
Paramètres Ramsete
Finally, we must include a pair of parameters for the RAMSETE controller. The values b
and zeta
shown below should work well for most robots, provided distances have been correctly measured in meters.
Larger values of b
make convergence more aggressive like a proportional term whereas larger values of zeta
provide more damping in the response. These controller gains only dictate how the controller will output adjusted velocities. It does NOT affect the actual velocity tracking of the robot. This means that these controller gains are generally robot-agnostic.
Note
Gains of 2.0
and 0.7
for b
and zeta
have been tested repeatedly to produce desirable results when all units were in meters. As such, a zero-argument constructor for RamseteController
exists with gains defaulted to these values.
60 // Reasonable baseline values for a RAMSETE follower in units of meters and seconds
61 public static final double kRamseteB = 2;
62 public static final double kRamseteZeta = 0.7;
64// Reasonable baseline values for a RAMSETE follower in units of meters and
65// seconds
66inline constexpr auto kRamseteB = 2.0 * 1_rad * 1_rad / (1_m * 1_m);
67inline constexpr auto kRamseteZeta = 0.7 / 1_rad;