I have the following problem: as the title says, im trying to control the distance of linear actuator to an object with arduino.
I have a ToF (time of flight) laser distance sensor attached to the head of the actuator to measure the current distance to an object placed infront of the actuator. Also with help of a potentiometer, a value for the target distance can be set.
The goal is that the actuator shaft travel to the distance set by the potentiometer and keep that distance, so if i move the object 1cm to the actuator the actuator retract in 1cm distance, and if i move it away the actuator extends in the same distance the object is moved.
I tried coding it with If and else if statments, so that it retracts when the set value smaller than the measured value and extends if the opposite is true, but the problem is that the actuator extends to the end and retracts to the end and does not stop at the desired distance.
If you have any ideas please help.
Im using BTS7960 as a motor driver and 4 inches high speed linear actuator from firgelli.
Show us how you have this connected to the Arduino and show the code and results when you are using the potentiometer. Is it working as you intend and giving the correct values between 0 and 1023?
upload your code (using code tags </>)
upload a schematic of the circuit
upload output of serial monitor of a run of code
upload a photo of system
what is the ToF sensor ?
What exact sensor? Have you tested just the ToF sensor with some,e code, and observed it supplying plausible values for you exact physical circumstances?
That would be a step one. Without performing successfully such an experiment to go further would be a waste of time.
Unfortunatly i have everything in the lab in my university so i can't show it right now. The potentiometer worked as intended. I even divided 1023 with 10.23 so i can get vlaues in mm (the maximum distance is 10cm).
But isn't that the ToF sensor? I wonder if the problem is that the feedback loop gain and dynamics are wrong - you need to have the speed of movement reduce as the actuator approaches the target distance; and probably have some other smoothing in the loop. So the speed you drive the actuator at will vary with the distance.
Yes, but that only gives the target position. You need to know where the actuator is at all times so you can slow to a stop when close. The ToF tells them where the free object is. Then the sensor on the actuator tells where you are vs where you need to be.
Its NOT going to work without position feedback. Your PID needs to know where it is to know how far/fast to move. Speed profile is trapezoid, stopped, ramp up, fly at speed, ramp down, stopped.
Why not? The one thing has to be a stated distance from the other thing, and to the extent it is not and in which way, the one thing has to move towards or away from the other thing.
I don't quite understand. Why can't i use the VL53L0X ToF sensor as a position feedback sensor. It reads the distance all the time. Do i need an actuator with a built-in position feedback? like a built-in potentiometer or sensors?