An interface for flight control software counting or timing function and a method for implementing the same

By constructing a global small frame number identifier and counter function, and using a static count array and a small frame number array, the problems of high coupling of counters and global variable risks in flight control software are solved, achieving code simplicity and improved security.

CN120315759BActive Publication Date: 2025-11-04SHENYANG AIRCRAFT DESIGN INST AVIATION IND CORP OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510444276.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-10
Publication Date
2025-11-04
Estimated Expiration
2045-04-10

AI Technical Summary

Technical Problem

Existing flight control software counter implementations suffer from issues such as high code coupling, significant risks associated with global variable operations, and difficulty in code reading, lacking a unified approach to counter usage.

Method used

Construct global small frame number identifier and counter functions, use static count array and small frame number array, and implement the encapsulation and unified management of counter through static subscript variables to avoid explicit definition and repeated operation of global variables.

Benefits of technology

It improves code readability and security, reduces the risk of counter coupling, simplifies the use of counters, and reduces code maintenance difficulty.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120315759B_ABST
    Figure CN120315759B_ABST
Patent Text Reader

Abstract

The application provides an interface for flight control software counting or timing function and an implementation method thereof, and belongs to the technical field of flight control software. The method defines a unified counter function, which includes a counting array and a small frame number array that can be used by multiple counters, and encapsulates the counting array and the small frame number array. When a new counter is added, a new global variable does not need to be defined. A static subscript variable is only needed to be defined at a code position where the counter is needed in the flight control software, and the static subscript variable is used to indicate an element in a counting array corresponding to the currently used counter. The address of the static subscript variable is transmitted to the counter function through a parameter. When the counter function is called, the accumulation or zero clearing of the counting is automatically implemented, and the coupled use of the counter is avoided. Since the counter function implements the counting function through the internal static counting array, the counting array is encapsulated in the counter function, and the risk of external tampering of the counter is maximally avoided.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of flight control software, and particularly relates to an interface for a counting or timing function of flight control software and an implementation method thereof. BACKGROUND

[0002] In flight control (embedded) software, it is often necessary to determine in logic whether it is the first time to enter a certain functional module or whether the duration of a certain instruction meets the requirements, and therefore the counter function needs to be frequently used.

[0003] The commonly used counter implementation method in flight control software is as follows:

[0004] a) a global counting variable is defined for accumulation;

[0005] b) a counter function is defined, and the global counting variable is incremented by 1 in the counter function;

[0006] c) the global counting variable is cleaned up after the use of the counter.

[0007] However, the above method can meet the requirements of flight control software on the counting or timing function and precision, but has the following disadvantages:

[0008] 1) each time the counter is used, a new global counting variable needs to be created, the global counting variable needs to be operated for accumulation during counting, and the global counting variable needs to be cleared after counting, the flight control software implementation method is loose, and the code coupling degree is high;

[0009] 2) the explicit definition of the global counting variable may cause incorrect operation of the global variable, resulting in failure of the counter, which violates the safety principle of the flight control system;

[0010] 3) each time the counter is added, the code needs to be re-written, and in the absence of unified principles, the variable naming and coding methods are different, which brings difficulties to code reading.

[0011] Therefore, a new interface implementation method for the counting or timing function of flight control software is needed to optimize the dependence of the conventional counter on the global variable, unify the use of the counter, and improve the code readability. SUMMARY

[0012] The application aims to provide an interface for the counting or timing function of flight control software and an implementation method thereof to solve or alleviate at least one problem in the background art.

[0013] In a first aspect, the technical solution of the application is an interface implementation method for the counting or timing function of flight control software, comprising:

[0014] A global small frame number identifier is constructed to represent a global small frame number added every small frame in the flight control software.

[0015] A counter function is constructed, and a count array and a small frame number array are set in the counter function, the counter function including three parameters, the first parameter being an array subscript, used to indicate the element position in the count array and the small frame number array corresponding to the currently used counter, the second parameter being the global small frame number, and the third parameter being a count interval.

[0016] A static subscript variable is constructed, and the static subscript variable and the counter function are set at the position where the counter is used, the currently used counter in the counter function is determined according to the static subscript variable, and whether the small frame number of the currently used counter in the small frame number array is the same as the global small frame number is compared, if the same, it indicates that the currently used counter is continuously called and continues to count, at this time, the element value of the currently used counter in the count array is added by the count interval to realize the update of counting, and the element value of the currently used counter in the small frame number array is updated; if different, it indicates that the currently used counter is not continuously called, at this time, the element value of the currently used counter in the count array is reset, and the element value of the currently used counter in the small frame number array is updated to the global small frame number.

[0017] Preferably, the global small frame number added value is 1.

[0018] Preferably, the element number of the count array and the small frame number array is the same, and the element number is determined according to the maximum use amount of the counter.

