Go Down

Topic: Precise control of a linear actuator (Read 977 times) previous topic - next topic

Smiles79

Hey all,

So I have an Arduino Mega reading in an inclinometer and controlling a linear actuator accordingly. It's a pretty simple linear actuator (a couple leads for power and a couple for the closed-loop position  feedback) so I'm not sure that I can use a servo-specific library.

I understand how to read in sensors and potentiometers and whatnot, but my question is how to get the actuator to move to a specific location. My original idea is as follows:

if (currentPosition < desiredPosition) {
  digitalWrite(upPin,LOW); //with the relay i'm using, writing the pin low activates the relay
  digitalWrite(downPin,HIGH);
}

if (currentPosition > desiredPosition) {
  digitalWrite(upPin,HIGH);
  digitalWrite(downPin,LOW);
}

if (currentPosition == desiredPosition) {
  digitalWrite(upPin,HIGH);
  digitalWrite(downPin,HIGH);

I figure there has to be a better way than this. Any help would be greatly appreciated.

Thanks!

keeper63

Well - that's a basic way - except you neglected to add a "dead band"; whether you'll need it will depend on where "currentPosition" is coming from. For example, if you are reading an analog potentiometer, it is very well possible that you won't land on the same "number" twice (if you understand what I mean). Whereas if you were using an absolute digital encoder, then it might be possible for you to land on the same number.

So - in the event that your position sensor isn't repeatably accurate - you need to introduce a deadband into your code - basically, a "window of values" (some percentage) "around" your "desiredPosition" value; something like:

Code: [Select]

if (currentPosition < desiredPosition + deadBand) {
  digitalWrite(upPin,LOW); //with the relay i'm using, writing the pin low activates the relay
  digitalWrite(downPin,HIGH);
}

if (currentPosition > desiredPosition - deadBand) {
  digitalWrite(upPin,HIGH);
  digitalWrite(downPin,LOW);
}

if (currentPosition <= desiredPosition + deadBand && currentPosition >= desiredPosition - deadBand) {
  digitalWrite(upPin,HIGH);
  digitalWrite(downPin,HIGH);
}


Of course, with such code if your desired position remains inside the window, the current position won't change.

The better way is to implement a PID algorithm; you can either use one of various libraries for the Arduino (there is a standard one, and there are many variants out there too) - or you can incorporate portions of the PID algorithm (or the whole thing) with your own functions. Given the speed of most linear actuators (ie - slow), a full PID algorithm likely isn't needed, but YMMV.
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

shooter

with relais you will not get a high precision, as they cn not cope with a PWM signal, how is the actuator inside? what motor is used.
maybe a SSR can help you. and as stated above it will need a PID control.

paul deelen
shooter@home.nl
making controls with codesys PLC and arduino

Go Up