Method and device for automatically generating embedded code

Through the sorting optimization of Modelica language model and template function conversion processing, embedded code is generated, which solves the problem that Modelica language conversion is difficult to apply to vehicle-mounted embedded chips in the existing technology, and achieves higher flexibility and compatibility. The scope of application of Modelica model.

CN119105749APending Publication Date: 2024-12-10BEIHANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411091463.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-09
Publication Date
2024-12-10

AI Technical Summary

Technical Problem

The prior art is difficult to convert the Modelica language into embedded code executable by vehicle-mounted embedded chips, and relies on a fixed conversion platform and its closed source model library, limiting its application scope.

Method used

By obtaining the Modelica language model, sorting optimization is performed to extract dynamic information, and convert dynamic information based on preset template functions to generate embedded code for executing automotive system functions, eliminating the huge runtime library and specific closings The dependency of the source Modelica model library.

Benefits of technology

It realizes the conversion of more Modelica models into embedded code executable by on-board embedded chips, which improves flexibility and compatibility and broadens the application scope of Modelica models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119105749A_ABST
    Figure CN119105749A_ABST
Patent Text Reader

Abstract

The invention provides an automatic generation method and device for embedded codes. The method comprises the steps that a Modelica language model used for representing automobile system functions is acquired; the Modelica language model is subjected to sorting optimization processing, and dynamic information in the Modelica language model is obtained; and converting the dynamic information based on a preset template function to obtain an embedded code for executing an automobile system function. According to the scheme, more Modelica models can be converted into embedded codes capable of being executed by the vehicle-mounted embedded chip, meanwhile, dependence on a huge runtime library and a specific closed source Modelica model library is eliminated, higher flexibility and compatibility are achieved, and therefore the application range of the Modelica models is widened.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a method and device for automatically generating embedded codes. Background Art

[0002] With the continuous development of the automotive field, modeling and simulation using modeling tools are key links in designing automotive control systems. Modelica is an equation-based and object-oriented language, and it is also a cross-domain modeling language. The graphical Modelica model written by developers can be converted into the corresponding C language code, which is suitable for relatively complex automotive systems.

[0003] In the related art, converting the Modelica language into C language code requires relying on a fixed conversion platform and its closed-source model library, which makes it impossible to convert the language into the C language embedded code required by the vehicle on the vehicle embedded chip.

[0004] Based on this, there is an urgent need for an automatic generation method and device of embedded code to solve the above technical problems. Summary of the invention

[0005] The embodiment of the present invention provides a method and device for automatically generating embedded code, which can realize the conversion of Modelica model into embedded code on a vehicle-mounted embedded chip.

[0006] In a first aspect, an embodiment of the present invention provides a method for automatically generating an embedded code, comprising:

[0007] Obtain the Modelica language model used to represent the functions of the automobile system;

[0008] Performing sorting optimization processing on the Modelica language model to obtain dynamic information in the Modelica language model;

[0009] The dynamic information is transformed and processed based on a preset template function to obtain an embedded code for executing the automobile system function.

[0010] In a second aspect, an embodiment of the present invention further provides an automatic generation device for embedded code, comprising:

[0011] An acquisition module is used to acquire a Modelica language model representing the functions of an automobile system;

[0012] A first processing module is used to perform sorting optimization processing on the Modelica language model to obtain dynamic information in the Modelica language model;

[0013] The second processing module is used to convert the dynamic information based on a preset template function to obtain an embedded code for executing the automobile system function.

[0014] In a third aspect, an embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in any embodiment of this specification is implemented.

[0015] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, enables the computer to execute the method described in any embodiment of this specification.

[0016] The embodiment of the present invention provides an automatic generation method and device of embedded code, firstly, the Modelica model designed by the developer is obtained, the model is optimized and sorted, the dynamic information in the model is obtained, and then the dynamic information is converted based on a preset template function, so that the embedded code for executing the function of the automobile system can be obtained. Through the above method, more Modelica models can be converted into embedded codes executable by vehicle-mounted embedded chips, and at the same time, the method also eliminates the dependence on a huge runtime library and a specific closed-source Modelica model library, achieving higher flexibility and compatibility, thereby broadening the application scope of the Modelica model. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0018] Figure 1 is a flow chart of a method for automatically generating embedded codes provided by an embodiment of the present invention;

