|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 4; i++) |
|
|
for(int i = 0; i < 4; i++) |
|
|
{ |
|
|
{ |
|
|
motors[i] *= maxSpeed; |
|
|
|
|
|
|
|
|
motors[i] *= factor; |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(mtx); |
|
|
std::unique_lock<std::mutex> lock(mtx); |
|
|
double rotationRatio = ratio(angle); |
|
|
double rotationRatio = ratio(angle); |
|
|
rotate(rotationRatio); |
|
|
rotate(rotationRatio); |
|
|
drive(1.0-rotationRatio); |
|
|
|
|
|
|
|
|
drive(1.0-std::fabs(rotationRatio)); |
|
|
unit(); |
|
|
unit(); |
|
|
adjustSpeed(); |
|
|
adjustSpeed(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
double maxAngularSpeed = 1.0; |
|
|
double maxAngularSpeed = 1.0; |
|
|
double speedRange = maxAngularSpeed - minAngularSpeed; |
|
|
double speedRange = maxAngularSpeed - minAngularSpeed; |
|
|
|
|
|
|
|
|
double minAngle = -90.0; |
|
|
|
|
|
double maxAngle = 90.0; |
|
|
|
|
|
|
|
|
double minAngle = -20.0; |
|
|
|
|
|
double maxAngle = 20.0; |
|
|
double angularRange = maxAngle - minAngle; |
|
|
double angularRange = maxAngle - minAngle; |
|
|
|
|
|
|
|
|
|
|
|
if(angle < minAngle) |
|
|
|
|
|
{ |
|
|
|
|
|
angle = minAngle; |
|
|
|
|
|
} |
|
|
|
|
|
if(angle > maxAngle) |
|
|
|
|
|
{ |
|
|
|
|
|
angle = maxAngle; |
|
|
|
|
|
} |
|
|
double progress = angle - minAngle; |
|
|
double progress = angle - minAngle; |
|
|
double progressPercent = progress/angularRange; |
|
|
double progressPercent = progress/angularRange; |
|
|
|
|
|
|
|
|
double speed = minAngularSpeed + progressPercent*speedRange; |
|
|
double speed = minAngularSpeed + progressPercent*speedRange; |
|
|
return std::fabs(speed); |
|
|
|
|
|
|
|
|
return speed; |
|
|
} |
|
|
} |