0

I'm trying to make a tool where i can poll data from BACnet in a certain interval (e.g. 100ms, 250ms, 500ms, 1s etc.). If I use a while loop with no timer, i get an answer from BACnet every 40-60ms:

import threading
from threading import Timer
from datetime import datetime

import BAC0

ZUL1_T = list()
TIME_T = list()

_rpm = {'address': address,
       'objects': {
           'analogInput:12':['presentValue'],
           'loop:1': ['presentValue'],
           }
       }

#=============================================================================#
# Main Loop                                                                   #
#=============================================================================#

if __name__=='__main__':

   i = 10
   
   try:
       bacnet = BAC0.lite(ip)
   except Exception as e:
       print(e)
       
   address, device_id = bacnet.whois()[0]
   
   while(i>0):
       ZUL1_T.append(bacnet.readMultiple(address, request_dict=_rpm))
       TIME_T.append(round(time.time_ns()/1000000))
       i-=1

What is the easiest way to make a poll without blocking the entire CPU? The intervals need to be precise (+-10ms) since I need the data for a system identification.

  • Add, lastRun, and Interval parameters to the request. Then when you run the task, update the lastRun variable. In the loop check to see if the currentTime > lastRun + interval, if so run the task again – Steven Smethurst Jul 08 '22 at 00:21
  • Out of curiosity, why is your requirement so fast ? – Christian Tremblay Jul 26 '22 at 13:13
  • @ChristianTremblay I'm trying to make a tool that automatically calculates the PID parameters of a controller for building automation systems (e.g. pressure, humidity and temperature controlling of a air conditioner for large buildings). I'm using step response and prbs signals to stimulate the system and measure input and output, to get a transfer function that describes the system (ARX- model). To get all the frequencies that influences the system behaviour, it has to be fast enough not to violate the Nyquist–Shannon sampling theorem. – Beginnerlevel Jul 27 '22 at 14:42
  • Happy to use Auto-Tune PIDs here :-) – Christian Tremblay Jul 28 '22 at 19:01
  • I'm not aware of all the details for those methods, but by experience, not having access to all the implementation details of a PID loop (DDC PIDs are not as documented as PLC PIDs) you will face issues. Also, you will be tricked by input filters as what you get over BACnet is often filtered in some way (debounce options, filters, etc.) I don't forget that inertia in a room, in coils, sensor reaction time will never trigger a feedback below a few seconds... – Christian Tremblay Jul 28 '22 at 19:05

0 Answers0