Intelligent rowing machine control method

The intelligent rowing machine control method based on the FreeRTOS multi-tasking architecture and STM32F407VET6 chip solves the problems of low accuracy and poor anti-interference ability in data acquisition and control of existing rowing machines, and realizes efficient and fast data transmission and resistance adjustment, thereby improving user experience and system scalability.

CN121008514BActive Publication Date: 2026-01-27SHANGHAI YINSHENG TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202511500655.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-21
Publication Date
2026-01-27
Estimated Expiration
2045-10-21

AI Technical Summary

Technical Problem

Existing rowing machines suffer from problems such as low accuracy in data acquisition and control, poor anti-interference ability, low transmission efficiency, large response delay, inability to achieve differentiated control, and poor scalability.

Method used

A smart rowing machine control method based on FreeRTOS multi-task architecture is adopted. Through parallel data acquisition, adaptive adjustment of transmission frequency, PWM output control and MQTT protocol, combined with the ADC1 controller and TIM4 timer of STM32F407VET6 chip, high-precision, low-latency data acquisition and resistance adjustment are achieved.

Benefits of technology

It achieves high-precision, low-latency data acquisition and control, has strong anti-interference capabilities, high transmission efficiency, rapid response, supports hardware and software expansion, and ensures user experience and system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121008514B_ABST
    Figure CN121008514B_ABST
Patent Text Reader

Abstract

The application discloses a kind of intelligent rowing machine control methods, including steps: S1: networking and communication setting and networking;S2: based on FreeRTOS multitask architecture setting start task, data acquisition and upload task and resistance control task;S3: system initialization;S4: realize the parallel data acquisition of multiple simulation channels and carry out control end processing upload to cloud server;S5: update mobile terminal or the data of meta-universe software server;S6: issue resistance level adjustment instruction;S7: receive resistance level adjustment instruction and according to resistance level adjustment the resistance of corresponding motor;S8: send feedback data;S9: update resistance state data;S10: carry out recovery to power generation energy.The application discloses a kind of intelligent rowing machine control methods, can realize zero CPU occupied parallel data acquisition, can realize adaptive adjustment transmission frequency, high-precision, low-delay cloud instruction reception and PWM output control, good expansibility.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of fitness device control technology, and particularly relates to a control method for an intelligent rowing machine. Background Technology

[0002] Existing rowing machines typically monitor only a single parameter, such as rotation speed or power, lacking systematic monitoring. Furthermore, their sequential data acquisition leads to asynchronous data timing, affecting control accuracy. They are usually limited to 8-10 bits of precision, resulting in limited resolution. Additionally, existing rowing machines generally use raw ADC values ​​directly for data acquisition, making them susceptible to electromagnetic interference and unable to intelligently identify changes in the equipment's operating status. They also use fixed-frequency transmission, resulting in a large amount of redundant data consuming bandwidth and low transmission efficiency.

[0003] Furthermore, existing rowing machines mostly use a single-task polling method, resulting in resistance adjustment response delays typically on the order of seconds, leading to a poor user experience. Additionally, existing systems usually only allow for overall resistance adjustment, failing to achieve differentiated control. The control system lacks comprehensive safety protection, making it prone to overload damage. Hardware and software scalability is poor, hindering the adaptation to functional upgrades. Summary of the Invention

[0004] To address the problems in the existing technology, this invention aims to provide an intelligent rowing machine control method that can achieve parallel data acquisition with zero CPU usage, high data acquisition accuracy, strong anti-interference capability, adaptive adjustment of transmission frequency, high-precision, low-latency cloud command reception and PWM output control, and good scalability.

[0005] To achieve the above objectives, the present invention provides a smart rowing machine control method, comprising the following steps:

[0006] S1: Configure the rowing machine's control unit for network and communication settings, and connect to the network;

[0007] S2: The control terminal is set up with a startup task, a data acquisition and upload task and a resistance control task based on the FreeRTOS multi-task architecture;

[0008] S3: The control terminal executes the startup task to initialize the system;

[0009] S4: The control terminal of the rowing machine starts the data acquisition and upload task, performs parallel data acquisition of multiple analog channels on the target of the rowing machine to obtain the acquired data, processes the data on the control terminal through a preset algorithm, and uploads the data processed by the control terminal to the cloud server.

[0010] S5: The cloud server updates the data of a mobile terminal or a metaverse software server based on the processed data;

[0011] S6: The mobile terminal or the metaverse software server sends a resistance level adjustment command to the cloud server via the MQTT protocol. The resistance level adjustment command includes resistance levels of 0 to 100 for at least two motors.

[0012] S7: The control terminal of the rowing machine initiates a resistance control task, receives the corresponding resistance level adjustment command from the cloud server, and adjusts the resistance of the motor according to the resistance level;

[0013] S8: Send feedback data to the cloud server through the data collection and upload task;

[0014] S9: The cloud server updates the resistance status data of the mobile terminal based on the feedback data;

[0015] S10: The rowing machine recovers the generated energy from the motor.

[0016] As one implementation, step S1 further includes the step of:

[0017] S101: When the control terminal is first started, it downloads and saves WiFi credentials via Bluetooth BluFi pairing.

[0018] S102: When connecting to the network, automatically connect to the network using the WiFi credentials, and prioritize WiFi mode for network connection. If the number of failed connections reaches a first threshold, automatically switch to 4G mode.

[0019] S103: Configure MQTT session.

[0020] As one implementation, step S4 further includes the following steps:

[0021] S41: The ADC1 controller based on the STM32F407VET6 chip uses the DMA2_Stream4 dedicated channel to acquire data from the target under test in parallel through multiple analog channels at preset time intervals; the target under test includes at least two motors of the rowing machine and a battery; the acquired data includes the generator voltage of the motor, the generator current of the motor, and the battery voltage of the battery;

[0022] S42: Perform multiple sampling average filtering on the collected data;

[0023] S43: Convert the generated voltage and the battery voltage after multiple sampling average filtering into actual voltage values;

[0024] S44: The actual voltage value and the generated current after the multiple sampling average filtering process are filtered in real time using the IIR low-pass filtering algorithm to obtain filtered data;

[0025] S45: Obtain the battery's charge percentage data based on the battery voltage in the filtered data;

[0026] S46: Monitor the operating status of the motor based on the generated voltage in the filtered data, and obtain motion status data based on the operating status;

[0027] S47: Obtain the device identification information, current PWM control value, filtered data, battery percentage data, and motion status data of the intelligent rowing machine, and encapsulate them in JSON format to obtain encapsulated data;

[0028] S48: Automatically adjust the data upload frequency based on the magnitude of changes in the filtered data, abnormal changes in battery power, and system mode switching;

[0029] S49: Upload the encapsulated data to the cloud server via the MQTT protocol according to the current data upload frequency.

[0030] As one implementation, step S45 further includes the step of:

[0031] S451: Use a linear mapping formula to convert the current battery voltage into a 0%-100% battery percentage data;

[0032] S452: When the calculated result of the battery percentage data exceeds 100%, it is forcibly set to 100%; when the calculated result of the battery percentage data is less than 0%, it is forcibly set to 0%.

[0033] S453: Determine whether the rate of change of the current battery percentage data is greater than or equal to a second threshold; if it is greater than or equal to the second threshold, automatically discard the current battery percentage data and keep the previous battery percentage data as the current battery percentage data; if it is less than the second threshold, determine that the current battery percentage data is valid data, update the corresponding system variables and output the corresponding debugging information through the serial port.

[0034] As one implementation, step S46 further includes the step of:

[0035] S461: When the generated voltage is greater than or equal to 1V and the motor is in a stopped state, the motor is determined to start; when the generated voltage is less than 1V and the motor is in a running state, the motor is determined to stop.