[0019] Preferably, the count array and the small frame number array are static arrays.

[0020] Preferably, the count interval is the same as the added value of the global small frame number.

[0021] Preferably, the static subscript variable is initialized before use, and the address of the static subscript variable is passed to the counter function as a parameter when used, and the array subscript is automatically sorted and assigned to the static subscript variable in the counter function, so as to distinguish different counters.

[0022] Preferably, the count array and the small frame number array are initialized before use, and the element values in the count array and the small frame number array are initialized to 0.

[0023] In a second aspect, the technical scheme provided by the present application is an interface for the counting or timing function of the flight control software, comprising:

[0024] A global small frame number identifier construction module is configured to construct a global small frame number identifier to represent a global small frame number added every small frame in the flight control software.

[0025] The counter function construction module is configured to construct a counter function, and set a counting array and a subframe number array in the counter function, wherein the counter function comprises three parameters, the first parameter is an array subscript, used to indicate the element position in the counting array and the subframe number array corresponding to the currently used counter, the second parameter is a global subframe number, and the third parameter is a counting interval;

[0026] The judging module is configured to construct a static subscript variable, set the static subscript variable and the counter function at the position where the counter is used, determine the currently used counter in the counter function according to the static subscript variable, compare the subframe number of the currently used counter in the subframe number array with the global subframe number, if they are the same, it indicates that the currently used counter is continuously called and continues to count, at this time, the element value of the currently used counter in the counting array is added by the counting interval to realize the update of counting, and the element value of the currently used counter in the subframe number array is updated; if they are different, it indicates that the currently used counter is not continuously called, at this time, the element value of the currently used counter in the counting array is reset, and the element value of the currently used counter in the subframe number array is updated to the global subframe number.

[0027] The interface implementation method for the counting or timing function of the flight control software provided in the application defines a unified counter function, which comprises a counting array and a subframe number array that can be used by multiple counters, and encapsulates the same. When a new counter is added, a new global variable does not need to be defined, and only a static subscript variable needs to be defined at the code position where the counter is used in the flight control software, which is used to indicate the element in the counting array corresponding to the currently used counter. The address of the static subscript variable is transmitted to the counter function through a parameter, so that the accumulation or zeroing of counting can be automatically realized when the counter function is called, thereby avoiding the coupled use of the counter. Since the counter function realizes the counting function through the internal static counting array, the counting array is encapsulated in the counter function, thereby avoiding the risk of external tampering with the counter to the maximum extent. BRIEF DESCRIPTION OF DRAWINGS

[0028] In order to more clearly illustrate the technical solutions provided in the application, the following will briefly introduce the drawings. Obviously, the drawings described below are only some embodiments of the application.

[0029] Figure 1 The figure is a schematic diagram of the interface implementation method for the counting or timing function of the flight control software provided in the application.

[0030] Figure 2 The figure is a schematic diagram of the interface for the counting or timing function of the flight control software provided in the application. DETAILED DESCRIPTION

[0031] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the present application will be described in more detail below in combination with the drawings in the present application.

[0032] In order to make the counting or timing function in the flight control software more secure and simple, the present application provides an interface for the counting or timing function of the flight control software and an implementation method thereof.

[0033] As shown in Figure 1 The interface implementation method for the counting or timing function of the flight control software provided by the present application includes:

[0034] S10, a global small frame number identifier is constructed, which is used to represent the global small frame number added by each small frame in the flight control software.

[0035] The flight control software is the core part of the flight control system of unmanned aerial vehicles, aircrafts and the like, which is responsible for processing sensor data, executing control algorithms and outputting control instructions, etc., to ensure the stable operation of the aircraft. The development tools commonly used in the flight control software include MATLAB / Simulink, PX4, ArduPilot, etc., so as to realize the whole process development from simulation to actual flight.

[0036] In the flight control software, "small frame" usually refers to a period or time slice (TimeSlice) in a high-frequency control cycle, which is used to execute fast and real-time control tasks. The small frame is the basic unit of the high-frequency control cycle in the flight control software, which is used to ensure that the flight control system can process sensor data and output control instructions in real time, and is crucial to the stability and response speed of the aircraft. Since the flight control system needs to process sensor data and output control instructions at high frequency, the control task is divided into multiple small frames, and each small frame completes a specific task in a very short time. For example, the flight control system runs at a fixed frequency (such as 100Hz, 500Hz), and each cycle is called a small frame. The period of the small frame is very short (usually a few milliseconds to tens of milliseconds, for example, 12.5ms in the present application), so as to ensure that the flight control system can quickly respond to changes in sensor data. The global small frame number is incremented by one every small frame (12.5ms), and the increment value can usually be 1.

