DonnyCraft1 / PIDArduino

A simple PID library for Arduino
MIT License
45 stars 21 forks source link

Optimize the code #16

Closed DonnyCraft1 closed 5 years ago

DonnyCraft1 commented 5 years ago

I got this feedback from stuxxnet over at The Coding Den Discord server:

you might want to re-do your PID project. There are quite a few things questionable about it:
* using doubles (or floats) on microcontrollers (µC) is often questionable, especially if they have no FPU, which the Ardunios don't have.
it is 50-100 times slower than integer calculations
* you're using Strings as parameters where simple bools would be enough. This means that in your 'compute' function, you do an expensive string compare every single time it is called
* your constructor should do the initialization of the object. Your object should never be in a non-initialized state. Why is there an 'init' variable
* speaking of the constructor: why do you re-declare all of your variables in the constructor? not only does this make no sense, it also has no effect at all
* your 'failsafe' makes the PID always return '0' if it is not initialized. That's not a failsafe, that's a valid value. This is pretty dangerous behavior

I'm working on this over at the feature/optimize branch.

DonnyCraft1 commented 5 years ago

Fixed the issues in the optimize branch. The only thing left is to change some of the doubles to integers.

DonnyCraft1 commented 5 years ago

Done. Closing issue.