[0036] S462: When it is determined that the motor has started, update the motor status to running and automatically count as the number of motion cycles. The running status is when the user starts moving.

[0037] S463: When it is determined that the motor has stopped, update the motor status to stopped;

[0038] The motion state data includes the number of motion cycles.

[0039] As one implementation method, in step S48,

[0040] By monitoring the battery charge change rate in real time, when the charge change rate is detected to be >1% / second, the data upload frequency is set to upload once every 0.1s;

[0041] The system mode switching includes the operating state being that the user has started moving and the PWM control value changing; when the operating state is that the user has started moving and the PWM control value changes, the data upload frequency is set to upload once every 0.1 seconds;

[0042] The step of automatically adjusting the data upload frequency based on the change amplitude of the filtered data further includes the following steps:

[0043] S481: Calculate the absolute difference between the current generation voltage and the previous generation voltage in the filtered data;

[0044] S482: Compare the absolute difference with a third threshold; when the absolute difference is greater than or equal to the third threshold, determine that the generated voltage is in a period of drastic signal change; when the absolute difference is less than the third threshold, determine that the generated voltage is in a period of stable signal.

[0045] S483: Automatically adjust the data upload frequency according to the type of signal change period during which the current generated voltage is located; when the signal is changing drastically, set the data upload frequency to upload once every 0.1s; when the signal is stable, set the data upload frequency to upload once every 30s.

[0046] As one implementation, in step S7, when the control terminal receives the corresponding resistance level adjustment command from the cloud server, the control terminal uses USART5 interrupt-driven reception and continuously listens to the USART5 receive buffer; and uses the vTaskDelay(pdMS_TO_TICKS(10)) function; the control terminal parses the resistance level adjustment command to support multiple formats;

[0047] The control terminal uses four channels of the TIM4 timer for PWM output control, forming four PWM control channels. During system initialization, all PWM control channels are fully initialized. The initial state is set to dual-motor mode. In dual-motor mode, the processing logic of two PWM control channels is not commented out, while the processing logic of the other two PWM control channels is commented out. The code structure of all four PWM control channels is complete. After parsing the resistance level adjustment command to support multiple formats, the following steps are also included:

[0048] The current motor mode is maintained or adjusted according to the number of PWM control channels in the resistance level adjustment command; when the number of PWM control channels is 2, the dual-motor mode is maintained; when the number of PWM control channels is 4, the comment masking of the processing logic of the two PWM control channels is removed, and the mode is switched to four-motor mode.

[0049] In step S7, the tasksENTER_CRITICAL() and taskEXIT_CRITICAL() functions are used to protect the USART5 serial port data reception.

[0050] As one implementation, step S7 further includes the following steps:

[0051] S71: The control terminal receives the corresponding resistance level adjustment command from the cloud server;

[0052] S72: Determine whether the resistance level is greater than 100. If it is, set the value of the resistance level to 100.

[0053] S73: Map the aforementioned resistance level to a duty cycle of 0%-30%;

[0054] S74: Calculate the PWM comparison value based on the duty cycle;

[0055] S75: Generate a resistance control signal based on the PWM comparison value and adjust the resistance of the motor accordingly using the resistance control signal;

[0056] S76: Update the PWM control value of the global variable to the value of the PWM comparison value;

[0057] In step S75, the resistance control signal is formed by directly operating the comparison register of the TIM4 timer using the __HAL_TIM_SET_COMPARE() macro based on the PWM comparison value.

[0058] As one implementation, the resistance state data is obtained based on the PWM control value in the feedback data, and the step S9 is followed by the following step:

[0059] S11: The cloud server sends the resistance status data to the mobile terminal or the metaverse software server.

[0060] S12: The user interface of the mobile terminal or the metaverse software corresponding to the metaverse software server displays the resistance status data.

[0061] In one implementation, in step S10, the motor is connected to the battery through a charging circuit. The charging circuit uses a capacitor as a temporary energy storage device and recharges the battery to recover the generated energy of the motor.

[0062] Because the present invention adopts the above technical solution, it has the following beneficial effects:

[0063] Downloading and saving WiFi credentials via Bluetooth BluFi pairing allows for automatic reconnection upon next network connection, supporting automatic switching between WiFi and 4G modes to ensure network effectiveness. The control unit, based on the FreeRTOS multi-tasking architecture, sets up startup, data acquisition and upload, and resistance control tasks, achieving high-precision, low-latency data acquisition, cloud command reception, and PWM output control. Priority scheduling ensures real-time performance. The MQTT protocol, lightweight and with low bandwidth consumption, efficiently enables command issuance, status reporting, and real-time motion data transmission between the device and the cloud, ensuring rapid interaction and stable, reliable data transmission. The MQTT protocol facilitates virtual-real synchronized data interaction between the rowing machine's control unit and the Metaverse software. The ADC1 controller, based on the STM32F407VET6 chip, uses the DMA2_Stream4 dedicated channel to achieve zero-CPU-occupy parallel data acquisition from multiple analog channels of the detected target on the intelligent rowing machine. First, multiple sampling average filtering is performed, followed by IIR low-pass filtering. Multiple sampling average filtering quickly removes high-frequency random noise and sampling jitter from the signal, improving signal stability and signal-to-noise ratio. Based on this, IIR low-pass filtering further filters out residual high-frequency components as needed, while retaining the signal's true low-frequency dynamic information, making the output smoother and more accurate. This two-stage processing also facilitates optimization of the filtering effects of the two stages separately during actual debugging. In the filtering of the battery percentage value, a built-in intelligent filtering algorithm is used. When an abnormal change in battery level exceeding 1% / s is detected, the previous valid value is maintained, avoiding incorrect battery level display due to ADC noise, voltage transients, or calculation errors. An intelligent transmission strategy is adopted, with critical changes immediately triggering a fast transmission mode. When any motor voltage change is ≥0.3V, the system immediately switches from the standard upload interval (30 seconds) to fast transmission mode (100ms), using ADC1's 12-bit precision sampling to detect voltage fluctuations, ensuring millisecond-level response to changes in operating status. Critical changes that trigger fast transmission mode immediately include sudden changes in motor voltage, abnormal changes in battery level, and system operating mode switching. The STM32F407VET6 main control chip serves as an edge computing node, enabling local fusion processing of multi-sensor data. Local preprocessing reduces the computational burden on the cloud server. The control terminal uses USART5 interrupt-driven reception, achieving zero-blocking data detection by polling the flag bit, avoiding the latency caused by traditional blocking serial port reading. Combined with the vTaskDelay(pdMS_TO_TICKS(10)) function, it ensures that cloud commands can be detected and processed within 10ms. The control terminal supports parsing multiple formats for the resistance level adjustment command, improving system compatibility.The control terminal uses four channels of the TIM4 timer for PWM output control, forming four PWM control channels. During system initialization, all PWM control channels are fully initialized, ensuring the hardware has the capability to expand from two motors to four motors without any hardware modification or reconfiguration. The `taskENTER_CRITICAL()` and `taskEXIT_CRITICAL()` functions protect the USART5 serial port data reception, avoiding data contention in a multi-tasking environment, ensuring the integrity of cloud-based command data, and minimizing critical section time to reduce system response latency. Based on the PWM comparison value, the `__HAL_TIM_SET_COMPARE()` macro directly manipulates the TIM4 timer's comparison register. This low-level hardware operation avoids the overhead of HAL library function calls, achieving microsecond-level latency from PWM value calculation to hardware output. Combined with a 2kHz PWM frequency setting, this ensures a rapid response from the resistance control system. Attached Figure Description

[0064] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0065] Figure 1 This is a flowchart of the intelligent rowing machine control method according to an embodiment of this application. Detailed Implementation

[0066] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0067] Please see Figure 1 An embodiment of the present invention provides a control method for an intelligent rowing machine, comprising the following steps:

