Jump to content

Is it okay to use events in a Timed Loop?


Stobber

Recommended Posts

I assume this is on a real-time target because of where the question was asked.  User events are supported on real-time targets, but I don't use them that often because of the other options of queues and FIFOs. 

 

What do you mean by adding delay in the execution? I want to tie a PID controller into an event-based messaging framework so it can be configured by and report to other components.

So you want to have a deterministic loop doing PID, but you want also be able to send commands to it (like setpoint) I assume.  I haven't used execution trace to look at it, but using an event structure is going to make it jittery (don't know by how much).  Personally I have used RT FIFO of type U8 array with the array size fixed to the largest datatype.  The Create RT FIFO has an input where you set the array size.  This will decrease any chance of buffer allocations.  Also I would use the Timed sequence structure.  It puts the loop in a priority thread, but has less overhead than the timed while loop (10% < CPU).

  • Like 1
Link to comment

If you have a timed loop with an event structure set to 0 seconds then it will execute as follows.

  1. Event Waiting?
    • Yes - Execute Event code

[*]Wait for (elapsed time - timed loop time)

If you use a while loop with the event stucture it executes the same as above without step 2, so you are adding overhead and increasing the time to react to event by using a timed loop. This would only make sense if you want your PID to not operate faster than a specific frequency.

Link to comment
GoGators wrote:

 

So you want to have a deterministic loop doing PID, but you want also be able to send commands to it (like setpoint) I assume.  I haven't used execution trace to look at it, but using an event structure is going to make it jittery (don't know by how much).  Personally I have used RT FIFO of type U8 array with the array size fixed to the largest datatype.  The Create RT FIFO has an input where you set the array size.  This will decrease any chance of buffer allocations.  Also I would use the Timed sequence structure.  It puts the loop in a priority thread, but has less overhead than the timed while loop (10% < CPU).

I normally use subroutine FGVs to pass data into and out of a PID control loop, but I want to tie in a "Stop" command from an event-based messaging framework I use. What I needed to hear from someone at NI is that using events introduces jitter, so thanks for that. I'll test the loop on hardware, and if the jitter affects the determinism, I'll write a translator that turns events into RT FIFO elements or uses them to control an FGV that enumerates expected messages.

 

gleichman wrote:

If you have a timed loop with an event structure set to 0 seconds then it will execute as follows.

  1. Event Waiting?
    • Yes - Execute Event code

[*]Wait for (elapsed time - timed loop time)

If you use a while loop with the event stucture it executes the same as above without step 2, so you are adding overhead and increasing the time to react to event by using a timed loop. This would only make sense if you want your PID to not operate faster than a specific frequency.

GoGators inferred my use case correctly. A PID controller doesn't need to be fast; it needs to be consistent. Maintaining determinism in the PID algorithm is more important than responsing to messages quickly.

Link to comment
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.