Hello,
I’m seeking advice and experiences from those who write control systems in C. I’ve been working on this embedded control system project for around 2 years, mostly on the application logic side.
Recently, Ive been porting code from an older system to the current one and its been a somewhat painful experience (mostly because the old code is some insane spaghetti and there are no real specifications for how the system should work in detail). In both of these systems, while physical I/O and other data are relatively well abstracted, they are very dependant from the libraries and tools of the control system hardware provider. This data is basically in global scope and available to be used anywhere in the application. Everything is dependent on everything which makes things like …
Hello,
I’m seeking advice and experiences from those who write control systems in C. I’ve been working on this embedded control system project for around 2 years, mostly on the application logic side.
Recently, Ive been porting code from an older system to the current one and its been a somewhat painful experience (mostly because the old code is some insane spaghetti and there are no real specifications for how the system should work in detail). In both of these systems, while physical I/O and other data are relatively well abstracted, they are very dependant from the libraries and tools of the control system hardware provider. This data is basically in global scope and available to be used anywhere in the application. Everything is dependent on everything which makes things like testing difficult.
I’ve been thinking of writing the code as a library with no dependencies. This would be fine, I could easily do whatever I want and write tests and verify my outputs etc. The using code allocates a context struct, fills it with input data, runs it through a function and collects the outputs. Then this code would be reusable and portable in the future.
However, I’m wondering about how I should handle the inputs since there are around 50 (multiple PI controllers with parameters, IO signals). They essentially need to be pushed into the context struct each cycle. I could pass them as handles to the real data, but I’m thinking that might not be the safest option. What do you think about this? Shall I just comply with the limits of the system and deal with the global data or write the library like I thought?
Another thing is that a lot of our code is very PLC-like, meaning its just a lot of if else statements in a row and static data in function scope, file scope and global scope. Im structuring my data better, writing reusable types and functions and organizing my code better etc. but apart from that have you tried any other architectures or techniques to write control system applications? I know higher level language constructs would make writing application code easier.