[0068] S1: Configure the rowing machine's control unit for network and communication settings, and connect to the network;

[0069] Step S1 further includes the following steps:

[0070] S101: When the control terminal is first started, it downloads and saves WiFi credentials via Bluetooth BluFi pairing.

[0071] S102: When connecting to the network, automatically connect to the network using the WiFi credentials, and prioritize WiFi mode for network connection. If the number of failed connections reaches a first threshold, automatically switch to 4G mode.

[0072] S103: Configure MQTT session.

[0073] Download and save WiFi credentials via Bluetooth BluFi pairing, enabling automatic connection the next time you connect to the internet. It supports automatic switching between WiFi and 4G modes to ensure network connectivity.

[0074] In this embodiment, when the rowing machine is powered on for the first time, it enters BLE broadcast mode, establishes a connection with the cloud server on the mobile device, enters the device password, and downloads WiFi credentials to the rowing machine control terminal via BLE. The control terminal saves the WiFi credentials, attempts to connect to the network in WiFi mode, and sends back the connection result. If the WiFi connection fails, it reconnects. If the number of reconnections exceeds 3 and the timeout period for each reconnection exceeds 5 seconds, it switches to 4G mode for network connection.

[0075] MQTT session configuration includes client configuration, message publishing configuration, and message subscription configuration.

[0076] Client configuration includes:

[0077] 1. Client ID generation: Generated using the unique hardware ID of the STM32F4 microcontroller.

[0078] 2. MQTT protocol version: 4

[0079] 3. Session Management: Enable session clearing mode.

[0080] 4. Connection duration: 7200 seconds.

[0081] Message publishing configuration includes:

[0082] 1. Default Quality of Service (QoS) level: 0; Delivery will be sent at most once, and delivery is not guaranteed.

[0083] 2. Message duplication flag: Off, no duplicate sending will occur;

[0084] 3. Message retention flag: Off, messages are not retained;

[0085] 4. Topic publishing: Utilizes macro definitions, allowing for easy modification at any time;

[0086] Message subscription configuration:

[0087] 1. Subscribe to a topic: Specify it via the RECV_TOPIC macro definition;

[0088] 2. Subscription service quality level: QoS 2, delivered only once, with the highest reliability;

[0089] 3. Message ID: Fixed at 10.

[0090] S2: The control terminal is set up with a startup task, a data acquisition and upload task and a resistance control task based on the FreeRTOS multi-task architecture;

[0091] The control terminal is based on the FreeRTOS multi-task architecture, which sets up startup tasks, data acquisition and upload tasks, and resistance control tasks. It achieves high-precision, low-latency data acquisition, cloud command reception, and PWM output control, and can use priority scheduling to ensure real-time requirements.

[0092] In this embodiment, the startup task serves as the system initialization task, responsible for creating other functional tasks and synchronization mechanisms. The stack size is 128 bytes.

[0093] The startup task is used for system initialization; the startup task includes creating binary semaphores and initializing system parameters.

[0094] The control terminal uses four channels of the TIM4 timer to perform PWM output control, forming four PWM control channels. During system initialization, all PWM control channels are fully initialized, including a unified configuration of 4200 precision and 2kHz frequency, and the initial comparison value is set to 495. This ensures that the hardware has the complete capability to expand from two motors to four motors without any hardware modification or reconfiguration.

[0095] At the software level, a complete set of four-channel data processing variables pwmvalue1~pwmvalue4 is pre-defined, and complete four-channel MQTT / JSON parsing logic is implemented. The initial state is set to dual-motor mode. In this mode, the processing logic of two of the PWM control channels is not commented out, while the processing logic of the other two PWM control channels is commented out. The code structure of all four PWM control channels is complete, providing a plug-and-play software foundation for future expansion.

[0096] The system is designed with a backward-compatible communication protocol mechanism, supporting both independent channel control of PWM1, PWM2, PWM3, and PWM4, and a unified control mode where a single PWM command is automatically mapped to all channels. This design ensures that the original dual-motor control logic remains fully effective when expanded to four motors, achieving seamless compatibility at the protocol level. Furthermore, the JSON data reporting structure reserves voltage fields for all four motors; activation is all that's needed to complete the expansion.

[0097] S3: The control terminal executes the startup task to initialize the system;

[0098] In addition, memory management has been optimized:

[0099] 1. Static memory allocation strategy:

[0100] Use a static array buf_temp_static[TRAN_SIZE] instead of dynamic memory allocation;

[0101] The static JSON buffer json_print_buffer

[512] avoids memory fragmentation;

[0102] Custom cJSON memory hook function, integrated with FreeRTOS memory management;

[0103] 2. Memory monitoring mechanism:

[0104] The check_memory() function monitors heap memory usage in real time.

[0105] The test_memory_allocation() function verifies memory allocation capabilities;

[0106] Memory address validity checks are performed to prevent unauthorized access.

[0107] 3. Error handling and monitoring:

[0108] System hook functions:

[0109] vApplicationStackOverflowHook(): Stack overflow detection and handling;

[0110] vApplicationMallocFailedHook(): Handling memory allocation failures.

[0111] S4: The control terminal of the rowing machine starts the data acquisition and upload task, performs parallel data acquisition of multiple analog channels on the target of the rowing machine to obtain the acquired data, processes the data on the control terminal through a preset algorithm, and uploads the data processed by the control terminal to the cloud server.

[0112] Step S4 further includes the following steps:

[0113] S41: The ADC1 controller based on the STM32F407VET6 chip uses the DMA2_Stream4 dedicated channel to acquire data from the target under test in parallel through multiple analog channels at preset time intervals; the target under test includes at least two motors of the rowing machine and a battery; the acquired data includes the generator voltage of the motor, the generator current of the motor, and the battery voltage of the battery;

[0114] The preset time interval is 10ms; the simulation channel includes four power generation voltage acquisition channels, four power generation current acquisition channels, one battery voltage acquisition channel and one reserved expansion channel; all the simulation channels are synchronously acquired under a 21MHz ADC clock and are equipped with a 500-data-point circular buffer.

[0115] In this embodiment, the detection targets include the four motors of the rowing machine. The collected data includes the generating voltage of the four motors, the generating current of the four motors, and the battery voltage of the battery.

[0116] The system first initializes the DMA acquisition mode of the 9 ADC channels using the `adc_nch_dma_init()` function. The PB0 pin (ADCHANNEL8) is dedicated to battery voltage detection, while the other pins detect generator voltage and current. The ADCs operate in 12-bit resolution mode, using a sampling time of 480 ADC clock cycles to ensure sampling accuracy. The DMA controller is configured in an automatic transfer mode with zero CPU usage, enabling continuous sampling without affecting system real-time performance.

[0117] S42: Perform multiple sampling average filtering on the collected data;

[0118] In step S42: the average value of every 10 samples of each analog channel in the data point circular buffer is calculated.

[0119] In the `adc_get_ch_nums_value()` function, the system performs 10 repeated samples for each ADC channel and then obtains a stable sampling result through mathematical averaging. Specifically, it sums the 10 sample values ​​for each channel in the buffer and then divides by the number of samples to obtain the average value `adcx`. This method effectively filters out high-frequency noise and random interference.

[0120] S43: Convert the generated voltage and the battery voltage after multiple sampling average filtering into actual voltage values;

[0121] The average values ​​of the generator voltage and battery voltage samples are converted into the actual generator voltage and the divided voltage of the battery voltage using the formula temp[j]=(float)adcx×(3.3f / 4096). Since the ADC has a 12-bit resolution, 4096 levels, and a reference voltage of 3.3V, this conversion accurately maps the digital value to the analog voltage range of 0-3.3V, providing standardized input data for subsequent filtering processing.

