|
7 | 7 | USB Usb; |
8 | 8 | XBOXRECV Xbox(&Usb); |
9 | 9 |
|
10 | | -//define Pi |
| 10 | +//define PI |
11 | 11 | const float pi = 3.14; |
12 | 12 |
|
13 | 13 | //Variables used to run autonomysly |
@@ -351,58 +351,53 @@ void loop() { |
351 | 351 | if(angle < 360) |
352 | 352 | { |
353 | 353 | angle += 30; //value to increase the time the robot turns |
354 | | - numSides = (360 / angle);//sets the number of sides equal to 360 / angle |
355 | 354 | } |
356 | 355 | } |
357 | 356 | if(Xbox.getButtonClick(LEFT,0)) |
358 | 357 | { |
359 | 358 | if(angle > 0) |
360 | 359 | { |
361 | 360 | angle -= 30; //value to decrease the time the robot turns |
362 | | - numSides = (360 / angle);//sets the number of sides equal to 360 / angle |
363 | 361 | } |
364 | 362 | } |
365 | 363 |
|
366 | 364 | //the amount of time in mS that it takes to turn by angle degrees |
367 | 365 | turnTime = angle * angleconstant; |
368 | 366 | //set the currentMillis counter to the current Clock time |
369 | 367 | currentMillis = millis(); |
370 | | - for(int i = 0; i < numSides; ++i) |
371 | | - { |
372 | 368 | //run this statment as long as the function has run less time than the alooted time via straightTime variable |
373 | | - if ((currentMillis - previousMillis) <= straightTime) |
374 | | - { |
375 | | - //Enable motors, set them to forward, and half speed |
376 | | - rightMotorGo = true; |
377 | | - leftMotorGo = true; |
378 | | - rightMotorForward = true; |
379 | | - rightMotorSpeed = 125; |
380 | | - leftMotorForward = true; |
381 | | - leftMotorSpeed = 125; |
382 | | - //run the tankDrive Function; |
383 | | - tankDrive(); |
384 | | - } |
385 | | - //run this statment as long as the function has surpased straight time, but is less than turnTime + straght Time |
386 | | - else if ((currentMillis - previousMillis) <= (straightTime + turnTime)) |
387 | | - { |
388 | | - //Enalbes Motors, turns left, and half speed |
389 | | - rightMotorGo = true; |
390 | | - leftMotorGo = true; |
391 | | - rightMotorForward = true; |
392 | | - rightMotorSpeed = 125; |
393 | | - leftMotorForward = false; |
394 | | - leftMotorSpeed = 125; |
395 | | - //run tankDrive Function |
396 | | - tankDrive(); |
397 | | - } |
398 | | - else |
399 | | - { |
400 | | - //Stop the motors |
401 | | - rightMotorGo = false; |
402 | | - leftMotorGo = false; |
403 | | - //set the previousMillis counter to that of the currentMills counter to run the loop again |
404 | | - previousMillis = currentMillis; |
405 | | - } |
| 369 | + if ((currentMillis - previousMillis) <= straightTime) |
| 370 | + { |
| 371 | + //Enable motors, set them to forward, and half speed |
| 372 | + rightMotorGo = true; |
| 373 | + leftMotorGo = true; |
| 374 | + rightMotorForward = true; |
| 375 | + rightMotorSpeed = 125; |
| 376 | + leftMotorForward = true; |
| 377 | + leftMotorSpeed = 125; |
| 378 | + //run the tankDrive Function; |
| 379 | + tankDrive(); |
| 380 | + } |
| 381 | + //run this statment as long as the function has surpased straight time, but is less than turnTime + straght Time |
| 382 | + else if ((currentMillis - previousMillis) <= (straightTime + turnTime)) |
| 383 | + { |
| 384 | + //Enalbes Motors, turns left, and half speed |
| 385 | + rightMotorGo = true; |
| 386 | + leftMotorGo = true; |
| 387 | + rightMotorForward = true; |
| 388 | + rightMotorSpeed = 125; |
| 389 | + leftMotorForward = false; |
| 390 | + leftMotorSpeed = 125; |
| 391 | + //run tankDrive Function |
| 392 | + tankDrive(); |
| 393 | + } |
| 394 | + else |
| 395 | + { |
| 396 | + //Stop the motors |
| 397 | + rightMotorGo = false; |
| 398 | + leftMotorGo = false; |
| 399 | + //set the previousMillis counter to that of the currentMills counter to run the loop again |
| 400 | + previousMillis = currentMillis; |
406 | 401 | } |
407 | 402 | break; |
408 | 403 | //uncomment the following code to impliment mode 3 |
|
0 commit comments