A wind factor measurement correction method running in a single-chip microcomputer in a shipboard environment

CN122366285BActive Publication Date: 2026-08-07OCEANOGRAPHIC INSTR RES INST SHANDONG ACAD OF SCI
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
OCEANOGRAPHIC INSTR RES INST SHANDONG ACAD OF SCI
Filing Date
2026-06-10
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

但是,由于风测量过程受到船舶运动影响,需要根据船的姿态对测量结果进行校正,且校正过程计算量较大,且真风反演算法涉及三角函数与矩阵乘法运算,若采用传统的单片机软件模拟浮点计算,这些校正过程和计算过程会极大占用CPU资源并导致严重延时

Benefits of technology

[0013] The beneficial effects of this invention's wind element measurement correction method operating within a microcontroller in a shipborne environment are as follows: For the dynamic shipborne environment, a wind element correction algorithm capable of running within a microcontroller is derived and implemented. By constructing a three-dimensional rotation matrix from the ship hull to the geographic coordinate system, rigorous spatial attitude compensation is performed on the apparent wind vector. Subsequently, combining the laws of relative motion, and relying on the true heading of the electronic compass and the GPS ground speed, the vector synthesis and inversion of the absolute true wind are completed. To eliminate sensor delay errors and data jitter caused by sea turbulence, a timestamp alignment mechanism is introduced, and an orthogonal vector moving average filtering algorithm is designed to fundamentally solve the problem of abrupt zero-crossing changes in meteorological wind direction between 0° and 360°.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122366285B_ABST
    Figure CN122366285B_ABST
Patent Text Reader

Abstract

The present application relates to the field of meteorological parameter observation, in particular to a wind factor measurement correction method running in a single-chip microcomputer under a shipborne environment, comprising: 1: constructing a three-dimensional rotation matrix of a ship body to a geographic coordinate system to obtain a visual wind vector relative to the earth's horizontal plane but superimposed with the ship's movement speed; 2: obtaining the absolute movement speed component of the air micro-cluster relative to the earth's stationary coordinate system to complete the vector synthesis and inversion of the absolute true wind; 3: using the smoothed orthogonal average value to perform polar coordinate transformation again to output the final meteorological data. The three-dimensional rotation matrix of the ship body to the geographic coordinate system is constructed to carry out strict spatial attitude compensation on the visual wind vector; then, combined with the relative motion law, relying on the true heading of the electronic compass and the ground speed of the GPS, the vector synthesis and inversion of the absolute true wind are completed. The time stamp alignment mechanism is introduced, and the orthogonal vector sliding average filtering algorithm is designed, so that the problem of zero-crossing mutation of the meteorological wind direction between 0° and 360° is fundamentally solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of marine meteorological parameter observation, specifically to a method for measuring and correcting wind elements operating within a microcontroller in a shipboard environment. Background Technology

[0002] The marine environment is complex and changeable. Frequent typhoons and hurricanes generate destructive storm surges that can destroy ships and offshore facilities. The unpredictability of extreme weather at sea poses a significant threat to maritime operations. Therefore, installing marine meteorological instruments on ships to monitor real-time meteorological elements such as wind speed, wind direction, temperature, relative humidity, and air pressure plays a crucial role in ensuring safe navigation and operations at sea. However, due to the complex sea conditions, including high salinity, high humidity, and high salt spray, conventional meteorological instruments and sensors used on land are difficult to widely apply at sea.

[0003] Currently, the marine economy is developing rapidly, and various types of small and medium-sized vessels are flourishing, leading to a surge in both the variety and number of vessels. Faced with this increasing number of small and medium-sized vessels, the demand for maritime meteorological information is also surging. Simultaneously, with the rapid development of electronic technology, low-power, high-reliability meteorological information sensing sensors have also been developed, making the development of portable shipboard meteorological equipment possible. Portable devices are not only small in size, low in power consumption, and extremely easy to install and disassemble, but more importantly, they break free from dependence on traditional large platforms. By embedding algorithms directly within a microcontroller (MCU), the system can independently complete the accurate collection, calculation, and storage of key meteorological elements such as wind speed and direction at sea without the need for an external host computer. This design not only significantly enhances the independence and survivability of the equipment in field operations, improving the safe navigation and operational productivity of various small and medium-sized vessels at sea, but also supplements the sparse meteorological data from marine meteorological stations. By supplementing the data from these stations, the forecasting capabilities for marine weather and extreme weather can be greatly improved. However, wind measurement is affected by ship motion, requiring correction of the measurement results based on the ship's attitude. This correction process is computationally intensive, and the true wind inversion algorithm involves trigonometric functions and matrix multiplication. If traditional microcontroller software is used to simulate floating-point calculations, these correction and calculation processes consume significant CPU resources and cause severe delays. The wind element measurement correction method of this invention, running within a microcontroller in a shipboard environment, can solve the problems of wind measurement accuracy and true wind calculation accuracy caused by ship motion. Summary of the Invention

[0004] To address the problems existing in the prior art, the purpose of this invention is to provide a wind element measurement correction method that can guarantee real-time performance and the rigor of multi-task processing, fully utilizes a microcontroller with a built-in hardware floating-point arithmetic unit, and combines it with the DSP mathematical library of an embedded system to efficiently complete the real-time calculation of the attitude matrix within the microcontroller, ensuring the millisecond-level refresh rate of the observation data.

[0005] To achieve the above objectives, the technical solution adopted by the present invention is: a method for measuring and correcting wind elements in a shipborne environment and operating within a microcontroller, comprising the following steps: Step 1: Define the ship's coordinate system and the geographic coordinate system to perform spatial vector transformation, construct a three-dimensional rotation matrix from the ship's coordinate system to the geographic coordinate system, perform strict spatial attitude compensation on the apparent wind vector, and obtain the apparent wind vector relative to the Earth's horizontal plane but superimposed with the ship's motion speed. Step 2: Based on the true heading of the electronic compass and the ground speed of the GPS, through strict physical vector synthesis and meteorological standard conversion, and according to Galileo's law of relative motion, the program calculates the absolute velocity components of the air particle relative to the Earth's stationary coordinate system through vector addition, thus completing the vector synthesis and inversion of the absolute true wind. Step 3: Introduce a timestamp alignment mechanism and design an orthogonal vector moving average filtering algorithm to eliminate sensor delay errors and data jitter caused by sea wave turbulence, avoid the sudden change trap of meteorological wind direction crossing zero between 0° and 360°, and use the smoothed orthogonal average value to re-perform polar coordinate transformation to output the final meteorological data.

[0006] The aforementioned wind element measurement and correction method operating within a microcontroller in a shipborne environment incorporates the math.h library into the microcontroller. Upon receiving complete wind speed, direction, and attitude data, a compensation function is triggered. The triggering of this compensation function includes the following steps: The program determines the status of the ultrasonic wind data reception completion flag in the global structure. If no new frame of meteorological data is received, the program will exit the function directly and retain the valid solution value of the previous cycle. When new data is detected, the program immediately clears the flag and latches the latest meteorological and attitude sensor data to ensure that the variables involved in the matrix operation are strictly aligned on the time scale. When performing spatial matrix rotation, the relative wind vector is reversed by multiplying it by a negative sign, and then projected onto the ship's front-left-lower rectangular coordinate system using trigonometric functions. It is then decomposed into orthogonal wind speed components along the X and Y axes. Since a two-dimensional ultrasonic anemometer is used, the vertical component is set to 0.

[0007] The aforementioned method for wind element measurement and correction in a shipborne environment operating within a microcontroller includes the following steps for spatial attitude compensation: Step 1-1: Extract the roll angle (Roll), pitch angle (Pitch), and true heading angle (Yaw) output by the inertial measurement unit, convert them to radians, and perform engineering reversal adaptation on the signs of the roll angle (Roll), pitch angle (Pitch), and true heading angle (Yaw). Steps 1-2: Pre-calculate the sine and cosine values ​​of roll angle (Roll), pitch angle (Pitch), and true heading angle (Yaw), and substitute them into the formula to construct a three-dimensional rotation matrix from the ship's coordinate system to the geographic coordinate system. Steps 1-3: Perform the multiplication operation of the three-dimensional rotation matrix and the three-dimensional wind speed column vector to calculate the orthogonal components of the apparent wind in the absolute geographic coordinate system after removing the effects of ship roll, pitch and yaw. Use the square root function to obtain the horizontal apparent wind speed after attitude compensation. Steps 1-4: Quadrant judgment logic is introduced, and the atan2() function in the C language standard mathematical library is called to calculate the apparent wind direction. When the returned radian value is less than 0, 2π is added to map it to the positive value range, and finally it is converted into the standard meteorological wind direction angle of 0°~360°. Steps 1-5: The calculated physical quantities are then updated to the system memory and used as a high-precision input source for the next level of the real wind inversion algorithm.

[0008] The above-mentioned method for wind element measurement and correction in a shipborne environment operating within a microcontroller, step 2 includes: Step 2-1: Use the positioning module to directly extract the ship's ground speed, and use the true heading angle output by the electronic compass in the ten-axis sensor to determine the ship's true heading; Step 2-2: According to the vector operation rules, the data obtained by the two-dimensional wind vector is attitude corrected to eliminate the measurement error caused by the platform tilt, so that the data is strictly defined in the horizontal plane. After obtaining the attitude-compensated apparent wind vector, the absolute true wind is calculated by physical vector synthesis and meteorological standard conversion.

[0009] The above-described method for wind element measurement and correction in a shipborne environment, operating within a microcontroller, includes the following steps in step 2-2: Step a: Use the quaternion method to obtain the corresponding bank angles. Rotate around the X-axis to get the roll angle (Roll), around the Y-axis to get the pitch angle (Pitch), and around the Z-axis to get the yaw angle (Yaw). The coefficient matrix of roll angle is , The coefficient matrix of pitch is , The coefficient matrix of the heading angle Yaw is , Obtain the rotation matrix ; Step b: Let the relative wind vector in the geodetic coordinate system be a, and the relative wind vector in the ship's true wind observation system coordinate system be a′. The components of the true wind vector in the geodetic coordinate system are ax, ay, and az, respectively, and the components of the relative wind vector in the ship's true wind observation system coordinate system are ax′, ay′, and az′, respectively. The true wind vector a can be calculated as follows: ; Step c: Decompose the relative wind speed and direction given by the ultrasonic anemometer into two horizontal directions: the positive X-axis of the bow ship and the positive Y-axis of the starboard ship, and obtain the component calculation formulas for each axis: , , The new vector a′ is formed by calculating the components of each axis: ; Step d: Based on the rotation matrix R Expand the vector a′ into the formula. , ; Step e: Substituting the relative wind vector measured by the sensor into the rotation matrix, the final relative wind a in the horizontal plane can be calculated as follows: .

[0010] The above-described wind element measurement and correction method operating within a microcontroller in a shipborne environment, in step 2-2, after obtaining the attitude-compensated apparent wind vector, calculates the absolute true wind, including: (The method involves physical vector synthesis and meteorological standard conversion.) Step f: Read the eastward and northward orthogonal components of the apparent wind output from the previous compensation stage and the eastward and northward orthogonal components of the ship's entanglement speed resolved by GPS; Step g: Based on Galileo's law of relative motion, the absolute velocity components of the air particle relative to the Earth's stationary coordinate system are obtained through vector addition, and the true absolute wind speed is synthesized using the square root function; Step h: Introduce multiple engineering optimization logics. When calling the inverse trigonometric function atan2(), swap the parameter passing order of the eastward component and the northward component. After swapping the parameters, use the characteristics of trigonometric functions to directly map the calculation results to a coordinate system commonly used in navigation and meteorology, with true north as 0° and increasing clockwise, to calculate the angle of the physical direction of wind movement. Step i: An extra-boundary judgment logic was added, the calculated angle was increased by 180° and the vector was reversed, the result greater than or equal to 360° was modulo-corrected, and the high-precision true wind data that completely eliminated the interference of ship motion and directly conformed to the meteorological broadcasting specifications was output.

[0011] The above-mentioned method for wind element measurement and correction in a shipborne environment operating within a microcontroller, step 3 includes: Step 3-1: A synchronization strategy of high-frequency data latching and medium-frequency data triggering is adopted. The interruption of the ultrasonic anemometer's reception is used as the main trigger source for the attitude compensation and real wind inversion algorithm. When the main loop detects a new frame of meteorological data, it immediately latches the attitude angle data and the latest GPS speed in the global structure of the system that are closest to the current time. With minimal memory overhead, the multi-source data is forcibly aligned in the time dimension within the microcontroller. Step 3-2: The orthogonal vector moving average filtering algorithm is adopted. First, orthogonal decomposition is performed, then independent filtering is performed, and then polar coordinate synthesis is performed to eliminate the filtering distortion caused by abrupt changes in zero crossing.

[0012] The above-mentioned method for wind element measurement and correction in a shipborne environment operating within a microcontroller, wherein step 3-2 includes: Step 3-21: Using the eastward and northward components of the true wind as filtering objects, open two floating-point FIFO ring buffers of depth N in the microcontroller RAM to store the eastward and northward true wind components calculated consecutively N times. Step 3-22: After each new orthogonal component is calculated, overwrite the oldest data in the circular buffer and update the tail pointer; traverse the two buffers and calculate the arithmetic mean of the eastward and northward components respectively; Step 3-23: Using the smoothed orthogonal components, call the square root function and the atan2() function again to resynthesize the final smoothed true wind speed and smoothed true wind direction for display.

[0013] The beneficial effects of this invention's wind element measurement correction method operating within a microcontroller in a shipborne environment are as follows: For the dynamic shipborne environment, a wind element correction algorithm capable of running within a microcontroller is derived and implemented. By constructing a three-dimensional rotation matrix from the ship hull to the geographic coordinate system, rigorous spatial attitude compensation is performed on the apparent wind vector. Subsequently, combining the laws of relative motion, and relying on the true heading of the electronic compass and the GPS ground speed, the vector synthesis and inversion of the absolute true wind are completed. To eliminate sensor delay errors and data jitter caused by sea turbulence, a timestamp alignment mechanism is introduced, and an orthogonal vector moving average filtering algorithm is designed to fundamentally solve the problem of abrupt zero-crossing changes in meteorological wind direction between 0° and 360°. Attached Figure Description

