Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Continuous Feedback Sensor on CANTalon (http://www.chiefdelphi.com/forums/showthread.php?t=148332)

TimTheGreat 08-05-2016 20:25

Continuous Feedback Sensor on CANTalon
 
Does anyone know if the CANTalon PID supports continuous feedback like the PIDController does?

ozrien 08-05-2016 21:41

Re: Continuous Feedback Sensor on CANTalon
 
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).

TimTheGreat 08-05-2016 22:31

Re: Continuous Feedback Sensor on CANTalon
 
Quote:

Originally Posted by ozrien (Post 1585115)
Hey Tim
Actually the sensor feedback is continuous by default.

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

ozrien 09-05-2016 16:41

Re: Continuous Feedback Sensor on CANTalon
 
1 Attachment(s)
Quote:

Originally Posted by TimTheGreat (Post 1585142)
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.

Ether 09-05-2016 17:21

Re: Continuous Feedback Sensor on CANTalon
 
Quote:

Originally Posted by ozrien (Post 1585375)
Attached is an excel sheet demonstrating a few examples of how to do this.

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



Ether 09-05-2016 17:36

Re: Continuous Feedback Sensor on CANTalon
 

Or in native units do this:
Code:


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 \n",P,T,SetPoint);
}

Output:
Code:

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).



Ether 09-05-2016 18:18

Re: Continuous Feedback Sensor on CANTalon
 

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

Code:

SetPoint = P + Math.IEEEremainder(T-P,360.0);
or in native units:

Code:

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



All times are GMT -5. The time now is 23:08.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi