Should I use if, while or boolean statement

Hi,

I have a setup to control the position of 3 linear actuators. I have three rotary potentiometers that I use to request a position for each motor. Each motor has a potentiometer inside.

Currently I am using three if statements saying:

if the motor has a higher position than the requested position, move the motor in

else if the motor has a lower position that the requested position, move the motor out

else, do nothing

The sketch does work but I have the issue that the motors can over shoot and go past their requested position.

This has me thinking whether using the if statement is the correct thing to do. I think that what is happening is that if a motor needs to be moved then it engages the motors movements. The sketch then goes onto the next two if statements and then back to the original. At this point it has over shot and if now requesting the else

Show us the code.

lparry92:
The sketch then goes onto the next two if statements and then back to the original. At this point it has over shot and if now requesting the else

That depends on what else is in the loop. If it is just that if / else-if / else then it doesn't run any other statements. Because they are "else" to the first if, it would return immediately after telling the motor to move and run that same statement again. We're talking about nanoseconds here. That's not your problem.

It may just be that the inertia of the actuator carries it a little past the position when you turn it off. Perhaps you should turn it off a little before it gets there. Or maybe you have a code problem. Nobody can tell because you've given us the symptom but not the patient. We don't know anything about your code, the motors, the actuators, how it's built, wired, or anything. You gotta give us something to go on.

OP seems to have decided to post the same again. I'll read there. Looks like it has code.

SMDH: http://forum.arduino.cc/index.php?topic=526670.0