[0014] Figure 1This is a schematic diagram of the software architecture in an embodiment of the present invention; Figure 2 This is a schematic diagram of the overall software design process in an embodiment of the present invention; Figure 3 This is a schematic diagram of the Modbus communication program flow in an embodiment of the present invention; Figure 4 This is a schematic diagram of I2C bus multi-slave communication connection in an embodiment of the present invention; Figure 5 This is a schematic diagram of the IIC acquisition and display program flow in an embodiment of the present invention; Figure 6 This is a schematic diagram of the serial port idle interrupt service process in an embodiment of the present invention; Figure 7 This is a schematic diagram of the attitude compensation process in an embodiment of the present invention; Figure 8 This is a schematic diagram of the true wind inversion process in an embodiment of the present invention; Figure 9 This is a schematic diagram of the filtering procedure in an embodiment of the present invention. Detailed Implementation

[0015] To enable those skilled in the art to better understand the technical solution of the present invention, the following detailed embodiments and appendices are provided. Figure 1 -Appendix Figure 9 The technical solution of the present invention will be described.

[0016] Since the true wind inversion algorithm involves a large number of trigonometric function and matrix multiplication operations, using traditional software-simulated floating-point calculations would consume a significant amount of CPU resources and cause severe latency. This system fully utilizes the STM32's built-in hardware floating-point unit and combines it with ARM's official DSP math library to efficiently complete the real-time calculation of the attitude matrix within the microcontroller, ensuring a millisecond-level refresh rate for the observation data.

[0017] Example 1 This embodiment mainly describes the overall architecture and design scheme of the software.

[0018] I. Overall Software Design Scheme This system enables real-time acquisition, processing, compensation calculation, and display of five key marine environmental parameters: wind speed, wind direction, temperature, humidity, and air pressure, as well as ship attitude angles, heading, GPS position, and speed. To ensure the system's real-time performance and the rigor of multi-tasking, the software design follows the principles of modularity and hierarchy.

[0019] (I) Software Development Environment and Hierarchical Structure.

[0020] The system's underlying hardware is based on a microcontroller with a built-in floating-point unit, while software development is based on the Keil μVision5 integrated development environment, using the Hardware Abstraction Layer (HAL) library for low-level driver development. Since the portable meteorological observation system requires access to multiple sensors for data acquisition, all meteorological parameter calculation and fusion algorithms are independently completed within the microcontroller (MCU). The Keil platform's built-in high-efficiency C / C++ compiler deeply optimizes the low-level driver code and core algorithms, fully utilizing the microcontroller's limited resources and ensuring real-time data processing. Simultaneously, its powerful online debugging and variable monitoring functions greatly enhance multi-interface communication, such as the integrated circuit bus I / O. 2 C. Serial port, and the development and troubleshooting efficiency of the main control program. In this embodiment, I 2 C and IIC represent different ways of writing integrated circuit buses.

[0021] The software architecture adopts a three-tier design, such as Figure 1 As shown, the layers are the Hardware Abstraction Layer (LL / HAL Layer), the Driver Layer, and the Application Layer. The Hardware Abstraction Layer focuses on the control of low-level peripherals and is responsible for configuring general-purpose input / output ports (GPIO), general-purpose synchronous / asynchronous transceivers (USART), and I / O pins. 2 C, Timer, and other peripheral registers provide a standardized hardware operation interface for the upper layer. The function driver layer encapsulates core capabilities above the hardware abstraction layer, integrating the Modbus-RTU protocol stack, NMEA-0183 parsing logic, and I / O. 2 The C communication timing and OLED driving functions transform complex protocols and hardware interactions into reusable modules. The application logic layer, as the top layer, coordinates business implementation and mainly includes multi-sensor scheduling logic, attitude compensation matrix operations, real wind inversion algorithms, and data anomaly filtering functions, directly supporting the system's core objectives. This three-layer architecture progresses progressively, from hardware control to protocol encapsulation to business logic, forming clear functional boundaries and collaboration paths.

[0022] (II) Software main program flow design.

[0023] After the system powers on, it completes system clock configuration, peripheral communication interface setup, and sensor initialization, laying the foundation for subsequent operation. Then, it enters the main program loop. To address the differences in sampling frequencies among different sensors, the software design employs a coordinated approach of timed interrupt sampling and main loop logic processing, thus balancing the data acquisition rhythms of various sensors. For high-frequency tasks, attitude angle and GPS data are received via DMA (Direct Memory Access) through the serial port, ensuring real-time dynamic compensation. Low-frequency tasks poll and collect temperature, humidity, and air pressure data at a frequency of 1Hz. In the core calculation stage, the compensation algorithm module is triggered immediately after each acquisition of complete raw data, ensuring timely integration of data processing and compensation. This architecture allows timed interrupts to focus on high-frequency or precisely synchronized sensor sampling, while the main loop concentrates on data parsing and status judgment logic, ensuring both timely acquisition of critical data and efficient overall process operation. The overall software design flowchart is as follows: Figure 2 As shown.

[0024] (III) Multi-sensor data fusion and synchronization.

[0025] The system involves industrial communication protocols Modbus and I... 2 C. Three communication interfaces are used, USART, and others. The update rates of each sensor differ; for example, ultrasonic anemometers typically update at 10Hz, while GPS updates at 1 to 5Hz. The software solution employs a global data structure as a data pool to address this. For timestamp alignment, the software triggers a synchronization signal upon receiving the recommended minimum positioning information (RMC) statement from GPS, locking the current attitude and wind speed data as input parameters for the true wind inversion algorithm, thus avoiding calculation errors caused by sensor delays. The data verification mechanism performs a 16-bit cyclic redundancy check (CRC16) on Modbus frames and checks and verifies NMEA data to ensure the authenticity and reliability of the data used in the algorithm calculations.

[0026] II. Low-level driver and communication program design.

[0027] The underlying drivers and communication programs serve as a bridge connecting the hardware physical layer and the upper-level core algorithms. Considering the complexity of the shipboard environment and electromagnetic interference, the underlying software design of this system, while ensuring real-time performance, emphasizes enhanced communication verification and fault tolerance mechanisms to ensure the accuracy and continuity of the observation data.

[0028] (a) Wind speed and direction data acquisition based on Modbus protocol.

[0029] 1. Modbus protocol.

[0030] Wind speed and direction data acquisition uses the Modbus protocol, which employs a strict master-slave architecture. It features a single master control mechanism, meaning only one master station can exist within the same Modbus network, but a maximum of 247 slave stations are allowed. All communication is initiated by the master station. The master station can send unicast requests (requiring a response) to slave stations at specific addresses, or send broadcast commands to address 0 without requiring a response. Slave stations are normally in a listening state, only executing actions and returning response data after receiving correct instructions from the master station.

[0031] Modbus serial transmission primarily includes two operating modes: ASCII mode and Remote Terminal Unit (RTU) mode. In Modbus ASCII mode, each 8-bit byte of a message is sent as two ASCII characters. Its advantages include visible characters, facilitating manual debugging, and allowing for a transmission interval of up to one second between characters without timeout errors. It employs LRC (Longitudinal Redundancy Check), and frames have explicit character markers for start and end. In Modbus RTU mode, each 8-bit byte of a message is transmitted directly in hexadecimal binary form. It employs strict CRC16 (Cyclic Redundancy Check), and frame differentiation does not rely on specific start / end characters but rather on time intervals, requiring at least 3.5 character idle times between frames. RTU mode has a significantly higher data density than ASCII mode, resulting in higher transmission efficiency at the same baud rate; ASCII mode, with its start and end markers, is more suitable for networks prone to long delays. Considering the high requirements of industrial environments for data transmission rate, real-time performance, and communication efficiency, this system uses an ultrasonic anemometer and ultimately selects Modbus RTU transmission mode for data transmission and reception.