[0019] Figure 2 is a hardware architecture diagram of an electronic device provided by an embodiment of the present invention;

[0020] Figure 3 It is a structural diagram of an automatic generation method of embedded code provided by an embodiment of the present invention;

[0021] Figure 4 is a variable mapping relationship diagram provided by an embodiment of the present invention;

[0022] Figure 5It is a flow chart of SimEqSystem analysis provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0023] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0024] As mentioned earlier, although there are some tools that generate C code from Modelica models, these tools often need to rely on fixed platform tools and their corresponding closed-source model libraries, making it difficult to apply the conversion technology to automotive embedded chips.

[0025] Based on this, the design concept of the present invention is to eliminate the dependence on a specific closed-source model library by establishing a template function for generating C code from a Modelica model, thereby achieving higher conversion flexibility and compatibility.

[0026] The specific implementation of the above concept is described below.

[0027] Please refer to Figure 1 , an embodiment of the present invention provides a method for automatically generating an embedded code, the method comprising:

[0028] Step 100, obtaining a Modelica language model for representing a function of an automobile system;

[0029] Step 102, performing sorting optimization processing on the Modelica language model to obtain dynamic information in the Modelica language model;

[0030] Step 104 , converting the dynamic information based on a preset template function to obtain an embedded code for executing the automobile system function.

[0031] In the embodiment of the present invention, the Modelica model designed by the developer is first obtained, the model is optimized and sorted, the dynamic information in the model is obtained, and the dynamic information is converted based on the preset template function to obtain the embedded code for executing the function of the automobile system. Through the above method, more Modelica models can be converted into embedded codes executable by vehicle-mounted embedded chips. At the same time, the method also eliminates the dependence on a huge runtime library and a specific closed-source Modelica model library, achieving higher flexibility and compatibility, thereby broadening the application scope of the Modelica model.

[0032] Described below Figure 1 How the various steps are performed.

[0033] First, for step 100 , a Modelica language model for representing the function of the automobile system is obtained.

[0034] In the key tool chain project of the automotive electronic control unit, the relevant simulation models are written by developers who are familiar with the structure of the vehicle, by dragging components on the graphical interface to automatically generate Modelica code. Models written in Modelica can support graphical display through comment statements, that is, dragging on the graphical interface can automatically generate Modelica models containing comments. At the same time, developers familiar with the Modelica language can also directly write Modelica models that do not contain comments and cannot be graphically displayed without the graphical interface, which will serve as the basis for subsequent conversion to generate C language.

[0035] Then, with respect to step 102, the Modelica language model is sorted and optimized to obtain dynamic information in the Modelica language model.

[0036] In the embodiment of the present invention, the dynamic information includes variable information and a set of equations, and the variable information includes the variable type and the number of each type of variables.

[0037] Specifically, the Modelica language model is processed to obtain SimCode, which is a MetaModelica class object. It is similar to an expression tree, that is, the equations in the Modelica language model are analyzed into expression trees of variables and operators. SimCode is an optimized and sorted equation. It is a MetaModelica union, which is nested and contains many other unions to form a tree structure, which contains all the information required for code generation.

[0038] In MetaModelica, you can use the Uniontype keyword to define a union, similar to Union in C; you can also use the Record keyword to define a structure, similar to a structure in C. Although there are no explicit classes or interfaces, nor inheritance or implementation in MetaModelica, as an object-oriented language, defining multiple Records in a Uniontype can mimic object-oriented behavior. It can be understood that Uniontype is the parent class, and Record is the child class of the parent class; or more precisely, since there is no information in the parent class, Uniontype is an interface, and the Record "class" implements this interface. For example, you can define a Uniontype for "expression", and then define multiple Records inside it, representing "unary expression", "binary expression", etc. When you do not need polymorphic features such as inheritance, you only need one class. You can define the "interface" provided by Uniontype and the "class" provided by Record as classes with the same name (different case), which means defining an independent class.

[0039] The SimCode union contains a ModelInfo object, a SimEqSystem list, and a hash table for variable name conversion.