[0037] S20, a counter function is constructed, and two arrays, a counting array and a small frame number array, are set in the counter function. The counter function includes three parameters, the first parameter is an array subscript, which is used to indicate the element position in the counting array and the small frame number array corresponding to the currently used counter, the second parameter is the global small frame number, and the third parameter is the counting interval.

[0038] An array is a data structure used to store a group of elements (numbers or strings) of the same type, and the elements in the array are accessed through the subscript, for example, the subscript 0 (starting from 0) accesses the first element in the array.

[0039] In the present application, the number of elements in the two arrays is determined according to the maximum usage of the counter, that is, the number of elements in the two arrays is not less than the maximum usage of the counter. For example, the counter in the flight control software can be used for a maximum of 10 times, and thus the count array C and the small frame number array F set in the counter function are set as arrays with 10 elements. The elements of the count array C and the small frame number array F are as follows:

[0040] The count array C is [C1, C2, C3, C4, C5, C6, C7, C8, C9, C10];

[0041] The small frame number array F is [F1, F2, F3, F4, F5, F6, F7, F8, F9, F10].

[0042] The array index set in the counter function can indicate the position of the currently used counter in the elements of the count array and the small frame number array. For example, when the array index is 1, the currently used counter is the element C2 in the count array C (that is, the count value C2), and the small frame number of the currently used counter is the element F2 in the small frame number array F (that is, the small frame number F2). By indicating the elements or their positions in the two arrays through an array index, the counter with the count and the small frame number is constructed, and each counter can be individually identified in the counter function.

[0043] In the preferred embodiment of the present application, the count array and the small frame number array are static arrays. By setting them as static arrays, the performance of the flight control software can be improved, and the memory management is simple and safe.

[0044] In the present application, the count interval generally represents the number of beats of the count interval, which is not the actual interval time. The count interval is generally the same as the self-increment value of the global small frame number, that is, the count interval can be set to 1 in the present embodiment.

[0045] S30, a static index variable is constructed, and a static index variable and a counter function are set at a position where the counter is needed to be used. The currently used counter in the counter function is determined according to the static index variable. Whether the small frame number of the currently used counter in the small frame number array is the same as the global small frame number is compared. If they are the same, it indicates that the currently used counter is continuously called and needs to continue counting. At this time, the element value of the currently used counter in the count array is added by the count interval to update the counting, and the element value of the currently used counter in the small frame number array is updated. If they are different, it indicates that the currently used counter is not continuously called and needs to be cleared. At this time, the element value of the currently used counter in the count array is reset to 0, and the element value of the currently used counter in the small frame number array is updated to the global small frame number.

[0046] In the present application, the static subscript variable usually needs to be initialized before use, that is, initialized to 0, and the address of the static subscript variable is passed to the counter function as a parameter when used, and the array subscript is automatically sorted and assigned to the static subscript variable in the counter function, so that different counters can be distinguished. For example, after the initialized static subscript variable is 0, it is passed to the counter function as a parameter, and the array subscript in the counter function is 0, and the count value of the counter used at this time is the first element value in the count array. When the static subscript variable is set at the second place, the static subscript variable is sorted to 1 in the counter function, and the count value of the counter used at this time is the second element value in the count array.

[0047] Similarly, when used, the count array and the small frame number array in the counter function also need to be initialized, that is, the element values in the array are set to 0.

[0048] The interface implementation method for the flight control software counting or timing function of the present application defines a unified counter function, which includes a count array and a small frame number array that can be used by multiple counters, and encapsulates them, so that when a new counter is added, a new global variable does not need to be defined, and only a static subscript variable needs to be defined at the code location where the counter is used in the flight control software to indicate the element in the count array corresponding to the currently used counter. The address of the static subscript variable is passed to the counter function as a parameter, so that the accumulation or clearing of the count can be automatically implemented when the counter function is called, avoiding the coupled use of the counter. Since the counter function implements the counting function through the internal static count array, the count array is encapsulated in the counter function, which maximizes the risk of external tampering of the counter.

[0049] As shown in Figure 2 The present application also provides an interface for the counting or timing function of the flight control software, which includes:

[0050] A global small frame number identifier construction module 101 is configured to construct a global small frame number identifier to represent the global small frame number added by each small frame in the flight control software;

[0051] A counter function construction module 102 is configured to construct a counter function, and set a count array and a small frame number array in the counter function. The counter function includes three parameters, the first parameter is an array subscript, which is used to indicate the element position in the count array and the small frame number array corresponding to the currently used counter, the second parameter is a global small frame number, and the third parameter is a count interval.

