Refactor RobotDrive squaring (#390)

This commit is contained in:
Austin Shalit
2017-05-07 09:40:48 -07:00
committed by Peter Johnson
parent d348a5b947
commit 4dae747343
3 changed files with 27 additions and 55 deletions

View File

@@ -312,21 +312,14 @@ void RobotDrive::TankDrive(double leftValue, double rightValue,
reported = true;
}
// square the inputs (while preserving the sign) to increase fine control
// while permitting full power
leftValue = Limit(leftValue);
rightValue = Limit(rightValue);
// square the inputs (while preserving the sign) to increase fine control
// while permitting full power
if (squaredInputs) {
if (leftValue >= 0.0) {
leftValue = (leftValue * leftValue);
} else {
leftValue = -(leftValue * leftValue);
}
if (rightValue >= 0.0) {
rightValue = (rightValue * rightValue);
} else {
rightValue = -(rightValue * rightValue);
}
leftValue = std::copysign(leftValue * leftValue, leftValue);
rightValue = std::copysign(rightValue * rightValue, rightValue);
}
SetLeftRightMotorOutputs(leftValue, rightValue);
@@ -443,19 +436,11 @@ void RobotDrive::ArcadeDrive(double moveValue, double rotateValue,
moveValue = Limit(moveValue);
rotateValue = Limit(rotateValue);
// square the inputs (while preserving the sign) to increase fine control
// while permitting full power
if (squaredInputs) {
// square the inputs (while preserving the sign) to increase fine control
// while permitting full power
if (moveValue >= 0.0) {
moveValue = (moveValue * moveValue);
} else {
moveValue = -(moveValue * moveValue);
}
if (rotateValue >= 0.0) {
rotateValue = (rotateValue * rotateValue);
} else {
rotateValue = -(rotateValue * rotateValue);
}
moveValue = std::copysign(moveValue * moveValue, moveValue);
rotateValue = std::copysign(rotateValue * rotateValue, rotateValue);
}
if (moveValue > 0.0) {
@@ -625,14 +610,14 @@ void RobotDrive::SetLeftRightMotorOutputs(double leftOutput,
/**
* Limit motor values to the -1.0 to +1.0 range.
*/
double RobotDrive::Limit(double num) {
if (num > 1.0) {
double RobotDrive::Limit(double number) {
if (number > 1.0) {
return 1.0;
}
if (num < -1.0) {
if (number < -1.0) {
return -1.0;
}
return num;
return number;
}
/**