A bare-metal decoupled control method, system, terminal, and medium for robot teaching.
By decoupling the read/write pointers of the circular buffer from the state machine in the robot teaching system, and combining local verification stubs and timeliness comparisons, the code refactoring problem and data frame corruption problem caused by hardware platform replacement are solved, achieving efficient and reliable communication and hardware adaptability.
Patent Information
- Application Number
- CN202611304034.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-26
- Publication Date
- 2026-11-17
AI Technical Summary
In existing technologies, robot teaching systems require refactoring of the overall business logic code when the hardware platform is replaced or iterated, resulting in low code reusability. Furthermore, the asynchronous writing mechanism causes the state machine to read scrambled data frames, reducing communication reliability.
By associating the read and write pointers of the circular buffer with the state machine and the direct memory access unit respectively, and combining the physical address direct mapping mechanism of the local verification stub with timeliness comparison, lock-free concurrency control is achieved to prevent the risk of data overwriting. Furthermore, the underlying driver functions are bound through the channel manager structure to achieve system decoupling.
It improves the communication reliability and data throughput of the robot teaching system in an operating system-free environment, reduces the code refactoring cost of cross-hardware platform porting, and ensures accurate response of communication timing and logical rigor of device operation.
Smart Images

Figure CN123103592A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of robot teaching technology, specifically relating to a bare-metal decoupling control method, system, terminal, and medium for robot teaching. Background Technology
[0002] Industrial robots and collaborative robots, as core equipment in intelligent manufacturing, are typically equipped with teach pendants for operation programming and motion guidance. In rapid teaching scenarios, the teach pendant control unit needs to frequently process button commands and engage in high-frequency data interaction with underlying peripherals. To control hardware costs and reduce system operating overhead, the industry often uses embedded microcontrollers without operating systems (bare-metal architecture) as the basic hardware platform for teach pendant communication and control.
[0003] In existing operating system-less architectures, robot teaching control primarily employs a combined foreground and background operation mode. The background uses interrupt responses to buttons and triggers serial port commands for transmission. On the data receiving end, Direct Memory Access (DMA) technology is mainly relied upon, with DMA hardware automatically transferring received data to a globally shared circular buffer. When an idle interrupt is triggered, the foreground business status machine intervenes, directly calling the underlying hardware communication driver or physical registers to extract data from this globally shared buffer for communication protocol parsing.
[0004] However, the aforementioned existing technologies lead to the following problems: First, the front-end business state machine is deeply coupled with the underlying hardware peripherals, and the application layer directly calls the hardware physical interface. When the system faces changes or iterations in the main control chip platform, it is often necessary to refactor the entire business logic code, resulting in low code reusability and limited scalability. Second, the DMA hardware and the front-end state machine asynchronously access the same global shared buffer. When the front-end state machine is reading the buffer to parse the previous frame of data, if the underlying bus continuously receives new data, the DMA will directly overwrite the new data to that memory area. This asynchronous write mechanism can cause the state machine to read overlapping and disordered data frames, leading to instruction parsing errors and reducing the communication reliability of the teaching system. Summary of the Invention
[0005] This invention addresses the problems in the prior art by providing a bare-metal decoupled control method, system, terminal, and medium for robot teaching. It solves the problems of deep coupling between the front-end business state machine and the underlying hardware peripherals, where the application layer directly calls the hardware physical interface. When the system faces changes or iterations in the main control chip platform, the entire business logic code often needs to be reconstructed, leading to low code reusability and limited scalability. Simultaneously, it solves the problem that asynchronous writing mechanisms can cause the state machine to read overlapping and disordered data frames, leading to instruction parsing errors and reducing the communication reliability of the teaching system.
[0006] The technical solution adopted in this invention is as follows: In a first aspect, this application provides a bare-metal decoupling control method for robot teaching, comprising the following steps: Step S1: Associate the write pointer update control of the circular buffer with the direct memory access unit, associate the read pointer update control of the circular buffer with the foreground state machine, and embed a local verification stub in the business sub-state of the foreground state machine. The local verification stub stores a physical read-only pointer for calling the circular buffer and a function pointer for calling the asynchronous communication interface driver. Step S2: When a key edge signal is captured and an external interrupt is triggered, in the interrupt service routine of the external interrupt, the function pointer in the local verification stub is called to write the teaching instruction code corresponding to the key edge signal into the transmit register of the asynchronous communication interface. Step S3: Enable the direct memory access unit to receive data from the asynchronous communication interface and write the data directly into the circular buffer. Increment the value of the write pointer in one direction according to the actual byte length of the written data. Step S4: When the bus idle flag of the asynchronous communication interface is detected to be set, the idle interrupt service routine is triggered, the current count value of the system hardware reference clock is read, the read-only token expiration timestamp is calculated based on the current count value and the preset security lifetime threshold, and a frame ready flag is generated. Step S5: When the foreground state machine detects the frame ready flag, it enters the corresponding service sub-state, executes the local verification stub corresponding to the service sub-state, reads the real-time count value of the system hardware reference clock, and compares the real-time count value with the read-only token expiration timestamp. Step S6: If the real-time count value does not exceed the expiration timestamp of the read-only token, the foreground state machine directly calls the physical read-only pointer in the local verification stub, reads the data in the absolute physical address space of the circular buffer mapped by the physical read-only pointer for parsing, and increments the read pointer in one direction after parsing is completed.
[0007] Furthermore, the write pointer and read pointer satisfy the following concurrency control: The direct memory access unit is the only physical update entity for the write pointer; The foreground state machine is the only physical update entity for the read pointer; Throughout the execution of the method, global interrupts are enabled, and global mutexes are not invoked.
[0008] Furthermore, in step S4, the timestamp is calculated as follows: Read the count value of the system hardware reference clock at the instant of the idle interrupt service routine response. ; Calculate the expiration timestamp : ,in This is a preset safe time window value in clock ticks; In step S5, if the real-time count value of the system hardware reference clock... If so, then proceed to step S6; like If the token is invalid, the physical address mapping of the physical read-only pointer is refused, and the data corresponding to the current frame ready flag in the circular buffer is discarded.
[0009] Furthermore, the configuration and calling method of the function pointer is as follows: Configure a channel manager structure, which stores the physical starting address of the function corresponding to the underlying driver function of the asynchronous communication interface; During the system initialization phase, the local verification stub accesses the channel manager structure to bind the function pointer to the physical starting address of the function; When the foreground state machine calls the asynchronous communication interface, it calls the underlying driver function by executing the function pointer, without directly accessing the physical registers of the asynchronous communication interface.
[0010] Furthermore, in the foreground state machine, the transition conditions between each service sub-state are jointly triggered by the external interrupt trigger flag, the frame ready flag, and the clock timeliness comparison result.
[0011] Furthermore, the business sub-states of the foreground state machine include idle state, instruction sending state, waiting for response state, data parsing state, and fault alarm state.
[0012] Secondly, this application provides a bare-metal decoupling control system for robot teaching, applied to an embedded microcontroller without an operating system. The microcontroller includes a hardware interrupt controller, an asynchronous communication interface, and a direct memory access unit, and a circular buffer is configured in the static memory to implement the bare-metal decoupling control method for robot teaching as described in the first aspect, including: The channel manager module is used to associate the write pointer update control of the circular buffer with the direct memory access unit and the read pointer update control of the circular buffer with the foreground state machine during system initialization. A local stub proxy module is embedded in the business sub-state of the foreground state machine. The local stub proxy module stores a physical read-only pointer to the circular buffer and a function pointer to the asynchronous communication interface driver. The key edge capture module is used to, when a key edge signal is captured and an external interrupt is triggered, write the teaching instruction code corresponding to the key edge signal into the transmit register of the asynchronous communication interface through the function pointer in the interrupt service routine of the external interrupt; The direct memory write module enables the direct memory access unit to receive data from the asynchronous communication interface and write the data into the circular buffer, and increments the write pointer value unidirectionally according to the actual byte length of the written data. The time reference and flag generation module is used to trigger the idle interrupt service routine when the bus idle flag of the asynchronous communication interface is set, calculate the read-only token expiration timestamp based on the current system time and the preset safe survival time threshold, and issue a frame ready flag. The foreground state machine module is used to read the real-time count value of the system hardware reference clock when the frame ready flag is detected. When the real-time count value does not exceed the read-only token expiration timestamp, the physical address of the circular buffer is directly read by calling the physical read-only pointer for parsing, and the read pointer is incremented unidirectionally after the parsing is completed.
[0013] Furthermore, the channel manager module stores a channel manager structure, which contains the physical starting address of the underlying driver function of the asynchronous communication interface. The local stub proxy module realizes the logical isolation between the foreground state machine business sub-state and the underlying physical driver through the mapping relationship between the function pointer it holds and the physical starting address of the underlying driver function.
[0014] Thirdly, this application provides a terminal, including: Memory, used to store the bare-metal decoupled control program for robot teaching; A processor is configured to implement the steps of the bare-metal decoupling control method for robot teaching as described in the first aspect when executing the bare-metal decoupling control program for robot teaching.
[0015] Fourthly, this application provides a computer-readable storage medium that stores computer instructions. When a computer reads the computer instructions in the storage medium, the computer executes the bare-metal decoupling control method for robot teaching as described in the first aspect.
[0016] As can be seen from the above technical solutions, the advantages of the present invention are: By associating the read and write pointers of the circular buffer with the state machine and the direct memory access unit respectively, and combining the physical address direct mapping mechanism of the local verification stub with timeliness comparison, redundant copying overhead of data between the underlying peripherals and the application layer is avoided, achieving efficient and low-latency communication in an operating system-free environment, and improving the data throughput of the microcontroller while ensuring memory safety.
[0017] By limiting the direct memory access unit and the foreground state machine to be the only physical update entities for the write pointer and read pointer respectively, and by keeping global interrupts enabled throughout the process and not calling mutex locks, the read-write conflicts of shared resources in a concurrent environment are eliminated, lock-free concurrent control is achieved, and the interference of traditional interrupt-disabling operations on the real-time response performance of the teaching system is avoided.
[0018] By calculating the count value at the instant of the idle interrupt response and superimposing it with the preset safe time window to generate the failure timestamp, and comparing it in real time before the local verification stub performs physical address mapping, it can proactively intercept and discard dirty data that has timed out. This achieves the prevention of data overwrite risk in the underlying asynchronous continuous write scenario and eliminates the logical loophole of checking the usage time.
[0019] By binding the physical starting address of the underlying driver function in the channel manager structure and using the function pointer of the local verification stub to proxy the call of the asynchronous communication interface, the hard-coded connection between the front-end business logic and the specific underlying physical registers is severed, realizing the decoupling of the system software and hardware architecture and reducing the code refactoring cost when porting across hardware platforms.
[0020] By using the external interrupt trigger flag, frame ready flag, and clock timeliness comparison results as the joint triggering conditions for the transition between various service sub-states of the foreground state machine, strict synchronization between state transitions and underlying communication events and memory safety states is ensured, thereby realizing the precise response and scheduling of communication timing by the service control logic.
[0021] By specifically dividing the business sub-states of the foreground state machine into idle state, instruction sending state, waiting for response state, data parsing state, and fault alarm state, the full-cycle control process of robot teaching operation is standardized, closed-loop management of complex interactive logic is realized under bare-metal architecture, and the logical rigor of equipment operation is improved.
[0022] By constructing a hardware control system that includes modules such as a channel manager, local stub agent, key edge capture, direct memory writing, time baseline generation, and foreground state machine, the underlying interrupt response, direct memory transfer, and upper-level time verification are modularly isolated at the system function level, enabling stable and efficient processing of teaching instructions on a microcontroller without an operating system.
[0023] By statically storing the physical starting address of the underlying driver function in the channel manager structure and relying on the pointer mapping relationship of the local stub proxy module for proxy calls, the direct dependency between the business sub-state and the underlying physical driver is isolated at the system level. This achieves transparency of the front-end state machine module to the differences in the underlying hardware and improves the hardware adaptability and scalability of the control system. Attached Figure Description
[0024] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the description will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 This is a flowchart of the bare-metal decoupling control method for robot teaching according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the bare-metal decoupling control system for robot teaching according to an embodiment of the present invention.
[0026] In the diagram: 1. Bed; 2. X-axis transmission mechanism; 3. Worktable; 4. Column; 5. Crossbeam; 6. Z-axis transmission mechanism; 7. Hydraulic cylinder; 8. Y-axis transmission mechanism. Detailed Implementation
[0027] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0028] Please see Figure 1 As shown, this application provides a bare-metal decoupling control method for robot teaching, which includes the following steps: Step S1: Associate the write pointer update control of the circular buffer with the direct memory access unit, associate the read pointer update control of the circular buffer with the foreground state machine, and embed a local verification stub in the business sub-state of the foreground state machine. The local verification stub stores a physical read-only pointer for calling the circular buffer and a function pointer for calling the asynchronous communication interface driver. In the above implementation, the circular buffer is allocated in the microcontroller's static random access memory (SRAM). Its memory space is statically allocated during the system compilation phase via a channel manager, thus avoiding the overhead of dynamic memory allocation and the risk of memory fragmentation at runtime. The local verification stub, acting as a proxy layer in software logic, is injected into the foreground state machine's context as a structure pointer. The physical read-only pointer held by this stub is restricted to read-only attributes by hardware memory protection mechanisms or software logic, preventing the foreground state machine from writing data to this address range.
[0029] As an example, in a handheld teach pendant for a six-axis robot, the main microcontroller allocates a contiguous 256-byte address space in SRAM as a circular buffer during initialization. The channel manager configures the peripheral target address of the Direct Memory Access (DMA) channel as the starting address of this buffer and binds the DMA transfer completion flag to the auto-increment logic of the system write pointer. Simultaneously, the foreground state machine is instantiated, and its internal local verification stub structure is assigned a read-only pointer to this 256-byte starting address, as well as a function pointer to the underlying Universal Asynchronous Receiver / Transmitter (UART) transmit function. This design enables the state machine to read data and invoke transmit functions, but physically deprives it of direct control over peripheral registers.
[0030] Step S2: When a key edge signal is captured and an external interrupt is triggered, in the interrupt service routine of the external interrupt, the function pointer in the local verification stub is called to write the teaching instruction code corresponding to the key edge signal into the transmit register of the asynchronous communication interface. In this step, the capture of the button edge signal relies on the microcontroller's External Interrupt Controller (EXTI) hardware circuitry, enabling microsecond-level response. The interrupt service routine (ISR) of the external interrupt does not contain any blocking delays or complex business logic calculations; it only completes context mapping and instruction issuance. The ISR utilizes the local verification stub of the passed context to directly call the pre-mounted asynchronous communication interface driver function, pushing the encoded teach instruction into the transmit data register.
[0031] As an example, when the operator presses the "J1 axis forward" physical button on the teach pendant, the falling edge of the pin level instantaneously triggers an external interrupt. The microcontroller pauses the current main loop and enters the interrupt service routine. Inside the interrupt service routine, the pre-bound UART transmit function entry is located through a local verification stub, and the preset hexadecimal instruction code representing "J1 axis forward" (e.g., 0x5A 0x01 0x01) is written to the UART data transmit register through the function pointer. After writing is complete, the interrupt service routine returns. The entire process takes only a few dozen clock cycles, ensuring high real-time performance of the teach instruction.
[0032] Step S3: Enable the direct memory access unit to receive data from the asynchronous communication interface and write the data directly into the circular buffer. Increment the value of the write pointer in one direction according to the actual byte length of the written data. In this embodiment, the Direct Memory Access Unit (DMI) is configured in a circular receive mode. When the receive shift register of the asynchronous communication interface receives a complete byte, the hardware automatically triggers a DMA request. The DMA controller then takes over the internal bus and moves the byte to the absolute physical address currently pointed to by the write pointer in the circular buffer. After each move, the DMA's internal transfer counter decrements, and the write pointer is unidirectionally incremented at the software level using modulo operation logic (modulo the total buffer capacity). When the write pointer reaches the end of the buffer, it automatically wraps back to the beginning address of the buffer. This entire process requires no intervention from the microcontroller's central processing unit.
[0033] As an example, the teach pendant's underlying board-level communication IC returns a 12-byte motor status data packet to the microcontroller. Each time the UART peripheral receives a byte, it triggers a DMA request, and the DMA then moves the byte into a pre-defined 256-byte circular buffer. After receiving these 12 bytes, the write pointer logical value of the circular buffer is incremented by 12. If the original write pointer is at address offset 250, after modulo 256, the new write pointer automatically wraps around and points to address offset 6, achieving circular utilization of memory space.
[0034] Step S4: When the bus idle flag of the asynchronous communication interface is detected to be set, the idle interrupt service routine is triggered, the current count value of the system hardware reference clock is read, the read-only token expiration timestamp is calculated based on the current count value and the preset security lifetime threshold, and a frame ready flag is generated. In this implementation, setting the bus idle flag signifies the completion of receiving a frame of variable-length data. The system hardware reference clock typically uses the kernel's built-in system tick timer, which provides high-precision hardware-level timestamps. By capturing the timestamp in the idle interrupt, the system assigns a time-stamped, lifecycle-bound tag to the currently received data frame and sets a global or local event flag to asynchronously notify the foreground state machine that new data is available for parsing.
[0035] As an example, when the transmission of the 12-byte motor status data packet ends and the bus maintains a high level for more than one byte cycle, the UART hardware sets the IDLE flag, triggering an idle interrupt. After entering the idle interrupt service routine, the program reads the current SysTick counter value as 50000. Based on a pre-set safe lifetime threshold (e.g., converted to 2000 ticks), the program calculates the expiration timestamp of the frame data as 52000, and then sets the frame ready flag to true.
[0036] Step S5: When the foreground state machine detects the frame ready flag, it enters the corresponding service sub-state, executes the local verification stub corresponding to the service sub-state, reads the real-time count value of the system hardware reference clock, and compares the real-time count value with the read-only token expiration timestamp. The foreground state machine uses either a polling or event-driven approach to detect the frame ready flag in the main loop. Once the flag is detected, the state machine transitions to a new state, waking up the local verification stub in the corresponding data parsing sub-state. To prevent the "check-to-use time" security vulnerability—that is, to prevent the background DMA from receiving a new round of data and overwriting the current memory while the foreground is preparing to read—the local verification stub must, before mapping memory, capture the real-time count value of the current hardware clock again and perform a strict algebraic comparison with the expiration timestamp generated in step S4.
[0037] As an example, when the foreground main loop executes the state machine scheduling function, it finds that the frame ready flag is true and immediately switches the state from "waiting for response" to "data parsing". At this time, the local verification stub is activated, and the stub's internal instructions read the current value of SysTick, which is 51500. The stub performs a logical operation to compare this real-time count value (51500) with the previously recorded expiration timestamp (52000) to assess whether the data in the current circular buffer is still within a safe and valid time window.
[0038] Step S6: If the real-time count value does not exceed the expiration timestamp of the read-only token, the foreground state machine directly calls the physical read-only pointer in the local verification stub, reads the data in the absolute physical address space of the circular buffer mapped by the physical read-only pointer for parsing, and increments the read pointer in one direction after parsing is completed.
[0039] Once the timestamp comparison passes, it indicates that the memory block in question has not been contaminated by a new round of DMA transfer operations. Under this security premise, the foreground state machine skips the traditional "data copy from the receive area to the application area (Memcpy)" operation and directly performs protocol header comparison and payload extraction (i.e., zero-copy parsing) in the existing circular buffer area using a physical read-only pointer. After completing the business logic processing, the read pointer is incremented unidirectionally according to the parsed data frame length, and modulo operations are also used to handle wraparound, thereby releasing the memory segment for subsequent DMA overwriting.
[0040] As an example, since the real-time time 51500 is less than the expiration timestamp 52000, the stub verification passes and the access permission to the physical read-only pointer is released. The data parsing function uses this read-only pointer to directly extract the first two bytes from the corresponding address in the SRAM's circular buffer according to the protocol rules for frame header verification, and then extracts the subsequent motor temperature and current payload. After the extraction and parsing operations are completed, the state machine increases the offset of the read pointer by 12 (i.e., the total length of the frame), completing the secure digestion of the frame data.
[0041] In some embodiments, the write pointer and read pointer satisfy the following concurrency control: The direct memory access unit is the only physical update entity for the write pointer; The foreground state machine is the only physical update entity for the read pointer; Throughout the execution of the method, global interrupts are enabled, and global mutexes are not invoked.
[0042] This read-write separation unidirectional control model constructs a lock-free circular queue at the software level. By limiting the write pointer to be driven unidirectionally only by the hardware DMA at the underlying level, and the read pointer to be driven unidirectionally only by the state machine at the application layer, physical isolation is achieved between the two in both memory space and time dimensions. Since there is no situation where multiple control flows simultaneously modify the same pointer variable, shared resource race conditions in concurrent environments are completely avoided. Under this architecture, the system does not need to use semaphores, mutexes, or brute-force global interrupt disable instructions to protect critical sections, thus ensuring the continuous responsiveness of the microcontroller's interrupt system.
[0043] As an example, when the robot is in a complex multi-axis linkage teaching state, the back-end bus is receiving feedback data from the servo drivers at high frequency (DMA continuously updates the write pointer), while the foreground state machine is simultaneously parsing the motion feedback results of the previous frame (state machine updates the read pointer). Due to the strict unidirectional update constraint, the system does not need to disable external interrupts when the state machine reads data. At this time, even if the operator presses the "emergency stop" button, the external interrupt can still interrupt the current operation and respond with zero delay, achieving highly reliable concurrent operation without deadlock or blocking.
[0044] In some embodiments, the timestamp is calculated in step S4 as follows: Read the count value of the system hardware reference clock at the instant of the idle interrupt service routine response. ; Calculate the expiration timestamp : ,in This is a preset safe time window value in clock ticks; In step S5, if the real-time count value of the system hardware reference clock... If so, then proceed to step S6; like If the token is invalid, the physical address mapping of the physical read-only pointer is refused, and the data corresponding to the current frame ready flag in the circular buffer is discarded.
[0045] To further improve the system's robustness and the scientific validity of the failure timestamp determination mechanism, the aforementioned safe time window value... The acquisition of this value is not limited to fixed empirical constants, but rather involves precise mathematical derivation and dynamic calculation based on system parameters such as the underlying hardware transmission rate, ring buffer margin, and clock frequency. Specifically, The calculation formula can be further refined and improved as follows:
[0046] in, This represents the total byte capacity of the circular buffer. This indicates the actual length of bytes received in the current frame, therefore It represents the boundary of the number of remaining bytes that the DMA can receive before the write pointer catches up with the current data; This indicates the number of physical bits per byte in asynchronous communication (usually including start, data, and stop bits). Indicates the baud rate of the asynchronous communication interface; This indicates the operating frequency of the system hardware reference clock; The reserved image stabilization tolerance factor (the value range is...) ).
[0047] Since microcontroller hardware timers mostly use a loop counting mode, the above timestamp calculation... It needs to be combined with the timer's maximum overload value. Perform the modulo operation, that is, actually calculate as This is to avoid logic errors caused by clock overflow.
[0048] As an example, in the system configuration, the total capacity of the circular buffer is... A byte is determined to have been received when the current idle interrupt is triggered. Bytes of data, serial communication parameters configured to baud rate Number of bits per byte System tick clock frequency The fault tolerance coefficient is taken as Based on the above-described formula, the microcontroller calculates the theoretically safe number of ticks required for the write pointer to overwrite the current data again at this rate: The number of ticks. The program uses this value as... Add to current clock Obtain If the foreground state machine is blocked due to processing other high-priority tasks, resulting in slower real-time read times... Exceeded the calculated The local verification stub will determine that the memory segment has a high risk of being corrupted, actively intercept the physical pointer mapping request of the state machine, and directly offset the read pointer past the data frame to ensure that the robot control system will not cause the robot to run away or move malfunctioning due to parsing the overwritten garbled data.
[0049] In some embodiments, the function pointer is configured and invoked in the following manner: Configure a channel manager structure, which stores the physical starting address of the function corresponding to the underlying driver function of the asynchronous communication interface; During the system initialization phase, the local verification stub accesses the channel manager structure to bind the function pointer to the physical starting address of the function; When the foreground state machine calls the asynchronous communication interface, it calls the underlying driver function by executing the function pointer, without directly accessing the physical registers of the asynchronous communication interface.
[0050] This mechanism, which bridges the gap between structure and function pointers, builds a hardware abstraction layer between the underlying physical hardware driver and the upper-level business logic. The channel manager structure acts as a resource registry. Changes to the underlying driver functions or switching of communication channels only require modifying the physical starting address assignment in the registry during the initialization phase. The local verification stub and its attached foreground state machine code do not require any modification, recompilation, or logic refactoring, achieving a high degree of software engineering decoupling and code reuse.
[0051] As an example, the first-generation robot teaching system's motherboard used the microcontroller's UART2 channel for external communication, with the channel manager structure binding the address of the driver function pointing to the UART2 hardware transmit register. When upgrading to the second-generation system, the hardware design changed to use the USART3 channel, or even the main microcontroller was replaced from vendor A's chip to vendor B's chip. In this case, developers only needed to rewrite the vendor B chip's USART3 driver function at the underlying level and, during system initialization, point the physical address of the function within the channel manager structure to the new driver function. The control logic code inside the foreground state machine remained completely unchanged, still executing the original function pointers to issue instructions, significantly reducing the time cost of cross-platform porting.
[0052] In some embodiments, in the foreground state machine, the transition conditions between each service sub-state are jointly triggered by the external interrupt trigger flag, the frame ready flag, and the clock timeliness comparison result.
[0053] The state machine's transitions are not based on a single linear timeline or a simple software delay function, but rather on a rigorous event-driven mechanism. This joint triggering mechanism constitutes the transition condition edges of the state machine's state transition diagram. Only when the Boolean logic combination of the underlying hardware event (such as button triggering or communication idle) and the software time-sensitive logic (comparison result security) satisfies a specific expectation will the current state transition to the next state, ensuring the system's immunity to abnormal timing or hardware jitter.
[0054] As an example, when the state machine is in the "waiting for response" state, its transition condition logic is set as follows: "frame ready flag set" logic AND "clock timeliness comparison passed". If the underlying layer fails to generate an idle interrupt (no frame ready), or if the timeliness comparison fails due to read delay caused by system busyness (token expires), this combined trigger condition is determined to be false. At this time, the state machine will not rashly enter the "data parsing state", but will directly transition to the "fault alarm state" according to the timeout protection logic to notify the user of communication abnormality.
[0055] In some embodiments, the business sub-states of the foreground state machine include idle state, instruction sending state, waiting for response state, data parsing state, and fault alarm state.
[0056] The aforementioned sub-states cover the entire lifecycle of robot teaching operations at the underlying control layer. In the idle state, the system is in a low-power or polling listening state; in the instruction sending state, it handles and maps action requests transmitted by external interrupts; in the waiting-for-response state, it activates a timeout protection mechanism to wait for feedback from the board-level IC; in the data parsing state, it extracts feedback parameters using a zero-copy mechanism; and in the fault alarm state, it handles various anomalies, including timeouts, token expiration, and checksum errors, and triggers necessary safety shutdown responses. By deconstructing the complex process into a deterministic finite state machine, the system's execution logic becomes highly predictable and traceable.
[0057] As an example, the teach pendant defaults to the idle state after power-on. When an external interrupt is detected by the jog button, it transitions to the instruction sending state and sends a motor running instruction via a function pointer. After the instruction is sent, it immediately transitions to the waiting response state and starts the software timeout timer. If a frame ready flag generated by the idle interrupt is detected within a specified time and the timestamp comparison passes, it transitions to the data parsing state to verify whether the motor position is in place. If the parsed data is normal, the state machine is reset and returns to the idle state to wait for the next button instruction, forming a complete and highly cohesive closed-loop control data flow.
[0058] Please see Figure 2 As shown, this application provides a bare-metal decoupled control system for robot teaching, applied to an embedded microcontroller without an operating system. The microcontroller includes a hardware interrupt controller, an asynchronous communication interface, and a direct memory access unit, and the circular buffer is configured in the static memory, including: The channel manager module is used to associate the write pointer update control of the circular buffer with the direct memory access unit and the read pointer update control of the circular buffer with the foreground state machine during system initialization. A local stub proxy module is embedded in the business sub-state of the foreground state machine. The local stub proxy module stores a physical read-only pointer to the circular buffer and a function pointer to the asynchronous communication interface driver. The key edge capture module is used to, when a key edge signal is captured and an external interrupt is triggered, write the teaching instruction code corresponding to the key edge signal into the transmit register of the asynchronous communication interface through the function pointer in the interrupt service routine of the external interrupt; The direct memory write module enables the direct memory access unit to receive data from the asynchronous communication interface and write the data into the circular buffer, and increments the write pointer value unidirectionally according to the actual byte length of the written data. The time reference and flag generation module is used to trigger the idle interrupt service routine when the bus idle flag of the asynchronous communication interface is set, calculate the read-only token expiration timestamp based on the current system time and the preset safe survival time threshold, and issue a frame ready flag. The foreground state machine module is used to read the real-time count value of the system hardware reference clock when the frame ready flag is detected. When the real-time count value does not exceed the read-only token expiration timestamp, the physical address of the circular buffer is directly read by calling the physical read-only pointer for parsing, and the read pointer is incremented unidirectionally after the parsing is completed.
[0059] In some embodiments, the channel manager module stores a channel manager structure, which contains the physical starting address of the underlying driver function of the asynchronous communication interface. The local stub proxy module realizes logical isolation between the foreground state machine business sub-state and the underlying physical driver through the mapping relationship between the function pointer it holds and the physical starting address of the underlying driver function.
[0060] In some embodiments, this application provides a terminal, including: Memory, used to store the bare-metal decoupled control program for robot teaching; A processor is used to implement the bare-metal decoupling control method for robot teaching when executing the bare-metal decoupling control system for robot teaching.
[0061] In some embodiments, this application provides a computer-readable storage medium that stores computer instructions. When a computer reads the computer instructions in the storage medium, the computer executes the bare-metal decoupling control method for robot teaching.
[0062] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit the scope of one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of one or more embodiments of this specification should be included within the protection scope of one or more embodiments of this specification.
Claims
1. A bare-metal decoupling control method for robot teaching, characterized in that, Includes the following steps: Step S1: Associate the write pointer update control of the circular buffer with the direct memory access unit, associate the read pointer update control of the circular buffer with the foreground state machine, and embed a local verification stub in the business sub-state of the foreground state machine. The local verification stub stores a physical read-only pointer for calling the circular buffer and a function pointer for calling the asynchronous communication interface driver. Step S2: When a key edge signal is captured and an external interrupt is triggered, in the interrupt service routine of the external interrupt, the function pointer in the local verification stub is called to write the teaching instruction code corresponding to the key edge signal into the transmit register of the asynchronous communication interface. Step S3: Enable the direct memory access unit to receive data from the asynchronous communication interface and write the data directly into the circular buffer. Increment the value of the write pointer in one direction according to the actual byte length of the written data. Step S4: When the bus idle flag of the asynchronous communication interface is detected to be set, the idle interrupt service routine is triggered, the current count value of the system hardware reference clock is read, the read-only token expiration timestamp is calculated based on the current count value and the preset security lifetime threshold, and a frame ready flag is generated. Step S5: When the foreground state machine detects the frame ready flag, it enters the corresponding service sub-state, executes the local verification stub corresponding to the service sub-state, reads the real-time count value of the system hardware reference clock, and compares the real-time count value with the read-only token expiration timestamp. Step S6: If the real-time count value does not exceed the expiration timestamp of the read-only token, the foreground state machine directly calls the physical read-only pointer in the local verification stub, reads the data in the absolute physical address space of the circular buffer mapped by the physical read-only pointer for parsing, and increments the read pointer in one direction after parsing is completed.
2. The bare-metal decoupling control method for robot teaching according to claim 1, characterized in that, The write pointer and read pointer satisfy the following concurrency control: The direct memory access unit is the only physical update entity for the write pointer; The foreground state machine is the only physical update entity for the read pointer; Throughout the execution of the method, global interrupts are enabled, and global mutexes are not invoked.
3. The bare-metal decoupling control method for robot teaching according to claim 1, characterized in that, In step S4, the timestamp is calculated as follows: Read the count value of the system hardware reference clock at the instant of the idle interrupt service routine response. ; Calculate the expiration timestamp : ,in This is a preset safe time window value in clock ticks; In step S5, if the real-time count value of the system hardware reference clock... If so, then proceed to step S6; like If the token is invalid, the physical address mapping of the physical read-only pointer is refused, and the data corresponding to the current frame ready flag in the circular buffer is discarded.
4. The bare-metal decoupling control method for robot teaching according to claim 1, characterized in that, The configuration and invocation method of the function pointer is as follows: Configure a channel manager structure, which stores the physical starting address of the function corresponding to the underlying driver function of the asynchronous communication interface; During the system initialization phase, the local verification stub accesses the channel manager structure to bind the function pointer to the physical starting address of the function; When the foreground state machine calls the asynchronous communication interface, it calls the underlying driver function by executing the function pointer, without directly accessing the physical registers of the asynchronous communication interface.
5. The bare-metal decoupling control method for robot teaching according to claim 1, characterized in that, In the foreground state machine, the transition conditions between each service sub-state are jointly triggered by the external interrupt trigger flag, the frame ready flag, and the clock timeliness comparison result.
6. The bare-metal decoupling control method for robot teaching according to claim 5, characterized in that, The business sub-states of the foreground state machine include idle state, instruction sending state, waiting for response state, data parsing state, and fault alarm state.
7. A bare-metal decoupling control system for robot teaching, applied to an embedded microcontroller without an operating system, wherein the microcontroller includes a hardware interrupt controller, an asynchronous communication interface, and a direct memory access unit, and the circular buffer is configured in static memory to implement the bare-metal decoupling control method for robot teaching as described in any one of claims 1-6, characterized in that, include: The channel manager module is used to associate the write pointer update control of the circular buffer with the direct memory access unit and the read pointer update control of the circular buffer with the foreground state machine during system initialization. A local stub proxy module is embedded in the business sub-state of the foreground state machine. The local stub proxy module stores a physical read-only pointer to the circular buffer and a function pointer to the asynchronous communication interface driver. The key edge capture module is used to, when a key edge signal is captured and an external interrupt is triggered, write the teaching instruction code corresponding to the key edge signal into the transmit register of the asynchronous communication interface through the function pointer in the interrupt service routine of the external interrupt; The direct memory write module enables the direct memory access unit to receive data from the asynchronous communication interface and write the data into the circular buffer, and increments the write pointer value unidirectionally according to the actual byte length of the written data. The time reference and flag generation module is used to trigger the idle interrupt service routine when the bus idle flag of the asynchronous communication interface is set, calculate the read-only token expiration timestamp based on the current system time and the preset safe survival time threshold, and issue a frame ready flag. The foreground state machine module is used to read the real-time count value of the system hardware reference clock when the frame ready flag is detected. When the real-time count value does not exceed the read-only token expiration timestamp, the physical address of the circular buffer is directly read by calling the physical read-only pointer for parsing, and the read pointer is incremented unidirectionally after the parsing is completed.
8. The bare-metal decoupling control system for robot teaching according to claim 7, characterized in that, The channel manager module stores a channel manager structure, which contains the physical starting address of the underlying driver function of the asynchronous communication interface. The local stub proxy module achieves logical isolation between the foreground state machine business sub-state and the underlying physical driver by mapping the function pointer it holds to the physical starting address of the underlying driver function.
9. A terminal, characterized in that, include: Memory, used to store the bare-metal decoupled control program for robot teaching; A processor, configured to implement the steps of the bare-metal decoupling control method for robot teaching as described in any one of claims 1-6 when executing the bare-metal decoupling control system for robot teaching.
10. A computer-readable storage medium, characterized in that, The storage medium stores computer instructions. When the computer reads the computer instructions from the storage medium, the computer executes the bare-metal decoupling control method for robot teaching as described in any one of claims 1-6.