[0122] In this context, `adcx` represents the 12-bit raw digital value acquired by the ADC1 module of the STM32F407VET6 main control chip. This digital value represents the discrete value of the quantized analog voltage signal. `3.3f` is the ADC reference voltage of the STM32F407VET6 system, in volts (V). According to the hardware architecture specification, the system uses 3.3V as the full-scale reference voltage for the ADC. When the analog input voltage is 3.3V, the ADC will output a maximum digital value of 4095; when the input is 0V, the ADC outputs a digital value of 0. The 4096 in the formula represents the total number of quantization levels of the 12-bit ADC, calculated as 2^12 = 4096. It indicates the smallest voltage difference that the ADC can distinguish. The ADC divides the continuous voltage range from 0V to 3.3V into 4096 discrete digital levels. `(float)adcx` forces the integer ADC digital value to a floating-point type, ensuring sufficient precision in subsequent multiplication operations and avoiding truncation errors in integer arithmetic.

[0123] adcx (3.3f / 4096) is the core linear scaling operation, multiplying the ADC digital value by the quantization precision to obtain the corresponding actual voltage value. The operation logic is as follows:

[0124] Actual voltage = digital quantity × voltage corresponding to a unit digital quantity;

[0125] tempj = adcx × 0.000805664V;

[0126] Conversion example:

[0127] Assume the digital quantity acquired by the ADC is adcx = 2048:

[0128] tempj=2048×(3.3÷4096)=2048×0.000805664=1.65V;

[0129] This result shows that when the ADC output is 2048, the corresponding actual analog input voltage is 1.65V, which is exactly half of the 3.3V reference voltage, consistent with the linear conversion characteristics of a 12-bit ADC.

[0130] This conversion method ensures that the STM32F407VET6 system can accurately convert discrete digital quantities into continuous analog voltage values, providing a reliable data foundation for subsequent monitoring of key parameters such as motor voltage and battery voltage.

[0131] The battery voltage needs to be amplified and calculated to obtain the actual voltage: Since the hardware design uses a 1:4 voltage divider circuit to protect the ADC input, the collected voltage value needs to be restored to the real battery voltage by using battery_level=temp8 / 0.25. The voltage divider coefficient of 0.25 ensures that the battery voltage is within the measurable range of the ADC after voltage division.

[0132] S44: The actual voltage value and the generated current after the multiple sampling average filtering process are filtered in real time using the IIR low-pass filtering algorithm to obtain the filtered data;

[0133] In this embodiment, the formula for the IIR low-pass filtering algorithm is: filtered_value = old_value × 0.8 + new_value × 0.2. An adjustable filtering coefficient of 0.95 is used for the battery voltage to further improve stability.

[0134] The IIR low-pass filtering algorithm performs secondary filtering on the data after multiple sampling and averaging, rather than filtering the direct output of the sensor. This hierarchical filtering architecture ensures high data quality and real-time system performance.

[0135] First, multiple sampling average filtering is performed, followed by IIR low-pass filtering. Multiple sampling average filtering can quickly remove high-frequency random noise and sampling jitter in the signal, improving signal stability and signal-to-noise ratio. On this basis, IIR low-pass filtering further filters out residual high-frequency components as needed, while retaining the true low-frequency dynamic information of the signal, making the output smoother and more accurate. Moreover, this two-stage processing makes it easier to optimize the filtering effects of the two stages separately in actual debugging.

[0136] S45: Obtain the battery's charge percentage data based on the battery voltage in the filtered data;

[0137] Step S45 further includes the following steps:

[0138] S451: Use a linear mapping formula to convert the current battery voltage into a 0%-100% battery percentage data;

[0139] S452: When the calculated result of the battery percentage data exceeds 100%, it is forcibly set to 100%; when the calculated result of the battery percentage data is less than 0%, it is forcibly set to 0%.

[0140] S453: Determine whether the rate of change of the current battery percentage data is greater than or equal to a second threshold; if it is greater than or equal to the second threshold, automatically discard the current battery percentage data and keep the previous battery percentage data as the current battery percentage data; if it is less than the second threshold, determine that the current battery percentage data is valid data, update the corresponding system variables and output the corresponding debugging information through the serial port.

[0141] In this embodiment, the second threshold is 1% / s.

[0142] A mathematical linear interpolation method is used to map the battery voltage range of 10.8V-12.5V to the 0%-100% power percentage. The mapping formula is int level=(int)(((battery_level-10.8) / (12.5-10.8))*100+ 0.5), which ensures the accuracy of power display.

[0143] 10.8V is the minimum operating voltage. When the battery voltage drops to this value, the system recognizes the charge as 0% and the battery needs to be charged immediately to avoid damage from over-discharge.

[0144] 12.5V is the full charge voltage, and the system uses this as the reference for 100% charge.

[0145] battery_level represents the current battery voltage, a real-time battery voltage value (in V) acquired by the ADC, ranging from 10.8V to 12.5V. This value comes from the battery voltage detection of channel PB0, and is calculated by converting it using tempj=(float)adcx×(3.3f / 4096) and then amplifying it.

[0146] (battery_level-10.8) is used to calculate the offset of the current voltage relative to the minimum operating voltage. For example, when battery_level=11.65V, the offset is 11.65-10.8=0.85V, indicating that the current voltage is 0.85V higher than the minimum voltage.

[0147] The formula ((battery_level-10.8) / (12.5-10.8)) is used to calculate the relative position of the current voltage within the operating range. The result is a decimal between 0 and 1, representing the percentage of charge. For example, 0.85V ÷ 1.7V = 0.5, which means the charge is 50%.

[0148] The (int) method is used to force a floating-point number result to an integer, resulting in the final integer value of the battery percentage.

[0149] Practical application example:

[0150] Assuming the current detected battery_level is 11.65V:

[0151] Voltage deviation: 11.65 - 10.8 = 0.85V;

[0152] Proportion calculation: 0.85 ÷ 1.7 = 0.5;

[0153] Percentage conversion: 0.5 × 100 = 50;

[0154] Rounding: 50 + 0.5 = 50.5;

[0155] Integerization: (int)50.5 = 50;

[0156] The final displayed battery level is 50%, accurately reflecting the actual battery status.

[0157] Next, boundary value processing is performed.

[0158] The software limits the battery percentage to ensure it remains within a reasonable range of 0%-100%. When the calculated result exceeds 100%, it is forcibly set to 100%, and when it is below 0%, it is forcibly set to 0%. This protection mechanism prevents invalid battery display caused by sensor malfunctions or voltage fluctuations.

[0159] Then, the intelligent filtering algorithm for the battery is implemented:

[0160] The `battery_levelthresholdfilter()` function implements intelligent filtering based on the rate of change, monitors the rate of change of battery level, and determines that when the rate of change exceeds 1% / second, it is an interference signal and retains the previous valid value, ensuring a smooth transition of battery level display, avoiding battery level jumps caused by instantaneous interference, and improving the stability of user experience.

[0161] The system obtains the current timestamp through HAL_GetTick(), calculates the time interval between the current timestamp and the last sampling, and then calculates the rate of change of battery power in percentage per second according to the formula change_rate=fabsf(new_value-last_battery_level) / time_diff_sec.

[0162] Wherein, new_value represents the current battery level, which is the latest battery percentage value calculated in the current sampling period, in %. This value is converted from the real-time battery voltage through the linear mapping formula int level=(int)(((battery_level-10.8) / (12.5-10.8))×100+0.5), reflecting the battery's instantaneous charge status.

[0163] `last_battery_level` represents the historical battery level, which is the percentage of battery charge recorded at the last valid sample, expressed as a percentage. This value is stored as a static variable inside the function and used to compare it with the current battery level to calculate the rate of change in battery charge. The initial value is 0.0f, and it is continuously updated during system operation.

[0164] `time_diff_sec` represents the time interval, which is the time difference between the current sampling time and the previous sampling time, in seconds (s). The millisecond value of the system tick counter is obtained through the `HAL_GetTick()` function and then converted to seconds, reflecting the actual time interval between two power measurements.

[0165] `fabsf(new_value-last_battery_level)`: This function takes the absolute value of the battery level difference using the `fabsf()` function, eliminating the influence of the sign and focusing only on the magnitude of the change. `fabsf()` is a function specifically designed for handling absolute values ​​of float data types, ensuring calculation precision.

[0166] Practical application example:

[0167] Suppose the system detects the following data:

[0168] Current battery level: new_value = 85%;

[0169] Last battery level: last_battery_level = 83%;

[0170] Time interval: time_diffsec = 2.0s;

[0171] Calculation process:

[0172] Battery capacity difference: 85% - 83% = 2%;

[0173] Absolute value: fabsf(2%) = 2%;

[0174] Rate of change: 2% ÷ 2.0s = 1.0% / s;

[0175] Threshold determination mechanism:

[0176] When the calculated change_rate > 1.0% / s, the system will determine it as an abnormal change and trigger the following response:

[0177] Maintain the previous valid battery level to avoid data display jumps;

[0178] This rate of change detection mechanism effectively filters out abnormal power display caused by ADC noise, voltage transients, or calculation errors, ensuring the stability and reliability of battery power display.

[0179] Filtering algorithm characteristics:

[0180] Change rate limiting mechanism: The function has a built-in intelligent filtering algorithm. When an abnormal change in the power change rate is detected that exceeds 1% / second, the previous valid value will be retained to avoid incorrect power display caused by ADC noise, voltage transients or calculation errors.

[0181] Smooth time window: Employs a timestamp comparison mechanism to ensure that power changes are within a reasonable physical range, providing stable and reliable battery status information for system power management, user interface display, and cloud data upload.

[0182] This filtering process ensures that the battery pack's power display reflects the true battery status while maintaining sufficient stability, avoiding user experience issues caused by hardware noise.

[0183] The intelligent battery power algorithm uses floating-point operations to ensure the accuracy and stability of power detection.

[0184] In addition, if the rate of change is within a reasonable range, the system accepts the new sampled value as valid data and updates the three status variables: filtered_battery_level, last_battery_level, and last_sample_time. Simultaneously, debugging information is output via serial port to facilitate monitoring the working status and verifying the effect of the filtering algorithm during development.

[0185] The serial ports here include: USART3 debug serial port;

[0186] Serial port identification: The debug serial port in the system mainly refers to USART3, which is a communication interface specifically used for outputting debug information during the development phase. USART3 is connected to the STM32F407VET6 via GPIO pins and configured in standard asynchronous serial communication mode.

[0187] Physical connection: Connect the TX and RX pins of USART3 to an external debugging device, such as the CH343 serial port tool, with the baud rate set to 115200 and the data format being 8 data bits, 1 stop bit, and no parity.

[0188] Connection architecture with the processor:

[0189] Hardware Interface: USART3, as a built-in peripheral of the STM32F407VET6, connects directly to the ARM Cortex-M4 core via the internal bus. The system clock provides the operating clock for USART3 through the PCLK1 bus, ensuring stable communication timing.

[0190] Battery power level monitoring information can be configured as follows:

[0191] Normal change record:

[0192] "Battery charge change: 2.50% / s, updated to: 85.0%";

[0193] Displaying the rate of change and the current battery percentage confirms that the filtering algorithm is working properly.

[0194] Alarm information for abnormal changes:

[0195] Warning: Threshold change exceeded

[0196] "Battery charge level changes too rapidly: 3.20% / s, last valid value: 83.0%";

[0197] Recording abnormal rate of change values ​​indicates that the system has maintained the previous stable value, thus avoiding display jumps.

[0198] State variable update log:

[0199] Key parameter tracking:

[0200] filtered_battery_level: The current effective battery level after filtering;

[0201] last_battery_level: The last recorded battery level baseline;

[0202] last_sample_time: timestamp update record;

[0203] time_diff_sec: Calculation result of the sampling time interval;

[0204] Algorithm performance metrics:

[0205] Filtering effect verification: This includes performance data such as numerical comparison before and after filtering, anomaly detection count statistics, and system response time measurement, to help developers optimize the parameter configuration of the battery_level_threshold_filter() function.

[0206] This debugging information is output through the u3_printf() function, providing developers with comprehensive system operation status monitoring and ensuring the reliability and accuracy of the battery power filtering algorithm in battery pack applications.

[0207] S46: Monitor the operating status of the motor based on the generated voltage in the filtered data, and obtain motion status data based on the operating status;

[0208] Step S46 further includes the following steps:

[0209] S461: When the generated voltage is greater than or equal to 1V and the motor is in a stopped state, the motor is determined to start; when the generated voltage is less than 1V and the motor is in a running state, the motor is determined to stop.

[0210] S462: When it is determined that the motor has started, update the motor status to running and automatically count as the number of motion cycles. The running status is when the user starts moving.

[0211] S463: When it is determined that the motor has stopped, update the motor status to stopped;

[0212] The motion state data includes the number of motion cycles.

[0213] The purpose of marking a new cycle is to discretize the continuous motor operation process into statistically significant motion events. Through this mechanism, the following can be achieved:

[0214] Precise statistics: Every rowing motion is accurately recorded and statistically analyzed;

[0215] Real-time feedback: Provides users with instant exercise data feedback;

[0216] Data analytics: Provides foundational data for cloud-based exercise analysis and health management;

[0217] Intelligent control: Provides decision-making basis for the adaptive control of equipment.

[0218] S47: Obtain the device identification information, current PWM control value, filtered data, battery percentage data, and motion status data of the intelligent rowing machine, and encapsulate them in JSON format to obtain encapsulated data;

[0219] The uploaded data structure is in JSON format and contains the following specific fields:

[0220] Category 1: Equipment Identification Information

[0221] sn (string type): Device serial number, used to identify the specific rowing machine in the cloud;

[0222] Category 2: PWM control data

[0223] pwm1 (numerical type): The PWM control value of motor 1, which comes from the global variable g_pwmvalue1;

[0224] pwm2 (numerical type): The PWM control value of motor 2, which comes from the global variable g_pwmvalue2;

[0225] pwm3 (Reserved): PWM control value for motor 3 (currently commented out, reserved for future expansion);

[0226] pwm4 (Reserved): PWM control value for motor 4 (currently commented out, reserved for future expansion);

[0227] Category 3: Motor voltage sensor data;

[0228] motor_1_voltage (floating-point type): Voltage value of motor 1, derived from temp[0] / 0.0769;

[0229] motor_2_voltage (floating-point type): Motor 2 voltage value, derived from temp[1] / 0.0769;

[0230] motor_3_voltage (Reserved): Motor 3 voltage value (currently commented out);

[0231] motor_4_voltage (Reserved): Motor 4 voltage value (currently commented out);

[0232] Category 4: Motor current sensor data;

[0233] motor_1_current (floating-point type): Motor 1 current value, sourced from temp[4] (acquired through PC0 channel);

[0234] motor_2_current (floating-point type): Motor 2 current value, sourced from temp[5] (acquired via PC1 channel);

[0235] motor_3_current (Reserved): Current value for motor 3 (currently commented out);

[0236] motor_4_current (Reserved): Current value for motor 4 (currently commented out);

[0237] Category 5: Battery management data;

[0238] battery_level (integer type): Battery percentage (0%-100%), the result after linear mapping and boundary value processing;

[0239] Category 6: Motion state data;

[0240] motor_1_number (integer type): Motor 1 new cycle marker, used to indicate whether the motor has completed a new motion cycle;

