Moddable-OpenSource / moddable

Tools for developers to create truly open IoT products using standard JavaScript on low cost microcontrollers.
http://www.moddable.com
1.32k stars 236 forks source link

[Review pre pull request] PID controller for moddable #190

Open wilberforce opened 5 years ago

wilberforce commented 5 years ago

Please see:

https://gist.github.com/wilberforce/88231ea867bc190199c33538c039201f

This is a class for a PID controller - example usage is to monitor the temperature and throttle the output of the heater so it does not over shoot.

I use it to brew beer ;-)

I can do a pull request for this - just not sure where it fits - it could go into contributed, however you might want a folder under /modules/data

The simulator is not the best - but gives and idea:

Output : 1000 ; Temp : 11.68°c setpoint:21°c
Output : 1000 ; Temp : 12.68°c setpoint:21°c
Output : 1000 ; Temp : 13.68°c setpoint:21°c
Output : 1000 ; Temp : 14.68°c setpoint:21°c
Output : 1000 ; Temp : 15.68°c setpoint:21°c
Output : 1000 ; Temp : 16.68°c setpoint:21°c
Output : 1000 ; Temp : 17.68°c setpoint:21°c
Output : 1000 ; Temp : 18.68°c setpoint:21°c
Output : 971 ; Temp : 19.63°c setpoint:21°c
Output : 519 ; Temp : 19.91°c setpoint:21°c
Output : 707 ; Temp : 20.47°c setpoint:21°c
Output : 295 ; Temp : 20.41°c setpoint:21°c
Output : 620 ; Temp : 20.85°c setpoint:21°c
Output : 173 ; Temp : 20.6°c setpoint:21°c
Output : 614 ; Temp : 21.03°c setpoint:21°c
Output : 88 ; Temp : 20.66°c setpoint:21°c
Output : 649 ; Temp : 21.13°c setpoint:21°c
Output : 11 ; Temp : 20.65°c setpoint:21°c
Output : 710 ; Temp : 21.21°c setpoint:21°c
Output : 0 ; Temp : 20.71°c setpoint:21°c
Output : 686 ; Temp : 21.24°c setpoint:21°c
Output : 0 ; Temp : 20.74°c setpoint:21°c
Output : 671 ; Temp : 21.25°c setpoint:21°c
Output : 0 ; Temp : 20.75°c setpoint:21°c
Output : 668 ; Temp : 21.25°c setpoint:21°c
phoddie commented 5 years ago

Very nice. I think contributed is a good place to start. The modules/data is intended more for local storage options. This is is an algorithm -- pure computation. If we collect a a couple more modules like that, it would make sense to have a directory for that.