Drilling Tool Attitude Acquisition and Processing System Based on MATLAB GUI
2026-04-06 07:14:16··#1
Introduction Accurate measurement of wellbore attitude is a prerequisite for wellbore trajectory control in oil drilling. Therefore, this paper fully combines the advantages of microcontrollers and MATLAB. Based on an event-driven communication mechanism, a visualization data processing method is proposed for real-time serial communication between a GUI-based PC and a System-on-Chip (SoC) C8051F060 in a MATLAB environment, and wellbore attitude monitoring is implemented. This method greatly simplifies the development process and improves system development efficiency. More importantly, MATLAB's computing power provides a guarantee for data processing. 1 System Introduction In this system, the host computer is a PC, and the slave computer uses the high-speed SoC C8051F060 from Silabs. A triaxial accelerometer is used to sense changes in wellbore attitude. The triaxial accelerometers are pairwise orthogonal, and the positive output direction satisfies the right-hand rule. The output values of the triaxial accelerations are converted between coordinates, and the current wellbore spatial attitude can be obtained using trigonometric relationships. Since the PC's serial port and the SoC's UART use different voltage standards, they are connected through a voltage conversion chip SP3223. The attitude signal sensed by the three-axis acceleration is conditioned by a circuit and a multiplexer before being sampled by the SoC's internal A/D converter. The acquired data is then stored in external memory. The data storage device uses a high-capacity K9K8G08U0M memory manufactured by Samsung, meeting the system's long-term data acquisition and storage requirements. The host computer software, developed using a GUI, communicates with the lower-level machine via serial port for command and data transmission, and processes the data acquired by the lower-level machine. 2. Hardware System The C8051060 is a fully integrated mixed-signal system-on-a-chip (SoC) MCU. Its internal CIP-51 core uses a pipelined architecture, achieving an instruction execution speed of up to 25 MIPS. Using such a high-performance microcontroller greatly simplifies the system hardware circuit design. The microcontroller's UART and serial port communicate with the PC via a voltage conversion module SP3223, while the C8051060's dual serial ports facilitate cascading of multiple systems. Data acquisition is performed by its internal ADC, and the acquired data is stored in the high-capacity external memory K9K8G08U0M via I/O lines. The system hardware block diagram is shown in Figure 1, where solid lines represent data flow and dashed lines represent control flow. During system operation, the host computer controls the slave computer to perform corresponding operations via commands. During data acquisition, the microcontroller controls the power supply to power the sensors. Each signal is sent to a multiplexer after passing through its respective conditioning circuit. The microcontroller selects the signal to be sampled by controlling the multiplexer and sends it to the SoC's built-in ADC for sampling. The sampled value is stored and awaits communication with the host computer. 3. Slave Computer Software After receiving the message from the PC, the slave SoC jumps to the corresponding subroutine through the serial port interrupt program, executes the corresponding operation, and finally returns a handshake signal as a status flag to confirm whether the command was executed correctly. The C8051060 uses UART0 for serial communication with the PC. The serial port is set to mode 3, which features hardware address recognition and multiprocessor communication. Timer 1 is used as the baud rate generator, with a baud rate of 115,200 b/s. Each data frame occupies 11 bits—one start bit, eight data bits, one programmable ninth bit, and one end bit. The software subroutines include: clearing the parameter area, clearing the data area, sending parameters, receiving parameters, starting acquisition, receiving data, and resetting. The specific implementation of each subroutine is not described in detail here. The software block diagram is shown in Figure 2. 4. Host Computer Software This system uses the graphical user interface development environment (GUIDE) provided by MATLAB to complete the interface design and host computer software development. The GUI's "what you see is what you get" programming method is simple and straightforward, making it very easy to learn. This software utilizes MATLAB's built-in toolboxes and ActiveX controls in the system to develop menu bars, toolbars, and various functional modules, realizing bidirectional transmission and display of commands, parameters, and data, as well as data filtering and plotting. 4.1 Implementation of Serial Communication MATLAB itself is cross-platform software and does not have direct hardware access capabilities. However, it can support serial ports through operations on the `serial` class. To use a serial port in MATLAB, a serial port object must first be created using the `serial` class and opened before use. After data transmission is complete, the serial port object must be closed to prevent other programs from being unable to use it. When the system no longer uses the serial port or exits the system, the serial port object must be cleared and removed from the MATLAB workspace to avoid consuming memory and affecting other system operations. When using the serial port for data transmission, read and write operations are required. Reading and writing to the serial port can be done in two ways: binary and text, similar to general file operations. To improve transmission speed, this system adopts a serial port binary asynchronous read/write method based on practical considerations. The MATLAB program sends commands to the lower-level machine through the serial port and receives handshake signals and data uploaded by the lower-level machine through the serial port. The source code for serial communication is as follows: When using the serial port for read and write operations, one point to note is the setting of the serial port data verification method attribute (Parity). If this setting does not match the lower-level software, it will cause read and write errors that are difficult to find the cause. 4.2 Use of ActiveX controls in the GUI interface The basic controls provided in MATLAB's GUIDE are very limited and cannot meet the needs of this system. Therefore, this system calls the ActiveX controls FlexArray and FlexGrid to display data in a table and calls the axes control to draw data graphs. The controls used in this program (including ActiveX controls) are created and their properties are set using the full-program method, the GUIDE property method, and a combination of both. The full-program method creates and sets controls using only the handle function provided by MATLAB. The GUIDE property method is similar to the design style of VB and is easy to learn, but this method makes the m-file too dependent on the fig file. The combination of the two methods makes the design more flexible. The following uses the combination of the GUIDE property method and the full-program method to create and call the FlexArray control as an example to explain the data display part of this system. The operation of basic controls is relatively simple and will not be described in detail here. The full name of the FlexArray control is C:\WINDOWS\System32\VSFLEX3.OCX. If you don't have it on your computer, you can download it online or copy it from another computer and then register it using regsvr32.exe. After completing these preparations, click the ActiveX button in the toolbox on the left side of the GUI, drag in the design area, and the "Select an ActiveX Control" dialog box will pop up. The "ActiveX Control List" list box in the dialog box lists all ActiveX controls registered on the current computer. Select the control in the list box and click the "Create" button. The control will be created in the blank editing area of the GUI. After successful creation, the handle automatically generated by the GUI for the control is stored as a member of the graphics window handle handles. For the Nth ActiveX control created, its handle is handles.activexN. You can use this handle to call the corresponding ActiveX control through functions. The properties of the control can be set by double-clicking the control or opening the property settings window by right-clicking the menu, or by setting them in the m-file using the set command. The get command can be used to retrieve the properties of the ActiveX control. To read or set the content of a cell in a FlexArray control table, first point to the target cell using the statement `handles.activexl.row=i;handles.activexl.col=j;`, and then convert the content of the target cell into a numerical value and assign it to the variable `fa` using the statement `fa=get(handles.activexl, 'text');fa=str2num(fa);`. You can also set the content of the target cell using the `set` command, and you can also set the fixed column title, but note that the row number of the fixed column is 0 and the column number of the fixed column is 0. 4.3 Filtering and Graphic Drawing If the collected sensor output data is used to directly calculate the wellbore attitude, it will cause a large error. The main reasons are: (1) During drilling, due to the harsh drilling environment, vibration and rotation will have a significant impact on the sensor output; (2) The electrical noise of the circuit itself has a certain impact on the collected data. After eliminating the influence of rotation on the experimental data, the filtering function is implemented using MATLAB. The specific implementation process is as follows: Based on the experimental data, a filter is designed in the FDAtool toolbox of MATLAB. After the filtering effect matches the actual situation, the transfer function of the filter is implemented using MATLAB and added to the program corresponding to the "Data Processing" function button to complete all data processing functions. The data before and after filtering are plotted and displayed using the axeS control, showing the difference in the description of the actual wellbore attitude before and after data processing. 5 Application Examples This system has been applied to the indoor experiment of the intelligent rotary steering system. Figure 3 is a screenshot of the operation using this software during the drilling process of the simulated drilling experiment on the indoor vertical well drilling platform. This figure well demonstrates the functions of the software: bidirectional transmission and display of data and commands, and subsequent data processing functions. In the figure, the black line represents the collected y-axis weight acceleration value GY, and the red line represents GY after data processing. It is easy to see that the latter's fluctuation range is significantly reduced, and the curve is smoother. Then, using the processed triaxial acceleration values, the spatial attitude angles of the drilling tool are calculated, yielding a spatial attitude that closely matches the actual situation. This provides a valuable method for accurate measurement of spatial attitude during mine drilling, reducing drilling downtime and enhancing drilling efficiency and safety. 6. Conclusion The host computer software, with its data processing, serial port operation control, and ActiveX control functionality, combined with the high-performance C8051F060 system-on-a-chip as the main chip in the downhole circuit, forms a simulated drilling attitude acquisition and processing system. At a serial port baud rate of 115200, it achieves the acquisition and processing of multiple downhole signals. Experimental results show that the calculated spatial angles, such as well inclination angle and tool face angle, closely match the actual situation, making it fully suitable for spatial attitude measurement applications of drilling tools. The powerful data processing capabilities, coupled with the human-machine interface, will enable MATLAB to find broader applications in industrial field monitoring.