Skip to content

Commit b20106b

Browse files
Add code to fix shape drawing algorithm
1 parent 3818724 commit b20106b

File tree

1 file changed

+33
-38
lines changed

1 file changed

+33
-38
lines changed

TrashBot.ino

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
USB Usb;
88
XBOXRECV Xbox(&Usb);
99

10-
//define Pi
10+
//define PI
1111
const float pi = 3.14;
1212

1313
//Variables used to run autonomysly
@@ -351,58 +351,53 @@ void loop() {
351351
if(angle < 360)
352352
{
353353
angle += 30; //value to increase the time the robot turns
354-
numSides = (360 / angle);//sets the number of sides equal to 360 / angle
355354
}
356355
}
357356
if(Xbox.getButtonClick(LEFT,0))
358357
{
359358
if(angle > 0)
360359
{
361360
angle -= 30; //value to decrease the time the robot turns
362-
numSides = (360 / angle);//sets the number of sides equal to 360 / angle
363361
}
364362
}
365363

366364
//the amount of time in mS that it takes to turn by angle degrees
367365
turnTime = angle * angleconstant;
368366
//set the currentMillis counter to the current Clock time
369367
currentMillis = millis();
370-
for(int i = 0; i < numSides; ++i)
371-
{
372368
//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;
406401
}
407402
break;
408403
//uncomment the following code to impliment mode 3

0 commit comments

Comments
 (0)