I appreciate the use of code generation for my flight simulation project. In particular, there is a requirement to allow the "average engineer" (without any wrongdoing myself) to define differential equations that describe a dynamic system in a more natural syntax than C ++. The idea is to develop an abstract descriptor language that can be easily understood and edited to generate C ++ code. This descriptor is provided by the modeling engineer and is used by those who implement and maintain the simulation environment to generate code.
I have something like this:
model Aircraft has state x1, x2; state x3; input double : u; input bool : flag1, flag2; algebraic double : x1x2; model Engine : tw1, tw2; model Gear : gear; model ISA : isa; trim routine HorizontalFight; trim routine OnGround, General; constant double : c1, c2; constant int : ci1; begin differential equations x1' = x1 + 2.*x2; x2' = x2 + x1x2; begin algebraic equations x1x2 = x1*x2 + x1'; end model
It is important to maintain the flexibility of the C language, so the descriptor language is intended only to define certain parts of the definition and implementation of the model class. Thus, one engineer provides the model from the descriptor language, as illustrated above, and the maintenance engineer will add all the code to read the parameters from the files, start / stop / pause the simulation, and how a specific object is created.
First of all, I want to generate two files from the descriptor file: one .h file containing declarations and one .cpp file containing the implementation of certain functions. Then they should be # included in the appropriate places
[File Aircarft.h] class Aircraft { public: void Aircraft(..);
Any thoughts or suggestions?
EDIT1:
I would like to clarify that there is a structure for expressing differential equations and (in real time) modeling a dynamic system. The problem is that most engineers with knowledge of the field are very skeptical about using C ++. In fact, we would like to make it easier for them to contribute (mathematical formulation), while maintaining the flexibility of C ++.
Of course, it is possible to use the MEX compiler to generate C code from MATLAB / Simulink models, but we would like to avoid the corresponding license fees.
Refactoring everything to use a common scripting language is likely to go beyond the capabilities of the workforce. In addition, this, as far as I can understand now and on the fly, requires engineers to also learn the scripting language. I am not yet convinced that this will be simpler than the syntax above.
EDIT2: accepted answer
I agree with Richard Harrison's answer because he shared his experience with custom code generators. I will also consider hints at scripting interfaces, although I am on the sidelines. I will not find time to implement all this as part of my dissertation. However, these pointers can help convince my colleagues to consider a more consistent class hierarchy. Many thanks!