Holonomik Sürücü Kontrolcüsü
Holonomik sürücü kontrolcüsü, holonomik aktarma organlarına sahip robotlar için bir yörünge izleyicidir (örn. sapma, mekanum, vb.). Bu, küçük sıkıntılar için düzeltme ile yörüngeleri doğru bir şekilde izlemek için kullanılabilir.
Holonomik Sürücü Kontrolcüsü Oluşturma
Holonomik sürücü kontrolcüsü, 2 PID kontrolcüsü ve 1 profilli PID kontrolcüsü ile somutlaştırılmalıdır.
Not
PID kontrolü hakkında daha fazla bilgi için bakınız WPILib’de PID Kontrolü.
2 PID kontrolcü, sırasıyla alana-göre x ve y yönlerindeki hatayı düzeltmesi gereken kontrolcülerdir. Örneğin, ilk 2 bağımsız değişken sırasıyla PIDController (1, 0, 0)
ve PIDController (1.2, 0, 0)
ise, holonomik sürücü kontrolcüsü; x yönündeki her hata metresi için x’ e saniyede ek bir metre ekleyecektir ve y yönündeki her hata metresi için y’ ye saniyede ek 1,2 metre ekleyecektir.
Son parametre, robotun dönüşü için bir ProfiledPIDController``dır. Bir holonomik aktarma organının dönüş dinamikleri x ve y yönlerindeki hareketten ayrıldığından, kullanıcılar bir yörüngeyi izlerken özel yön referansları ayarlayabilir. Bu rota referansları, ``ProfiledPIDController
içinde ayarlanan parametrelere göre profillenmiştir.
var controller = new HolonomicDriveController(
new PIDController(1, 0, 0), new PIDController(1, 0, 0),
new ProfiledPIDController(1, 0, 0,
new TrapezoidProfile.Constraints(6.28, 3.14)));
// Here, our rotation profile constraints were a max velocity
// of 1 rotation per second and a max acceleration of 180 degrees
// per second squared.
frc::HolonomicDriveController controller{
frc::PIDController{1, 0, 0}, frc::PIDController{1, 0, 0},
frc::ProfiledPIDController<units::radian>{
1, 0, 0, frc::TrapezoidProfile<units::radian>::Constraints{
6.28_rad_per_s, 3.14_rad_per_s / 1_s}}};
// Here, our rotation profile constraints were a max velocity
// of 1 rotation per second and a max acceleration of 180 degrees
// per second squared.
from wpimath.controller import (
HolonomicDriveController,
PIDController,
ProfiledPIDControllerRadians,
)
from wpimath.trajectory import TrapezoidProfileRadians
controller = HolonomicDriveController(
PIDController(1, 0, 0),
PIDController(1, 0, 0),
ProfiledPIDControllerRadians(
1, 0, 0, TrapezoidProfileRadians.Constraints(6.28, 3.14)
),
)
# Here, our rotation profile constraints were a max velocity
# of 1 rotation per second and a max acceleration of 180 degrees
# per second squared.
Ayarlanmış Hızları Alma
Holonomik sürücü kontrolcüsü, robot bu hızları takip ettiğinde hedef noktasına doğru bir şekilde ulaşacak şekilde “ayarlanmış hızları” geri döndürür. Kontrolcü, yeni hedefle periyodik olarak güncellenmelidir. Hedef, istenen bir poz, doğrusal hız ve rotadan oluşur.
Not
The “goal pose” represents the position that the robot should be at a particular timestamp when tracking the trajectory. It does NOT represent the trajectory’s endpoint.
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 and the desired heading as the last parameter. For the middle parameters, one overload accepts the desired pose and the linear velocity reference while the other accepts a Trajectory.State
object, which contains information about the goal pose. The latter method is preferred for tracking trajectories.
// Sample the trajectory at 3.4 seconds from the beginning.
Trajectory.State goal = trajectory.sample(3.4);
// Get the adjusted speeds. Here, we want the robot to be facing
// 70 degrees (in the field-relative coordinate system).
ChassisSpeeds adjustedSpeeds = controller.calculate(
currentRobotPose, goal, Rotation2d.fromDegrees(70.0));
// Sample the trajectoty at 3.4 seconds from the beginning.
const auto goal = trajectory.Sample(3.4_s);
// Get the adjusted speeds. Here, we want the robot to be facing
// 70 degrees (in the field-relative coordinate system).
const auto adjustedSpeeds = controller.Calculate(
currentRobotPose, goal, 70_deg);
from wpimath.geometry import Rotation2d
# Sample the trajectory at 3.4 seconds from the beginning.
goal = trajectory.sample(3.4)
# Get the adjusted speeds. Here, we want the robot to be facing
# 70 degrees (in the field-relative coordinate system).
adjustedSpeeds = controller.calculate(
currentRobotPose, goal, Rotation2d.fromDegrees(70.0)
)
Ayarlanmış Hızları Kullanma
Ayarlanan hızlar ChassisSpeeds
tipindedir, bir `` vx ‘’ (ileri yönde doğrusal hız) içerir, a `` vy ‘’ (yan yöndeki doğrusal hız) ve bir `` omega ‘’ (robot çerçevesinin merkezi etrafındaki açısal hız).
Döndürülen ayarlanmış hızlar, aktarma sistemi tipiniz için kinematik sınıfları kullanılarak kullanılabilir hızlara dönüştürülebilir. Aşağıdaki örnek kodda, bir swerve sürücü robotu varsayacağız; bununla birlikte, kinematik kodu, MecanumDriveKinematics
kullanımı haricinde bir mecanum tahrik robotu için tamamen aynıdır.
SwerveModuleState[] moduleStates = kinematics.toSwerveModuleStates(adjustedSpeeds);
SwerveModuleState frontLeft = moduleStates[0];
SwerveModuleState frontRight = moduleStates[1];
SwerveModuleState backLeft = moduleStates[2];
SwerveModuleState backRight = moduleStates[3];
auto [fl, fr, bl, br] = kinematics.ToSwerveModuleStates(adjustedSpeeds);
fl, fr, bl, br = kinematics.toSwerveModuleStates(adjustedSpeeds)
Bu sapma modülü durumları, hala hızlar ve açılar olduğundan; bu hızları ve açıları ayarlamak için PID kontrolcüleri kullanmanız gerekecektir.