how to use arduino PID library?
hi
i new arduino programming , want use pid library using motor position encoder, example provided on arduino pid website confusing
my current code :
#include <pid_v1.h>
//define variables we'll connecting to
double setpoint, input, output;
int counta=0;
int last_a;
float error_a, error_int_a, error_calc_a, d_a;
int forward = 9;
int backward = 7;
int pwm = 10;
int directionforward = 5;
int directionbackward = 2;
//specify links , initial tuning parameters
pid mypid(&input, &output, &setpoint,5,0,30, direct);
void setup()
{ //motota
pinmode(pwm, output);
pinmode(forward, output);
pinmode(backward, output);
pinmode(directionbackward , input);
pinmode(directionforward , input);
attachinterrupt(digitalpintointerrupt(directionbackward ), pulsecounta, rising);
serial.begin(19200);
//initialize variables we're linked to
input = digitalread(5);
setpoint = 100;
// setoutputlimits(-255, 255);
//turn pid on
mypid.setmode(automatic);
}
void loop()
{
input = digitalread(5);
mypid.compute();
analogwrite(10,output);
digitalwrite(backward, high);
digitalwrite(forward, low);
serial.print("counta: "); serial.println(counta);
}
but code not performing needed, instead motor runs contieously position 6000 , not stop @ 100.
can please? or share code?
thanks
i new arduino programming , want use pid library using motor position encoder, example provided on arduino pid website confusing
my current code :
#include <pid_v1.h>
//define variables we'll connecting to
double setpoint, input, output;
int counta=0;
int last_a;
float error_a, error_int_a, error_calc_a, d_a;
int forward = 9;
int backward = 7;
int pwm = 10;
int directionforward = 5;
int directionbackward = 2;
//specify links , initial tuning parameters
pid mypid(&input, &output, &setpoint,5,0,30, direct);
void setup()
{ //motota
pinmode(pwm, output);
pinmode(forward, output);
pinmode(backward, output);
pinmode(directionbackward , input);
pinmode(directionforward , input);
attachinterrupt(digitalpintointerrupt(directionbackward ), pulsecounta, rising);
serial.begin(19200);
//initialize variables we're linked to
input = digitalread(5);
setpoint = 100;
// setoutputlimits(-255, 255);
//turn pid on
mypid.setmode(automatic);
}
void loop()
{
input = digitalread(5);
mypid.compute();
analogwrite(10,output);
digitalwrite(backward, high);
digitalwrite(forward, low);
serial.print("counta: "); serial.println(counta);
}
but code not performing needed, instead motor runs contieously position 6000 , not stop @ 100.
can please? or share code?
thanks
also, 1 more question
how use arduino autotune library?
how use arduino autotune library?
Arduino Forum > Using Arduino > Programming Questions > how to use arduino PID library?
arduino
Comments
Post a Comment