Change the P and D values
This commit is contained in:
parent
b335a6ef96
commit
9134fe0440
1 changed files with 15 additions and 8 deletions
|
|
@ -4,9 +4,9 @@ QTRSensors qtr;
|
||||||
const uint8_t SensorCount = 8;
|
const uint8_t SensorCount = 8;
|
||||||
uint16_t sensorValues[SensorCount];
|
uint16_t sensorValues[SensorCount];
|
||||||
|
|
||||||
float Kp = 0.085; //set up the constants value
|
float Kp = 0.1; //set up the constants value
|
||||||
float Ki = 0.00004;
|
float Ki = 0;
|
||||||
float Kd = 0.66;
|
float Kd = 0.5;
|
||||||
int P;
|
int P;
|
||||||
int I;
|
int I;
|
||||||
int D;
|
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
|
//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 maxspeeda = 150;
|
||||||
const uint8_t maxspeedb = 150;
|
const uint8_t maxspeedb = 150;
|
||||||
const uint8_t basespeeda = 120;
|
const uint8_t basespeeda = 100;
|
||||||
const uint8_t basespeedb = 120;
|
const uint8_t basespeedb = 100;
|
||||||
|
|
||||||
// adding minspeed so it can reverse
|
// adding minspeed so it can reverse
|
||||||
const int minspeeda = -150;
|
const int minspeeda = -150;
|
||||||
|
|
@ -74,7 +74,7 @@ void calibration() {
|
||||||
void loop() {
|
void loop() {
|
||||||
if(digitalRead(buttonstart) == HIGH) {
|
if(digitalRead(buttonstart) == HIGH) {
|
||||||
onoff =! onoff;
|
onoff =! onoff;
|
||||||
if(onoff = true) {
|
if(onoff == true) {
|
||||||
delay(1000);//a delay when the robot starts
|
delay(1000);//a delay when the robot starts
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -114,16 +114,23 @@ void speedcontrol(int mota, int motb) {
|
||||||
forward_brake(mota, motb);
|
forward_brake(mota, motb);
|
||||||
}
|
}
|
||||||
if (mota < 0 && motb >= 0) {
|
if (mota < 0 && motb >= 0) {
|
||||||
//dreapta
|
|
||||||
mota = 0 - mota;
|
mota = 0 - mota;
|
||||||
right_brake(mota, motb);
|
right_brake(mota, motb);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (mota >= 0 && motb < 0) {
|
if (mota >= 0 && motb < 0) {
|
||||||
//stanga
|
|
||||||
motb = 0 - motb;
|
motb = 0 - motb;
|
||||||
left_brake(mota, 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() {
|
void PID_control() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue