Moderator: miprotek

 
hanssimi
Topic Author
Posts: 2
Joined: 18 Oct 2018, 11:57

Limits of (high frequency) sampling of AIO using RevPiModIO python

22 Oct 2018, 10:31

Hi,

I was wondering what the limits are for the python programs running (using RevPiModIO) on the RevPi for pure measuring purposes (sensor values from the AIO)

I want to measure a 4..20 mA signal at a e.g. freq. of 100Hz. Currently (this was before I saw the concept of cycleloop) I've tried this with a manual loop (see part of script below). But this causes regularly crashes, without knowing the issues.

Also in a next step I want to write this data to a (binary) file to transfer it to the cloud. So I was wondering if you have examples or best practises for doing exactly this:
- simply measuring AIO values (4..20mA, 0-10V, RTD, ...)
- frequencies up to 100Hz --> limit??
- writing this data to file and upload files (-> too load intensive for RevPi??)


Thanks a lot,
IO_LIST = ['InputValue_1','InputValue_2','InputValue_4']
perf_time_next = now + 1
number_of_samples = 60*100 # 1 minute at 100Hz
sample_count = 0
rawdata = []
polling_time = 0.010  # 10 ms -> 100Hz

while sample_count < total_number_of_samples:
    # Wait until next planned sample point start time
    while perf_time_next > time.perf_counter():
        pass
    perf_time_next += polling_time # seconds

    # ---------------------------------
    # Sample
    values = []
    for input_name in IO_LIST:
        values.append(float(revpi.io[input_name].value))

    sample_count += 1
    rawdata.append(values)
 
User avatar
miprotek
Posts: 150
Joined: 20 Jan 2017, 08:44
Contact:

Re: Limits of (high frequency) sampling of AIO using RevPiModIO python

22 Oct 2018, 13:36

Hi hanssimi!

If you are using a RevPi3, there will be no problem to go to 10ms cycle rate. But if it is a RevPi 1, it will be to much load! You have to check the cycle time of the piControl System to stay in sync.

The cycleloop will be an easy thing to get data periodically, but you can build you own loop, of course.

BUT:

You python program kills the CPU...
# Killing part
while perf_time_next > time.perf_counter():
        pass
This loop will run fast as possible on the CPU and you should not do it like that. You have to use a .wait(...) function somewhere in your code... So try this:
# -*- coding: utf-8 -*-
import revpimodio2
from time import sleep, perf_counter

IO_LIST = ['InputValue_1', 'InputValue_2', 'InputValue_4']
number_of_samples = 60 * 100  # 1 minute at 100Hz
sample_count = 0
rawdata = []
polling_time = 0.010  # 10 ms -> 100Hz

# Revolution Pi (without autorefresh!)
revpi = revpimodio2.RevPiModIO()

while sample_count < number_of_samples:
    # Set start time to find out runtime of the loop
    perf_time = perf_counter()

    # Sync process image
    revpi.readprocimg()

    # Sample
    values = []
    for input_name in IO_LIST:
        values.append(float(revpi.io[input_name].value))

    sample_count += 1
    rawdata.append(values)

    # Calc the runtime till now to reach exact polling_time
    wait_time = polling_time - (perf_counter() - perf_time)

    if wait_time > 0:
        # Wait, to do not kill the CPU
        sleep(wait_time)
    else:
        # Your loop takes more than polling_time
        raise RuntimeError("too much cpu load - {0}".format(wait_time))

print(rawdata)
Sven
python3-RevPiModIO - https://revpimodio.org/ || Supported by miprotek GmbH - http://www.miprotek.de || Der RevPi ist das Beste, was passieren konnte!

Who is online

Users browsing this forum: No registered users and 1 guest