Skip to content
Alex Omar edited this page Jan 3, 2017 · 18 revisions

Flight System

Single producer, multi-consumer model. Everything in parallel. Nice because no thread will move faster than the producer and no thread is slowed down by another thread because they are all independent of each other.

Producer

Responsible for polling flight instrumentation sensors, moving those values into memory locations shared between itself and the consumers (one memloc per consumer), and notifying each consumer that new data is available.

Pseudo code

sensor_data = get_data()

for c in consumers:
    if( c.shared_mem.is_avail() ):
        c.lock_shared_mem()
        c.update_shared_mem(sensor_data)
        c.unlock_shared_mem()
        c.notify()

State Machine

Producer State Machine

Notes

The notification mechanism is a binary semaphore signifying that data is "fresh" or "stale". The producer will overwrite fresh data.

Consumer

Reads data from shared memory and then operates on it. Controls consumer crunches the meco algorithm. Logging consumer writes to a file, Comms consumer does communication stuff.

Pseudo code

while True:
    if( notified() ):
        lock_shared_mem()
        local_data = shared_mem; //copy data
        unlock_shared_mem()
        
        //comms() or controls() or log()

State Machine

Consumer State Machine

Notes

If a consumer is slow enough, the producer will update the shared memory with fresh data multiple times before the consumer can read. This means dropped data, but it is also means that we will never run a consumer on stale data.

Clone this wiki locally