PID controlled Linear Slider


a little bit of background - im trying use motorized linear slider attached gearstick move gearstick different positions.

this first project btw..

the code below very simple , controls speed of motor, can't figure out how control direction, or links similar projects in can learn how work helpful.

in end, im hoping able move gear stick 1st 2nd 3rd 4th , first again.


code: [select]
#include <pid_v1.h>

double input, output;
double setpoint1;
double setpoint2;
pid mypid1(&input, &output, &setpoint1, 2, 0.05, 1, direct);
pid mypid2(&input, &output, &setpoint2, 2, 0.05, 1, direct);
void setup()
{
  //iinitialize variables we're linked to//
  input = analogread(0);
  setpoint1 = 250;
  setpoint2 = 500;

  //turn pid on //
  mypid1.setmode(automatic);
  mypid2.setmode(automatic);
  serial.begin(9600);
}

void loop()
{
  do{
    input = analogread(0);
  mypid1.compute();
  analogwrite(3, output);
  }while(input!=setpoint1);

  do{
    input = analogread(0);
    mypid2.compute();
    analogwrite(3,output);
  }while(input!=setpoint2);
}



thanks help, hope havent broken rules of forum, , im sorry if have....

why need pid?

i imagine gearstick positions defined. suspect need acceleration , deceleration through known number of steps. sounds me job stepper motor , accelstepper library.

pid works when there plenty of time error , trial.

...r


Arduino Forum > Using Arduino > Project Guidance > PID controlled Linear Slider


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???