Device control method, device, electronic device, and readable storage medium
By setting up parallel task states and shared state areas in the state machine and decoupling the task states and shared states, the problems of low operating efficiency and high development difficulty of electronic equipment are solved, and more efficient task execution is achieved.
Patent Information
- Application Number
- CN202211117441.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-14
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2042-09-14
AI Technical Summary
The functional states of electronic devices are coupled with each other and the switching logic is complicated, resulting in low operating efficiency and high development difficulty.
Using the state machine method, the task state and shared state are separated into two state areas running in parallel. By running the task state in the first state area and the shared state in the second state area, the task state and shared state are decoupled and executed in parallel.
It improves the operating efficiency of electronic equipment, reduces the difficulty of developing task states, and avoids complicated switching logic between states.
Smart Images

Figure CN115599014B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of device control, and in particular to a device control method, a device control apparatus, an electronic device, and a readable storage medium. Background Art
[0002] With the continuous development of artificial intelligence (AI) technology, intelligent electronic devices are widely used in various fields of production and life, providing great convenience for people. For example, cleaning robots can clean the house and mowing robots can mow the lawn. However, when electronic devices perform their tasks, they often face difficulties due to the interconnected functional states and complex switching logic. This seriously affects the efficiency of various electronic functions and increases the difficulty of developing new features. Summary of the Invention
[0003] The present application provides a device control method, a device control apparatus, an electronic device and a readable storage medium, aiming to solve the technical problem that when an electronic device performs a task function, the functional states of the self-mobile devices are mutually coupled and the switching logic is complicated, resulting in low operating efficiency and high development difficulty.
[0004] In a first aspect, the present application provides a device control method, the method comprising:
[0005] When a first event is detected, a first task state corresponding to the first event is run in a first state area of the state machine; the state machine is provided with a first state area and a second state area running in parallel;
[0006] The first shared state called by the first task state is acquired, the first shared state is run in the second state area of the state machine, and the running result of the first shared state is fed back to the first task state.
[0007] In a second aspect, the present application provides a device control apparatus, the apparatus comprising:
[0008] A task state running module is used to run a first task state corresponding to the first event in a first state area of a state machine when a first event is detected; the state machine is provided with a first state area and a second state area running in parallel;
[0009] The shared state running module is used to obtain the first shared state called by the first task state, run the first shared state in the second state area of the state machine, and feed back the running result of the first shared state to the first task state.
[0010] In a third aspect, the present application also provides an electronic device, comprising a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program and implement the device control method as described above when executing the computer program.
[0011] In a fourth aspect, the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the device control method as described above.
[0012] In the device control method provided in this application, a state machine may be provided on the electronic device, and the state machine may be provided with two state areas running in parallel, namely, a first state area and a second state area. When the electronic device detects a first event, the electronic device may run a first task state corresponding to the first event in the first state area of the state machine. Furthermore, the electronic device may obtain a first shared state corresponding to the first task state and run the first shared state in the second state area of the state machine.
[0013] Through the above method, the electronic device can decouple the task state and the shared state. The task state can implement the corresponding function of the shared state by calling the shared state, which reduces the difficulty of developing the task state. At the same time, the electronic device can run the task state and the shared state in parallel through the first state area and the second state area, thereby improving the operating efficiency of the task state to a certain extent. Therefore, the above method can, to a certain extent, solve the problems of high state development difficulty and low operating efficiency in existing state machine solutions. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0015] Figure 1 This is a flow chart of a device control method provided in an embodiment of the present application;
[0016] Figure 2 An example diagram of a navigation state of a mobile device provided in an embodiment of the present application;
[0017] Figure 3 Another schematic flow chart of a device control method provided in an embodiment of the present application;
[0018] Figure 4 A structural block diagram of a device control device provided in an embodiment of the present application;
[0019] Figure 5 A schematic block diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0021] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, combined, or partially merged, so the actual execution order may vary depending on the actual situation.
[0022] It should be understood that the terms used in this specification are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in this specification and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms unless the context clearly indicates otherwise.
[0023] It will also be understood that the term "and / or" used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0024] Embodiments of the present application provide a device control method, a device control apparatus, an electronic device, and a readable storage medium.
[0025] The device control method provided in the embodiments of the present application can be applied to electronic devices. The above-mentioned electronic device can be any one of the types of devices such as mobile phones, tablet computers, industrial computers, personal digital assistants, self-mobile devices, etc. Among them, the self-mobile device can be a device that includes a self-mobility assistance function. The self-mobility assistance function can be implemented by a vehicle-mounted terminal, and accordingly, the self-mobile device can be a vehicle with the vehicle-mounted terminal. The self-mobile device can also be a semi-autonomous mobile device or a fully autonomous mobile device. For example, a lawn mower, a sweeper, a robot with a navigation function, etc. For the sake of convenience of explanation, in each embodiment described below, the self-mobile device is used as an electronic device for explanation.
[0026] The following describes some embodiments of the present application in detail with reference to the accompanying drawings. In the absence of conflict, the following embodiments and features therein may be combined with each other.
[0027] See also Figure 1 , Figure 1This is a flow chart of a device control method provided by an embodiment of the present application. This device control method can functionally decouple the task state and shared state by running them in parallel, avoiding complex switching logic between states and thus improving the operating efficiency of the electronic device. Furthermore, the task state can implement the corresponding function of the shared state by calling the shared state, reducing the difficulty of developing the task state.
[0028] like Figure 1 As shown, the device control method includes:
[0029] Step S101 : when a first event is detected, a first task state corresponding to the first event is run in a first state area of a state machine; the state machine is provided with a first state area and a second state area that run in parallel.
[0030] In the device control method provided in the present application, a state machine is provided in the mobile device, and the state machine can be provided with two state areas running in parallel, namely a first state area and a second state area. Different state areas can be used to run different types of states.
[0031] State machine is the abbreviation of finite state automaton. The state machine can perform state transitions according to pre-set states based on control signals. It is the control center that coordinates related signal actions and completes specific operations. The state machine can be used to describe a finite number of states, as well as to describe behaviors such as transitions and actions between these states (i.e., the execution order and switching logic between a finite number of states). Each state node (state for short) of the state machine can be a business process, a function, or even a step. Each state node can perform a response operation based on the input and pass the output to the next state node. In an embodiment of the present application, the state machine can be used to control the execution order of multiple states of a mobile device and the switching conditions between each state. The task state and shared state mentioned in the embodiment of the present application can be understood as the corresponding state nodes in the state machine. The above-mentioned task state can be a pre-configured state with a specific business logic function, and the above-mentioned task state can be run in the first state area of the state machine.
[0032] When the self-mobile device detects a first event, the self-mobile device may execute a first task state corresponding to the first event in a first state area of the state machine.
[0033] The triggering method of the first event can be set according to actual needs. For example, in one example, the self-mobile device can trigger the first event corresponding to the task instruction when receiving the task instruction sent by other devices (such as the user's mobile phone); in another example, the user presses the physical button of the self-mobile device, and the self-mobile device can respond to the user's pressing operation and trigger the first event corresponding to the physical button. For example, the user presses the emergency stop button in the self-mobile device, and the self-mobile device can respond to the user's operation and trigger the emergency stop event corresponding to the emergency stop button; in another example, the self-mobile device can also trigger the corresponding first event due to environmental factors during the operation process. For example, when the self-mobile device detects an insurmountable obstacle in the forward direction, it triggers an obstacle avoidance event; in some other examples, the first event can also be triggered by other methods. The embodiment of the present application does not limit the triggering method of the first event.
[0034] For example, see Figure 2 , taking the navigation function of a mobile device as an example:
[0035] like Figure 2 As shown, the state machine of the self-mobile device can be provided with a first state area and a second state area. The first state area of the self-mobile device can run the task state, and the second state area can run the basic state (also known as the shared state). The above-mentioned task state may include but is not limited to business logic states such as global coverage state, edge control state, obstacle avoidance state, and patrol state. The above-mentioned shared state may include but is not limited to basic logic states such as path planning state and local control state.
[0036] Specifically, the global coverage state controls the mobile device to operate globally within the work area. The edge control state controls the mobile device to operate at the boundaries of the work area. The obstacle avoidance state controls the mobile device to automatically circumvent obstacles when they are detected in its forward direction. The patrol state controls the mobile device to monitor its surroundings using its own data collection device, providing a safety warning function.
[0037] The path planning state refers to the state in which the optimal path for the mobile device is calculated based on a preset path planning algorithm. This path planning algorithm can be Dijkstra's algorithm, A* algorithm, genetic algorithm, etc., but is not limited here. The local control state refers to the driving strategy for the mobile device within a specified local area.
[0038] In some embodiments of the present application, the state machine may further include an initialization state and an idle state. The initialization state is a self-test state when the mobile device is started. The idle state is a state when the mobile device is in a standby phase.
[0039] Step S102 : obtaining a first shared state called by the first task state, running the first shared state in the second state area of the state machine, and feeding back the running result of the first shared state to the first task state.
[0040] The second status area can be used to run the shared state. After determining the first task state, the mobile device can obtain the first shared state corresponding to the first task state.
[0041] The shared state can provide the running results for the task state to support the smooth running of the task state. The shared state can be the basic logic involved in multiple task states, such as basic operations, basic code implementation, etc.
[0042] Continue to refer Figure 2 To ensure that the performance of the self-moving device is maintained, the global coverage state, edge path state, obstacle avoidance state, and patrol state can be divided into task states running in the first state area. Specifically, the business logic functions of the self-moving device correspond one-to-one with these task states. The path planning state and local control state can be divided into shared states running in the second state area. The results of the shared states are used to provide the data required by the task states to assist them in completing their corresponding functions. This decouples the task states from the shared states, separating them into independent states.
[0043] Since the task state in the first state area and the shared state in the second state area can run in parallel in their respective threads, the task state and the shared state are functionally decoupled, avoiding complicated switching logic between states, thereby improving the operating efficiency of the electronic device.
[0044] For example, in one example, when the first task state is the edge control state, since the edge control state needs to control the edge movement of the mobile device based on the planned path output by the path planning state, the path planning state can be determined as the first shared state. In this case, the mobile device can run the edge control state in the first state area and run the path planning state in parallel in the second state area. The path planning state feeds back the operation results (i.e., the planned path) to the edge control state, and the edge control state controls the mobile device's operation at the edge of the work area based on the planned path.
[0045] In another example, when the first task state is the global coverage state, the self-mobile device needs to operate globally along a planned path within a set area. In other words, the operation of the global coverage state requires the path planning state to provide a planned path. In this case, the self-mobile device can determine the path planning state as the first shared state, operate the global coverage state in the first state area, and run the path planning state in parallel in the second state area. The path planning state feeds back the planned path to the global coverage state, and the global coverage state operates globally according to the planned path fed back by the path planning state.
[0046] As can be seen from the two examples above, both the edge control state and the global coverage state require the corresponding planned path. Developing path planning functions separately for the edge control state and the global coverage state would not only lead to duplicate development and waste manpower and resources, but also increase the complexity and difficulty of development for both the edge control state and the global coverage state.
[0047] Therefore, in the method provided in the embodiment of the present application, functions such as path planning functions that provide data support for the operation of multiple task states can be independently converted into shared states. When a mobile device runs a task state in the first state area, the corresponding shared state can be run in parallel in the second state area, and the shared state feeds back the operation results to the task state. Through the above method, the task state and the shared state are decoupled, and the task state can realize the function of the shared state by calling the shared state. There is no need to develop the shared state in the task state, which avoids repeated development, reduces the complexity of the task state, and reduces the difficulty of developing the task state.
[0048] Further, refer to Figure 3 Based on the above embodiment, another embodiment of the device control method of the present application is proposed. In this embodiment, the above first event corresponds to multiple first task states. In this case, the above step S101 may include step S201 and step S202.
[0049] Step S201: Obtain the priorities between the first task states.
[0050] When a first event is detected from a mobile device, at least one first task state involved in the first event may be determined, and the priority corresponding to each first task state may be determined. The priority is used to indicate the importance of each first task state.
[0051] Step S202 : running each first task state in sequence in the first state area of the state machine according to the priority between the first task states.
[0052] After the priorities corresponding to the first task states are determined, the first task states may be sorted from high to low in priority, and the first task states may be executed in sequence according to the sorting result.
[0053] Specifically, in some embodiments, the mobile device can start from the task state with the highest priority and run each first task state in sequence in the first state area of the state machine; after each execution of the current first task state, the execution result of the current first task state is stored, and the first task state to be executed next is initialized and configured according to the execution result.
[0054] By using the priorities between the first task states, the first task states can be executed sequentially in the first state area, thereby avoiding problems such as confusion and duplication in the execution logic of the first task states.
[0055] For example, when the first event received by the state machine of the self-mobile device is a mowing event, it is determined that the mowing event corresponds to the arcuate line coverage state and the edge control state. The arcuate line coverage state refers to the self-mobile device performing an arcuate line movement operation within a preset operating area. The arcuate line coverage state and the edge control state are both independent first task states, associated with each other, and pre-configured with corresponding priorities. The self-mobile device can then determine the execution order of the arcuate line coverage state and the edge control state by comparing their corresponding priorities. If the priority of the bow line coverage state is higher than the priority of the edge control state, the bow line coverage state will be run in the first state area first. After the bow line coverage state is completed, the bow line coverage state will be switched to the edge control state for operation, and the edge control state will be initialized and configured according to the operation result of the bow line coverage state. For example, the edge control state will be initialized and configured according to the posture of the mobile device when the bow line coverage state is stopped; if the priority of the edge control state is higher than the priority of the bow line coverage state, the edge control state will be run in the first state area first. After the edge control state is completed, the edge control state will be switched to the bow line coverage state for operation.
[0056] In some embodiments, when multiple first shared states are called in the first task state, the above-mentioned running of the first shared states in the second state area of the state machine includes: determining the running order of each first shared state based on the first task state; and running each first shared state in the second state area of the state machine in sequence according to the running order.
[0057] Specifically, when no task state is running in the first state area, or the task state running in the first state area does not limit the running order of the shared state, the mobile device can run each shared state in sequence in the second state area according to the priority of each shared state or the pre-configured default running order.
[0058] When the task states running in the first state area define the running order of the shared states, the shared states can be run in sequence in the second state area according to the running order.
[0059] Therefore, when the first task state is running in the first state area, the self-mobile device can determine the first shared state to be called based on the first task state, as well as the execution order of each first shared state. Then, the self-mobile device can run each first shared state in sequence in the second state area according to the above execution order.
[0060] Exemplarily, when the first task state is the global coverage state, the self-mobile device can determine the path planning state and the local control state as the first shared state based on the global coverage state, and determine the operation order to first run the path planning state and then run the local control state. Afterwards, the self-mobile device can first run the path planning state in the second state area according to the above operation order to obtain the optimal path between each path point in the operation area. Then, the optimal path output by the path planning state is given to the global coverage state and the local control state. The local control state outputs the driving strategy of the self-mobile device according to the optimal path. The above driving strategy includes movement speed, steering control, hovering, U-turn and other contents. The local control state feeds back the driving strategy to the global coverage state in the first state area, so that the global coverage state controls the self-mobile device to perform global operations according to the optimal path and driving strategy.
[0061] In some embodiments, the above method also includes: when a second event is detected, obtaining the priority of a second task state corresponding to the second event; if the priority of the second task state corresponding to the second event is higher than the priority of the currently running first task state, stopping the currently running first task state and running the second task state in the first state area.
[0062] The second event may be an emergency event caused by the mobile device being affected by current environmental factors, such as an obstacle event, a slipping event, or a raining event; or it may be an event actively triggered by the user, such as the user issuing a new instruction.
[0063] When the mobile device detects the second event, if the first task state corresponding to the first event has not yet completed, the mobile device may obtain the priority of the second task state corresponding to the second event. If the priority of the second task state is higher than the priority of the first task state, the mobile device may stop executing the first task state and execute the second task state. If the priority of the second task state is lower than the priority of the first task state, the mobile device may continue to execute the first task state and execute the second task state after completing the first task state.
[0064] In addition, if the mobile device stops executing the first task state and executes the second task state, the mobile device may return to the stopped first task state after completing the second task state.
[0065] For example, suppose a mobile device is operating in the edge control state and detects a pedestrian passing in the direction of the mobile device's motion. The mobile device can detect the pedestrian avoidance event and determine the priority of the emergency stop state corresponding to the pedestrian avoidance. Because the emergency stop state has a higher priority than the edge control state, the mobile device can exit the edge control state and enter the emergency stop state. After the pedestrian leaves, the emergency stop state meets the exit conditions. At this point, the mobile device can exit the emergency stop state and return to the edge control state.
[0066] In another embodiment of the present application, the above process of executing the first task state and the second task state according to priority is also applicable to states in other state areas.
[0067] In some embodiments, the state machine may include, in addition to the first state area and the second state area, a third state area, wherein the third state area includes a non-operating state, including but not limited to a recharging state and an escape state.
[0068] The recharge state is a state in which the self-mobile device is controlled to return to the charging base when the battery is low, or the self-mobile device is controlled to return to the charging base after completing the operation. The escape state is a state in which the self-mobile device is controlled to perform escape actions such as reverse when the self-mobile device moves to a dead end on the path, gets stuck in the mud, is stuck by branches, or walks out of the working area, so that the self-mobile device returns to the normal working area through a preset motor control strategy. The priority of each non-working state in the third state area is higher than the task state in the first state area and the shared state in the second task area. For example, when the battery of the self-mobile device is about to run out, the self-mobile device stops executing the current task state and shared state and executes the recharge state.
[0069] Furthermore, in some embodiments, the device control method further includes: if a currently running task state (e.g., a first task state) is interrupted due to a non-working state, saving the running result at the time of the interruption; switching the currently running task state of the mobile device to a non-working state; and when the non-working state of the mobile device completes and switches from the non-working state to the interrupted task state (i.e., the interrupted first task state), obtaining the running result at the time of the interruption of the task state, and continuing to run the task state based on the running result at the time of the interruption.
[0070] For example, when the mobile device is running in the path planning state, if it is detected that the mobile device is low on power, an interrupt state instruction will be triggered, thereby interrupting the operation of the path planning state, saving the operation results when the path planning state is interrupted, and switching the state of the mobile device to the recharging state for charging.
[0071] In addition, in some embodiments, the self-mobile device can use the glue layer to store the running results of the state, so as to share the above-mentioned running results with other states, thereby realizing more complex business logic functions. The glue layer is designed for communication between various states, and the data required for communication are all stored in the cache area of the glue layer. At the same time, the glue layer also has method functions shared by various states, as well as methods for linking external libraries, etc. For example, when the self-mobile device encounters an obstacle, it can switch the currently running business state to the obstacle avoidance state, and at the same time save the running results of the self-mobile device before obstacle avoidance, such as the position and path of the self-mobile device before obstacle avoidance, for reconfiguration and planning of the path after obstacle avoidance is completed.
[0072] Specifically, in the first state area, the self-mobile device can execute each task state in sequence from the highest priority to the lowest priority, and save the result of each operation in the glue layer, so that when switching to the next lower priority task state, the next running task state can be initialized and configured according to the running result of the previous running task state.
[0073] Exemplarily, it is assumed that the obstacle avoidance state in the first state area has the highest priority, and the self-mobile device is currently running in the edge control state. When the self-mobile device encounters an obstacle in the forward direction, the operation result of the current edge control state can be saved in the glue layer and switched to the obstacle avoidance state. Among them, the operation result of the edge control state can be the current position, motion parameters, etc. of the self-mobile device. After the self-mobile device completes obstacle avoidance, the self-mobile device can save the operation result of the obstacle avoidance state in the glue layer, such as the current position of the self-mobile device. Then, the self-mobile device can exit the obstacle avoidance state, initialize the configuration of the edge control state according to the operation result of the obstacle avoidance state, and switch to the edge control state. For example, the motion parameters are readjusted according to the current position of the self-mobile device.
[0074] In some embodiments of the present application, the above-mentioned implementation of initializing the configuration of the next running task state based on the running results of the previous task state is also applicable to the initialization configuration between the shared states in the second state area, or the initialization configuration between the task state and the shared state, or the initialization configuration between the shared state and the non-working state, or the initialization configuration between the task state and the non-working state, and is not limited here.
[0075] For example, in one example, when a mobile device is operating in the global coverage state and detects that its battery is low, it needs to initiate the recharge state in the non-operating state. At this point, the mobile state can first stop executing the global coverage state and save the current location of the mobile device and the area where it is not operating in the glue layer. The mobile device then switches to the recharge state, controlling the mobile device to move back to the base station for charging. When the mobile device is fully charged, the recharge state can be terminated and the battery life state can be switched to the breakpoint.
[0076] The breakpoint continuation state is a state in which the mobile device is controlled to return to the position where the last operation was not performed after charging is completed and continue to perform the operation.
[0077] Therefore, when switching to the breakpoint continuation state, the mobile device can retrieve the previously saved global coverage state execution results from the glue layer and control the mobile device to return to the location where the global coverage state was interrupted based on the above results. After reaching the location where the global coverage state was interrupted, the breakpoint continuation state can be exited and the global coverage state execution can be continued.
[0078] In another example, while the mobile device is running the global coverage state in the first state area, it is running the path planning state in the second state area. After the path planning state is completed, the results of the path planning state (i.e., the planned path) can be saved to the glue layer. The global coverage state can obtain the planned path through the glue layer and perform global operations based on the planned path.
[0079] In other words, different states can save and share data through the glue layer, thereby supporting sequential and parallel execution between states to facilitate the implementation of complex logical states.
[0080] Exemplarily, when the self-mobile device runs the global coverage state in the first state area, it can be determined that the path planning state and the local control state need to be called, and the path planning state has a higher priority than the local control state. Therefore, the self-mobile device can first run the path planning state in the second state area to obtain the optimal path between each path point in the global coverage area. After running the path planning state, the optimal path can be saved in the glue layer. When running the local control state, the local control state can obtain the optimal path from the glue layer, and plan the driving strategy of the self-mobile device according to the optimal path, such as controlling the movement speed, controlling the steering, hovering, U-turns, etc. The local control state saves the driving strategy in the glue layer. The global coverage state can obtain the above-mentioned optimal path and the above-mentioned driving strategy from the glue layer, and control the global operation of the self-mobile device according to the optimal path and the driving strategy.
[0081] From the above examples, we can see that after using the glue layer, data can be shared more conveniently between different states, reducing the difficulty of implementing various complex logics, thereby improving the working performance of mobile devices.
[0082] In an embodiment of the present application, when a first event is detected, before running a first task state corresponding to the first event in a first state area of the state machine, the device control method further includes:
[0083] Get the configuration information and configure the task status corresponding to different events according to the configuration information.
[0084] Among them, the configuration information can be parameter information of various interfaces, as well as the hierarchical relationship between various interfaces, etc., which is not limited here. The above-mentioned interfaces can include one or more interfaces such as configuration interfaces, execution interfaces, and result processing interfaces. Specifically, the configuration interface can be used to process the initialization-related operations that need to be input when entering the task state, for example, by turning on the power button of the self-mobile device, the self-mobile device executes the initialization state; the execution interface can be used to implement the task execution process according to the task state of the event, for example, after the self-mobile device completes the initialization state, it switches to the patrol state, so that the self-mobile device executes the corresponding function of the patrol state; the result processing interface can be used to perform the operations required to output the results after the self-mobile device completes the task state of the event, such as storing and sharing the execution results of the task state. The processing process between the above-mentioned various interfaces involves the hierarchical relationship of each interface, that is, the hierarchical relationship includes an inheritance relationship, for example, the execution interface inherits the parameters of the configuration interface. The execution order of each task state in the same event is achieved through the configuration information and hierarchical relationship of various interfaces, so that the code execution between different task states in the same event does not interfere with each other. When a task state corresponding to a new business logic function is subsequently created in the first state area of the self-mobile device, it is only necessary to supplement the corresponding business logic code, interface parameter information, and hierarchical relationships in the first state area, thereby solving the ever-changing task function requirements of the self-mobile device and improving development efficiency.
[0085] In an embodiment of the present application, the state machine is configured with one or more switchable task states and shared states corresponding to different events, and can be configured with the execution order between the above-mentioned multiple task states, the execution order between multiple shared states, the parallel execution order of task states and shared states, and related switching conditions and other information.
[0086] Specifically, in order to clarify the switching logic between task states of different events, the device control method also includes: associating multiple states involved in the same event according to configuration information, for example, the task state and shared state corresponding to the same event can be associated; or, multiple task states involved in the same event can be associated; or, multiple shared states involved in the same event can be associated.
[0087] That is, developers can determine configuration information based on the actual association logic between the task states and shared states involved in the same event, and input the configuration information into the mobile device. After the mobile device obtains the configuration information, it can associate the event with one or more states based on the configuration information. For example, if the developer configures the association between the obstacle encounter event and the obstacle avoidance state in the configuration information, the mobile device can establish the association between the obstacle encounter event and the obstacle avoidance state based on the configuration information.
[0088] The following introduces an apparatus embodiment of the present application, which can be used to execute the device control method in the above-mentioned embodiment of the present application. Figure 4 The structural block diagram of the device control device provided in the embodiment of the present application is schematically shown. Figure 4 As shown, the present application provides a device control device, the device control device comprising:
[0089] The task state running module 401 is used to run the first task state corresponding to the first event in the first state area of the state machine when a first event is detected; the state machine is provided with a first state area and a second state area running in parallel;
[0090] The shared state running module 402 is configured to obtain the first shared state called by the first task state, run the first shared state in the second state area of the state machine, and feed back the running result of the first shared state to the first task state.
[0091] In the embodiment of the present application, when the first event corresponds to multiple first task states, the shared state operation module 402 specifically further includes:
[0092] A first acquisition submodule, configured to acquire the priorities between the first task states;
[0093] The first running submodule is configured to run the first task states in sequence in the first state area of the state machine according to the priorities of the first task states.
[0094] In this embodiment of the present application, the operation submodule includes:
[0095] A task running unit, configured to run each first task state in sequence in the first state area of the state machine starting from the task state with the highest priority;
[0096] The task configuration unit is used to store the running result of the current first task state each time the current first task state is run, and initialize the configuration of the first task state to be run next according to the running result.
[0097] In the embodiment of the present application, the device control apparatus further includes:
[0098] a priority acquisition module, configured to acquire the priority of a second task state corresponding to the second event when a second event is detected;
[0099] The task switching module is configured to stop the currently running first task state and run the second task state in the first state area if the priority of the second task state corresponding to the second event is higher than the priority of the currently running first task state.
[0100] In the embodiment of the present application, the device control apparatus further includes:
[0101] The return execution module is used to return to the first task state where the execution is stopped after the second task state is completed.
[0102] In the embodiment of the present application, when the first task state calls multiple first shared states, the shared state running module 402 specifically further includes:
[0103] A sequence determination submodule, configured to determine the execution sequence of each first shared state based on the first task state;
[0104] The second running submodule is used to run the first shared states in sequence in the second state area of the state machine according to the running order.
[0105] In the embodiment of the present application, the device control apparatus further includes:
[0106] The configuration module is used to obtain configuration information and configure the task status corresponding to different events according to the configuration information.
[0107] See also Figure 5 , Figure 5 1 is a schematic block diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device may be a self-moving device.
[0108] See Figure 5 The electronic device includes a processor, a memory, and a network interface connected through a system bus, wherein the memory may include a non-volatile storage medium and an internal memory.
[0109] The non-volatile storage medium can store an operating system and a computer program. The computer program includes program instructions, which, when executed, can cause the processor to execute any device control method.
[0110] The processor is used to provide computing and control capabilities to support the operation of the entire mobile device.
[0111] The internal memory provides an environment for the operation of the computer program in the non-volatile storage medium. When the computer program is executed by the processor, the processor can execute any device control method.
[0112] The network interface is used for network communication, such as sending assigned tasks, etc. Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the self-moving device to which the solution of the present application is applied. The specific self-moving device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0113] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc.
[0114] A computer-readable storage medium is also provided in an embodiment of the present application. The computer-readable storage medium stores a computer program. The computer program includes program instructions. The processor executes the program instructions to implement any device control method provided in the embodiment of the present application.
[0115] The computer-readable storage medium may be an internal storage unit of the mobile device described in the aforementioned embodiment, such as a hard disk or memory of the mobile device. The computer-readable storage medium may also be an external storage device of the mobile device, such as a plug-in hard disk, a smart memory card (SMC), a secure digital (SD) card, a flash memory card, etc., equipped on the mobile device.
[0116] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present application, and such modifications or substitutions should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. A device control method, characterized in that: The method comprises: When a first event is detected, a first task state corresponding to the first event is run in a first state area of a state machine; the state machine is provided with a first state area and a second state area running in parallel, wherein the task state running in the first state area includes a business logic state, and the shared state running in the second state area includes a basic logic state; Obtain a first shared state called by the first task state, run the first shared state in the second state area of the state machine, and feed back a running result of the first shared state to the first task state, where the running result is used to support the running of the first task state.
2. The method according to claim 1, characterized in that When the first event corresponds to a plurality of first task states, running the first task state corresponding to the first event in the first state area of the state machine includes: Obtaining the priority between the first task states; According to the priorities between the first task states, the first task states are sequentially executed in the first state area of the state machine.
3. The method according to claim 2, characterized in that The step of sequentially running the first task states in the first state area of the state machine according to the priority between the first task states includes: Starting from the task state with the highest priority, run the first task states in sequence in the first state area of the state machine; Each time the current first task state is completed, the running result of the current first task state is stored, and the first task state to be run next is initialized and configured according to the running result.
4. The method according to claim 1, wherein The method further comprises: When a second event is detected, obtaining a priority of a second task state corresponding to the second event; If the priority of the second task state corresponding to the second event is higher than the priority of the currently running first task state, the currently running first task state is stopped and the second task state is run in the first state area.
5. The method according to claim 4, characterized in that The method further comprises: After the second task state is completed, the operation returns to the first task state where the operation is stopped.
6. The method according to claim 1, characterized in that When the first task state calls a plurality of first shared states, running the first shared states in the second state area of the state machine includes: determining an execution order of each of the first shared states based on the first task state; According to the running sequence, each of the first shared states is run in sequence in the second state area of the state machine.
7. The method according to any one of claims 1 to 6, characterized in that Before executing the first task state corresponding to the first event in the first state area of the state machine when the first event is detected, the method further includes: Acquire configuration information, and configure task states corresponding to different events according to the configuration information.
8. A device control device, characterized in that: include: A task state running module, configured to run a first task state corresponding to the first event in a first state area of a state machine when a first event is detected; The state machine is provided with a first state area and a second state area running in parallel, wherein the task state running in the first state area includes the business logic state, and the shared state running in the second state area includes the basic logic state; A shared state running module is used to obtain the first shared state called by the first task state, run the first shared state in the second state area of the state machine, and feed back the running result of the first shared state to the first task state, where the running result is used to support the running of the first task state.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor; The memory is used to store computer programs; The processor is configured to execute the computer program and implement the device control method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, causes the processor to implement the device control method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Device and method for controlling multiple function of communication apparatus by related parallel state machine
CN101309254A
Intelligent robot system and working method thereof
CN105082142A
Robot control method and device
CN112454369A
Medical device having failsafe state machine
CN113439309A
GPP-based 5g terminal common platform optimization method and system
WO2018223932A1