rice-eclipse / resfet

Hybrid rocket engine control software for engine tests (coldflow and hotfire), written in C++.
http://eclipse.rice.edu/resfet
GNU General Public License v3.0
1 stars 1 forks source link

Data #14

Closed ty19 closed 5 years ago

ty19 commented 5 years ago

ADC reader, circular buffer, and periodic thread for reading and logging data.

The ADC reader is pretty much unchanged from previous code since we are using the same ADC and microcontroller. The ADC reader has a count_up() method that is currently being used for debugging since we aren't testing on the hardware

The circular buffer manages an array of struct data_items that include a reading and a timestamp. When data is ready to be sent (currently when the buffer is full, but potentially after some interval), data is copied item by item from the buffer into a provided array. The header is written during this copying process. This sounds slow, but timing tests show no problem with adding items at 2 kHz (max was about 100 kHz). This may change if we actually sample from the ADC instead of counting up.

The periodic thread uses Unix pthreads. Each thread runs at a frequency and handles multiple sensors. For example, all load cells can be sampled at 2 kHz, so one thread samples the load cells. The initialization of the thread is clunky because we pass in a struct thread_param pointer. A better way would be to use std::thread and simply use the thread class's member variables. A thread has a buffer and a logger for each sensor it samples and logs to a file when the buffer is full.

TODOs (in addition to the comments) Split logger into separate classes for data and message logging Use std::thread for PeriodicThread Verify buffer implementation is fast enough with real hardware Write to a socket when we log data. Decouple socket and file logging so data is saved even if the network goes down

A few code style changes we can make are capitalizing class names and ordering variables by size and name.

ty19 commented 5 years ago

I tried sending over the existing TCP socket but I think I was getting errors because we're blocking on receive. We probably want to use epoll to avoid this issue @andrewobler.

andrewobler commented 5 years ago

epoll is noted. Should we take care of the TODOs in this branch or merge it now and make the improvements later?

ty19 commented 5 years ago

After reading some more, there seem to be some downsides to epoll such as making it tricky to share file descriptors between threads. select and poll might be easier to use if the benefits of epoll aren't that significant.

I can fix a few TODOs this week but I would want to test with UDP before merging. How is UDP going?

andrewobler commented 5 years ago

It's pretty much done, gonna test a few things before submitting the PR. I can do that by tomorrow. I'll let you know when it's ready.

ty19 commented 5 years ago

Tested UDP sending with the UDP echo server. The echo server prints out the header (0, 1, 2, or 3) and data received (15 packets per message, count up by 4 each packet). There is a slight bug with the circular buffer size resulting from pointer arithmetic, but the only effect is that the last data_item is empty.

@berkalpyakici Can you try testing this with the GUI?

andrewobler commented 5 years ago

I changed PeriodicThread a bit to use std::thread instead of the messier pthread. Didn't test super thoroughly, but everything seems in order.