[0040] The ModelInfo union stores the general information of the model. It contains only one Record field with the same name, including the model name, the number of variables of each type varInfo, the variable group vars, and the function group functions. The variable group and function group collect all the variables and functions.

[0041] The SimEqSystem union contains various types of equations. This union is the starting point for converting the Modelica language model into C language code. It contains multiple Record fields. Each Record field contains the same Integer type index variable, indicating which equation this is in the Modelica language model.

[0042] SimEqSystem contains SES_SIMPLE_ASSIGN and SES_ALGORITHM, where SES_SIMPLE_ASSIGN represents a simple assignment expression for this equation, which contains the following: 1. cref of ComponentRef type, i.e. the left value of the equation, the object to be assigned 2. exp of Exp type, i.e. the right side equation of the equation. SES_ALGORITHM is another Record in SimEqSystem, indicating that this is the most common operation expression, which contains only a list of Statement type in addition to the index, used to store all statements.

[0043] In summary, by using the above structure to perform sorting and optimization processing on the Modelica language model, it is possible to extract dynamic information from the Modelica language model.

[0044] With respect to step 104 , the dynamic information is transformed based on a preset template function to obtain an embedded code for executing the automobile system function.

[0045] In the embodiment of the present invention, the template function includes a main function and a simulation step function, and the simulation step function includes a first processing function and a second processing function.

[0046] In the embodiment of the present invention, the main function, as the beginning of the simulation, first sets a flag variable for ending the simulation, and defines a current simulation state enumeration as OK. Then, the initialization function is called to initialize and check whether the structure pointer is empty. Then, the current time currentTime, the simulation step size stepSize, and the end time endTime are defined.

[0047] In an embodiment of the present invention, the conversion process includes the following steps: initializing the variable information to obtain the position subscript of each variable; using the simulation step function to decompose the equation group to obtain the equivalent expression of the Modelica equation in the C language; combining the variables, the main function and the equivalent expression to obtain the embedded code for executing the automobile system function.

[0048] In an embodiment of the present invention, the position subscript of a variable is obtained by the following steps: macro definition and type definition are performed on the variable type in sequence to obtain a mapping relationship between the Modelica language variable type and the C language variable type; based on the mapping relationship, a structure array of the C language model is established; wherein the structure array is used to store variables of the Modelica language model, and the variables include unknowns and parameters; assignment processing is performed on the structure array to obtain the position subscript of each variable in the structure array; wherein the position subscript is used to represent the address position of the variable in the Modelica model.

