feat: turn dec speed

This commit is contained in:
玖叁 2025-01-02 01:05:02 +08:00
parent 10c60159dc
commit 2453391b57
1 changed files with 15 additions and 7 deletions

View File

@ -80,13 +80,20 @@ void TrackingController::update()
float leftSpeed = baseSpeed; float leftSpeed = baseSpeed;
float rightSpeed = baseSpeed; float rightSpeed = baseSpeed;
if (offset != 0) if (offset != 0) {
{ // 在大偏移时降低基础速度
float speedFactor = 1.0f;
if (abs(offset) > 1.0f) {
speedFactor = 0.7f;
leftSpeed *= speedFactor;
rightSpeed *= speedFactor;
}
// 根据偏移量调整左右轮速度 // 根据偏移量调整左右轮速度
float speedDiff = baseSpeed * (abs(offset) / 2.0f); // 最大差速为基础速度的一半 float speedDiff = baseSpeed * (abs(offset) / 2.0f) * speedFactor; // 差速也要相应降低
// 增加最小速度差以确保能够转向 // 增加最小速度差以确保能够转向
float minSpeedDiff = baseSpeed * 0.5f; // 最小速度差为基础速度的10% float minSpeedDiff = baseSpeed * 0.5f * speedFactor; // 最小速度差也要相应降低
if (speedDiff < minSpeedDiff) if (speedDiff < minSpeedDiff)
{ {
speedDiff = minSpeedDiff; speedDiff = minSpeedDiff;
@ -106,8 +113,9 @@ void TrackingController::update()
} }
// 确保速度不超过限制 // 确保速度不超过限制
leftSpeed = constrain(leftSpeed, -baseSpeed, baseSpeed); float maxSpeed = baseSpeed * speedFactor; // 最大速度也要相应降低
rightSpeed = constrain(rightSpeed, -baseSpeed, baseSpeed); leftSpeed = constrain(leftSpeed, -maxSpeed, maxSpeed);
rightSpeed = constrain(rightSpeed, -maxSpeed, maxSpeed);
} }
// 调试信息 // 调试信息