[0241] motor_2_number (integer type): Motor 2 new cycle marker, used to indicate whether the motor has completed a new motion cycle;

[0242] motor_3_number (Reserved): New cycle marker for motor 3 (currently commented out);

[0243] motor_4_number (Reserved): New cycle marker for motor 4 (currently commented out).

[0244] S48: Automatically adjust the data upload frequency based on the magnitude of changes in the filtered data, abnormal changes in battery power, and system mode switching;

[0245] The step of automatically adjusting the data upload frequency based on the change amplitude of the filtered data further includes the following steps:

[0246] S481: Calculate the absolute difference between the current generation voltage and the previous generation voltage in the filtered data;

[0247] S482: Compare the absolute difference with a third threshold; when the absolute difference is greater than or equal to the third threshold, determine that the generated voltage is in a period of drastic signal change; when the absolute difference is less than the third threshold, determine that the generated voltage is in a period of stable signal.

[0248] S483: Automatically adjust the data upload frequency according to the type of signal change period during which the current generated voltage is located; when the signal is changing drastically, set the data upload frequency to upload once every 0.1s; when the signal is stable, set the data upload frequency to upload once every 30s.

[0249] The third threshold is 0.3V.

[0250] By monitoring the battery power change rate in real time, when the power change rate is detected to be >1% / second, it is determined that the battery power is abnormally changing, and the data upload frequency is set to upload once every 0.1s;

[0251] The system mode switching includes the operating state being that the user has started moving and the PWM control value changing; when the operating state is that the user has started moving and the PWM control value changes, the data upload frequency is set to upload once every 0.1 seconds.

[0252] In this embodiment, for the generator voltage signal of the motor, the system calculates the absolute difference between the current value and the historical value: fabs(current_value-last_value). When the difference is ≥0.3V, it is determined that the signal has changed drastically.

[0253] During periods of drastic signal changes: send_interval=10, data is uploaded every 0.1 seconds;

[0254] During periods of stable signal: send_interval=3000, data is uploaded every 30 seconds.

[0255] The data is encapsulated in JSON format to optimize transmission efficiency. An example of uploading data in standard JSON format is:

[0256] {

[0257] "sn": "030001",

[0258] "pwm1": 0,

[0259] "pwm2": 0,

[0260] "motor_1_voltage": 12.5,

[0261] "motor_2_voltage": 12.3,

[0262] "motor_1_current": 2.1,

[0263] "motor_2_current": 1.8,

[0264] "battery_level": 85,

[0265] "motor_1_number": 1,

[0266] "motor_2_number": 0

[0267] };

[0268] S49: Upload the encapsulated data to the cloud server via the MQTT protocol according to the current data upload frequency.

[0269] The control terminal of the intelligent rowing machine also has a built-in AES CBC encryption and decryption module, which is used to encrypt a small number of sensitive fields and then publish them to an independent encrypted topic, stopping after a certain number of reports; other routine data, such as voltage, current, battery level, PWM control value, and sliding judgment event, are reported in plaintext, which improves the security of user data uploads.

[0270] S5: The cloud server updates the data of a mobile terminal or a metaverse software server based on the processed data;

[0271] S6: The mobile terminal or the metaverse software server sends a resistance level adjustment command to the cloud server via the MQTT protocol. The resistance level adjustment command includes resistance levels of 0 to 100 for at least two motors.

[0272] The MQTT protocol is lightweight and has low bandwidth consumption, which can efficiently realize the issuance of commands, status reporting and real-time transmission of motion data between devices and the cloud, ensuring rapid interactive response and stable and reliable data transmission. Through the MQTT protocol, the virtual and real synchronous data interaction between the rowing machine control terminal and the Metaverse software can be realized.

[0273] In step S6, the resistance level adjustment command is packaged into JSON format.

[0274] Packaging resistance level adjustment instructions into JSON format can optimize transmission efficiency.

[0275] In this embodiment, the resistance level adjustment command can be packaged into JSON format as follows:

[0276] { "pwm1": 50,

[0277] "pwm2": 30,

[0278] "pwm3": 70,

[0279] "pwm4": 20

[0280] };

[0281] In this embodiment, a connection to the cloud is established through MyMQTT_Connect.

[0282] S7: The control terminal of the rowing machine initiates a resistance control task, receives the corresponding resistance level adjustment command from the cloud server, and adjusts the resistance of the motor according to the resistance level;

[0283] Step S7 further includes the following steps:

[0284] S71: The control terminal receives the corresponding resistance level adjustment command from the cloud server;

[0285] When the control terminal receives the corresponding resistance level adjustment command from the cloud server, the control terminal uses USART5 interrupt-driven reception and continuously listens to the USART5 receive buffer; and uses the vTaskDelay(pdMS_TO_TICKS(10)) function; the control terminal parses the resistance level adjustment command in multiple formats.

[0286] The control terminal uses USART5 interrupt-driven reception and achieves zero-blocking data detection by polling the flag bit, avoiding the latency caused by traditional blocking serial port reading. Combined with the vTaskDelay(pdMS_TO_TICKS(10)) function, it ensures that cloud commands can be detected and processed within 10ms. Compared to traditional second-level or minute-level control, this millisecond-level scheduling significantly reduces command response latency. Simultaneously, FreeRTOS's task priority management ensures that PWM control tasks have a sufficiently high execution priority.

[0287] In this embodiment, the system continuously monitors the USART5 receive buffer:

[0288] if(g_usart5_rx_sta & 0x8000) {

[0289] uint16_t len ​​= g_usart5_rx_sta & 0X7FFF;

[0290] pwm_str = strstr((char *)g_usart5_rx_buf, "pwm1:");

[0291] if(pwm_str && sscanf(pwm_str, "pwm1:%d", &pwmvalue1) == 1)

[0292] };

[0293] The system employs a USART5 interrupt-driven receive mechanism. When MQTT data arrives, an interrupt is triggered immediately, storing the data in the `g_usart5_rx_buf` buffer and setting the `g_usart5_rx_sta` flag. Tasks achieve zero-blocking data detection by polling this flag, avoiding the latency associated with traditional blocking serial port reading. This design ensures that cloud commands can be detected and processed within 10ms.

[0294] The control unit supports parsing multiple formats for the resistance level adjustment command. A fast parsing mechanism compatible with multiple formats supports various PWM data formats, including pwm1:50, "pwm1":50, and a unified pwm:50 format. The system uses the strstr() function for fast string matching, combined with sscanf() for numerical extraction, avoiding the complex full JSON parsing process. When multiple formats are detected, the fastest string matching is prioritized, reducing CPU overhead and time latency in protocol parsing. When parsing one format fails, other formats are automatically tried, maximizing communication reliability and compatibility.

[0295] For example, the control terminal supports commands in the following format:

[0296] 1. Standard format: pwm1:50, pwm2:30;

[0297] 2. JSON format: {"pwm1":50, "pwm2":30};

[0298] 3. Compatible format: pwm:40, applied to all channels, using the get_value function for buffer search.

[0299] Following the step of parsing the resistance level adjustment command to support multiple formats, the method further includes the following steps:

[0300] The current motor mode is maintained or adjusted according to the number of PWM control channels in the resistance level adjustment command; when the number of PWM control channels is 2, the dual-motor mode is maintained; when the number of PWM control channels is 4, the comment masking of the processing logic of the two PWM control channels is removed, and the mode is switched to four-motor mode.

[0301] The system possesses the ability to intelligently identify the current operating mode, automatically adapting to dual-motor or quad-motor mode based on the number of received PWM channels. When only PWM1 and PWM2 commands are detected, the system operates in dual-motor mode; when PWM3 and PWM4 commands are detected, it automatically switches to quad-motor mode. This real-time adaptive mechanism ensures a smooth transition without manual intervention or system restart.