[0052] The judging module 103 is used for constructing a static subscript variable, setting the static subscript variable and a counter function at a position where a counter is needed, determining a currently used counter in the counter function according to the static subscript variable, comparing whether a subframe number of the currently used counter in a subframe number array is same as a global subframe number, if same, indicating that the currently used counter is continuously called and needs to continue counting, at this time, updating the currently used counter in the counting array by adding an element value of the currently used counter in the counting array by a counting interval, and updating an element value of the currently used counter in the subframe number array; if different, indicating that the currently used counter is not continuously called, at this time, resetting the element value of the currently used counter in the counting array, and updating the element value of the currently used counter in the subframe number array as the global subframe number.

[0053] The interface and the implementation method thereof for the flight control software counting or timing function of the application can achieve the counter function by only two lines of code, one line is to define a static subscript variable to represent a new counter, and the other line is to call the counter function. The two lines of code can be unified in writing style, enhance the robustness of code writing, and facilitate code reading and testing.

[0054] The above is only a specific embodiment of the application, but the protection scope of the application is not limited to this. Any person skilled in the art can easily think of changes or replacements within the technical range disclosed in the application, which should be covered in the protection scope of the application. Therefore, the protection scope of the application should be subject to the protection scope of the claims.

Claims

1. An interface implementation method for flight control software counting or timing functions, characterized in that, The application relates to a method for constructing a counter in a flight control software, comprising the following steps: A global small frame number identifier is constructed to represent a global small frame number self-added in the flight control software every small frame; A counter function is constructed, and a counting array and a small frame number array are set in the counter function, the counter function comprises three parameters, the first parameter is an array subscript, used for indicating the element position in the counting array and the small frame number array corresponding to the currently used counter, the second parameter is a global small frame number, and the third parameter is a counting interval; A static subscript variable is constructed, and the static subscript variable and the counter function are set at the position where the counter is used, the currently used counter in the counter function is determined according to the static subscript variable, whether the small frame number of the currently used counter in the small frame number array is the same as the global small frame number is compared, if the small frame number is the same, it indicates that the currently used counter is continuously called and continues to count, at this time, the element value of the currently used counter in the counting array is added with the counting interval to realize the updating of counting, and the element value of the currently used counter in the small frame number array is updated; if the small frame number is different, it indicates that the currently used counter is not continuously called, at this time, the element value of the currently used counter in the counting array is reset, and the element value of the currently used counter in the small frame number array is updated as the global small frame number.

2. The interface implementation method for fly-by-wire software counting or timing functions as recited in claim 1, wherein, The self-added value of the global small frame number is 1.

3. The interface implementation method for fly-by-wire software counting or timing functions as recited in claim 1, wherein, The element quantity of the counting array and the small frame number array is the same, and the element quantity is determined according to the maximum use quantity of the counter.

4. The interface implementation method for fly-by-wire software counting or timing functions according to claim 3, characterized in that, The counting array and the small frame number array are static arrays.

5. The interface implementation method for fly-by-wire software counting or timing functions as recited in claim 2, wherein, The counting interval is the same as the self-added value of the global small frame number.

6. The method for interface implementation of fly-by-wire software counting or timing function according to any one of claims 1 to 5, characterized in that, The static subscript variable is initialized before use, the address of the static subscript variable is used as the parameter to be transmitted to the counter function when the static subscript variable is used, the array subscript is automatically sorted in the counter function and is assigned to the static subscript variable, so that different counters are distinguished.

7. The interface implementation method for fly-by-wire software counting or timing functions as claimed in claim 6, wherein, The counting array and the small frame number array are initialized before use, and the element values in the counting array and the small frame number array are initialized as 0.

8. An interface for flight control software counting or timing functions, characterized by, The application relates to a method for constructing a counter in a flight control software, comprising the following steps: A global small frame number identifier construction module is used for constructing a global small frame number identifier to represent a global small frame number self-added in the flight control software every small frame; A counter function construction module is used for constructing a counter function, and a counting array and a small frame number array are set in the counter function, the counter function comprises three parameters, the first parameter is an array subscript, used for indicating the element position in the counting array and the small frame number array corresponding to the currently used counter, the second parameter is a global small frame number, and the third parameter is a counting interval; The judgment module is used for constructing a static subscript variable, setting the static subscript variable and a counter function in the position of using the counter, determining the currently used counter in the counter function according to the static subscript variable, comparing whether the subframe number of the currently used counter in the subframe number array is same as the global subframe number, if same, indicating that the currently used counter is continuously called and continues to count, at this time, the element value of the currently used counter in the counting array is added with a counting interval to realize the updating of counting, and the element value of the currently used counter in the subframe number array is updated; if different, indicating that the currently used counter is not continuously called, at this time, the element value of the currently used counter in the counting array is reset, and the element value of the currently used counter in the subframe number array is updated as the global subframe number.

Citation Information

Patent Citations

  • Component model supporting dynamic configuration, and component factory

    CN102622227A

  • Memory interface with reduced energy transmit mode

    US20230043152A1