State machine model construction method, operation method, operation device and storage medium
By building and running the state machine model, the problem of inflexible update of traditional on-board power control systems is solved, flexible deployment and update is achieved, cost reduction and responsiveness is improved, and it is suitable for the rapidly changing needs of the modern automotive industry.
Patent Information
- Application Number
- CN202411252616.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2044-09-09
AI Technical Summary
Traditional on-board power control systems are not flexible and efficient enough when updating or modifying logic in the modern automotive industry with rapidly changing demands, resulting in system downtime and reprogramming time-consuming and costly.
By configuring the state table, state migration table, interface table and condition table, building a state machine model, generating configuration files, and using the state machine interpreter, interface management module, condition judgment module and trigger execution module to achieve flexible deployment and update of the state machine. Allows dynamic adjustment of the behavior and logic of the state machine at runtime.
Implement flexible deployment and update of state machines, reduce development and maintenance costs, improve system modularity and maintainability, and allow modification and expansion of state machine models without interrupting system operation to quickly respond to external events and changes. .
Smart Images

Figure CN118760485B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the technical field of vehicle electronic control systems, and specifically relates to a construction method, an operation method and a storage medium of a state machine model. Background Art
[0002] Existing on-board power control systems have significant limitations in terms of flexibility, update speed, etc., especially in the modern automotive industry where demands change rapidly.
[0003] Traditional in-vehicle power control systems typically rely on hard-coded state machines, which, while stable, are inflexible and inefficient when logic needs to be updated or modified. Each update may require system downtime and reprogramming, which is time-consuming and costly. Summary of the invention
[0004] The technical purpose of this application is to address the technical problem that traditional vehicle power control systems are not flexible and efficient enough when the logic needs to be updated or modified. A state machine model construction method, operation method, operation device and storage medium are provided to achieve flexible deployment and update of the state machine.
[0005] In order to achieve the above technical objectives, this application adopts the following technical solutions.
[0006] In a first aspect, an embodiment of the present application provides a method for constructing a state machine model, including:
[0007] The state machine model is obtained by configuring a state table, a state transition table, an interface table and a condition table; a configuration file of the state machine model is generated according to the configuration information of the state machine model, and the configuration file is used to support the operation of the state machine model;
[0008] Wherein, the state table includes a state identifier of each state;
[0009] The state transition table includes a state identifier of a transition source state, a state identifier of a transition target state, and a condition identifier of a transition condition;
[0010] The interface table includes an interface identifier of each interface;
[0011] The condition table includes a condition identifier of a migration condition, an interface identifier of an interface corresponding to the migration condition, an expected value of the interface, and a state migration logic, wherein the migration logic is used to determine a preset relationship between the expected value and the actual value of the interface, so as to trigger state migration when the expected value and the actual value of the interface satisfy the preset relationship.
[0012] In some implementations, the state table, the state transition table, the interface table, and the condition table are all stored in a relational database.
[0013] In some embodiments, the construction method further comprises:
[0014] A state machine editor is provided, and the state machine editor implements adding, modifying or deleting the state machine model by visual editing or providing a command line interface to read scripts.
[0015] In some implementations, generating a configuration file of the state machine model according to the configuration information of the state machine model includes:
[0016] Establishing a connection with a database storing configuration information of the state machine model;
[0017] Creating a main function, the main function is used to convert the configuration information of the state machine model from database data into a configuration file in JSON format, the main function calls the first sub-function, the second sub-function and the third sub-function;
[0018] Creating the first sub-function, the first sub-function is used to query the configuration information of the state machine model from the database using a query statement to obtain a query result; the query result may include information of all states and information of all state transitions;
[0019] Creating the second sub-function, where the second sub-function is used to convert the query result into JSON data;
[0020] The third sub-function is created, and the third sub-function is used to convert and write the JSON data into the configuration file.
[0021] In some implementations, the state table further includes a state name and a state type.
[0022] In some implementations, the state transition table further includes a transition identifier for each transition.
[0023] In some implementations, the interface table further includes each interface name, a default value of the interface, and description information of the interface.
[0024] In a second aspect, an embodiment of the present application provides a method for operating a state machine model, including: constructing the state machine model using a method for constructing a state machine model provided in any possible implementation manner of the first aspect;
[0025] Constructing a state machine interpreter, wherein the state machine interpreter is configured to obtain a configuration file of the state machine model and set states and state transition logic according to the configuration file;
[0026] Constructing an interface management module, wherein the interface management module is configured to perform an input operation or an output operation through an interface and determine an actual value of the interface;
[0027] Constructing a condition judgment module, wherein the condition judgment module is configured to query the migration logic of the state according to the current state and the actual value of the interface, and judge whether the migration logic for triggering the state migration is satisfied;
[0028] A trigger execution module is constructed, and the trigger execution module is configured to execute the corresponding state migration if the condition judgment module determines that the migration logic is satisfied.
[0029] In a third aspect, an embodiment of the present application provides an operating device for a state machine model, including:
[0030] A state machine model construction module, configured to construct the state machine model by adopting the state machine model construction method provided in any possible implementation manner of the first aspect;
[0031] A state machine interpreter is configured to obtain a configuration file of the state machine model and set states and state transition logic according to the configuration file;
[0032] An interface management module, configured to perform an input operation or an output operation through an interface and determine an actual value of the interface;
[0033] A condition judgment module is configured to query the migration logic of the state according to the current state and the actual value of the interface, and judge whether the migration logic is triggered;
[0034] The trigger execution module is configured to execute the corresponding state migration if the condition judgment module determines that the migration logic is satisfied.
[0035] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method for constructing a state machine model as provided in any possible implementation scheme of the first aspect.
[0036] Compared with the prior art, the state machine model construction method provided in the embodiment of the present application configures the state machine model into multiple tables with association relationships, so that each part focuses on its specific functions and information, thereby improving the modularity and maintainability of the system; due to the independence and association between the tables, the state machine model can be flexibly modified and expanded according to actual needs without the need for large-scale reconstruction of the entire system, which is convenient for developers to understand and maintain; the configuration information of the state machine model is defined through a configuration file, making the modification and update of the model simple and quick, and the function can be adjusted without modifying the code.
[0037] Compared with the prior art, the operation method of the state machine model provided in the embodiment of the present application dynamically sets the state and its migration logic according to the configuration file through the state machine interpreter, so that the configuration of the state machine can be flexibly adjusted at runtime without modifying and recompiling the code. The interface management module allows input and output operations to be performed through the interface, and determines the actual value of the interface. This mechanism enables the state machine to interact flexibly with an external system or user. The condition judgment module and the trigger execution module can judge and trigger state migration in real time according to the current state and the actual value of the interface, so that the state machine can respond quickly to external events and changes. Since the state machine is dynamically constructed through the configuration file, the behavior of the state machine and the migration logic of the state can be adjusted by modifying the configuration file without interrupting the operation of the system.
[0038] Compared with the prior art, the operating device of the state machine model provided in the embodiment of the present application has the same technical effect as the operating method of the above state machine model, and will not be elaborated on. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The drawings described herein are for explanation purposes only and are not intended to limit the scope of the present application in any way. In addition, the shapes and proportional dimensions of the components in the drawings are only for illustration purposes and are used to help understand the present application. They do not specifically limit the shapes and proportional dimensions of the components of the present application. Under the guidance of the present application, those skilled in the art can select various possible shapes and proportional dimensions to implement the present application according to specific circumstances. In the drawings:
[0040] Figure 1 A schematic diagram of a method for constructing a state machine model provided in an embodiment of the present application;
[0041] Figure 2 A schematic diagram of the operating device structure of the state machine model provided in an embodiment of the present application. DETAILED DESCRIPTION
[0042] In order to enable those skilled in the art to better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0043] See also Figure 1 , the embodiment of the present application provides a method for constructing a state machine model, including:
[0044] Step S1: Obtain a state machine model by configuring a state table, a state transition table, an interface table, and a condition table;
[0045] Step S2: Generate a configuration file of the state machine model according to the configuration information of the state machine model, the configuration file is used to support the operation of the state machine model; wherein the state table includes the state identifier of each state; the state migration table includes the state identifier of the migration source state, the state identifier of the migration target state and the condition identifier of the migration condition. The interface table includes the interface identifier of each interface.
[0046] The condition table includes the migration condition identifier of the condition, the interface identifier of the interface corresponding to the migration condition, the expected value of the interface, and the migration logic of the state. The migration logic is used to determine the preset relationship between the expected value and the actual value of the interface, so as to trigger the state migration when the expected value and the actual value of the interface meet the preset relationship.
[0047] As an example, the state table, state transition table, interface table and condition table are all stored in a relational database. A relational database management system (RDBMS) uses tables to organize data and expresses the relationship between data through associations between tables (such as foreign keys).
[0048] Relational databases use SQL (Structured Query Language) as the standard data operation language, including data query, insert, update, and delete operations. The standardization of the SQL language makes it highly portable between different database systems.
[0049] In some embodiments, the method for constructing a state machine model further includes: setting a state machine editor, which implements adding, modifying or deleting the state machine model through visual editing or providing a command line interface to read scripts. Among them, the visual editing method can provide a drag-and-drop interface, allowing users to intuitively add, edit and delete states, transitions, etc.; allowing users to set properties for each state, transition, condition and trigger, such as name, description, trigger condition, etc.
[0050] Alternatively, the state machine editor uses a scripting tool that provides a command line interface, allowing users to automate the creation, modification, and deletion of state machines by writing scripts. The state machine editor can support one or more scripting languages (such as Python, JavaScript, etc.), in which users can write custom logic to handle complex operations of the state machine.
[0051] In some embodiments, the state table also includes the name of the state and the type of the state. Adding name and type information to the state makes the state machine model more intuitive and easy to understand; the name provides an intuitive description of the state, and the type may be used to distinguish different types of states.
[0052] In some embodiments, the state migration table also includes a migration identifier for each migration. Assigning a unique identifier to a migration helps to quickly locate a specific migration operation in a complex migration logic, which can be used for debugging, logging, or state machine optimization.
[0053] In some embodiments, the interface table also includes the name of each interface, the default value of the interface, and the description information of the interface. The interface name provides an intuitive identification of the interface, while the description information further explains the function and purpose of the interface, which helps developers quickly understand the intent and restrictions when using the interface, reducing errors and misunderstandings.
[0054] The embodiments of the present application can introduce more functions and features to the state machine model without changing the existing structure by adding additional attributes (such as type, description information, etc.) to states, transitions, and interfaces.
[0055] The following are some key SQL table design examples:
[0056] Configure the state table to define all possible states and their properties in the state machine:
[0057] CREATE TABLE States (
[0058] StateID INT PRIMARY KEY,
[0059] Name VARCHAR(255),
[0060] Type ENUM('main', 'sub'),
[0061] GroupName VARCHAR(255) );
[0063] Among them, StateID represents the state identifier of the state, which is unique. Name represents the name of the state, which is used to describe the state. Type represents the type of the state, which can be a main state ('main') or a substate ('sub'), which helps to distinguish the hierarchy in the state machine. GroupName represents the group name to which the state belongs, which may be used for group management or logical grouping.
[0064] Configure the state transition table to define the transition rules between states in the state machine, including the source state, target state, and transition conditions that trigger the transition:
[0065] CREATE TABLE Transitions (
[0066] TransitionID INT PRIMARY KEY,
[0067] SourceStateID INT,
[0068] TargetStateID INT,
[0069] ConditionID INT,
[0070] FOREIGN KEY (SourceStateID) REFERENCES States(StateID),
[0071] FOREIGN KEY (TargetStateID) REFERENCES States(StateID),
[0072] FOREIGN KEY (ConditionID) REFERENCES Conditions(ConditionID) );
[0074] Among them, TransitionID represents the unique identifier of the migration. SourceStateID represents the state identifier ID of the migration source state, which points to a state in the state table. TargetStateID represents the state identifier ID of the migration target state, which also points to a state in the state table. ConditionID represents the condition identifier ID of the migration condition that triggers the migration, which points to a condition in the condition table.
[0075] Configure the interface table to define the external interfaces or parameters that may be involved in the state machine. These interfaces or parameters may be used for data exchange during condition judgment or state migration:
[0076] CREATE TABLE Interfaces (
[0077] InterfaceID INT PRIMARY KEY,
[0078] InterfaceName VARCHAR(255),
[0079] DefaultValue VARCHAR(255),
[0080] Description TEXT );
[0082] Among them, InterfaceID indicates the unique interface identifier of the interface. InterfaceName indicates the name of the interface. DefaultValue indicates the default value of the interface. Description indicates the detailed description of the interface.
[0083] Configure the condition table to define the conditions that trigger the state transition. These conditions are based on the actual interface values in the interface table and the comparison results with the expected values:
[0084] CREATE TABLE Conditions (
[0085] ConditionID INT PRIMARY KEY,
[0086] InterfaceID INT,
[0087] ExpectedValue VARCHAR(255),
[0088] LogicRelation VARCHAR(255),
[0089] FOREIGN KEY (InterfaceID) REFERENCES Interfaces(InterfaceID) );
[0091] Among them, ConditionID represents the unique condition identifier of the migration condition. InterfaceID represents the interface identifier ID related to the migration condition, pointing to an interface in the interface table. ExpectedValue represents the expected value of the interface, which is used to compare with the actual value of the interface. LogicRelation represents the migration logic of the state, such as "equal to" and "greater than", which is used to describe the logic of condition judgment.
[0092] As shown in the above example, the state table and the state transition table are associated through the state identifier of the migration source state and the state identifier of the migration target state, the state transition table and the condition table are associated through the condition identifier of the migration condition, and the condition table and the interface table are associated through the interface identifier. Such a design allows the construction of a flexible and extensible state machine system, in which states, transitions, and conditions can be defined and modified as needed.
[0093] In some embodiments, the configuration information of the state machine model generates a configuration file of the state machine model, including: establishing a connection with a database that stores the configuration information of the state machine model; creating a main function, the main function is used to convert the configuration information of the state machine model from the database data into a configuration file in JSON format, the main function calls a first sub-function, a second sub-function and a third sub-function; creating a first sub-function, the first sub-function is used to use a query statement to query the configuration information of the state machine model from the database to obtain a query result, the query result includes information of all states and information of all state transitions; creating a second sub-function, the second sub-function is used to convert the query result into JSON data; creating a third sub-function, the third sub-function is used to convert the JSON data into a configuration file in JSON format (hereinafter referred to as "JSON file"), and return the configuration file.
[0094] As an example, here is a pseudo-code example and architectural description of how a state machine model is converted to a configuration file or other parameter list in JSON format:
[0095] The conversion process involves extracting the relevant data of the state machine from the database and formatting it into a parameter list in JSON or other formats. This process usually includes three main steps: data extraction, data conversion, and file generation.
[0096] The pseudo code example is as follows:
[0097] # Define a function to convert the state machine data in the database into a JSON file.
[0098] def convertStateMachineToJSON(databaseConnection):
[0099] # Get state machine data from the database
[0100] stateMachineData = fetchStateMachineData(databaseConnection)
[0101] # Convert the acquired data into JSON format
[0102] jsonFormat = transformDataToJSON(stateMachineData)
[0103] # Generate JSON file
[0104] jsonFile = generateJSONFile(jsonFormat)
[0105] # Return the generated JSON file path
[0106] return jsonFile
[0107] # Define a function to extract the state and transition data of the state machine from the database
[0108] def fetchStateMachineData(databaseConnection):
[0109] # Execute SQL query to obtain data of all states
[0110] states = databaseConnection.executeQuery("SELECT * FROM States")
[0111] # Execute SQL query to obtain data of all state transitions
[0112] transitions = databaseConnection.executeQuery("SELECT * FROMTransitions")
[0113] # Return a dictionary containing status and conversion data
[0114] return {"States": states, "Transitions": transitions}
[0115] # Define a function to convert the state machine data into JSON format
[0116] def transformDataToJSON(stateMachineData):
[0117] # Initialize an empty dictionary to store JSON data
[0118] jsonData = {}
[0119] # Use list comprehension to construct a JSON-formatted status list from the status data
[0120] jsonData["states"] = [{"id": state.id, "name": state.name} forstate in stateMachineData["States"]]
[0121] # Use list comprehension to construct a JSON transformation list from the transformation data
[0122] jsonData["transitions"] = [{"from": trans.sourceStateID, "to":trans.targetStateID} for trans in stateMachineData["Transitions"]]
[0123] # Return constructed JSON data
[0124] return jsonData
[0125] # Define a function to generate a JSON file and write data to the file
[0126] def generateJSONFile(jsonData):
[0127] # Set the name of the JSON file
[0128] jsonFile = "state_machine_config.json"
[0129] # Call the function that writes the file to write the JSON data to the file
[0130] writeToFile(jsonFile, jsonData)
[0131] # Return the path to the JSON file
[0132] return jsonFile
[0133] The state machine model construction method provided in the embodiment of the present application has flexibility and fast response performance. Engineers can quickly respond to changes in requirements and update the state machine model through simple database operations without going deep into the underlying code. It has high cost efficiency and reduces the development and maintenance costs caused by frequent system downtime and reprogramming. The modular design of the state machine model makes the system easier to expand and maintain, and also facilitates the reuse of functions.
[0134] An embodiment of the present application also provides a method for operating a state machine model, including: constructing a state machine model using the state machine model construction method of the above embodiment; constructing a state machine interpreter, the state machine interpreter is configured to obtain a configuration file of the state machine model, and set the state and the state migration logic according to the configuration file; constructing an interface management module, the interface management module is configured to perform input operations (such as sensor input) or output operations (such as actuator output) through the interface, and determine the actual value of the interface; constructing a condition judgment module, the condition judgment module is configured to query the state migration logic according to the current state and the actual value of the interface, and determine whether the migration logic for triggering state migration is met; constructing a trigger execution module, the trigger execution module is configured to execute the corresponding state migration if the condition judgment module determines that the migration logic is met.
[0135] In one scenario of the embodiment, the vehicle power management system needs to dynamically adjust the power output according to the ambient temperature and vehicle speed. Through the operation method of the state machine model provided in the embodiment of the present application, developers can configure the relevant states and transition logic in the database, and the generated JSON configuration file is transmitted to the vehicle wirelessly, and the new configuration information is dynamically loaded by the microcontroller unit (MCU). This process not only does not require manual intervention, but can also be completed in real time during the operation of the vehicle.
[0136] The embodiments of the present application enable the configuration of the state machine to be flexibly adjusted at runtime without modifying and recompiling the code, can flexibly interact with external systems or users, can receive new state machine configuration files without interrupting system operation, and dynamically update its behavior, thereby adjusting the behavior and logic of the state machine by modifying the configuration files.
[0137] Based on the same inventive concept as the above embodiments, the present application also provides an operating device for a state machine model, such as Figure 2 As shown, it includes a state machine model building module, a state machine interpreter, an interface management module, a condition judgment module and a trigger execution module.
[0138] The state machine model construction module is configured to construct the state machine model using the state machine model construction method as described above;
[0139] The state machine interpreter is configured to obtain the configuration file of the state machine model and set the state and the state transition logic according to the configuration file;
[0140] The interface management module is configured to perform an input operation or an output operation through the interface and determine an actual value of the interface;
[0141] The condition judgment module is configured to query the state migration logic according to the current state and the actual value of the interface, and judge whether the migration logic for triggering the state migration is satisfied;
[0142] The trigger execution module is configured to execute the corresponding state migration if the condition judgment module determines that the migration logic is satisfied.
[0143] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method for constructing a state machine model as described above is implemented.
[0144] The above is a detailed introduction to the construction method, operation method, operation device and storage medium of the state machine model provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the concept of the present application and should not be understood as limiting the scope of protection of the present application.
Claims
1. A method for constructing a state machine model, characterized in that: The construction method comprises: The state machine model is obtained by configuring a state table, a state transition table, an interface table and a condition table; a configuration file of the state machine model is generated according to the configuration information of the state machine model, and the configuration file is used to support the operation of the state machine model; Wherein, the state table includes a state identifier of each state; The state transition table includes a state identifier of a transition source state, a state identifier of a transition target state, and a condition identifier of a transition condition; The interface table includes an interface identifier of each interface; The condition table includes a condition identifier of a migration condition, an interface identifier of an interface corresponding to the migration condition, an expected value of the interface, and a migration logic of a state, wherein the migration logic is used to determine a preset relationship between the expected value and an actual value of the interface, so as to trigger a state migration when the expected value and the actual value of the interface satisfy the preset relationship; The method for constructing the state machine model also includes: A state machine editor is provided, wherein the state machine editor implements adding, modifying or deleting the state machine model by visual editing or providing a command line interface to read scripts; Generating a configuration file of the state machine model according to the configuration information of the state machine model includes: Establishing a connection with a database storing the configuration information; Creating a main function, the main function is used to convert the configuration information from the database data into a configuration file in JSON format, the main function calls the first sub-function, the second sub-function and the third sub-function; Creating the first sub-function, where the first sub-function is used to query the configuration information from the database using a query statement; Creating the second sub-function, where the second sub-function is used to convert the query result into JSON data; The third sub-function is created, and the third sub-function is used to write the JSON data into the configuration file.
2. The method for constructing a state machine model according to claim 1, characterized in that: The state table, the state transition table, the interface table and the condition table are all stored in a relational database.
3. The method for constructing a state machine model according to claim 1, characterized in that: The state table also includes the name of the state and the type of the state.
4. The method for constructing a state machine model according to claim 1, characterized in that: The state transition table also includes a transition identifier of each transition.
5. The method for constructing a state machine model according to claim 1, characterized in that: The interface table also includes the name of each interface, the default value of the interface and the description information of the interface.
6. A method for operating a state machine model, characterized in that: include: Constructing the state machine model using the state machine model construction method as described in any one of claims 1 to 5; Constructing a state machine interpreter, wherein the state machine interpreter is configured to obtain the configuration file and set the state and the state migration logic according to the configuration file; Constructing an interface management module, wherein the interface management module is configured to perform an input operation or an output operation through an interface and determine an actual value of the interface; Constructing a condition judgment module, wherein the condition judgment module is configured to query the migration logic of the state according to the current state and the actual value of the interface, and judge whether the migration logic is satisfied; A trigger execution module is constructed, and the trigger execution module is configured to execute the corresponding state migration if the condition judgment module determines that the migration logic is satisfied.
7. A running device of a state machine model, characterized in that: include: A state machine model construction module, configured to construct the state machine model using the state machine model construction method as described in any one of claims 1 to 5; A state machine interpreter is configured to obtain the configuration file and set the state and the state transition logic according to the configuration file; An interface management module, configured to perform an input operation or an output operation through an interface and determine an actual value of the interface; A condition judgment module is configured to query the state migration logic according to the current state and the actual value of the interface, and judge whether the migration logic is satisfied; The trigger execution module is configured to execute the corresponding state migration if the condition judgment module determines that the migration logic is satisfied.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for constructing a state machine model as described in any one of claims 1 to 5 is implemented.
