Mouse code for the MacroRat
Diff: main.h
- Revision:
- 37:3dcc95e9321c
- Parent:
- 36:9c4cc9944b69
- Child:
- 38:fe05f93009a2
diff -r 9c4cc9944b69 -r 3dcc95e9321c main.h --- a/main.h Sat May 27 02:40:10 2017 +0000 +++ b/main.h Sat May 27 03:37:24 2017 +0000 @@ -172,12 +172,12 @@ //#define II_CONSTANT 0.06 //#define ID_CONSTANT 7.55 -const int desiredCount180 = 3200; // change accordingly to the terrain +const int desiredCount180 = 3400; // change accordingly to the terrain const int desiredCountR = 1600; const int desiredCountL = 1590; const int oneCellCount = 5400; -const int oneCellCountMomentum = 4800;//4570 (.15) speed;//4800; // one cell count is actually approximately 5400, but this value is considering momentum! +const int oneCellCountMomentum = 4900;//4570 (.15) speed;//4800; // one cell count is actually approximately 5400, but this value is considering momentum! double receiverOneReading = 0.0; double receiverTwoReading = 0.0; @@ -198,7 +198,7 @@ double speed0 = 0.11; double speed1 = -0.12; // change back to 0.13 if turns stop working, testing something out! - double kp = 0.000085; + double kp = 0.000080; int counter = 0; int initial0 = encoder0.getPulses(); @@ -221,9 +221,7 @@ error0 = desiredCount0 - count0; // is negative error1 = desiredCount1 - count1; // is positive - - //serial.printf("%f, %f\n", error0, error1 ); - + right_motor.move(error1*kp); left_motor.move(error0*kp); counter = 0; @@ -232,7 +230,6 @@ right_motor.brake(); left_motor.brake(); } - if (counter > 60) { break; } @@ -274,8 +271,6 @@ error0 = desiredCount0 - count0; // is positive error1 = desiredCount1 - count1; // is negative - //serial.printf("%f, %f\n", error0, error1 ); - right_motor.move(error1*kp); left_motor.move(error0*kp); counter = 0; @@ -284,7 +279,6 @@ right_motor.brake(); left_motor.brake(); } - if (counter > 60) { break; } @@ -298,8 +292,10 @@ inline void turn180() { - double speed0 = -0.15; - double speed1 = 0.16; + double speed0 = -0.10; + double speed1 = 0.11; + + double kp = 0.000055; int counter = 0; int initial0 = encoder0.getPulses(); @@ -314,25 +310,23 @@ double error0 = count0 - desiredCount0; double error1 = count1 - desiredCount1; - while(1) { - if(!(abs(error0) < 1) && !(abs(error1) < 1)) { + if(!(abs(error0) < 3) && !(abs(error1) < 3)) { count0 = encoder0.getPulses(); count1 = encoder1.getPulses(); - error0 = count0 - desiredCount0; - error1 = count1 - desiredCount1; + error0 = desiredCount0 - count0; + error1 = desiredCount1 - count1; - right_motor.move(speed0); - left_motor.move(speed1); + right_motor.move(error1*kp); + left_motor.move(error0*kp); counter = 0; } else { counter++; right_motor.brake(); left_motor.brake(); } - if (counter > 60) { break; }