PID controlled Linear Slider

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

this is my first project btw..

the code below is very very simple and only controls the speed of the motor, I can't figure out how to control direction, some help or links to similar projects in which I can learn how to get this to work would be helpful.

in the end, im hoping that I will be able to move the gear stick from 1st to 2nd to 3rd to 4th and then back to first again.

#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 the 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 for you Help, i hope i havent broken any rules of this forum, and im sorry if i have....

Why would you need PID?

I imagine that gearstick positions are well defined. I suspect what you need is acceleration and deceleration through a known number of steps. Sounds to me like a job for a stepper motor and the AccelStepper library.

PID only works when there is plenty of time for error and trial.

...R

I'm not 100% sure I do,

I am designing a gearstick durability test, and need to be able to repeat these movements 1000s of times over, therefore I though PID would be the best way. ??

the plan is to use PID or something that would be able to move to a position stay there while the gearstick is placed in and out of gear 100 times and then move to the next position and so on...

this all will need to happen with no human input.

what would you suggest I do??

Thomaswates:
the plan is to use PID or something that would be able to move to a position stay there while the gearstick is placed in and out of gear 100 times

That is confusing.

If you stay in a position how can you move in and out of the position.

I suspect a diagram of the machine you are trying to build would help.

If you mean that you want to move from (say) first gear to neutral and back 100 times and then from second gear to neutral 100 times I can't imagine why you think PID has a role. Maybe you can explain your thinking as I may well be wrong.

Also, moving a gearshift from (say) first gear to neutral 100 times does not seem like a realistic test because most gearboxes are used in a way where they progress up and down the range of gears which introduces all sorts of other stresses on the parts.

...R

Please post a link to the linear actuator data sheet or product page and a wiring diagram. A photo of the setup would probably be helpful.

okay right.. I'm sorry that I don't make much sense, I find it very hard to explain my self in words, so ill start again

I am trying to test the real word durability of the gear stick mechanism it self and not so much the gear box, however because the gearbox gives voltage readings in both x and y direction I thought that I could use this and 2 dc motors. One attached to a slider and the other attached to something else that I haven't worked out yet.

the slider ( which I haven't chosen yet ) will control the Cross gate (x direction ). This is the area of code I am working on, I need the gearstick to move in the cross gate between gears, then stop in the cross gate ready for the Y direction motor to move the gearstick in and out of gear, but for now I am only focusing on the X direction - moving the gear stick in a straight line between 6 different points

I hope this helps you to understand what I am trying to-do.

the hardware I have at the moment is

  • 2xDC motor
  • dual axis voltage feedback ( ranges from 0 to 5v in both x and y )
    -arduino uno
    -L298N motor Controller
  • simple linear slider ( adapted to use one DC motor to move )

I'm not sure what else I need to tell you and I am sorry if I'm still not making sense....

this is all very new to me and for now I have only working on the X direction.

Hi,

Can you tell us your electronics, programming, Arduino, hardware experience?

Before playing with PID, have you got some simple code written that JUST controls your DC motor, that is make it go forward, stop, reverse, stop etc.

You will need to write your code in stages, so forget about PID and just get the motors working, then get the slider input working, by then you may find PID is not needed.

Is the gear pattern the standard H pattern and how many gears?

Also can you please post a copy of your circuit so far with the motors, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Thomaswates:
I am trying to test the real word durability of the gear stick mechanism it self and not so much the gear box, however because the gearbox gives voltage readings in both x and y direction

You need to tell us a lot more about this. What gearbox are you referring to?

It's been a few years since I took a car apart and I don't recall any feedback system from the gearbox. Nor did the gearbox have 6 positions across the gate - only 3 IIRC. I guess a 6-speed box would need 4 cross-positions.

If the gearbox provides a voltage reading to indicate the position of the gear shift lever then what are the voltage readings for each position?

Does the voltage vary smoothly or in discrete jumps?

...R