[0032] In RTU mode, message transmission requires a pause of at least 3.5 character duration. The entire message frame consists of four core parts: address code, function code, data area, and error check code. The RTU frame format can be summarized as shown in Table 1.

[0033] Table 1 Modbus RTU Information Frame Format Table .

[0034] (1) Start bit and end bit: Bus idle time, marking the start and end of a message frame. The RTU protocol relies on time intervals to divide data frames. In the same data frame, the transmission interval between each byte cannot exceed 1.5 character time; and between two data frames, at least 3.5 character time of bus idle time must be guaranteed.

[0035] (2) Address code: The address of the slave device of the communication target. The address code occupies 1 byte, and each slave device has a unique address code. The valid range is 1~247.

[0036] (3) Function code: The master indicates the specific operation instruction to be executed by the slave, such as reading / writing registers. It defines the operation logic and business class of data interaction and is the core semantic carrier of the Modbus protocol. The function code occupies 1 byte and its effective range is 1~255.

[0037] (4) Data area: Additional operation data, the length of which varies depending on the function code and the amount of data transmitted, so that the slave device can read or write data.

[0038] (5) Checksum: CRC16 Cyclic Redundancy Check (CRC). Note that the low byte comes first, and the high byte comes last. The sender performs a CRC16 calculation on all bytes of the address code, function code, and data area, and appends the result to the end of the message. After receiving the complete frame, the receiver recalculates the CRC and compares it with the received checksum. If they do not match, it is determined that the data was interfered with during transmission, and the frame will be discarded. This ensures the reliability of data transmission in industrial environments.

[0039] 2. RS485 program design based on Modbus RTU.

[0040] In the portable meteorological observation equipment of this system, meteorological data acquisition adopts the method of directly reading data from digital sensors. To achieve reliable communication with other meteorological nodes or standard industrial equipment, the system uses an RS485 bus and runs the Modbus RTU protocol. Since the equipment operates independently, all data parsing, CRC verification, and protocol packaging are completed directly within the microcontroller (MCU), without the need for a host computer.

[0041] RS485 is a half-duplex communication bus. Therefore, in program design, in addition to configuring the USART2 of the main control chip, an additional GPIO pin must be used to control the RS485 transceiver, such as the transmit / receive enable state of the SP3485. To ensure that the bus can listen for external commands or weather data at any time when it is idle, the default state of RS485 must be configured as receive mode.

[0042] Configure the USART parameters, initializing the USART3 transmit (TX) and receive (RX) pins, setting the baud rate to 9600bps, 8 data bits, 1 stop bit, and no parity bit. Simultaneously, the USART3 receive interrupt must be enabled to respond immediately and enter the receive service function when data arrives on the bus. Configure a GPIO pin; here, PD7 is chosen as the transmit / receive direction control pin. In the final step of initialization, set this pin low to put the RS485 transceiver in receive mode by default, constantly monitoring bus data.

[0043] When the microcontroller receives data via the RS485 bus, the hardware timer automatically resets and restarts after each byte of data is received. If the timer count exceeds 3.5 character times without being reset, the Modbus protocol determines that the bus is idle, meaning a complete data frame has been received. At this point, a timer interrupt is generated, and the main program is notified to parse the data frame.

[0044] First, the program extracts the device address code from the message to determine if the frame data is an instruction sent to the local machine. If the address matches, a CRC16 check is performed on the received core data segment. After successful check, the program further reads the function code and data storage area address to determine if the function code is supported by the system. If the function code is correct, the MCU will directly execute the corresponding task internally. After processing, the response data is packaged in RTU format and returned to the master device. If any abnormalities are found during this process, such as an unsupported function code or an out-of-bounds data address, the system will generate the corresponding exception code according to the Modbus protocol standard, encapsulate it in the response frame, and return it to the master device, thus completing a complete request-response communication process. The Modbus communication flowchart is as follows: Figure 3 As shown.

[0045] (2) I 2 Temperature and humidity acquisition via USB-C interface and OLED display implementation 1. I 2 C protocol.

[0046] Temperature and humidity data acquisition uses I 2 The C (Inter-Integrated Circuit) protocol is a synchronous, bidirectional, half-duplex serial bus protocol. Its physical layer design is simple, requiring only two signal lines—a serial data line (SDA) and a serial clock line (SCL)—along with a ground terminal (GND) for communication. This protocol supports multiple slave devices on the bus, each with a unique 7-bit or 10-bit address. The master device can precisely select the target slave device by sending its address code after sending a start signal. In this system, for example... Figure 4Slave device 1 and slave device 2 shown are a temperature and humidity sensor and an OLED display, respectively. Furthermore, to ensure reliable data transmission, I... 2 C also has a dedicated acknowledgment mechanism. For each byte of data transmitted, the receiver must send back an acknowledgment bit (ACK) or a non-acknowledgment bit (NACK) to the sender.

[0047] 2. Based on I 2 C Protocol Interface Programming The high-precision digital temperature and humidity sensor AHT20 is mounted together with an OLED display on the same I-group. 2 C-bus, relying on the high-performance hardware I-bus of the microprocessor 2 C peripherals, the core of related program design revolves around I 2 The initialization configuration and data read / write process of C are described below. The hardware initialization configuration is divided into two parts: first, GPIO configuration, which requires setting the pins corresponding to SCL and SDA to open-drain output mode and enabling internal or external pull-up resistors to match I. 2 The physical characteristics of the C bus, and secondly, the I 2 For C peripheral parameter configuration, the communication rate and clock duty cycle need to be set as needed, while the host's own address is usually configured to 0x00; in terms of data read and write processes, the program can use I... 2 The C interface directly reads the raw digital signals from the meteorological sensor. To improve bus stability when multiple nodes are connected, the software design incorporates I... 2 The timing of C was strictly controlled.

[0048] The temperature and humidity data acquisition logic mainly involves the microcontroller sending a start signal (Start) and the sensor write address to the bus, followed by issuing a single high-precision measurement command. After waiting for the sensor to complete analog-to-digital conversion (typically tens of milliseconds), the read address is sent again to continuously read the temperature and humidity data bytes and their corresponding CRC-8 checksums. The program incorporates a CRC lookup algorithm; after verifying the data, it uses the sensor's datasheet formulas to calculate the temperature (°C) and relative humidity (%RH). In the OLED asynchronous refresh mechanism, considering that refreshing the full-screen pixel count is 128×64, requiring a long cycle and potentially blocking the main loop, the software employs a memory mapping and partial refresh mechanism. After the main program obtains new environmental parameters or real wind data, it only updates the corresponding area's character dot matrix in the microcontroller's memory array; then, using a timer flag, without blocking other high-speed serial port reception, the memory data is transmitted in batches via I / O. 2 C is written into the circular random access memory (GRAM) of the OLED to achieve a smooth display of the human-computer interaction interface.

