nouvvelle version du code servostrap

master
Vincent MERIL 9 years ago
parent 3fa09f41be
commit 1165a683e2

@ -42,9 +42,9 @@ https://github.com/danithebest91/ServoStrap
// ------------- CONSTANTE DU PID ------------- // ------------- CONSTANTE DU PID -------------
float KP = 5 ; //Porportionnel float KP = 3 ; //Porportionnel
float KI = 0.1; // Intergrale float KI = 2; // Intergrale
float KD = 2.0; // derive float KD = 15; // derive
// ------------- CONSTANTE DU PID ------------- // ------------- CONSTANTE DU PID -------------
@ -70,9 +70,9 @@ long previousMillis = 0; // will store last time LED was updated
long interval = 5; // interval at which to blink (milliseconds) long interval = 5; // interval at which to blink (milliseconds)
//for motor control ramps 1.4 //for motor control ramps 1.4
bool newStep = false; //bool newStep = false;
bool oldStep = false; //bool oldStep = false;
bool dir = false; //bool dir = false;
void setup() { void setup() {
pinModeFast(2, INPUT); pinModeFast(2, INPUT);
@ -188,6 +188,8 @@ void docalc() {
} else if(sumError < iMin){ } else if(sumError < iMin){
sumError = iMin; sumError = iMin;
} }
Serial.println(motorspeed);
if(motorspeed > 0){ if(motorspeed > 0){
if( motorspeed >= 255) motorspeed=255; if( motorspeed >= 255) motorspeed=255;
@ -226,15 +228,19 @@ void doEncoderMotor0(){
else { else {
encoder0Pos-- ; // CCW encoder0Pos-- ; // CCW
} }
} }
} }
void countStep(){ void countStep(){
//dir=digitalRead(DIR_PIN)==HIGH; //dir=digitalRead(DIR_PIN)==HIGH;
dir = (PINC&B0000001); // dir=digitalRead(dir_pin) read PC0, 14 digital; //dir = (PINC&B0000001); // dir=digitalRead(dir_pin) read PC0, 14 digital;
//here will be (PINB&B0000001) to not use shift in the stable version //here will be (PINB&B0000001) to not use shift in the stable version
if (dir) target1++; if (PINC&B0000001) {
else target1--; target1++;
}
else
{
target1--;
}
} }
Loading…
Cancel
Save