diff --git a/pid-example/pid-example.ino b/pid-example/pid-example.ino index 3c2eb5e..f99f944 100644 --- a/pid-example/pid-example.ino +++ b/pid-example/pid-example.ino @@ -4,9 +4,9 @@ QTRSensors qtr; const uint8_t SensorCount = 8; uint16_t sensorValues[SensorCount]; -float Kp = 0.085; //set up the constants value -float Ki = 0.00004; -float Kd = 0.66; +float Kp = 0.1; //set up the constants value +float Ki = 0; +float Kd = 0.5; int P; int I; int D; @@ -17,8 +17,8 @@ boolean onoff = false; //Increasing the maxspeed can damage the motors - at a value of 255 the 6V motors will receive 7,4 V const uint8_t maxspeeda = 150; const uint8_t maxspeedb = 150; -const uint8_t basespeeda = 120; -const uint8_t basespeedb = 120; +const uint8_t basespeeda = 100; +const uint8_t basespeedb = 100; // adding minspeed so it can reverse const int minspeeda = -150; @@ -74,7 +74,7 @@ void calibration() { void loop() { if(digitalRead(buttonstart) == HIGH) { onoff =! onoff; - if(onoff = true) { + if(onoff == true) { delay(1000);//a delay when the robot starts } else { @@ -114,16 +114,23 @@ void speedcontrol(int mota, int motb) { forward_brake(mota, motb); } if (mota < 0 && motb >= 0) { - //dreapta + mota = 0 - mota; right_brake(mota, motb); } if (mota >= 0 && motb < 0) { - //stanga + motb = 0 - motb; left_brake(mota, motb); } + if (mota < 0 && motb < 0) { + // both reversing — clamp or handle as a pivot/brake depending on your track + mota = -mota; + motb = -motb; + // e.g. sharp spin: one motor forward, one back + right_brake(mota, motb); // or left_brake, or forward_brake(0,0) to just brake + } } void PID_control() {