I am using a DC motor which is connected to a spindle combined with a string potentiometer for positional feedback. I want to be able to move the motor to a predefined position and use acceleration and deceleration to get there. The speed of the motor will be controlled with a PWM signal.
Programming this all be myself would be possible, but I am sure there is already a library to do that, which will be a much easier and probably a more reliable solution. But so far I was only able to find libraries for stepper motors or servo motors. Or could I use a library for servo motors? If so, which one would be best suited for my task?
That is a specific use of the DC motor. I have not heard of such a library.
There are continuous servo motors that can set the speed, but that would make it unnecessary complex. You might have to write the code yourself.
Can the motor go forward and backward ? Do yo have a direction signal + pwm signal ?
Linear acceleration and deacceleration ? I think that is good enough.
So there is a maximum speed and the steepness of the ramp.
With a ramp, you need timing.
Do you have an idea how to do the timing ? millis ?
How often do you want to change the PWM value ?
It is easy for a led, since the human eye is slow, so 10Hz...50Hz update is good. I used 25Hz here (the Uno has a PWM of about 500Hz).
It is also easy for a servo motor, their position is often changed every 10ms or 20ms. I used 10ms here.
A analog input has noise. You can take the average of a number of analogRead() and perhaps a little low-pass filter in software. If there are vibrations because of the motor, then a low-pass filter should solve those problems.
I suggest to use a value of 0...1 or 0...100% as a floating point number for the position. Then the sketch is easy to read.
[ADDED] A PID control for the motor might be possible, but that also needs tuning and I think that overshoot is really bad.
Yes, the motor can go forward and backward. I plan to use the Pololu G2 Motor Driver, they have a PWM and DIR pin.
Linear acceleration and deceleration should be fine, I don't need any complex acceleration curves.
I plan to use millis for the timing, but I am not sure yet how often I want to change the PWM value. The idea so far is to start with a PWM signal of 0 and then increase it in every cycle by 1 until I reach the maximum value (255 or maybe a bit less).
But then I still have to figure out when I should start to decelerate and also make sure that I can actually reach the maximum velocity, or otherwise stop accelerating, so I have enough time to decelerate again.
You use a PID controller library to provide a feedback loop - the potentiometer reading provides the current position, compare this to a set point as the inputs to the PID, and the PID output is converter into a drive signal for the motor driver in question.
PID loops are standard components of motion control systems.
Thanks for the suggestion. However I do not fully understand how to do that in practice. All the examples I found online used an encoder for measuring the rotations of the motor, and I am not sure how to apply this to my setup with the potentiometer for absolute positional measurements. Do you maybe have a short example?
Here is a demo code that will position a gear motor connected to a (string) pot to a position controlled by another pot. It is a simple proportional only control. The string pot is the feedback element and the control pot the control element. No acceleration though. I leave that to you.
Thanks for the responses so far! I thought the explanation in the first post was understandable but now I see how this can be interpreted in different ways.
For better understanding how a string potentiometer works:
The end of the string potentiometer is connected to a "gantry" that is moving back and forth. The potentiometer then outputs different analog values according to the position of the gantry. I want to send a value/position to the microcontroller and then move the gantry to this position by comparing the value I sent with the analog value from the potentiometer. While also accelerating and decelerating. I think I now have an idea of how it could work with PID control.