[0049] Specifically, in Modelica, a properly functioning model requires the number of unknowns to be equal to the number of equations. Other variables are called parameters (parameters can be Modelica's built-in variable time). Therefore, in the C language structure, first and foremost, a double-type currentTime must be included to represent the current time. After that, a structure is generated for Modelica variables of the same type and kind. For example, if there are three Real-type unknowns, a double-type array of length 3 is generated. Figure 4 As shown, arrays are divided into two categories, namely unknowns and parameters; there are at most four types in each category, namely integer, real, Boolean, and string.

[0050] Furthermore, in the process of generating embedded code, there is a completely fixed part, namely the macro definition and type definition at the beginning of the file. The macro definition mainly defines True and False in Modelica as int type constants 1 and 0 in C language. Type definition is to express Modelica types with existing types in C language, which is convenient for subsequent understanding. That is, Modelica integer Integer corresponds to C language int type, real type Real corresponds to C language double precision floating point double, Boolean type Boolean corresponds to C language int type, and its truth or falsity is resolved by the previous macro definition, and string type corresponds to C language constant character pointer const char*. Through this definition processing, the mapping relationship between Modelica language variable type and C language variable type can be obtained.

[0051] Furthermore, according to this mapping relationship, a suitable storage structure is designed for the variables. Here, all variables are collected into the same structure, and arrays of appropriate sizes are allocated for variables of different types and categories. Then, the variables are assigned the correct initial values. If there is no explicit initialization assignment in Modelica, the default value is assigned, that is, 0 or a class 0 value. When the variables are initialized, the array defined during declaration is initialized in a certain order, which is equivalent to defining the mapping relationship between the array subscript and the Modelica variable. The array subscript is the subscript used to characterize the position of the variable in the Modelica model. When using the variable later, the correct array subscript can be found according to the variable, which facilitates the call of the subsequent conversion process.

[0052] It is worth noting that the definition and assignment of variables are separate. When defining, only a structure array of appropriate size is allocated. When assigning, the array subscript corresponding to the variable can be determined.

[0053] In an embodiment of the present invention, the conversion process of the set of equations includes: determining the type of the set of equations; wherein the type of the set of equations includes assignment expressions and conditional judgment expressions; converting each type of set of equations to obtain the equivalent expression, wherein, when the set of equations is an assignment expression, the set of equations is converted using a first processing function and a second processing function to obtain a first equivalent set of equations; when the set of equations is a conditional judgment expression, the set of equations is converted using a second processing function to obtain a second equivalent set of equations having an if conditional judgment statement.

[0054] Specifically, if Figure 5 As shown in the figure, the simulation step function is used to perform simulation, that is, to run the equivalent statements of Modelica equations in C language. In SimCode, there is an allEquations variable, which is a list of SimEqSystem, storing the equations that need to be converted. Therefore, the key to generating simulation statements is to use the derivation formula to disassemble the list in the main file template function and convert each SimEqSystem union one by one. The conversion of SimEqSystem is implemented by the equation_ template function. The role of the equation_ function is to form a framework in C language for each SimEqSystem.

[0055] For example, SES_SIMPLE_ASSIGN is a simple assignment statement, which means that the left side should have a single value, and the right side is an expression. Then the equation_ function generates a structure of leftValue=rightExp for it, which is the first equivalent equation group (it only generates the equal sign, and the two sides are further implemented by other functions). The left value has actually reached the leaf node of the expression tree and is processed by the first processing function (cref function), and the right side is handed over to the second processing function (daeExp function) for processing.

[0056] For SES_ALGORITHM, since it contains a statement list, the equation_ function simply disassembles the statement list and passes it to the statement function for further processing.

[0057] The statement template function processes the passed statement list, which includes STMT_ASSIGN and STMT_IF. STMT_ASSIGN is the most common statement block, and its Modelica form is similar to a:=b;, so there are only two Exp types on the left and right; STMT_IF is the statement block of the if statement, which contains an Exp as the condition of if, and a list of statements to be executed when the condition is met, that is, a list of Statement type list <statement>statements, followed by an Else union, which contains three types of Records, namely NOELSE, IFELSE, and ELSE, to distinguish between the situations of no else, elseif, and else.

[0058] For STMT_ASSIGN, it is similar to the equation_ function processing SIMPLE_ASSIGN, generating a structure of leftValue=rightExp. For the same STMT_IF structure, it is processed recursively. That is, the if keyword is generated and deaExp is called to process the conditional judgment expression contained in STMT_IF, and then it recursively calls itself to process the statement when if succeeds, and finally calls the elseStatement template function to process the else situation, and obtains the second equivalent equation group.

[0059] The deaExp template function determines what kind of C language structure to generate for it according to the type of the formal parameter exp passed in. If the type of exp is a constant type, such as RCONST, that is, a real constant, then the corresponding digital representation can be directly given. If the type of exp is LUNARY, and the operator is NOT, indicating that it is a unary non-statement, then the !() operator is generated and recursively calls itself. If the type of exp is BINARY, it is a binary expression, and the corresponding C language operator is generated according to the type of operator. If the type of exp is RELATION, it means that it is a conditional judgment expression, which is also a binary structure, and it is processed together with the previous binary expression by deaExpBinary. If the type of exp is IFEXP, a C language ternary operator is used to judge, that is, exp1? exp2:exp3.

[0060] In summary, by judging the type of SimEqSystem, then judging the type of the subtype, and continuously performing decomposition and judgment, until a simple assignment statement or conditional judgment statement is found, the corresponding C language equivalent expression is generated, and then the cref function and deaExp function are used to further fill the variables stored in the structure array into the corresponding positions of the equation. Combined with the preset main function, the corresponding C language embedded code can be obtained.

[0061] In an embodiment of the present invention, after the embedded code is obtained, it can be simulated according to the simulation data set in the main function: the C language expression is looped based on the simulation step of the main function to obtain the loop return state; when the loop time is the same as the simulation time of the main function, the loop processing is ended.

[0062] Specifically, after entering the loop, the DoStep function is first called for calculation, and then the return value of the DoStep function determines the value of the current model state enumeration variable. Then a switch statement checks the model state. If an Error occurs, the end simulation flag variable is set to 1 to prepare to end the simulation. After judging the state, determine whether to end the simulation. If it ends, jump out of the loop and end. If the simulation can continue, the simulation step is incremented, and the current time is updated according to the step size, current time, and simulation step. When the time reaches the simulation time, the loop is terminated.

[0063] It is worth noting that the equations in the Modelica model are not always linear equations. Modelica provides the der operator as a derivative symbol to support ordinary differential equations (ODE). When the equation contains the calculus operator der, a corresponding solver should be designed to approximate the specific value of the calculus through an algorithm. When there is no high requirement for accuracy, the Euler solver can be used.

[0064] The implementation of the solver is placed after the function that executes the simulation step, that is, a model must first solve equations other than equations involving calculus, and then use the results to substitute into the Euler expression to update the entire set of ordinary differential equations.

[0065] In this embodiment, the forward Euler method is used to calculate the formula:

[0066] states[i+1]=states[i]+statesDerivatives[i]*(step);

[0067] As you can see, in the formula, both the derivative statesDerivatives and the original function states appear, which means that in C language, this expression must have the definition of both the derivative variable and the original function variable. When a derivative appears, an additional C language variable needs to be defined for the derivative of the original function variable in order to complete the Euler method. For example, when the equation a=time b=der(a) appears in the model, three C language variables ab der(a) need to be defined, that is, the length of the defined RealVars array is no longer 2, but 3.

[0068] like Figure 2 , Figure 3 As shown, an embodiment of the present invention provides an automatic generation device for embedded code. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. From the hardware level, Figure 2 As shown, it is a hardware architecture diagram of an electronic device where an automatic generation device of an embedded code provided by an embodiment of the present invention is located, except Figure 2 In addition to the processor, memory, network interface, and non-volatile memory shown, the electronic device in the embodiment may also include other hardware, such as a forwarding chip responsible for processing messages, etc. Taking software implementation as an example, Figure 3 As shown, as a device in a logical sense, the CPU of the electronic device in which it is located reads the corresponding computer program in the non-volatile memory into the memory and runs it. This embodiment provides an automatic generation device of embedded code, including:

[0069] An acquisition module 300 is used to acquire a Modelica language model representing a function of an automobile system;

[0070] The first processing module 302 is used to perform sorting optimization processing on the Modelica language model to obtain dynamic information in the Modelica language model;

[0071] The second processing module 304 is used to convert the dynamic information based on a preset template function to obtain an embedded code for executing the automobile system function.

[0072] In the embodiment of the present invention, the dynamic information includes variable information and a set of equations, and the variable information includes the variable type and the number of each type of variables.

[0073] In the embodiment of the present invention, the template function includes a main function and a simulation step function, and the simulation step function includes a first processing function and a second processing function.

[0074] In the embodiment of the present invention, when the second processing module 304 performs the conversion processing of dynamic information based on the preset template function to obtain the embedded code for executing the automobile system function, it is specifically used to perform the following operations: initialize the variable information to obtain the position subscript of each variable; use the simulation step function to disassemble the equation group to obtain the equivalent equation group of the Modelica equation in the C language; combine the variables and the equivalent equation group to obtain the C language expression; use the main function to simulate and solve the C language expression to obtain the embedded code for executing the automobile system function.

[0075] In an embodiment of the present invention, variable information is initialized to obtain a position subscript of each variable, including: macro definition and type definition are performed on variable types in sequence to obtain a mapping relationship between Modelica language variable types and C language variable types; based on the mapping relationship, a structure array of the C language model is established; wherein the structure array is used to store variables of the Modelica language model, and the variables include unknowns and parameters; and assignment processing is performed on the structure array to obtain a position subscript of each variable in the structure array; wherein the position subscript is used to represent the address position of the variable in the Modelica model.

[0076] In an embodiment of the present invention, a simulation step function is used to convert a group of equations to obtain an equivalent group of equations of the Modelica equations in the C language, including: determining the type of the group of equations; wherein the type of the group of equations includes an assignment expression and a conditional judgment expression; and converting each type of group of equations to obtain an equivalent expression.

[0077] In an embodiment of the present invention, each type of equation group is converted to obtain an equivalent expression, including: when the equation group is an assignment expression, the equation group is converted using a first processing function and a second processing function to obtain a first equivalent equation group; when the equation group is a conditional judgment expression, the equation group is converted using the second processing function to obtain a second equivalent equation group with an if conditional judgment statement.

[0078] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on an automatic generation device for an embedded code. In other embodiments of the present invention, an automatic generation device for an embedded code may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0079] The information interaction, execution process and other contents between the modules in the above-mentioned device are based on the same concept as the embodiment of the method of the present invention. For specific contents, please refer to the description in the embodiment of the method of the present invention, and no further description is given here.

