PID for variable Setpoint : your advice

Before asking my question, allow me to briefly present my project in order to make me understand.

This project involves improving the tracking speed of a telesope.

An arduino card (UONO32) that I program gives the instructions in "Pulse and Dir" mode to a driver. This driver controls a two-phase step motor (200 steps) in micro step mode (128 micro steps per step). This stepper motor rotates an worm screw against a wheel that has 360 teeth. And finaly, this wheel rotates the axis of the telescope to make one revolution per day.

To reduce the speed error caused by imprecision of the wheel and screw, a high precision encoder (1800 000 PPR) is placed at the end of the axis of rotation of the telescope. My goal is to work in closed loop with the stepper motor and the encoder feadback.

I need your advice for the PID algorithm. Here is my idea but I am not sure that this is valid:

  1. SP (Setpoint) : the desired position of the encoder. The encoder is in 4x reading mode.

At time t, this gives : SP(t)= ( t sec) * (4* 1800000 PPR)/(86164 sec/day)

I can convert into micro-step :

(360 turns_motor)(200 steps)(128 micro-steps) = 4*1800 000 encoder pulses

  1. PV : the process variable. This is the measured position of the encoder.

  2. E : the error , E= SP-PV

  3. Command : I act on the frequency of the pulses to vary the speed of the motor according to this error

My question :

Can this PID with variable setpoint work in your opinion ?

I have already done tests, but these are not conclusive. On the other hand I am not certain of this algorithm.

Thanks for your advices,

Marc.

Yes, that algorithm is used by many motor controllers set motor speed, based on a shaft encoder.

Possible problems with your setup include the fact that microsteps are not precise and at higher values of microstepping resolution, it is very likely that the motor will fail to take steps altogether.

See Tutorials

Can this PID with variable setpoint work in your opinion ?

Yes. PID does not rely on the setpoint being constant, as long as the setpoint is not random.

On any given call to the compute() method, the current position matches the setpoint, or it doesn't.

  1. Command : I act on the frequency of the pulses to vary the speed of the motor according to this error

The frequency of pulses is zero if the telescope isn't moving, isn't it? The frequency of steps is directly related to the speed that the stepper is moving isn't it? It seems to me that you are trying to adjust the speed based on frequency, which is a function of speed. Chasing your tail is seems.

At the very slow speed you're talking about, I don't see any reason to even use a PID. What does that buy you other than added complexity? You'll be outputting single pulses, spaced far apart, which you can do just fine using a timer interrupt to output those single pulses, and varying the timing of the pusles slightly based on the actual position read from the encoder. I don't see a PID helping at all.

Also, beyond about 10:1 microstepping is of very limited value. Micro-stepping is primarily of value in providing smoother motion, but does not generally significantly improve either resolution or accuracy. The higher the micro-stepping ratio, the less accurate the steps are. At 128:1, many "steps" will actually not move the motor at all.

Regards,
Ray L.

With accurate, full step timing and suitable gearing, there is no need for either an encoder or PID.

Thank you for your reply. I'm glad to know that the setpoint can be variable. Allow me to respond to your remarks.

  1. I do not complicate. The telescope operates without an encoder and PID but with relative tracking accuracy and open loop stepper motor.
    In astrophotography, the telescope has to follow better than a pixel. What is in my case a second of arc on the sky.
    Due to the inevitable imperfection of the wheel and the worm, I get an accuracy of 10 seconds of arc.
    My goal is to work in a closed loop to increase accuracy for speed tracking at better than one pixel.
    The encoder placed on the axis of the telescope is intended to inform errors caused by the wheel and the screw. The correction of this error must be done by the PID ....

  2. Concerning micro-steps .....

The ratio 1/128 is chosen so that in theory the motor gives a tracking speed to better than one pixel:

360 * 60 * 60 / (360 * 200 * 128) = 0.14 second of arc

  1. The generation of the micro-steps is provided by a timer of the uno card. Indeed by varying the period of the timer, one varies the speed of the motor to react to the response of the PID. There is no other method of reaction.

Marc.

MarcStorme:
Thank you for your reply. I'm glad to know that the setpoint can be variable. Allow me to respond to your remarks.

  1. I do not complicate. The telescope operates without an encoder and PID but with relative tracking accuracy and open loop stepper motor.
    In astrophotography, the telescope has to follow better than a pixel. What is in my case a second of arc on the sky.
    Due to the inevitable imperfection of the wheel and the worm, I get an accuracy of 10 seconds of arc.
    My goal is to work in a closed loop to increase accuracy for speed tracking at better than one pixel.
    The encoder placed on the axis of the telescope is intended to inform errors caused by the wheel and the screw. The correction of this error must be done by the PID ....

  2. Concerning micro-steps .....

The ratio 1/128 is chosen so that in theory the motor gives a tracking speed to better than one pixel:

360 * 60 * 60 / (360 * 200 * 128) = 0.14 second of arc

  1. The generation of the micro-steps is provided by a timer of the uno card. Indeed by varying the period of the timer, one varies the speed of the motor to react to the response of the PID. There is no other method of reaction.

Marc.

Your 0.14 seconds of arc for a microstep is a nice looking number, but be warned it will NOT work that way in the real world. Your actual resolution will be far less than that, and the accuracy worse still. Micro-stepping is HIGHLY imprecise, and the higher the ratio, the worse it gets. At any given point you can easily be off by as much as 1/4-1/2 a step. If you want true accuracy, reduce the micro-stepping to something reasonable (like 10:1 or 16:1 at most), and put a zero-backlash planetary gearbox or harmonic drive between the motor and the worm. Anything else, and you're fooling yourself. And if you have backlash in the worm drive (and you almost certainly will), that will drive the PID nuts, and limit your ability to tune it for best performance.

Again, for simply tracking, the PID seems unnecessary, due to the extremely slow speed. Track, in software, where you want the thing to be at any point in time, and once you're behind by more than 1/2 a step, issue a step pulse. If that doesn't get you to where you want to be in a reasonable period of time, issue another one, and repeat until you get caught up. At best, you'd need P+I. The D will be useless at such low speed.

Regards,
Ray L.