# Research on the Positioning Method of Steel Belt Anchor Holes Applied in Coal Mine Underground
## 2 Overall System Design
### FreeRTOS Introduction and Porting  
FreeRTOS is a lightweight embedded operating system developed by C programming language. The number of tasks is not limited in the system and a priority scheduling algorithm is supported. Each task is assigned a certain priority and the processor prioritizes tasks in a ready state. FreeRTOS also supports a round-robin scheduling algorithm, which allows different tasks to have the same priority level and enables these tasks to share the processor within the same period.  
This paper adopts CubeMX to integrate the FreeRTOS. The main parameters to be configured include the preemptive scheduler, system main frequency, system clock, maximum priority number, and heap size. All these configurations are reflected in the related macro definitions in the FreeRTOSConfig.h file. In addition, FreeRTOS execution requires a call to osSystickHandler() in the SysTick_Handler interrupt function, where the SVC_Handler and PendSV_Handler system interrupting are modified internally to construct operating beats for the real-time operating system. FreeRTOS mainly consists of files such as list.c (kernel scheduling linked lists), queue.c (queues), croutime.c (shared stack tasks), and task.c (tasks). This paper employs individual shared stack tasks (task.c) to establish multiple task threads, which support preemptive scheduling among them.  
The whole control system is capable of communication with the host computer, controlling motors, as well as data collection and processing. To meet the demands for system real-time performance and stability, the open-source real-time operating system FreeRTOS is ported. The task planning is shown in Figure 3.  
(1) System Initialization  
The initialization task is mainly about the system, which includes the system clock, serial ports, IIC buses, GPIO pins, timers, and suspending its own tasks after application task creation.  
(2) Host Computer Communication Task  
The host computer communication task requires the host computer to send control commands to the control system through this task. The task employs DMA for data transfer to improve the MCU utilization rate. To respond promptly to control commands sent by the host computer, a DMA receive interrupt is set up. When the DMA interrupt is triggered,  
Figure 3: Control system task planning.  
the interrupt service routine releases a semaphore. Acquiring this semaphore, the blocked host communication task exits the blocked state, and enters the ready state, waiting for the system scheduler to dispatch it for execution. When ready, the task interprets the received control commands.  
(3) Data Collection Task  
The data collection task involves collecting voltage, coordinates, and touch switch status data. The controller directs the stepper motors to move the XY mobile platform, which carries an inductive sensor to perform a comprehensive detection of the steel belt and sends real-time voltage signals to the controller during the detection. As the platform moves, the grating ruler on the X and Y axes outputs pulse signals, which are received by the controller with its internal encoder mode to determine the coordinates of the inductive sensor. The controller collects these coordinate data and voltage values from the inductive sensor to identify and locate anchor holes later. When the inductive sensor moves to the ends of the slider, the loading board will touch the microswitch, prompting the controller to adjust the motor's direction of motion.