[0080] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, an automatic generation method of an embedded code in any embodiment of the present invention is implemented.

[0081] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the processor executes a method for automatically generating an embedded code in any embodiment of the present invention.

[0082] Specifically, a system or device equipped with a storage medium can be provided, on which software program code that implements the functions of any of the above-mentioned embodiments is stored, and a computer (or CPU or MPU) of the system or device can be enabled to read and execute the program code stored in the storage medium.

[0083] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.

[0084] The storage medium embodiments for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer by a communication network.

[0085] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.

[0086] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or to a memory provided in an expansion module connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or expansion module is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned embodiments.

[0087] It should be noted that, in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the existence of other identical factors in the process, method, article or device including the elements.

[0088] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk, etc., various media that can store program codes.

[0089] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.< / statement>

Claims

1. A method for automatically generating embedded code, characterized in that: include: Obtain the Modelica language model used to represent the functions of the automobile system; Performing sorting optimization processing on the Modelica language model to obtain dynamic information in the Modelica language model; The dynamic information is transformed and processed based on a preset template function to obtain an embedded code for executing the automobile system function.

2. The method according to claim 1, characterized in that: The dynamic information includes variable information and a set of equations, wherein the variable information includes variable types and the number of each type of variables.

3. The method according to claim 2, characterized in that The template function includes a main function and a simulation step function, and the simulation step function includes a first processing function and a second processing function.