[0049] The entire process of temperature and humidity acquisition and OLED display is divided into four stages: system initialization, triggering and pure digital quantity reading, verification and calculation, and display memory update and refresh. Figure 5 As shown, during the system initialization phase, the microcontroller's I / O is initialized first. 2 The peripheral clock and GPIO pins are then used to send initialization commands such as multiplexing rate, display offset, and contrast to the OLED and clear the screen. Simultaneously, an initialization command is sent to the AHT20, and its status word is read to check if calibration is needed. If calibration is required, a calibration command is issued. In the trigger and pure digital reading phase, the temperature and humidity acquisition task is triggered by the main loop or timer. The host sends a trigger measurement command of 0xAC and corresponding parameters via IIC, delays for more than 80ms to wait for the sensor to complete the digital conversion internally, and then directly reads the data containing 1 byte of status word, 2.5 bytes of humidity data, and 2 bytes of other parameters via IIC. The system reads 6 bytes of digital data, consisting of 0.5 bytes of temperature data and 1 byte of CRC checksum. During the verification and calculation phase, a CRC-8 checksum is performed on the first 5 bytes. If the checksum does not match the CRC code of the 6th byte, the abnormal data is discarded, the valid value from the previous cycle is retained, and the error is recorded. If they match, the concatenated 20-bit digital value is calculated into floating-point numbers for temperature and relative humidity according to the official formula. During the memory update and refresh phase, the calculated floating-point environment parameters are first formatted as a string, then converted into dot matrix data using a modulo algorithm and the microcontroller's internal local memory is updated. Finally, the data is processed via I... 2 C sends the page address and column address settings to the OLED in sequence, and writes batch data to the display memory to complete the physical screen refresh.

[0050] (III) Asynchronous reception of multi-channel serial port data and NMEA protocol parsing This portable meteorological observation system requires simultaneous access to a GPS module and a ten-axis attitude sensor, including an inertial measurement unit, an electronic compass, and a barometer. According to the overall system design, the GPS module is specifically used to acquire the ship's ground speed; while the ship's roll, pitch, and yaw angles, as well as the ship's heading provided by the electronic compass, and barometric pressure data, are all measured and output in real time by the ten-axis attitude sensor. These two types of sensors have high output frequencies and long data messages. Using traditional single-byte serial port interrupts would easily consume a large amount of microcontroller computing power, and could even cause data overflow and main program lag. Therefore, this section designs an efficient asynchronous reception and parsing strategy for multi-channel serial communication.

[0051] To maximize the CPU computing power of the microcontroller for subsequent complex attitude compensation and real wind inversion algorithms, this system employs a combined working mode of DMA direct memory access and serial port idle interrupt in the USART receiver's underlying architecture. For example... Figure 6As shown, during system initialization, the program configures the DMA receive channel for the corresponding USART peripheral and allocates two independent memory buffers. When the sensor continuously sends data, the data stream is automatically moved to the designated memory buffer under the control of the underlying hardware bus, without CPU intervention. When a complete data packet transmission ends and the bus experiences an idle state exceeding one byte, the hardware automatically triggers a serial port idle interrupt. In the interrupt service function, the main program only needs to calculate the length of the received data and set the reception completion flag. Subsequently, the complete packet is processed centrally in the main loop. This mechanism effectively eliminates frequent context switching during high-frequency reception, significantly improving the real-time performance and robustness of the system's data acquisition.

