|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Continuous Feedback Sensor on CANTalon
Does anyone know if the CANTalon PID supports continuous feedback like the PIDController does?
|
|
#2
|
||||
|
||||
|
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). |
|
#3
|
||||
|
||||
|
Re: Continuous Feedback Sensor on CANTalon
So if the sensor is at 200 and I want it to go to 1000 it will go backwards 223?
|
|
#4
|
||||
|
||||
|
Re: Continuous Feedback Sensor on CANTalon
Quote:
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. |
|
#5
|
||||
|
||||
|
Re: Continuous Feedback Sensor on CANTalon
Quote:
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 |
|
#6
|
||||
|
||||
|
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);
}
Code:
P=200.000000 T=1000.000000 SetPoint=-24.000000 (Because 0 is equivalent to 1024, just as 0 is equivalent to 360 degrees). Last edited by Ether : 09-05-2016 at 18:08. |
|
#7
|
||||
|
||||
|
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); Code:
SetPoint = P + Math.IEEEremainder(T-P,1024.0); |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|