Articles Hierarchy

Articles Home » RPI » RPI operates ARDUINO PID control

RPI operates ARDUINO PID control


CURRENT TREND MODULE
if i now want to add a so called "current trend"
i need to learn first
- how i know there are new data ( currently i read every sec and don't know if the data are new)
- how to make a array and fill it with PV SP OUT ( real )
- - how to make it a ring buffer
- how to open a new window and show PLOT

i start on one end: array and matplot lib (and play on desktop computer)

it was essential that the plots have same color as in faceplate
PV yellow, SP white, OUTPUT blue.
and even it could result in range problems i like them in one plot,
that's best for check on PID loop tuning.

today start same from RPI IDLE, and need 10sec ( with cpu 100% ), but it runs ( remember we installed matplotlib for a first test )
with a array length of 100.000 it needs 20sec, but still runs and no problem in taskmanager/memory
i do not understand the RPI operating system, but i expect that if (RAM - RAMDISK) is too small for OS and program variables ( like here long real arrays ) there will be a write / usage of a swap file on SD card, what means burning them.


that array / plot now is only a list, not a graph over time ( what is needed if the arduino reporting is NOT time equidistant
or i need a realtime axis ), check here and here
that date handling is tricky:
the record time i get via the csv line in ram disk file, as 6 strings, ",Y,m,d,H,M,S,,"
this can be packed in one string:
gettime= rec_year+"-"+rec_month+"-"+rec_day+" "+rec_hour+":"+rec_min+":"+rec_sec
and with strptime converted to a python date time info
datetime.strptime(gettime,'%Y-%m-%d %H:%M:%S')
and that can be converted to a matplot time float number
mgettime = mdates.date2num(..) function.
now i use that number to compare it with the prior record reading if that's a new record
and only then i do the faceplate update and the storing to array.


writing to a array with a specific length ( all filled with 0.0 ) i use a pointer.
where=where+1
if (where >= maxlength) : where = 0 # ring pointer
that is very fast ring buffer.
but when i call the trend ( and only at that moment have lots of time )
i need to make it to a clean linear list for matplotlib trend.
reshuffel a array every time you add/write a value ( 2 sec) is waste if time
only do it when you need the array for further processing,
like show trend after operator press the "CT" current trend button.
( now configured with 900 samples ( of 2 sec arduino send data ) == 30min )