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

@ -79,14 +79,21 @@ void TrackingController::update()
// 计算基础速度和转向调整
float leftSpeed = baseSpeed;
float rightSpeed = baseSpeed;
if (offset != 0) {
// 在大偏移时降低基础速度
float speedFactor = 1.0f;
if (abs(offset) > 1.0f) {
speedFactor = 0.7f;
leftSpeed *= speedFactor;
rightSpeed *= speedFactor;
}
if (offset != 0)
{
// 根据偏移量调整左右轮速度
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)
{
speedDiff = minSpeedDiff;
@ -106,8 +113,9 @@ void TrackingController::update()
}
// 确保速度不超过限制
leftSpeed = constrain(leftSpeed, -baseSpeed, baseSpeed);
rightSpeed = constrain(rightSpeed, -baseSpeed, baseSpeed);
float maxSpeed = baseSpeed * speedFactor; // 最大速度也要相应降低
leftSpeed = constrain(leftSpeed, -maxSpeed, maxSpeed);
rightSpeed = constrain(rightSpeed, -maxSpeed, maxSpeed);
}
// 调试信息