RevPiModIO: RuntimeWarning: cycle time of 20 ms exceeded

Moderator: RevPiModIO

Post Reply
saardrimer
Posts: 18
Joined: 15 Jun 2021, 14:16

RevPiModIO: RuntimeWarning: cycle time of 20 ms exceeded

Post by saardrimer »

Hello all

On one of our two CONNECT+ systems (with MIO and DO modules connected) we occasionally get the following warning from revpimodio2:

Code: Select all

/usr/lib/python3/dist-packages/revpimodio2/helper.py:617: RuntimeWarning: cycle time of 20 ms exceeded - can not hold cycle time!
  RuntimeWarning

I'd like to investigate why this happens -- and why on only one of the systems -- but I'm not sure what the warning actually means. In plain English, does it mean something like:
I'm warning you that it took me longer than 20ms to perform the IO refresh cycle
or
I'm warning you because I'm supposed to refresh the IOs every 20ms, but it took longer than that between my invocations
or something else?

Any suggestions for where to look, what to do to debug, etc. would be welcome.

This is how I instantiate RevPiModIO:

Code: Select all

import revpimodio2
revpi_io = revpimodio2.RevPiModIO(autorefresh=True)
User avatar
RevPiModIO
KUNBUS
Posts: 347
Joined: 20 Jan 2017, 08:44
Contact:

Re: RevPiModIO: RuntimeWarning: cycle time of 20 ms exceeded

Post by RevPiModIO »

Hi saardrimer!

Your cycle loop function takes to long to execute - Maybe because of a .sleep or .wait or things like that. If you are using the cyclelooop, the cycle function must return in the given cycle time.

Do you have a code example you are using?
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
saardrimer
Posts: 18
Joined: 15 Jun 2021, 14:16

Re: RevPiModIO: RuntimeWarning: cycle time of 20 ms exceeded

Post by saardrimer »

RevPiModIO wrote: 11 Mar 2022, 15:17 Hi saardrimer!

Your cycle loop function takes to long to execute - Maybe because of a .sleep or .wait or things like that. If you are using the cyclelooop, the cycle function must return in the given cycle time.

Do you have a code example you are using?
Thanks for the clarification! I was careful to code in such a way that there are no idle sleeps. And, curiously, it only happens in one of the systems. I have since re-written some of the code and will see if the issue persists.
Heron
Posts: 43
Joined: 13 Jul 2017, 15:30

Re: RevPiModIO: RuntimeWarning: cycle time of 20 ms exceeded

Post by Heron »

Hallo,

ich hänge mich mal an diesen Thread dran, da ich das gleiche Problem habe.

ich habe das Bespiel von Sven Sager genommen um Phyton auszuprobieren...

Ich habe Anfangs das Beispiel unverändert getestet, es läuft. Bis auf der Fehler:

Code: Select all

 warnings.warn(
/usr/lib/python3/dist-packages/revpimodio2/helper.py:627: RuntimeWarning: io refresh time of 20 ms exceeded!


Im Original wird in der Loop ein "wait" von 500ms ausgeführt. Ich bin, nach diesem Thread, davon ausgegangen, das der Fehler an diesem wait(0.5) liegt. Dam ist nicht so. Ich habe das wait umgestellt und der Fehler blieb.

Hier die Änderung (unten im start, die loop funktion):

Code: Select all

#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# (c) Sven Sager, License: GPLv3
#
"""Combined events with mainloop() and own cyclic functions.
Let the LED A1 blink green during program is running. Switch on output O_1
if I_1 goes to True and switch off output O_1 if I_1 goes to True again.
piCtory Setup: RevPICore | DIO
"""
# ROGRAMMBESCHREIBUNG
# Das Programm soll den Ausgang O_1 auf True setzen, wenn I_1 auf True wechselt und diesen aktiv lassen. 
# Wenn I_1 erneut auf True wechselt, soll O_1 wieder auf False gesetzt werden (FlipFlop Schaltung).
#
# Parallel soll während das Programm läuft, die LED A1 vom Core im Takt von 500 Millisekunden grün blinken!
#
import revpimodio2
import time

class MyRevPiApp():
  """Mainapp for RevPi."""
  def __init__(self):
    """Init MyRevPiApp class."""
    # Instantiate RevPiModIO
    self.rpi = revpimodio2.RevPiModIO(autorefresh=True)
    
    # Handle SIGINT / SIGTERM to exit program cleanly
    self.rpi.handlesignalend(self.cleanup_revpi)
    
    # Register event to toggle output O_1 with input I_1
    self.rpi.io.I_1.reg_event(self.event_flipflop_o1, edge=revpimodio2.RISING)
      
  def cleanup_revpi(self):
    """Cleanup function to leave the RevPi in a defined state."""
    # Switch of LED and outputs before exit program
    self.rpi.core.a1green.value = False
    self.rpi.io.O_1.value = False
      
  def event_flipflop_o1(self, ioname, iovalue):
    """Called if I_1 goes to True."""
    # Switch on/off output O_1
    self.rpi.io.O_1.value = not self.rpi.io.O_1.value
      
  def start(self):
    """Start event system and own cyclic loop."""
    # Start event system without blocking here
    self.rpi.mainloop(blocking=False)
    
    print("Application running.")
    old_time = time.perf_counter()
    
    while not self.rpi.exitsignal.is_set():
      current_time = time.perf_counter()
      elapsed_time = (current_time - old_time) * 1000
      
      if elapsed_time > 500:
        self.rpi.core.a1green.value = not self.rpi.core.a1green.value
        old_time = current_time

    print("Application has stopped.")
                  
if __name__ == "__main__":
  # Start RevPiApp app
  root = MyRevPiApp()
  root.start()
  
Woran kann das noch liegen?


MfG,
Heron
Post Reply