Update steering and also update Kp
This commit is contained in:
		
							parent
							
								
									576f4a8293
								
							
						
					
					
						commit
						33611fcfb1
					
				
					 1 changed files with 35 additions and 4 deletions
				
			
		|  | @ -4,9 +4,9 @@ QTRSensors qtr; | |||
| const uint8_t SensorCount = 8; | ||||
| uint16_t sensorValues[SensorCount]; | ||||
| 
 | ||||
| float Kp = 0.09;//set up the constants value
 | ||||
| float Kp = 0.093;//set up the constants value
 | ||||
| float Ki = 0.0008; | ||||
| float Kd = 0.34; | ||||
| float Kd = 0.6; | ||||
| int P; | ||||
| int I; | ||||
| int D; | ||||
|  | @ -95,7 +95,38 @@ void forward_brake(int posa, int posb) { | |||
|   analogWrite(aenbl, posa); | ||||
|   analogWrite(benbl, posb); | ||||
| } | ||||
| void PID_control() { | ||||
| 
 | ||||
| void left_brake(int posa, int posb) { | ||||
|   digitalWrite(aphase, LOW); | ||||
|   digitalWrite(bphase, LOW); | ||||
|   analogWrite(aenbl, posa); | ||||
|   analogWrite(benbl, posb); | ||||
| } | ||||
| void right_brake(int posa, int posb) { | ||||
|   digitalWrite(aphase, HIGH); | ||||
|   digitalWrite(bphase, HIGH); | ||||
|   analogWrite(aenbl, posa); | ||||
|   analogWrite(benbl, posb); | ||||
| } | ||||
| 
 | ||||
| void speedcontrol(int mota, int motb) { | ||||
|   if (mota >= 0 && motb >= 0) { | ||||
|     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); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void PID_control() {   | ||||
|   uint16_t position = qtr.readLineBlack(sensorValues); | ||||
|   int error = 3500 - position; | ||||
| 
 | ||||
|  | @ -121,5 +152,5 @@ void PID_control() { | |||
|     motorspeedb = minspeedb; | ||||
|   }  | ||||
|   //Serial.print(motorspeeda);Serial.print(" ");Serial.println(motorspeedb);
 | ||||
|   forward_brake(motorspeeda, motorspeedb); | ||||
|   speedcontrol(motorspeeda, motorspeedb); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue