Simple Solution?
teganburns
Posts: 134
I'm currently tuning a PID controller (For the first time) on my tricopter and from what I've read you start with a P controller. Then you set you gain to a value that will get you there the quickest but without overshooting.
My problem is that that any whole number is an overshot and when i try and use something like "3/4" or "1/2" it always rounds it down to zero. I have read about floating points a little but I feel like there is an easier way to solve this.
Any ideas? Thanks
My problem is that that any whole number is an overshot and when i try and use something like "3/4" or "1/2" it always rounds it down to zero. I have read about floating points a little but I feel like there is an easier way to solve this.
Any ideas? Thanks
Comments
The LSB effect becomes a smaller fraction in each case, and you need only to check that no numeric overflow occurs during the calculation.
Lets say the range of numbers you are working with is 0 to 100 in steps of 0.1, and you need a P of 0.3 for optimum control. Multiply them by 10 and you now have a range of 0 to 1000 and a P of 3. Do all the calculations and then divide the result by 10. This works even better if the multiplier is a power of 2 so shifts can be used in place of multiplies and divides.
If it is possible I do all the calculations using the binary numbers received directly from the sensors.
What's the advantage to that?
So, in short, if your numbers have decimal points, multiply them so the decimal / fraction goes away: 0.1 becomes 1, 0.123 becomes 123, et cetera. Also, try to use the intrinsic data type when possible so the compiler doesn't have to cast an 8 bit char to 32 bit integer.
In some instances storing four 8 bit char's (or bytes or gasp... Booleans) can take up as much memory as four 32 bit integers.
I'll shut up now and let the pro's correct me.
As abecedarian posted the advantage is not having to do a lot of conversions. That can save cpu cycles you may need for something else. A pid loop calculation does not care what the units are. It takes an input measurement, compares it to the desired measurement (set point), and uses the difference ( error signal ) to calculate a change to the output signal that controls the input signal. If you have binary numbers coming in and binary numbers going out why not skip the conversions and do all the calculations in binary?
Which is why we have objects and math routines written by helpful generous people who do ken it.