[0052] Other multi-channel serial port asynchronous data reception uses the NMEA-0183 protocol. This protocol uses ASCII serial communication and stipulates that messages must begin with a "$" symbol and end with a carriage return and line feed character. <cr> <lf>The message ends with an asterisk (*). The message consists of multiple data fields separated by commas (,"). To ensure reliable data transmission, the message tail includes an asterisk "*" followed by two hexadecimal checksums.

[0053] The main program polls the receive flag in the while(1) loop of the main loop. After detecting a complete data packet, the program first identifies the data source. For the GPS module, the program performs an XOR check after locating the NMEA protocol frame header. After the check passes, only the ground speed is extracted and the unit is converted, from knots to m / s. To avoid calculation errors caused by GPS heading drift when the ship is sailing at low speed, the system actively discards the GPS heading field here. For the ten-axis attitude sensor, after completing the integrity check of the data packet, the program accurately extracts the roll angle, pitch angle, air pressure, and high-precision heading measured by the internal electronic compass.

[0054] Example 2 This embodiment is an implementation of a shipborne environment upwind element measurement correction algorithm based on the software program constructed in Embodiment 1.

[0055] In shipborne marine meteorological observations, the data measured by the anemometers installed on the shipboard platform represent relative wind. This data not only includes the actual meteorological wind in nature but also incorporates induced winds caused by the ship's speed and heading, as well as high-frequency disturbances caused by the ship's rolling, pitching, and yaw movements in the waves. This section aims to obtain high-precision true wind parameters by establishing a multi-coordinate system transformation model and a multi-source sensor fusion algorithm, and then using software programming to sequentially implement attitude compensation, true wind inversion, and data filtering.

[0056] A method for measuring and correcting wind elements in a shipborne environment, operating within a microcontroller, includes the following steps.

[0057] Step 1: Coordinate system establishment and attitude compensation program design.

[0058] Define the ship's coordinate system and the geographic coordinate system to perform spatial vector transformation, construct a three-dimensional rotation matrix from the ship's coordinate system to the geographic coordinate system, perform strict spatial attitude compensation on the apparent wind vector, and obtain the apparent wind vector relative to the Earth's horizontal plane but superimposed with the ship's motion speed.

[0059] To achieve spatial vector transformation, the system defines two Cartesian coordinate systems: a ship coordinate system and a geographic coordinate system. In the STM32 microcontroller, directly performing floating-point trigonometric function calculations and matrix multiplications consumes a certain number of clock cycles. The program imports the math.h library header file, which triggers the compensation function each time complete wind speed, direction, and attitude data are received. Figure 7 This paper demonstrates the specific execution flow of the shipborne attitude compensation algorithm in the microcontroller (MCU). To balance the real-time performance and low power consumption requirements of portable systems, the algorithm module incorporates a pre-determination mechanism for data validity and a lookup table pre-calculation mechanism.

[0060] Since the output frequency of ultrasonic anemometers is typically lower than the polling frequency of the microcontroller's main loop, the program first checks the status of the ultrasonic wind data reception completion flag in the global structure before entering the compensation calculation. If no new frame of meteorological data is received, the program will directly exit the function, retaining the valid calculation value from the previous cycle. This error-proofing design effectively avoids the MCU performing invalid floating-point matrix operations in each loop, significantly saving system computing power. When new data is detected, the program immediately clears the flag and latches the latest meteorological and attitude sensor data to ensure that the variables involved in the matrix operation are strictly aligned on the time scale. The relative wind direction output by the meteorological sensor is essentially the direction of the incoming wind, i.e., the polar coordinate angle of the wind blowing towards the sensor. However, when performing spatial matrix rotation, the actual velocity vector of the air particles needs to be used. Therefore, the program first reverses the relative wind vector by multiplying it by a negative sign, and then uses trigonometric functions to project it onto the front-left-lower rectangular coordinate system of the ship, decomposing it into orthogonal wind speed components along the X and Y axes. Since a two-dimensional ultrasonic anemometer is used, the vertical component is set to 0.

[0061] The program begins by extracting the roll, pitch, and yaw angles from the inertial measurement unit (IMU) and converting them to radians. To adapt to the coordinate system definition of the specific hardware, the program reverses the signs of parameters such as the pitch angle at this stage. Subsequently, it pre-calculates the sine and cosine values ​​of these three Euler angles and substitutes them into a formula to construct a three-dimensional rotation matrix from the ship's coordinate system to the geographic coordinate system. By performing a multiplication operation between the 3×3 rotation matrix and the three-dimensional wind speed column vector, the system calculates the orthogonal components of the apparent wind in the absolute geographic coordinate system after removing the effects of ship roll, pitch, and yaw. After obtaining the orthogonal wind speed components in the geographic coordinate system, the program uses the square root function to calculate the horizontal apparent wind speed after attitude compensation. When calculating the apparent wind direction, the `atan2()` function from the C language standard mathematical library is called. Since the function's return value range is (-π, π], the program specifically introduces quadrant judgment logic. When the returned radian value is less than 0, 2π is added to map it to the positive range, ultimately converting it into a standard meteorological wind direction angle of 0°~360°. The calculated physical quantity is then updated to the system memory and used as a high-precision input source for the next-level true wind inversion algorithm.

[0062] Step 2: Implementation of the real wind inversion algorithm based on speed and heading.

[0063] Based on the true heading of the electronic compass and the ground speed of the GPS, through rigorous physical vector synthesis and meteorological standard conversion, and in accordance with Galileo's law of relative motion, the program calculates the absolute velocity components of air particles relative to the Earth's stationary coordinate system through vector addition, thus completing the vector synthesis and inversion of the absolute true wind.

[0064] After compensation, we obtained the apparent wind vector relative to the Earth's horizontal plane but superimposed with the ship's speed. The true wind vector, as defined in meteorology, refers to the movement of air relative to a fixed Earth surface. The "induced wind" vector generated by the ship's motion is equal in magnitude and opposite in direction to the ship's speed vector. In this system, the ship's ground speed (boat_sog) is directly extracted from the GPS module, while the ship's true heading (boat_true_heading) is obtained from the true heading angle output by the electronic compass in the ten-axis sensor. This design avoids the problem of inaccurate heading analysis by GPS at low speeds. Based on vector operation rules, the wind speed is calculated using an algorithmic formula.

[0065] Algorithm research on wind.

[0066] Shipborne coordinate system rotation matrix attitude compensation: To accurately describe the ship's motion state on the sea surface and the spatial vector relationship between wind speed and direction, a unified spatial coordinate system must first be established. This system mainly involves two core coordinate systems: the geographic coordinate system and the ship's hull coordinate system.

[0067] The geographic coordinate system uses the northeast-east (NED) coordinate system as the reference. In this system, the origin O is defined as the ship's center of gravity, the X-axis points due north, the Y-axis points due east, and the Z-axis points vertically to the Earth's center. This coordinate system serves as an inertial reference system to describe the absolute speed and direction of the true wind.

[0068] The ship's coordinate system is fixed to the ship and moves with the ship's motion. The origin O is defined to coincide with the sensor's installation location or to the same origin through translation. The X-axis points along the ship's longitudinal axis towards the bow, the Y-axis points along the ship's transverse axis towards the starboard side, and the Z-axis is perpendicular to the deck, pointing downwards or upwards. The data directly measured by the ultrasonic anemometer is the relative airflow vector based on this coordinate system.

[0069] Attitude angles are defined as the swaying of a ship under the influence of waves, described by three Euler angles, which form the basis of attitude calculation. These angle data are collected by attitude sensors, such as gyroscopes and accelerometers. Using quaternion methods or direction cosine matrix algorithms, a rotation matrix connecting the ship's coordinate system and the geographic coordinate system can be constructed, providing a mathematical basis for subsequent wind speed vector projection.

[0070] The attitude sensor module used in this embodiment integrates a 32-bit microprocessor. It acquires data from the accelerometer, gyroscope, and magnetometer in real time and runs a complex Kalman filter algorithm internally to obtain smooth and stable attitude angles, including roll, pitch, and yaw. On a ship, due to the ship's rolling and pitching motion at sea, the data measured by the wind sensor may have errors, requiring attitude correction by the attitude sensor. The corresponding tilt angles can be obtained using the quaternion method: rotation around the X-axis yields the roll angle, rotation around the Y-axis yields the pitch angle, and rotation around the Z-axis yields the yaw angle.

[0071] The coefficient matrix for rotation around X is: .

[0072] The coefficient matrix for rotation around Y is: .

[0073] The coefficient matrix for rotation around Z is: .

[0074] In the absence of ship rolling, the target wind vector measured by the ship's true wind observation system should be consistent with the target wind vector when the system is not in spatial motion. However, the actual wind vector obtained differs because the ship's spatial motion causes a shift and rotation in its original coordinate system. Therefore, a three-dimensional attitude matrix must be introduced for correction. When multiplied by a vector, the rotation matrix only modifies the direction of the vector, not its magnitude. Therefore, to eliminate the influence of ship rolling from the obtained data, we can imagine rotating the actual wind force measurement data, i.e., the relative wind data, to a coordinate system without ship rolling using a rotation matrix. In other words, the true wind vector can be obtained by multiplying the rotation matrix by the relative wind vector.

[0075] For ease of calculation, let the relative wind vector in the geodetic coordinate system be *a*, and the relative wind vector in the ship's true wind observation system coordinate system be *a′*. Let the components of the true wind vector in the geodetic coordinate system be *ax*, *ay*, and *az*, and the components of the relative wind vector in the ship's true wind observation system coordinate system be *ax′*, *ay′*, and *az′*. The true wind vector *a* can then be calculated as: .

[0076] Because the ultrasonic anemometer used provides pre-processed relative wind speed and direction data, these two values ​​need to be converted into X and Y components. This means decomposing the measured wind into two horizontal directions: the positive X-axis (longitudinal axis) on the bow and the positive Y-axis (transverse axis) on the starboard side. Most two-dimensional anemometers cannot measure vertical wind speed, which is usually assumed to be 0. The formulas for calculating the components of each axis are shown in Figures 2.1 to 2.3. After processing, a new vector a′ is formed and entered into the formula.

[0077] , , , Vector a′ is: The rotation matrix R The corresponding calculation formula can be obtained from the previous section: Expanding the formula, we get: , .

[0078] However, since this system uses a two-dimensional ultrasonic anemometer, the vertical wind speed component az = 0 in its sensor coordinate system. Substituting the relative wind vector measured by the sensor into the rotation matrix, the final relative wind a in the horizontal plane can be calculated as: .

[0079] The horizontal wind speed vector 'a' after attitude compensation is the result of matrix rotation and projection transformation to an absolute horizontal geographic coordinate system. Essentially, it represents the horizontal relative wind component, eliminating the effects of ship roll, pitch, and heading angle. This method effectively eliminates measurement errors caused by platform tilt, ensuring the data is strictly defined within the horizontal plane. However, this is still not true wind; it includes the sailing wind generated by the ship's own motion, i.e., the superposition effect of ship speed in calm wind. To obtain true wind, the ship's sailing speed vector, transformed to the geographic coordinate system, needs to be subtracted from the attitude-compensated relative wind vector to remove sailing wind interference, ultimately yielding true wind data purely generated by atmospheric motion.

[0080] Figure 8 This paper demonstrates the execution flow of the system's true wind inversion algorithm based on speed and heading. After obtaining the apparent wind vector after attitude compensation, the program performs rigorous physical vector synthesis and meteorological standard conversion to ultimately calculate the absolute true wind. First, the program reads the eastward and northward orthogonal components of the apparent wind output from the previous compensation stage, along with the eastward and northward orthogonal components of the ship's entrainment velocity resolved from GPS, v_e and v_n. Based on Galileo's law of relative motion, the program uses vector addition to obtain the absolute velocity components of the air mass relative to the Earth's stationary coordinate system—that is, the eastward and northward components of the true wind—and uses the square root function to synthesize the true absolute wind speed.

[0081] In the true wind direction calculation stage, the program design incorporates several engineering optimization logics. When calling the inverse trigonometric function atan2(), the program deliberately swaps the parameter order of the east and north components. Since standard mathematical polar coordinates have the X-axis as 0° and increase counterclockwise, swapping the parameters allows the calculation results to be directly mapped to the coordinate system commonly used in navigation and meteorology, with true north as 0° and increasing clockwise. The angle calculated at this point represents the physical direction of wind movement. Finally, to strictly adhere to the international meteorological observation standard that "wind direction should be the direction from which the wind is blowing," the program adds 180° to the calculated angle for vector inversion. Considering that addition operations may cause the angle to exceed the standard 360° range, the program adds an out-of-bounds judgment logic to perform modulo correction on results greater than or equal to 360°. After the above complete process, the system finally outputs high-precision true wind data that completely eliminates interference from ship movement and directly conforms to meteorological broadcasting standards.

[0082] Step 3: Multi-sensor data synchronization and vector moving average filtering.

[0083] A timestamp alignment mechanism is introduced, and an orthogonal vector moving average filtering algorithm is designed to eliminate data jitter caused by sensor delay error and sea wave turbulence, avoid the sudden change trap of meteorological wind direction crossing zero between 0° and 360°, and use the smoothed orthogonal average value to re-perform polar coordinate transformation to output the final meteorological data.

[0084] This system integrates three key sensor types: a ten-axis attitude sensor, an ultrasonic anemometer, and a GPS module. The data update rates of these sensors differ significantly, and if variables from different time points are used during calculation, severe time lag errors will occur. To address this issue, the microcontroller software employs a synchronization strategy of high-frequency data latching and mid-frequency data triggering. The completion interrupt of the ultrasonic anemometer's reception serves as the primary trigger source for the attitude compensation and real wind inversion algorithms. When the main loop detects a new frame of meteorological data, the program immediately latches the nearest frame of attitude angle data (time difference < 10ms) and the latest GPS speed from the system's global structure. This mechanism achieves forced alignment of multi-source data in the time dimension within the microcontroller with minimal memory overhead. Due to the influence of sea waves and gusts, the instantaneously calculated true wind data will produce high-frequency spikes. Direct output will cause the display data to fluctuate violently, losing its observational significance. The traditional approach is to perform a moving arithmetic mean on the data sequence. However, wind direction, as a periodic polar coordinate variable, has abrupt changes at 0° and 360° in its domain. For example, when the true wind direction fluctuates slightly in due north, the true wind direction measured twice consecutively may be 359° and 1°. Directly calculating the arithmetic mean will result in 180°, which is completely wrong in meteorology and physics. To fundamentally eliminate the filtering distortion caused by zero-crossing abrupt changes, this system abandons the direct averaging of polar coordinate wind direction and instead adopts an orthogonal vector moving average filtering algorithm. The core idea of ​​this algorithm is to first perform orthogonal decomposition, then independent filtering, and finally polar coordinate synthesis. Since the system has already obtained the eastward component v_true_e and the northward component v_true_n of the true wind during the true wind inversion, the program directly uses these two orthogonal physical quantities as filtering objects. Two floating-point FIFO (First-In-First-Out) circular buffers of depth N are allocated in the microcontroller's RAM to store the eastward and northward true wind components calculated N times consecutively. The microcontroller's execution logic is as follows: after each calculation of a new orthogonal component, the oldest data in the circular buffer is overwritten and the tail pointer is updated; the two buffers are traversed, and the arithmetic mean of the eastward and northward components is calculated respectively. Since the orthogonal components are continuous real numbers in the Cartesian coordinate system, there is no angle abruptness problem, and the arithmetic mean can be directly calculated; using the smoothed orthogonal components, the square root function and the atan2() function are called again to resynthesize the final smoothed true wind speed and smoothed true wind direction for display.

[0085] Figure 9 This paper demonstrates the vector moving average filtering process designed by our system to address the problems of sea state noise and sudden changes in wind direction at zero crossings. Unlike traditional scalar averaging, this algorithm establishes a dual-channel circular buffer based on Cartesian coordinates within the microcontroller. The system independently stores the eastward and northward orthogonal components of the true wind in a queue of depth N for arithmetic averaging. Due to the rigorous mathematical continuity of Cartesian coordinate components, this method avoids the abrupt change traps at 0° and 360° from the underlying logic. Subsequently, the program uses the smoothed orthogonal average to perform a polar coordinate transformation again, outputting the final meteorological data. Experiments show that this algorithm occupies very little MCU memory, has high execution efficiency, effectively smooths high-frequency disturbances caused by ship rolling, significantly improves the readability and accuracy of data displayed on the OLED terminal, and completes the software system closed loop.

[0086] Examples 1 and 2 detail the overall software scheme and core algorithm implementation of the portable marine five-element meteorological observation system. A multi-task scheduling architecture based on a microcontroller was designed, and the underlying communication driver development was completed: the Modbus-RTU protocol was used to read wind elements, and I... 2 The C-drive bus enables asynchronous refresh of temperature and humidity data acquisition and OLED display memory. Simultaneously, DMA combined with a serial port idle interrupt mechanism allows for efficient and non-blocking parsing of high-frequency GPS and ten-axis attitude sensor data. For the dynamic shipboard environment, a wind element correction algorithm capable of running within the microcontroller is derived and implemented. By constructing a three-dimensional rotation matrix from the ship to the geographic coordinate system, rigorous spatial attitude compensation is performed on the apparent wind vector. Subsequently, combining the laws of relative motion, and relying on the electronic compass true heading and GPS ground speed, the vector synthesis and inversion of the absolute true wind are completed. To eliminate sensor delay errors and data jitter caused by sea turbulence, a timestamp alignment mechanism is introduced, and an orthogonal vector moving average filtering algorithm is designed to fundamentally solve the physical problem of sudden zero-crossing changes in meteorological wind direction between 0° and 360°. The software designed in this chapter has rigorous logic and strong anti-interference capabilities, laying a solid foundation for the field equipment integration and performance testing conducted at the marine experimental station in the next chapter.

[0087] The above embodiments are merely illustrative of the structural concept and features of the present invention, intended to enable those skilled in the art to understand the content of the present invention and implement it accordingly, and should not be construed as limiting the scope of protection of the present invention. All equivalent changes or modifications made based on the essence of the present invention should be covered within the scope of protection of the present invention.< / lf> < / cr>

Claims

1. A method for measuring and correcting wind elements in a shipborne environment while operating within a microcontroller, characterized in that, Includes the following steps: Step 1: Define the ship coordinate system and geographic coordinate system to perform spatial vector transformation, construct the three-dimensional rotation matrix from the ship to the geographic coordinate system, perform spatial attitude compensation on the apparent wind vector, and obtain the apparent wind vector relative to the Earth's horizontal plane but superimposed with the ship's motion speed. Introduce the math.h library into the microcontroller, and trigger the compensation function after receiving complete wind speed, wind direction and attitude data each time. Step 2: Based on the electronic compass true heading and GPS ground speed, through physical vector synthesis and meteorological standard conversion, and according to Galileo's law of relative motion, the program calculates the absolute velocity components of air particles relative to the Earth's stationary coordinate system through vector addition, thus completing the vector synthesis and inversion of the absolute true wind. Step 3: Introduce a timestamp alignment mechanism and design an orthogonal vector moving average filtering algorithm to eliminate data jitter caused by sensor delay errors and sea turbulence, avoid the abrupt change trap of meteorological wind direction crossing zero between 0° and 360°, and use the smoothed orthogonal average to re-perform polar coordinate transformation to output the final meteorological data, including: Step 3-1: A synchronization strategy of high-frequency data latching and medium-frequency data triggering is adopted. The interruption of the ultrasonic anemometer's reception is used as the main trigger source for the attitude compensation and real wind inversion algorithm. When the main loop detects a new frame of meteorological data, it immediately latches the attitude angle data and the latest GPS speed in the global structure of the system that are closest to the current time. With minimal memory overhead, the multi-source data is forcibly aligned in the time dimension within the microcontroller. Step 3-2: Employ the orthogonal vector moving average filtering algorithm, first performing orthogonal decomposition, then independent filtering, and finally polar coordinate synthesis to eliminate filtering distortion caused by abrupt zero-crossing changes, including: Step 3-21: Using the eastward and northward components of the true wind as filtering objects, open two floating-point FIFO ring buffers of depth N in the microcontroller RAM to store the eastward and northward true wind components calculated consecutively N times. Step 3-22: After each new orthogonal component is calculated, overwrite the oldest data in the circular buffer and update the tail pointer; traverse the two buffers and calculate the arithmetic mean of the eastward and northward components respectively; Step 3-23: Using the smoothed orthogonal components, call the square root function and the atan2() function again to resynthesize the final smoothed true wind speed and smoothed true wind direction for display.

2. The wind element measurement and correction method operating within a microcontroller in a shipborne environment according to claim 1, characterized in that, The compensation function is triggered before the following: The program determines the status of the ultrasonic wind data reception completion flag in the global structure. If no new frame of meteorological data is received, the program will exit the function directly and retain the valid solution value of the previous cycle. When new data is detected, the program immediately clears the flag and latches the latest meteorological and attitude sensor data to ensure that the variables involved in the matrix operation are aligned on the time scale. When performing spatial matrix rotation, the relative wind vector is reversed by multiplying it by a negative sign, and then projected onto the ship's front-left-lower rectangular coordinate system using trigonometric functions. It is then decomposed into orthogonal wind speed components along the X and Y axes. Since a two-dimensional ultrasonic anemometer is used, the vertical component is set to 0.

3. The wind element measurement and correction method operating within a microcontroller in a shipborne environment according to claim 2, characterized in that, The spatial attitude compensation includes the following steps: Step 1-1: Extract the roll angle (Roll), pitch angle (Pitch), and true heading angle (Yaw) output by the inertial measurement unit, convert them to radians, and perform engineering reversal adaptation on the signs of the roll angle (Roll), pitch angle (Pitch), and true heading angle (Yaw). Steps 1-2: Pre-calculate the sine and cosine values ​​of roll angle (Roll), pitch angle (Pitch), and true heading angle (Yaw), and substitute them into the formula to construct a three-dimensional rotation matrix from the ship's coordinate system to the geographic coordinate system. Steps 1-3: Perform the multiplication operation of the three-dimensional rotation matrix and the three-dimensional wind speed column vector to calculate the orthogonal components of the apparent wind in the absolute geographic coordinate system after removing the effects of ship roll, pitch and yaw. Use the square root function to obtain the horizontal apparent wind speed after attitude compensation. Steps 1-4: Quadrant judgment logic is introduced, and the atan2() function in the C language standard mathematical library is called to calculate the apparent wind direction. When the returned radian value is less than 0, 2π is added to map it to the positive value range, and finally it is converted into the standard meteorological wind direction angle of 0°~360°. Steps 1-5: The calculated physical quantities are then updated to the system memory and used as a high-precision input source for the next level of the real wind inversion algorithm.

4. The wind element measurement and correction method operating within a microcontroller in a shipborne environment according to claim 3, characterized in that, Step 2 includes: Step 2-1: Use the positioning module to directly extract the ship's ground speed, and use the true heading angle output by the electronic compass in the ten-axis sensor to determine the ship's true heading; Step 2-2: According to the vector operation rules, the data obtained by the two-dimensional wind vector is attitude corrected to eliminate the measurement error caused by the platform tilt, so that the data is defined in the horizontal plane. After obtaining the attitude-compensated apparent wind vector, the absolute true wind is calculated by physical vector synthesis and meteorological standard conversion.

5. The wind element measurement and correction method operating within a microcontroller in a shipborne environment according to claim 4, characterized in that, In step 2-2, the posture correction includes the following steps: Step a: Use the quaternion method to obtain the corresponding bank angles. Rotate around the X-axis to get the roll angle (Roll), around the Y-axis to get the pitch angle (Pitch), and around the Z-axis to get the yaw angle (Yaw). The coefficient matrix of roll angle is , The coefficient matrix of pitch is , The coefficient matrix of the heading angle Yaw is , Obtain the rotation matrix ; Step b: Let the relative wind vector in the geodetic coordinate system be a, and the relative wind vector in the ship's true wind observation system coordinate system be a′. The components of the true wind vector in the geodetic coordinate system are ax, ay, and az, respectively, and the components of the relative wind vector in the ship's true wind observation system coordinate system are ax′, ay′, and az′, respectively. The true wind vector a can be calculated as follows: ; Step c: Decompose the relative wind speed and direction given by the ultrasonic anemometer into two horizontal directions: the positive X-axis of the bow ship and the positive Y-axis of the starboard ship, and obtain the component calculation formulas for each axis: , , The new vector a′ is formed by calculating the components of each axis: ; Step d: Based on the rotation matrix R Expand the vector a′ into the formula. , ; Step e: Substituting the relative wind vector measured by the sensor into the rotation matrix, the final relative wind a in the horizontal plane can be calculated as follows: 。 6. The wind element measurement and correction method operating within a microcontroller in a shipborne environment according to claim 5, characterized in that, In step 2-2, after obtaining the attitude-compensated apparent wind vector, the absolute true wind is calculated through physical vector synthesis and meteorological standard conversion, including: Step f: Read the eastward and northward orthogonal components of the apparent wind output from the previous compensation stage and the eastward and northward orthogonal components of the ship's entanglement speed resolved by GPS; Step g: Based on Galileo's law of relative motion, the absolute velocity components of the air particle relative to the Earth's stationary coordinate system are obtained through vector addition, and the true absolute wind speed is synthesized using the square root function; Step h: Introduce multiple engineering optimization logics. When calling the inverse trigonometric function atan2(), swap the parameter passing order of the eastward component and the northward component. After swapping the parameters, use the characteristics of trigonometric functions to directly map the calculation results to a coordinate system commonly used in navigation and meteorology, with true north as 0° and increasing clockwise, to calculate the angle of the physical direction of wind movement. Step i: An extra-boundary judgment logic was added, the calculated angle was increased by 180° and the vector was reversed, the result greater than or equal to 360° was modulo-corrected, and the high-precision true wind data that completely eliminated the interference of ship motion and directly conformed to the meteorological broadcasting specifications was output.

Citation Information

Patent Citations

  • Shipborne platform wind speed measurement correction method

    CN116223842A

  • Low-altitude aircraft autonomous operation obstacle avoidance method and system

    CN121704494A