Reduce scope of for loop variables to for loop initializer (#517)

This commit is contained in:
Chris Gregory
2017-05-06 23:15:34 -07:00
committed by Fred Silberberg
parent dbe821baee
commit a5cd24e7ea
8 changed files with 42 additions and 51 deletions

View File

@@ -633,13 +633,12 @@ double RobotDrive::Limit(double num) {
*/
void RobotDrive::Normalize(double* wheelSpeeds) {
double maxMagnitude = std::fabs(wheelSpeeds[0]);
int i;
for (i = 1; i < kMaxNumberOfMotors; i++) {
for (int i = 1; i < kMaxNumberOfMotors; i++) {
double temp = std::fabs(wheelSpeeds[i]);
if (maxMagnitude < temp) maxMagnitude = temp;
}
if (maxMagnitude > 1.0) {
for (i = 0; i < kMaxNumberOfMotors; i++) {
for (int i = 0; i < kMaxNumberOfMotors; i++) {
wheelSpeeds[i] = wheelSpeeds[i] / maxMagnitude;
}
}