Long loop in the component #1032
Replies: 1 comment
-
It depends. The usual solution is to drive the component off a rate group (in your case running at 1KHz) and on each call do one unit of work (one high/low pair of the GPIO lines). This allows the work to get done while ensuring that the system keeps running. This solution can arbitrarily extended by placing a state machine in the handler of the rate group call and any arbitrary work can be done, one unit or "state" per tick. Hook up to a clock of the correct frequency and you should be good. The up-side of this solution is that the component can be written for high-priority (exact timing) without bringing the system down. It comes at the cost of complexity. This is typically used to drive time sensitive hardware. Another solution is to use a "worker" component. This component is usually set to a lower priority so that it doesn't steal all resources of the system, and it should not be hooked up to health. Here the loop can be in-line (i.e. I have run both models. The first is much better on a busy system as you have control of timing. The second is much simpler to write. |
Beta Was this translation helpful? Give feedback.
-
This question pops up after I read about wait or sleep in F'. If I have a task that requires running a while or for loop that might takes a while, what could be the best implementation of that on F' so that it doesn't block the other threads. For example, I have a component that handle the a stepper motor driver board, which requires something like 6400 iterations of GPIO High and Low with small delay (1000 microseconds). Is there a way to make each iteration of the loop into one thread so the scheduler can handle each of them according to its priority? Or do you think it's better to just have a separated microcontroller to handle this loop and have a main OBC send a command to operate that MCU?
Beta Was this translation helpful? Give feedback.
All reactions