[0302] The transition from the current dual-motor to quad-motor expansion is completely seamless: the first phase maintains the existing dual-motor operating mode, with all four hardware channels ready but the software only activating the first two channels; the second phase simply requires uncommenting the relevant code and activating the processing logic and data reporting for PWM3 and PWM4, without any hardware modifications. The entire transition process achieves zero downtime, backward compatibility, and real-time monitoring capabilities, demonstrating the system's excellent scalability and engineering practicality.

[0303] This extended functionality not only meets the current requirements for dual-motor control of rowing machines, but also provides a complete technical reserve for future functional expansion.

[0304] In step S7, the tasksENTER_CRITICAL() and taskEXIT_CRITICAL() functions are used to protect the USART5 serial port data reception.

[0305] The USART5 serial port data reception is protected by the taskENTER_CRITICAL() and taskEXIT_CRITICAL() functions, which avoids data contention in a multi-tasking environment, ensures the integrity of cloud command data, and keeps the critical section time within the shortest range, thereby reducing system response latency.

[0306] The pre-allocated static buffer mechanism avoids the latency of dynamic memory allocation. The system uses a fixed-size g_usart5_rx_buf receive buffer and a static PWM value variable to avoid memory fragmentation and allocation latency caused by malloc / free operations. At the same time, memset() is used to quickly clear the buffer, ensuring that the next round of data reception is ready.

[0307] S72: Determine whether the resistance level is greater than 100. If it is, set the value of the resistance level to 100.

[0308] S73: Map the aforementioned resistance level to a duty cycle of 0%-30%;

[0309] S74: Calculate the PWM comparison value based on the duty cycle;

[0310] S75: Generate a resistance control signal based on the PWM comparison value and adjust the resistance of the motor accordingly using the resistance control signal;

[0311] In step S75, the __HAL_TIM_SET_COMPARE() macro is used to directly operate the comparison register of the TIM4 timer to form the resistance control signal based on the PWM comparison value. This low-level hardware operation avoids the extra overhead of HAL library function calls and realizes a microsecond-level delay from PWM value calculation to hardware output. Combined with a 2kHz PWM frequency setting, it ensures the fast response of the resistance control system.

[0312] S76: Update the PWM control value of the global variable to the value of the PWM comparison value;

[0313] The principle of resistance adjustment is as follows:

[0314] PWM control controls the power generation efficiency by adjusting the electrical load of the motor. When the PWM duty cycle increases, the electrical load of the motor increases, thus increasing the power generation efficiency, but the user experiences increased resistance. When the PWM duty cycle decreases, the electrical load of the motor decreases, thus reducing the power generation efficiency, but the user experiences decreased resistance.

[0315] In this embodiment, a scaling algorithm is used to convert the resistance level to the PWM comparison value:

[0316] After receiving the resistance levels from 0 to 100, a two-level mapping is performed using the pwm_scale_to_compare function:

[0317] static uint32_t pwm_scale_to_compare(uint8_t scale_value){

[0318] / / Restrict the input range;

[0319] if(scale_value > 100) scale_value = 100;

[0320] / / Map the 0-100 scale to a 0%-30% duty cycle;

[0321] float actual_duty = (float)scale_value * 30.0f / 100.0f;

[0322] / / Calculate the PWM compare value;

[0323] uint32_t compare_value = (__HAL_TIM_GET_AUTORELOAD(&g_timx_pwm_chy_handle) + 1)* (100.0f - actual_duty) / 100.0f;

[0324] return compare_value;}

[0325] The mapping strategy is as follows:

[0326] The user can set the scale from 0-100 to the actual duty cycle from 0%-30%;

[0327] 0% duty cycle = minimum resistance; 30% duty cycle = maximum resistance.

[0328] This design ensures the safe operating range of the resistance system.

[0329] The `pwm_scale_to_compare()` function implements efficient numerical mapping, linearly mapping a user-defined scale of 0-100 to a PWM comparison value. Internally, the function uses floating-point multiplication and boundary checks to avoid complex mathematical operations. The calculation process includes input limiting (setting >100 to 100), scale mapping (0-100 → 0%-30%), and register value conversion; the entire calculation is completed within milliseconds.

[0330] The critical upper limit truncation correction mechanism is implemented in the `pwm_scale_to_compare` function: when `scale_value` exceeds 100, it is automatically set to 100, ensuring that the PWM control never exceeds the maximum safe resistance range. This saturation operation method uses the built-in saturation instructions of the ARM Cortex-M4 architecture, achieving efficient hardware-level boundary protection.

[0331] In step S54, a control update is performed for each PWM channel. Taking channel 1 PWM control as an example:

[0332] if(pwmvalue1 >= 0 && pwmvalue1 <= 100) {

[0333] uint32_t compare_val = pwm_scale_to_compare(pwmvalue1);

[0334] __HAL_TIM_SET_COMPARE(&g_timx_pwm_chy_handle,GTIM_TIMX_PWM_CH1,compare_val);

[0335] / / Update global state;

[0336] g_pwmvalue1 = pwmvalue1;

[0337] g_pwmvalue_sta1 = 1;};

[0338] In the control section, hardware control is only applied when the PWM value simultaneously meets the conditions of >=0 and <=100. Invalid values ​​outside the range are silently ignored and do not affect the current state of the system. This design ensures the stability of the system, allowing it to continue operating normally using the previous valid value even if an abnormal instruction is received.

[0339] S8: Send feedback data to the cloud server through the data collection and upload task;

[0340] The feedback data is the uploaded data from the data acquisition and upload task, including the device identification information of the intelligent rowing machine, the current PWM control value, the filtered data, the battery percentage data, and the motion status data.

[0341] S9: The cloud server updates the resistance status data of the mobile terminal based on the feedback data;

[0342] The resistance state data is obtained based on the PWM control value in the feedback data.

[0343] S10: The rowing machine recovers the generated energy from the motor.

[0344] In step S10, the motor is connected to the battery through a charging circuit. The charging circuit uses a capacitor as a temporary energy storage device and recharges the battery to recover the generated energy of the motor.

[0345] In this embodiment, the charging circuit is externally connected to a Type-C interface and a Type-A interface. The Type-C interface allows for bidirectional charging and discharging, while the Type-A interface only allows for discharging. The inclusion of the Type-C and Type-A interfaces provides the hardware foundation for external charging and discharging of the battery.

[0346] The step S9 is followed by the following step:

[0347] S11: The cloud server sends the resistance status data to the mobile terminal or the metaverse software server.

[0348] S12: The user interface of the mobile terminal or the metaverse software corresponding to the metaverse software server displays the resistance status data.

[0349] It should be noted that while the preferred embodiments of the present invention are provided in the specification and accompanying drawings, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. These embodiments are not intended to impose additional limitations on the content of the present invention; their purpose is to provide a more thorough and comprehensive understanding of the disclosure of the present invention. Furthermore, the above-described technical features can be combined with each other to form various embodiments not listed above, all of which are considered to be within the scope of the present invention specification. Moreover, those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.

[0350] The present invention has been described in detail above with reference to the accompanying drawings and embodiments. Those skilled in the art can make various modifications to the present invention based on the above description. Therefore, certain details in the embodiments should not be construed as limiting the present invention, and the scope of protection of the present invention shall be defined by the appended claims.

Claims

