Mouse code for the MacroRat
Diff: main.h
- Revision:
- 33:68ce1f74ab5f
- Parent:
- 32:69acb14778ea
- Child:
- 35:a5bd9ef82210
diff -r 69acb14778ea -r 68ce1f74ab5f main.h --- a/main.h Fri May 26 03:46:03 2017 +0000 +++ b/main.h Fri May 26 06:23:19 2017 +0000 @@ -170,22 +170,18 @@ //#define IP_CONSTANT 8.2 //#define II_CONSTANT 0.06 //#define ID_CONSTANT 7.55 - -#define IP_CONSTANT 0.25 -#define II_CONSTANT 0 -#define ID_CONSTANT 0.00 -const int desiredCount180 = 2870; +const int desiredCount180 = 3000; // change accordingly to the terrain const int desiredCountR = 1700; const int desiredCountL = 1700; const int oneCellCount = 5400; -const int oneCellCountMomentum = 4550;//4800; // one cell count is actually approximately 5400, but this value is considering momentum! +const int oneCellCountMomentum = 4570;//4800; // one cell count is actually approximately 5400, but this value is considering momentum! -float receiverOneReading = 0.0; -float receiverTwoReading = 0.0; -float receiverThreeReading = 0.0; -float receiverFourReading = 0.0; +double receiverOneReading = 0.0; +double receiverTwoReading = 0.0; +double receiverThreeReading = 0.0; +double receiverFourReading = 0.0; float ir1base = 0.0; float ir2base = 0.0; @@ -206,7 +202,7 @@ inline void turnLeft() { double speed0 = 0.11; - double speed1 = -0.13; + double speed1 = -0.12; // change back to 0.13 if turns stop working, testing something out! int counter = 0; int initial0 = encoder0.getPulses(); @@ -254,7 +250,7 @@ inline void turnRight() { double speed0 = -0.11; - double speed1 = 0.13; + double speed1 = 0.12; // change back to 0.13 if turns stop working, testing something out! int counter = 0; int initial0 = encoder0.getPulses(); @@ -297,57 +293,10 @@ turnFlag = 0; currDir += 1; } - -inline void turnLeft180() -{ - double speed0 = 0.15; - double speed1 = -0.15; - - int counter = 0; - int initial0 = encoder0.getPulses(); - int initial1 = encoder1.getPulses(); - - int desiredCount0 = initial0 - desiredCountL*2; - int desiredCount1 = initial1 + desiredCountL*2; - - int count0 = initial0; - int count1 = initial1; - - double error0 = count0 - desiredCount0; - double error1 = count1 - desiredCount1; - - - while(1) { - - if(!(abs(error0) < 1) && !(abs(error1) < 1)) { - count0 = encoder0.getPulses(); - count1 = encoder1.getPulses(); - - error0 = count0 - desiredCount0; - error1 = count1 - desiredCount1; - - right_motor.move(speed0); - left_motor.move(speed1); - counter = 0; - } else { - counter++; - right_motor.brake(); - left_motor.brake(); - } - - if (counter > 60) { - break; - } - } - - right_motor.brake(); - left_motor.brake(); - currDir -= 2; -} - + inline void turnRight180() { - double speed0 = -0.16; + double speed0 = -0.15; double speed1 = 0.16; int counter = 0;