Continuous Feedback Sensor on CANTalon

Does anyone know if the CANTalon PID supports continuous feedback like the PIDController does?

Hey Tim
Actually the sensor feedback is continuous by default.

AnalogEncoder is continuous (over and under wraps are tracked so 3.3V=>0V equates to sensor pos 1023=>1024).

Same is true for PulseWidth sensors and the CTRE Magnetic Encoder.

AnalogPot is not continuous (meant to be used with analog sources that cannot wrap).

1 Like

So if the sensor is at 200 and I want it to go to 1000 it will go backwards 223?

So assuming 1024 units per rotation (analog sensor), if you want to go “backwards” set the target to -23. This will move backwards by -223 (since your current position is 200), instead of moving forward by 800 (pos200=>pos1000).

The basic idea is if you want to move forward, use the appropriate multiple of your target position in the positive direction. If you want to move reverse, use the appropriate multiple in the negative direction. If you want to servo using the shortest distance, calculate how far the target is moving forward, and moving backwards, pick the shortest one, and use that as the final set point.

Attached is an excel sheet demonstrating a few examples of how to do this.

continuous_wheel.xlsx (13.2 KB)

continuous_wheel.xlsx (13.2 KB)

1 Like

If I may:

Let P be your present angle sensor reading (converted to degrees)

Let T be your desired angle position (in degrees)

the angle between them (let’s call it ERR) is found by the equation:

ERR = (T-P) - 360*floor(0.5+(T-P)/360);

the above returns a value for ERR between -180 and +180 degrees,
the shortest angle path to the target.

So it tells you which direction to rotate as well as how much to rotate.

So compute your setpoint:

SetPoint = P + ERR

*Or in native units do this:

*double P=200;
double T=1000;
double SetPoint;

void main(void){
SetPoint  = T - 1024*floor(0.5+(T-P)/1024);
printf("P=%f  T=%f   SetPoint=%f 


P=200.000000  T=1000.000000   SetPoint=-24.000000

If the sensor goes from 0 to 1023, then you have to go backward 224 steps (not 223) from 200 to get to 1000.

(Because 0 is equivalent to 1024, just as 0 is equivalent to 360 degrees).

*If your compiler supports the REMAINDER function “x REM y” per IEC 60559 as specified on Page 235 Section of ISO/IEC 9899:TC3 (which java does I believe), then the following single line of code should work:

SetPoint = P + Math.IEEEremainder(T-P,360.0);

or in native units:

SetPoint = P + Math.IEEEremainder(T-P,1024.0);