1. A method for controlling an intelligent rowing machine, comprising the following steps: S1: Configure the rowing machine's control unit for network and communication settings, and connect to the network; S2: The control terminal is set up with a startup task, a data acquisition and upload task and a resistance control task based on the FreeRTOS multi-task architecture; S3: The control terminal executes the startup task to initialize the system; S4: The control terminal of the rowing machine starts the data acquisition and upload task, performs parallel data acquisition of multiple analog channels on the target of the rowing machine to obtain the acquired data, processes the data on the control terminal through a preset algorithm, and uploads the data processed by the control terminal to the cloud server. S5: The cloud server updates the data of a mobile terminal or a metaverse software server based on the processed data; S6: The mobile terminal or the metaverse software server sends a resistance level adjustment command to the cloud server via the MQTT protocol. The resistance level adjustment command includes resistance levels of 0 to 100 for at least two motors. S7: The control terminal of the rowing machine initiates a resistance control task, receives the corresponding resistance level adjustment command from the cloud server, and adjusts the resistance of the motor according to the resistance level; S8: Send feedback data to the cloud server through the data collection and upload task; S9: The cloud server updates the resistance status data of the mobile terminal based on the feedback data; S10: The rowing machine recovers the generated energy from the motor; Step S4 further includes the following steps: S41: The ADC1 controller based on the STM32F407VET6 chip uses the DMA2_Stream4 dedicated channel to acquire data from the target under test in parallel through multiple analog channels at preset time intervals; the target under test includes at least two motors of the rowing machine and a battery; the acquired data includes the generator voltage of the motor, the generator current of the motor, and the battery voltage of the battery; S42: Perform multiple sampling average filtering on the collected data; S43: Convert the generated voltage and the battery voltage after multiple sampling average filtering into actual voltage values; S44: The actual voltage value and the generated current after the multiple sampling average filtering process are filtered in real time using the IIR low-pass filtering algorithm to obtain the filtered data; S45: Obtain the battery's charge percentage data based on the battery voltage in the filtered data; S46: Monitor the operating status of the motor based on the generated voltage in the filtered data, and obtain motion status data based on the operating status; S47: Obtain the device identification information, current PWM control value, filtered data, battery percentage data, and motion status data of the intelligent rowing machine, and encapsulate them in JSON format to obtain encapsulated data; S48: Automatically adjust the data upload frequency based on the magnitude of changes in the filtered data, abnormal changes in battery power, and system mode switching; S49: Upload the encapsulated data to the cloud server via the MQTT protocol according to the current data upload frequency; In step S48 By monitoring the battery charge change rate in real time, when the charge change rate is detected to be >1% / second, the data upload frequency is set to upload once every 0.1s; The system mode switching includes the operating state being that the user has started moving and the PWM control value changing; When the operating state is that the user starts moving and the PWM control value changes, the data upload frequency is set to upload once every 0.1 seconds; The step of automatically adjusting the data upload frequency based on the change amplitude of the filtered data further includes the following steps: S481: Calculate the absolute difference between the current generation voltage and the previous generation voltage in the filtered data; S482: Compare the absolute difference with a third threshold; when the absolute difference is greater than or equal to the third threshold, determine that the generated voltage is in a period of drastic signal change; when the absolute difference is less than the third threshold, determine that the generated voltage is in a period of stable signal. S483: Automatically adjust the data upload frequency according to the type of signal change during which the current power generation voltage is located; When the signal is fluctuating drastically, the data upload frequency is set to once every 0.1 seconds; when the signal is stable, the data upload frequency is set to once every 30 seconds.

2. The intelligent rowing machine control method according to claim 1, characterized in that, Step S1 further includes the following steps: S101: When the control terminal is first started, it downloads and saves WiFi credentials via Bluetooth BluFi pairing. S102: When connecting to the network, automatically connect to the network using the WiFi credentials, and prioritize WiFi mode for network connection. If the number of failed connections reaches a first threshold, automatically switch to 4G mode. S103: Configure MQTT session.

3. The intelligent rowing machine control method according to claim 1, characterized in that, Step S45 further includes the following steps: S451: Use a linear mapping formula to convert the current battery voltage into a 0%-100% battery percentage data; S452: When the calculated result of the battery percentage data exceeds 100%, it is forcibly set to 100%; when the calculated result of the battery percentage data is less than 0%, it is forcibly set to 0%. S453: Determine whether the rate of change of the current battery percentage data is greater than or equal to a second threshold; if it is greater than or equal to the second threshold, automatically discard the current battery percentage data and keep the previous battery percentage data as the current battery percentage data; if it is less than the second threshold, determine that the current battery percentage data is valid data, update the corresponding system variables and output the corresponding debugging information through the serial port.

4. The intelligent rowing machine control method according to claim 3, characterized in that, Step S46 further includes the following steps: S461: When the generated voltage is greater than or equal to 1V and the motor is in a stopped state, the motor is determined to start; when the generated voltage is less than 1V and the motor is in a running state, the motor is determined to stop. S462: When it is determined that the motor has started, update the motor status to running and automatically count as the number of motion cycles. The running status is when the user starts moving. S463: When it is determined that the motor has stopped, update the motor status to stopped; The motion state data includes the number of motion cycles.

5. The intelligent rowing machine control method according to claim 4, characterized in that, In step S7, when the control terminal receives the corresponding resistance level adjustment command from the cloud server, the control terminal uses USART5 interrupt-driven reception and continuously listens to the USART5 receive buffer; and uses the vTaskDelay(pdMS_TO_TICKS(10)) function; the control terminal parses the resistance level adjustment command in multiple formats; The control terminal uses four channels of the TIM4 timer for PWM output control, forming four PWM control channels. During system initialization, all PWM control channels are fully initialized. The initial state is set to dual-motor mode. In dual-motor mode, the processing logic of two PWM control channels is not commented out, while the processing logic of the other two PWM control channels is commented out. The code structure of all four PWM control channels is complete. After parsing the resistance level adjustment command to support multiple formats, the following steps are also included: The current motor mode is maintained or adjusted according to the number of PWM control channels in the resistance level adjustment command; when the number of PWM control channels is 2, the dual-motor mode is maintained; when the number of PWM control channels is 4, the comment masking of the processing logic of the two PWM control channels is removed, and the mode is switched to four-motor mode. In step S7, the tasksENTER_CRITICAL() and taskEXIT_CRITICAL() functions are used to protect the USART5 serial port data reception.

6. The intelligent rowing machine control method according to claim 5, characterized in that, Step S7 further includes the following steps: S71: The control terminal receives the corresponding resistance level adjustment command from the cloud server; S72: Determine whether the resistance level is greater than 100. If it is, set the value of the resistance level to 100. S73: Map the aforementioned resistance level to a duty cycle of 0%-30%; S74: Calculate the PWM comparison value based on the duty cycle; S75: Generate the resistance control signal based on the PWM comparison value and adjust the resistance of the motor accordingly using the resistance control signal; S76: Update the PWM control value of the global variable to the value of the PWM comparison value; In step S75, the resistance control signal is formed by directly operating the comparison register of the TIM4 timer using the __HAL_TIM_SET_COMPARE() macro based on the PWM comparison value.

7. The intelligent rowing machine control method according to claim 6, characterized in that, The resistance state data is obtained based on the PWM control value in the feedback data. Step S9 is followed by the following step: S11: The cloud server sends the resistance status data to the mobile terminal or the metaverse software server. S12: The user interface of the mobile terminal or the metaverse software corresponding to the metaverse software server displays the resistance status data.

8. The intelligent rowing machine control method according to claim 6, characterized in that, In step S10, the motor is connected to the battery through a charging circuit. The charging circuit uses a capacitor as a temporary energy storage device and recharges the battery to recover the generated energy of the motor.

Citation Information

Patent Citations

  • Improvement in cloth-steaming apparatus

    US115200A

  • Method for realizing simulated boating scene by utilizing vehicle-mounted boating machine

    CN110681110A

  • Upper limb strength training auxiliary system based on universe and use method of upper limb strength training auxiliary system

    CN116099181A

  • Pull hand dragon boat training motion induction control method, equipment and medium

    CN116966531A

  • Intelligent fitness method and system

    CN120586365A