4. The method according to claim 3, characterized in that The dynamic information is converted based on a preset template function to obtain an embedded code for executing a vehicle system function, including: Initialize the variable information to obtain the position subscript of each variable; The simulation step function is used to transform the equation group to obtain an equivalent expression of the Modelica equation in C language; The variables, the main function and the equivalent expression are combined and processed to obtain an embedded code for executing the automobile system function.

5. The method according to claim 4, characterized in that The initialization process of the variable information to obtain the position subscript of each variable includes: Performing macro definition and type definition on the variable type in turn to obtain a mapping relationship between the Modelica language variable type and the C language variable type; Based on the mapping relationship, a structure array of a C language model is established; wherein the structure array is used to store variables of the Modelica language model, and the variables include unknowns and parameters; The structure array is assigned a value to obtain a position subscript of each variable in the structure array; wherein the position subscript is used to represent a mapping relationship between the array and the variable position in the Modelica language model.

6. The method according to claim 4, characterized in that The method of converting the set of equations by using the simulation step function to obtain an equivalent expression of the Modelica equation in C language includes: Determine the type of the equation group; wherein the equation group type includes an assignment equation group and a conditional judgment equation group; Each type of system of equations is transformed to obtain the equivalent expression.

7. The method according to claim 6, characterized in that Each type of equation group is converted to obtain the equivalent expression, including: When the equation group is an assignment expression, the equation group is converted by using the first processing function and the second processing function to obtain a first equivalent equation group; When the equation group is a conditional judgment expression, the equation group is converted using a second processing function to obtain a second equivalent equation group with an if conditional judgment statement.

8. An automatic generation device for embedded code, characterized in that: include: An acquisition module is used to acquire a Modelica language model representing the functions of an automobile system; A first processing module is used to perform sorting optimization processing on the Modelica language model to obtain dynamic information in the Modelica language model; The second processing module is used to convert the dynamic information based on a preset template function to obtain an embedded code for executing the automobile system function.

9. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed in a computer, the computer is caused to execute the method according to any one of claims 1 to 7.