Business logic control method for cleaning robot
By encapsulating the program units of the cleaning robot into unit classes and calling the corresponding program units according to the current state, the problem of code coupling and maintenance difficulties is solved, and code reuse and maintainability are improved.
Patent Information
- Application Number
- CN202210112963.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-29
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2042-01-29
AI Technical Summary
The existing software architecture of cleaning robots lacks modular programming, resulting in serious code coupling, inability to implement code reuse, and difficulty in maintaining.
Modular programming and decoupling of the code is achieved by encapsulating the program unit into a unit class and calling the corresponding program unit to execute tasks according to the current state of the cleaning robot.
It realizes code reuse, improves the maintainability and portability of the code, and improves the efficiency of software development and code security.
Smart Images

Figure CN114578727B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of cleaning robot logic control, and in particular relates to a service logic control method for a cleaning robot. Background Art
[0002] The existing software architecture of cleaning robots is not open source. There are many developers with inconsistent coding styles. When the project is in progress for a long time, many minor problems hidden in the inconsistent coding styles may lead to serious consequences such as project failure. Due to the inconsistent coding styles of developers, the separable algorithm modules will be coupled with other business logic processing modules, resulting in high coupling between codes, inability to reuse code, and the generation of unfindable bugs.
[0003] The existing modular programming method separates the interactive interface, business model and controller, and controls the business model to process data through the controller. However, this application method is more practical for application scenarios where the internal logic of each business model is independent of each other. For cleaning robots, the usage scenarios are quite complex. When facing the processing of an external command, it is necessary to process it according to the working state, working condition, or even multiple command sequences of the robot. In the process of processing external commands, multiple business models are required to work at the same time at any time. For example, when identifying that the robot is in the working state of recharging, it is also necessary to identify whether the robot is in a trapped state; in addition, each business model calls the robot's own functions (such as distance detection, collision detection) and peripherals (such as accelerometers, infrared transmitters, and receivers). In other words, the code reuse ratio between each business model is very high. In the process of existing project development, the codes are often mixed with each other, and the development is difficult. Even if the conventional software architecture and development method that can realize logical separation of code such as MVC are developed, the code coupling cannot be solved, and the control logic obtained is still difficult to maintain. Summary of the invention
[0004] In view of this, the main purpose of the present invention is to provide a business logic control method for a cleaning robot that is easy to add, delete, change and modify.
[0005] To achieve the above object, the technical solution of the present invention is achieved as follows:
[0006] A business logic control method for a cleaning robot, the method comprising:
[0007] According to the current state of the cleaning robot, calling each program unit to execute a task corresponding to the current state;
[0008] The program unit is encapsulated as a unit class, and the calling specifically includes instantiating the unit class into a unit object, and executing part of the code in the program unit through the unit object;
[0009] The execution of the task specifically includes running the code in the unit object, and calling other program units or calling tool classes to implement collection functions through the code in the program unit, wherein the tool class includes code to implement one or a group of specific functions.
[0010] Furthermore, in the unit object, the method in the program unit called corresponds to the current state.
[0011] Furthermore, when parameters need to be specified when calling a method in the program unit, parameters corresponding to the current state are specified.
[0012] Furthermore, when the unit object uses other program units, a secondary unit object is instantiated in the unit object, and the secondary unit object includes part of the code in the other program units to implement one or a group of specific functions.
[0013] Furthermore, the method also includes: in the current state of the cleaning robot, detecting a trigger event, and when the trigger event is detected, determining whether a trigger action corresponding to the trigger event is to be executed in the current state, and executing the trigger action according to the determination result.
[0014] Further, executing the trigger action according to the judgment result includes: when the trigger action corresponding to the trigger event is executed in the current state, calling at least one of the program units to execute a task corresponding to the current state to realize the trigger action.
[0015] Furthermore, executing the trigger action according to the judgment result includes: when the trigger action corresponding to the trigger event is not executed in the current state, switching the state of the cleaning robot, calling at least one of the program units to execute the task corresponding to the current state to realize the trigger action.
[0016] Furthermore, the trigger event is a command sent by a host computer.
[0017] Without solving the above technical problems, the present application also proposes a business logic control device for a cleaning robot and discloses the following technical solution.
[0018] A service logic control device for a cleaning robot, the device comprising:
[0019] A control module, configured to call each program unit through a calling module according to the current state of the cleaning robot, and execute a task corresponding to the current state through an execution module;
[0020] A packaging module, used for packaging the program unit into a unit class;
[0021] A calling module, used to instantiate the unit class into a unit object, and execute part of the code in the program unit through the unit object;
[0022] The execution module is used to run the code in the unit object, and through the code in the program unit, call other program units or call tool classes through the calling module to implement the collection function, wherein the tool class includes code to implement one or a group of specific functions.
[0023] Compared with the prior art, the present invention can realize code reuse and modular programming, decouple algorithms from business logic, improve code maintainability and portability, and improve software development efficiency, code maintainability, and security of code problems. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 A flowchart of an embodiment of a service logic control method for a cleaning robot according to the present application;
[0025] Figure 2 is a structural schematic diagram of an embodiment of a service logic control device for a cleaning robot according to the present application;
[0026] Figure 3 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0028] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, article or device. In the absence of more restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, article or device including the element.
[0029] refer to Figure 1, a business logic control method for a cleaning robot, the method comprising:
[0030] Step S100: according to the current state of the cleaning robot, calling each program unit to execute a task corresponding to the current state;
[0031] Specifically, a state machine and a program unit are set for the cleaning robot, wherein the state machine specifies the specific working state of the cleaning robot. Under the state machine, the cleaning robot must implement at least some functions and implement other functions according to actual operation needs. In this embodiment, the state machine of the cleaning robot at least includes:
[0032] Abnormal state machine. Under this state machine, the cleaning robot automatically checks for abnormal conditions generated by itself, including battery power supply, side wheel rotation, sensor detection, universal wheel rotation, host computer communication, cleaning robot posture detection, etc. The abnormal conditions generated by the cleaning robot itself are detected through the abnormal state machine.
[0033] Charging state machine, in this state machine, the cleaning robot manages the charging process of the battery by the external power supply according to the charging strategy.
[0034] Escape state machine. In this state machine, the cleaning robot drives itself to try to escape according to the specific type of entrapment and the corresponding escape strategy, and detects the escape situation.
[0035] Recharging state machine. In this state machine, the cleaning robot drives itself to the location of the charging seat according to the specific recharging strategy, and docks with the charging seat, so that the cleaning robot and the charging connector and spring installed on the charging seat are docked to connect the battery charging circuit.
[0036] The running state machine, under which the cleaning robot cleans the area to be cleaned according to the set cleaning strategy.
[0037] Pause state machine: in this state machine, the cleaning robot pauses and listens to preset commands or external commands.
[0038] The classification of program units is based on the execution of specific functions, and the codes for executing the above-mentioned specific functions are collected and managed through program units. Specifically, this embodiment includes at least the following program units:
[0039] Path unit: used for code management and storage of navigation, path planning and other functions.
[0040] Mapping unit: used for coordinate system maintenance, cleaning robot map drawing, calling and other functions of code management and storage.
[0041] APP unit: used for communication between the cleaning robot and the App running on the host computer, as well as task interaction, and management and storage of codes required for data (maps and others) interaction.
[0042] Radar unit: management and storage of codes used for radar operation, scheduling, parameter setting management, and data collection and collation.
[0043] MCU unit: used for scheduling the MCU on the cleaning robot, managing and storing the data interaction code.
[0044] It can be seen that in a state machine, the cleaning robot needs to perform multiple corresponding functions, and the codes for implementing the above functions are stored in different program units. It is necessary to run part of the code in each program unit to realize the multiple functions of the cleaning robot in a specific state.
[0045] The program unit is encapsulated as a unit class, and the calling specifically includes instantiating the unit class into a unit object, and executing part of the code in the program unit through the unit object;
[0046] Specifically, the above-mentioned program unit centrally manages and stores the codes for implementing relevant functions. However, in any state machine, when the cleaning robot needs to implement the corresponding function, it is not necessary to run all the program codes in a program unit uniformly, but only execute part of the code as needed. For example, in the recharging state machine, the cleaning robot needs to obtain the approximate position of the charging seat. At this time, the cleaning robot needs to execute the code for the map content extraction function in the mapping unit without executing the map drawing code.
[0047] On the basis of the above, each code segment in the mapping unit is run more than once. For example, when the cleaning robot performs wall cleaning in the running state machine, the code for map content extraction in the mapping unit also needs to be called in order to determine the location of walls and obstacles.
[0048] Therefore, the program unit is encapsulated as a unit class, and part of the related code in the program unit is called by instantiating the class, thereby realizing the reuse of the code in the program unit.
[0049] The execution of the task specifically includes running the code in the unit object, and calling other program units or calling tool classes to implement collection functions through the code in the program unit, wherein the tool class includes code to implement one or a group of specific functions.
[0050] Specifically, the tool class stores more basic functions than the program unit. In the present embodiment, it at least includes: relevant codes applied to external components, such as the calling interface for the accelerometer, the program code for obtaining the instantaneous acceleration vector value through the accelerometer, and the accelerometer tool class for obtaining the driving distance of the cleaning robot and the instantaneous movement direction of the cleaning robot through the integral operation of acceleration. Similar tool classes are classified according to the specific hardware structures such as side wheels, side brushes, and infrared signal units for code classification.
[0051] It also includes distance measurement tool class, grid counting tool class, arc tool class, and other tool classes based on specific actions to achieve some basic actions.
[0052] The code in the tool class is more basic and is called by each unit object instantiated by various running units to implement the user-oriented functions of the unit object.
[0053] In order to realize the functions it provides, the unit object may also call other program units. In one embodiment, the cleaning robot needs to transmit the cleaning map to the host computer in real time and download historical maps from the host computer for reference and comparison. Therefore, the unit object instantiated in the mapping unit will call the code in the APP unit and instantiate an APP object to handle the data interaction with the host computer.
[0054] Cleaning robots are different from other pure software engineering projects. They need to process a variety of external information, handle multiple tasks concurrently, and perform multiple functions crosswise. Compared with other industrial control robots and other intelligent devices, cleaning robots have a very compact structure. Many hardware resources and programs need to be reused in multiple functions and called at the same time. If these codes are developed separately, conflicts are likely to occur during the calling and running process, causing deadlocks. What is more serious is that unexpected running results affect the running efficiency and reliability of the cleaning robot. This solution divides the cleaning robot code into different program units, and also provides tool classes to implement basic functions, which are called by programs in program units to achieve more user-oriented functions. This is conducive to the management and modification of the code, and it is easy to add and replace the functions of the cleaning robot. The project development function is fast and robust.
[0055] This embodiment is implemented based on object-oriented programming thinking. In the implementation process of object-oriented programming, a thing is defined as a class, and several class-related methods are defined in the class. When it is necessary to operate this thing, the class is instantiated into an object, and the method defined in the class is called through the object, so as to achieve classification management and reuse of many codes. Further, in the unit object, the method in the program unit called corresponds to the current state.
[0056] Specifically, the unit object calls the code in the program unit according to the current state, which reduces the running overhead and makes the program run more efficiently.
[0057] Furthermore, when parameters need to be specified when calling a method in the program unit, parameters corresponding to the current state are specified.
[0058] Specifically, by specifying the state to call, it is convenient to call the function in the degree unit, and this solution can improve the convenience of code development.
[0059] Furthermore, when the unit object calls other program units, a secondary unit object is instantiated in the unit object, and the secondary unit object includes part of the code in the other program units to implement one or a group of specific functions.
[0060] Specifically, the secondary object is only used in the unit object, and the security of code operation is improved by limiting the operation scope of the code in the secondary object.
[0061] Furthermore, the method also includes: Step S200: In the current state of the cleaning robot, detecting a trigger event, and when the trigger event is detected, determining whether a trigger action corresponding to the trigger event is to be executed in the current state, and executing the trigger action according to the determination result.
[0062] Specifically, the cleaning robot receives trigger events in real time during operation, and performs trigger actions through trigger events to provide corresponding functions. When performing trigger actions, it is necessary to consider whether the trigger action is running in the current state. When the trigger action is running in the current state corresponding to it, the functions provided by the cleaning robot can fully adapt to the above trigger actions. In one embodiment, the cleaning robot detects being trapped, and being trapped is a trigger event. The corresponding trigger action is to escape from the trap. If the current state is the running state, the cleaning robot will continue to perform the function for the movement of the cleaning robot in the running state, which may hinder the cleaning robot from escaping from the trap. In the escape state corresponding to the escape action, the function performed by the cleaning robot is more conducive to the cleaning robot escaping from the trap, and the cleaning robot also provides a function of detecting the escape situation in the escape state, which is conducive to the cleaning robot successfully escaping from the trap. Obviously, for the trigger action of escaping from the trap, it is more suitable to be performed in the escape state. Executing the trigger action according to the above judgment result is conducive to improving the reliability of the control method.
[0063] Further, executing the trigger action according to the judgment result includes: Step S201: when the trigger action corresponding to the trigger event is executed in the current state, calling at least one of the program units to execute the task corresponding to the current state to realize the trigger action.
[0064] Furthermore, executing the trigger action according to the judgment result includes: Step S202: when the trigger action corresponding to the trigger event is not executed in the current state, switching the state of the cleaning robot, calling at least one of the program units to execute the task corresponding to the current state to realize the trigger action.
[0065] Furthermore, the trigger event is a command sent by a host computer.
[0066] Specifically, the trigger event is a specific command sent by the host computer, and the corresponding trigger action is executed according to the specific content of the command.
[0067] Without solving the above technical problems, the present application also proposes a business logic control device for a cleaning robot and discloses the following technical solution.
[0068] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0069] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0070] For further reference, Figure 2 As an implementation of the above method, the present application provides an embodiment of a service logic control device for a cleaning robot. Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0071] A service logic control device for a cleaning robot, the device comprising:
[0072] The control module 100 is used to call each program unit through the calling module according to the current state of the cleaning robot, and execute the task corresponding to the current state through the execution module;
[0073] The encapsulation module 200 is used to encapsulate the program unit into a unit class;
[0074] A calling module 300 is used to instantiate the unit class into a unit object, and execute part of the code in the program unit through the unit object;
[0075] The execution module 400 is used to run the code in the unit object, and through the code in the program unit, call other program units or call tool classes through the calling module to implement the collection function, wherein the tool class includes code to implement one or a group of specific functions.
[0076] This solution can achieve code reuse and modular programming, decouple algorithms from business logic, improve code maintainability and portability, and improve software development efficiency, code maintainability, and security of code problems.
[0077] To solve the above technical problems, the present application also provides a computer device. Figure 3 , Figure 3 This is a basic structural block diagram of the computer device in this embodiment.
[0078] The computer device 6 includes a memory 61, a processor 62, and a network interface 63 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 6 with components 61-63, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0079] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0080] The memory 61 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 61 can be an internal storage unit of the computer device 6, such as a hard disk or memory of the computer device 6. In other embodiments, the memory 61 can also be an external storage device of the computer device 6, such as a plug-in hard disk equipped on the computer device 6, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 61 can also include both the internal storage unit of the computer device 6 and its external storage device. In this embodiment, the memory 61 is generally used to store the operating system and various application software installed on the computer device 6, such as a program code of a business logic control method for a cleaning robot, etc. In addition, the memory 61 can also be used to temporarily store various types of data that have been output or are to be output.
[0081] The processor 62 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 62 is generally used to control the overall operation of the computer device 6. In this embodiment, the processor 62 is used to run the program code stored in the memory 61 or process data, such as running the program code of the business logic control method for a cleaning robot.
[0082] The network interface 63 may include a wireless network interface or a wired network interface. The network interface 63 is generally used to establish a communication connection between the computer device 6 and other electronic devices.
[0083] The present application also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores a business logic control program for a cleaning robot, and the business logic control program for a cleaning robot can be executed by at least one processor so that the at least one processor performs the steps of a business logic control method for a cleaning robot as described above.
[0084] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0085] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A service logic control method for a cleaning robot, characterized in that: The method includes: According to the current state of the cleaning robot, calling each program unit to execute a task corresponding to the current state; Specifically, by running some codes in each program unit, multiple functions of the cleaning robot in the current state are realized; The program unit is encapsulated as a unit class, and the calling specifically includes instantiating the unit class into a unit object, and executing part of the code in the program unit through the unit object; in the unit object, the method in the program unit called corresponds to the current state; The execution of the task specifically includes running the code in the unit object, and calling other program units or calling tool classes to implement the collection function through the code in the program unit, wherein the tool class includes code to implement one or a group of specific functions; In the current state of the cleaning robot, a trigger event is detected, and when the trigger event is detected, it is determined whether a trigger action corresponding to the trigger event is to be executed in the current state, and the trigger action is executed according to the determination result; Specifically, when the trigger action corresponding to the trigger event is not executed in the current state, the state of the cleaning robot is switched, and at least one of the program units is called to execute the task corresponding to the current state to implement the trigger action.
2. A service logic control method for a cleaning robot according to claim 1, characterized in that: When parameters need to be specified when calling a method in the program unit, parameters corresponding to the current state are specified.
3. A service logic control method for a cleaning robot according to claim 2, characterized in that: When the unit object calls other program units, a secondary unit object is instantiated in the unit object, and the secondary unit object includes part of the code in the other program units to implement one or a group of specific functions.
4. A service logic control method for a cleaning robot according to claim 3, characterized in that: The executing the trigger action according to the judgment result includes: when the trigger action corresponding to the trigger event is executed in the current state, calling at least one of the program units to execute a task corresponding to the current state to realize the trigger action.
5. A service logic control method for a cleaning robot according to any one of claims 1 to 4, characterized in that: The method also includes that the trigger event is a command sent by a host computer.
6. A service logic control device for a cleaning robot, characterized in that: The device includes: A control module, configured to call each program unit through a calling module according to the current state of the cleaning robot, and execute a task corresponding to the current state through an execution module; Specifically, by running some codes in each program unit, multiple functions of the cleaning robot in the current state are realized; A packaging module, used for packaging the program unit into a unit class; A calling module, used to instantiate the unit class into a unit object, and execute part of the code in the program unit through the unit object; An execution module, used to run the code in the unit object, and through the code in the program unit, call other program units or call tool classes through the calling module to implement the collection function, wherein the tool class includes the code to implement one or a group of specific functions; In the current state of the cleaning robot, a trigger event is detected, and when the trigger event is detected, it is determined whether a trigger action corresponding to the trigger event is to be executed in the current state, and the trigger action is executed according to the determination result; Specifically, when the trigger action corresponding to the trigger event is not executed in the current state, the state of the cleaning robot is switched, and at least one of the program units is called to execute the task corresponding to the current state to implement the trigger action.
Citation Information
Patent Citations
System for implementing script operation in preset embedded system
CN105843592A