|
@@ -25,6 +25,7 @@ int dirs_pin[2] = {4, 7};
|
|
|
|
|
|
int threshold = 30 ;
|
|
|
|
|
|
+int manualMaxSpeed = 1024 ;
|
|
|
const int maxSpeed_pin = A0;
|
|
|
const int driftCorrection_pin = A1 ;
|
|
|
int maxSpeed = 1024;
|
|
@@ -62,11 +63,13 @@ Serial.begin(9600); // Pour a bowl of Serial (for debugging)
|
|
|
|
|
|
void loop() {
|
|
|
|
|
|
- //Read and scale analog inputs
|
|
|
+// Read and scale analog inputs
|
|
|
// maxSpeed = map (analogRead(maxSpeed_pin), 0, 1024, 0, 255);
|
|
|
+ maxSpeed = manualMaxSpeed ;
|
|
|
// driftCorrection = analogRead(driftCorrection_pin) ;
|
|
|
-// driftCorrection = driftCorrection / 512 - 1 ; // -1..1
|
|
|
-// driftCorrection *= 0.5 ;
|
|
|
+ driftCorrection = 511 ;
|
|
|
+ driftCorrection = driftCorrection / 512 - 1 ; // -1..1
|
|
|
+ driftCorrection *= 0.5 ;
|
|
|
|
|
|
Serial.print("maxSpeed:"); //Serial debugging stuff
|
|
|
Serial.println(maxSpeed);
|
|
@@ -79,6 +82,14 @@ void loop() {
|
|
|
ch2 = pulseIn(ch2_pin, HIGH, 25000); // each channel
|
|
|
ch1 = middleThreshold(ch1, threshold);
|
|
|
ch2 = middleThreshold(ch2, threshold);
|
|
|
+ if(ch1 == 0) {ch1 = 1500;}
|
|
|
+ if(ch2 == 0) {ch2 = 1500;}
|
|
|
+
|
|
|
+ Serial.print("ch1:"); //Serial debugging stuff
|
|
|
+ Serial.println(ch1);
|
|
|
+
|
|
|
+ Serial.print("ch2:"); //Serial debugging stuff
|
|
|
+ Serial.println(ch2);
|
|
|
|
|
|
//Refresh and scale raw move values
|
|
|
move = map(ch2, 1000,2000, -255, 255); //center over zero
|
|
@@ -96,15 +107,18 @@ void loop() {
|
|
|
int speeds[2] = {0, 0} ;
|
|
|
|
|
|
int Dir = move>0 ? 1 : 0;
|
|
|
- move = min( abs(move), maxSpeed) ;
|
|
|
+// move = min( abs(move), maxSpeed) ;
|
|
|
+ move = abs(move);
|
|
|
turn = constrain(turn, -move, move);
|
|
|
|
|
|
if (turn>0) { speeds[0] = move; speeds[1] = move - turn ; }
|
|
|
if (turn<=0) { speeds[0] = move + turn ; speeds[1] = move ; }
|
|
|
|
|
|
- if (driftCorrection>0) { speeds[0] *= 1-driftCorrection ; }
|
|
|
- if (driftCorrection<=0) { speeds[1] *= 1+driftCorrection ; }
|
|
|
+// if (driftCorrection>0) { speeds[0] *= 1-driftCorrection ; }
|
|
|
+// if (driftCorrection<=0) { speeds[1] *= 1+driftCorrection ; }
|
|
|
//
|
|
|
+
|
|
|
+
|
|
|
Serial.print("speeds: "); //Serial debugging stuff
|
|
|
Serial.print(speeds[0]);
|
|
|
Serial.print(" - ");
|