Contrôleur Ramsete

Avertissement

Ramsete Controller has been deprecated. Use LTV Unicycle Controller which has more intuitive tuning.

The Ramsete Controller is a trajectory tracker that is built in to WPILib. This tracker can be used to accurately track trajectories with correction for minor disturbances for differential drivetrains.

Construire l’objet contrôleur Ramsete

Le contrôleur Ramsete doit être initialisé avec deux gains, à savoir b et zeta. Des valeurs plus grandes de b rendent la convergence plus agressive comme un terme proportionnel tandis que des valeurs plus grandes de zeta fournissent plus d’amortissement dans la réponse. Ces gains de contrôleur dictent uniquement la manière dont le contrôleur produira les vitesses ajustées. Cela n’affecte PAS le suivi de la vitesse réelle du robot. Cela signifie que ces gains de contrôleur sont généralement indépendants du robot.

Note

Les gains de 2.0 et 0.7 pour b et zeta ont été testés à plusieurs reprises pour produire des résultats souhaitables lorsque toutes les unités étaient en mètres. En tant que tel, un constructeur qui ne passe aucun argument à RamseteController aura ses gains réglés par défaut à ces valeurs.

// Using the default constructor of RamseteController. Here
// the gains are initialized to 2.0 and 0.7.
RamseteController controller1 = new RamseteController();
// Using the secondary constructor of RamseteController where
// the user can choose any other gains.
RamseteController controller2 = new RamseteController(2.1, 0.8);
// Using the default constructor of RamseteController. Here
// the gains are initialized to 2.0 and 0.7.
frc::RamseteController controller1;
// Using the secondary constructor of RamseteController where
// the user can choose any other gains.
frc::RamseteController controller2{2.1, 0.8};
from wpimath.controller import RamseteController
# Using the default constructor of RamseteController. Here
# the gains are initialized to 2.0 and 0.7.
controller1 = RamseteController()
# Using the secondary constructor of RamseteController where
# the user can choose any other gains.
controller2 = RamseteController(2.1, 0.8)

Obtention de vitesses ajustées

The Ramsete controller returns « adjusted velocities » so that the when the robot tracks these velocities, it accurately reaches the goal point. The controller should be updated periodically with the new reference, which is where it should be at the current time. The reference comprises of a desired pose, desired linear velocity, and desired angular velocity. Furthermore, the current position of the robot should also be updated periodically. The controller uses these four arguments to return the adjusted linear and angular velocity. Users should command their robot to these linear and angular velocities to achieve optimal trajectory tracking.

Note

The « reference pose » represents the position that the robot should be at a particular timestep when tracking the trajectory. It does NOT represent the final endpoint of the trajectory, which is the goal.

The controller can be updated using the Calculate (C++) / calculate (Java/Python) method. There are two overloads for this method. Both of these overloads accept the current robot position as the first parameter. For the other parameters, one of these overloads takes in the reference as three separate parameters (pose, linear velocity, and angular velocity) whereas the other overload accepts a Trajectory.State object, which contains information about the reference pose. For its ease, users should use the latter method when tracking trajectories.

Trajectory.State reference = trajectory.sample(3.4); // sample the trajectory at 3.4 seconds from the beginning
ChassisSpeeds adjustedSpeeds = controller.calculate(currentRobotPose, reference);
const Trajectory::State reference = trajectory.Sample(3.4_s); // sample the trajectory at 3.4 seconds from the beginning
ChassisSpeeds adjustedSpeeds = controller.Calculate(currentRobotPose, reference);
reference = trajectory.sample(3.4)  # sample the trajectory at 3.4 seconds from the beginning
adjustedSpeeds = controller.calculate(currentRobotPose, reference)

These calculations should be performed at every loop iteration, with an updated robot position and reference.

Utilisation des vitesses ajustées

Les vitesses ajustées sont de type ChassisSpeeds, qui contient un vx (vitesse linéaire dans la direction avant), un vy (vitesse linéaire dans la direction latérale) et un omega (vitesse angulaire autour du centre du châssis du robot). Étant donné que le contrôleur Ramsete est un contrôleur pour les robots non holonomiques (robots qui ne peuvent pas se déplacer latéralement), l’objet à vitesses ajustées a un vy de zéro.

Les vitesses ajustées renvoyées peuvent être converties en vitesses utilisables en utilisant les classes cinématiques pour votre type de transmission. Par exemple, les vitesses ajustées peuvent être converties en vitesses gauche et droite pour un entraînement différentiel à l’aide d’un objet DifferentialDriveKinematics.

ChassisSpeeds adjustedSpeeds = controller.calculate(currentRobotPose, reference);
DifferentialDriveWheelSpeeds wheelSpeeds = kinematics.toWheelSpeeds(adjustedSpeeds);
double left = wheelSpeeds.leftMetersPerSecond;
double right = wheelSpeeds.rightMetersPerSecond;
ChassisSpeeds adjustedSpeeds = controller.Calculate(currentRobotPose, reference);
DifferentialDriveWheelSpeeds wheelSpeeds = kinematics.ToWheelSpeeds(adjustedSpeeds);
auto [left, right] = kinematics.ToWheelSpeeds(adjustedSpeeds);
adjustedSpeeds = controller.calculate(currentRobotPose, reference)
wheelSpeeds = kinematics.toWheelSpeeds(adjustedSpeeds)
left = wheelSpeeds.left
right = wheelSpeeds.right

Because these new left and right velocities are still speeds and not voltages, two PID Controllers, one for each side may be used to track these velocities. Either the WPILib PIDController (C++, Java, Python) can be used, or the Velocity PID feature on smart motor controllers such as the TalonSRX and the SPARK MAX can be used.

Ramsete dans un environnement basé sur les commandes (Command -based Framework)

Par souci de facilité pour les utilisateurs, une classe RamseteCommand est intégrée à WPILib. Pour un didacticiel complet sur la mise en œuvre d’un mode autonome qui suit une trajectoire précise à l’aide de RamseteCommand, voir Didacticiel sur la pratique des trajectoires.