An AI model upgrading method and device based on double PLCs and a medium
By loading a new AI model and synchronizing data in the hot standby PLC of the dual PLC system, new inference results are generated. The processing instructions are determined by combining feature similarity and equipment status. This solves the production efficiency loss and safety hazards caused by downtime updates during PLC system upgrades, realizes dynamic upgrades and switching of AI models, and ensures system stability and decision reliability.
Patent Information
- Application Number
- CN202511241745.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-02
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2045-09-02
AI Technical Summary
In existing technologies, upgrading the AI model of a PLC system requires downtime for updates, resulting in losses in production efficiency and safety hazards. Furthermore, the model verification process is disconnected from the production environment, making it difficult to ensure the consistency of decisions after the update.
An AI model upgrade method based on dual PLCs is adopted. The new version of the AI model is loaded through the hot standby PLC and the input data of the main PLC is synchronized to generate new inference results. The processing instructions are determined by feature similarity value and equipment status to realize dynamic upgrade and switching, including prompt, rollback and fine-tuning instructions, to ensure continuous and stable operation of the system.
This ensures the continuous and stable operation of the system, avoids production line interruptions and safety monitoring function failures caused by upgrades, improves the decision-making reliability of the new version of the AI model in the production environment, enhances the system's ability to defend against model upgrade risks, and extends the service life of the equipment.
Smart Images

Figure CN120743321B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of industrial automation control, and in particular to a method, device and medium for upgrading an AI model based on dual PLCs. Background Technology
[0002] In the field of industrial automation control, programmable logic controllers (PLCs) serve as core control devices, using built-in algorithms to achieve data acquisition and real-time control of electromechanical equipment and sensors. In recent years, with the deep integration of artificial intelligence technology, PLC systems with field-level AI algorithm support capabilities have been widely used in high-reliability scenarios such as smart manufacturing and smart mines, continuously iterating AI models to improve the system's decision-making accuracy.
[0003] In existing technologies, upgrading AI models in PLC systems generally adopts a shutdown update mechanism: the equipment operation needs to be interrupted or the AI function turned off, the complete firmware or new model file is burned to the storage medium, and then the system is restarted to load the update. This mechanism has significant drawbacks in continuous industrial production scenarios: production line shutdowns lead to production efficiency losses, interruptions of AI functions in key areas (such as underground safety monitoring) may cause safety accidents, and the model verification process is disconnected from the production environment, making it difficult to ensure the consistency of decisions after the update.
[0004] Therefore, how to achieve dynamic upgrading and switching of AI models while ensuring the continuous and stable operation of industrial automation systems has become an urgent technical problem to be solved. Summary of the Invention
[0005] This application provides an AI model upgrade method, device, and medium based on dual PLCs to solve the following technical problem: how to achieve dynamic upgrades and switching of AI models while ensuring the continuous and stable operation of industrial automation systems.
[0006] In a first aspect, embodiments of this application provide an AI model upgrade method based on dual PLCs, applied to a PLC control system. The PLC control system includes a primary PLC and a hot standby PLC that serve as hot backups for each other. The method includes: loading a new version of the AI model through the hot standby PLC; synchronizing the input data of the primary PLC through the hot standby PLC and processing the input data based on the new version of the AI model to generate a new inference result; comparing the new inference result with the old inference result generated by the primary PLC based on the old version of the AI model to determine a feature similarity value; determining a processing instruction based on the feature similarity value, the device status of the primary PLC, and the device status of the hot standby PLC; wherein the processing instruction includes a prompt instruction, a rollback instruction, and a fine-tuning instruction; when the processing instruction is a fine-tuning instruction, fine-tuning the new version of the AI model based on the difference between the new and old inference results, and regenerating the feature similarity value; switching the hot standby PLC to the primary PLC and controlling the original primary PLC to synchronize the new version of the AI model.
[0007] In one implementation of this application, the input data of the main PLC is synchronized through a hot standby PLC, and the input data is processed based on a new version of the AI model to generate a new inference result. Specifically, this includes: establishing a communication connection between the hot standby PLC and the main PLC to obtain the input data of the main PLC; wherein the input data includes at least monitoring data collected by sensors and equipment status data; performing inference operations on the input data using the new version of the AI model through the hot standby PLC to obtain inference intermediate results; and generating a new processing result based on the inference intermediate results; wherein the new processing result includes alarm information and / or control commands.
[0008] In one implementation of this application, the feature similarity value is determined by comparing the new inference result with the old inference result generated by the main PLC based on the old version of the AI model. Specifically, this includes: the hot standby PLC acquiring the old processing result output by the main PLC; wherein the old processing result is alarm information and / or control commands generated based on the old version of the AI model; extracting feature vectors from the new processing result and the old processing result to obtain new feature vectors and old feature vectors; and processing the similarity between the new feature vectors and the old feature vectors based on a preset cosine similarity algorithm to obtain the feature similarity value.
[0009] In one implementation of this application, the processing instruction is determined based on the feature similarity value, the device status of the main PLC, and the device status of the hot standby PLC. Specifically, this includes: obtaining the CPU utilization rate, memory utilization rate, and communication latency of the main PLC to determine the device status of the main PLC; obtaining the CPU utilization rate, memory utilization rate, and communication latency of the hot standby PLC to determine the device status of the hot standby PLC; calculating the absolute difference between the device status of the main PLC and the device status of the hot standby PLC to generate a resource status difference value; when the feature similarity value is greater than or equal to a first threshold, no instruction is generated; when the feature similarity value is less than the first threshold but greater than a second threshold, and the resource status difference value is less than a third threshold, a prompt instruction is generated; when the feature similarity value is less than or equal to the second threshold, a rollback instruction or a fine-tuning instruction is generated.
[0010] In one implementation of this application, when the feature similarity value is less than a first threshold and greater than a second threshold, and the resource status difference value is less than a third threshold, a prompt instruction is generated. Specifically, this includes: constructing a prompt message data packet containing the feature similarity value, the resource status difference value, and the current timestamp; transmitting the prompt message data packet to the monitoring terminal through a preset system log interface and / or human-computer interaction interface; continuously monitoring user confirmation signal input within a preset delay time window; generating a handover permission flag when a valid user confirmation signal input is received; and generating a handover abort instruction when no valid user confirmation signal input is received within the delay time window.
[0011] In one implementation of this application, when the processing instruction is a fine-tuning instruction, the new version of the AI model is fine-tuned based on the difference between the new inference result and the old inference result, and the feature similarity value is regenerated. Specifically, this includes: parsing the alarm type distribution data and control parameter values in the new inference result to generate a new result data vector; parsing the alarm type distribution data and control parameter values in the old inference result to generate an old result data vector; calculating the difference vector between the new result data vector and the old result data vector; constructing a model loss function based on the difference vector, and adjusting the weight parameters of the new version of the AI model through a preset backpropagation algorithm; processing the input data based on the new version of the AI model container after adjusting the weight parameters to generate the fine-tuned inference result; extracting the feature vector of the fine-tuned inference result, and executing the feature similarity value calculation process to regenerate the feature similarity value.
[0012] In one implementation of this application, the method further includes: initializing a fine-tuning counter and setting a maximum fine-tuning count threshold; incrementing the fine-tuning counter when the regenerated feature similarity value is less than the preset fine-tuning threshold; determining whether the fine-tuning counter's count has reached the maximum fine-tuning count threshold; if the fine-tuning counter's count has reached the maximum fine-tuning count threshold, triggering a rollback instruction: unloading the currently loaded new version AI model container on the hot standby PLC; loading a backup of the old version AI model container stored locally on the hot standby PLC; and outputting a rollback alarm message data packet containing the number of fine-tuning failures and the rollback status through the system log interface.
[0013] In one implementation of this application, the hot standby PLC is switched to the master PLC, and the original master PLC is controlled to synchronize the new version of the AI model. Specifically, this includes: sending a switching control signal to the control status registers of the master PLC and the hot standby PLC; switching the operating mode of the hot standby PLC to master control mode to obtain control of the device; switching the operating mode of the original master PLC to hot standby mode to release control of the device; and transmitting the image file data of the new version of the AI model container to the original master PLC through a preset shared memory area or communication link.
[0014] Secondly, this application also provides an AI model upgrade device based on dual PLCs for use in a PLC control system. The PLC control system includes a main PLC and a hot standby PLC that are hot-standby for each other. The device includes: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores instructions that can be executed by the at least one processor, which enable the at least one processor to: load a new version of the AI model through the hot standby PLC; synchronize the input data of the main PLC through the hot standby PLC and process the input data based on the new version of the AI model to generate a new inference result; compare the new inference result with the old inference result generated by the main PLC based on the old version of the AI model to determine a feature similarity value; determine a processing instruction based on the feature similarity value, the device status of the main PLC, and the device status of the hot standby PLC; wherein the processing instruction includes a prompt instruction, a rollback instruction, and a fine-tuning instruction; when the processing instruction is a fine-tuning instruction, fine-tune the new version of the AI model based on the difference between the new inference result and the old inference result, and regenerate the feature similarity value; switch the hot standby PLC to the main PLC and control the original main PLC to synchronize the new version of the AI model.
[0015] Thirdly, this application embodiment also provides a non-volatile computer storage medium for AI model upgrade based on dual PLCs, storing computer-executable instructions applied to a PLC control system. The PLC control system includes a main PLC and a hot standby PLC that serve as hot backups for each other. The computer-executable instructions are configured as follows: loading a new version of the AI model through the hot standby PLC; synchronizing the input data of the main PLC through the hot standby PLC and processing the input data based on the new version of the AI model to generate a new inference result; comparing the new inference result with the old inference result generated by the main PLC based on the old version of the AI model to determine the feature similarity value; determining a processing instruction based on the feature similarity value, the device status of the main PLC, and the device status of the hot standby PLC; wherein the processing instruction includes a prompt instruction, a rollback instruction, and a fine-tuning instruction; when the processing instruction is a fine-tuning instruction, fine-tuning the new version of the AI model based on the difference between the new and old inference results, and regenerating the feature similarity value; switching the hot standby PLC to the main PLC and controlling the original main PLC to synchronize the new version of the AI model.
[0016] The AI model upgrade method, device, and medium based on dual PLCs provided in this application embodiment have at least the following technical effects:
[0017] While the main PLC is loading the new version of the AI model in the hot standby PLC, it can still process sensor data and output control commands in real time, avoiding production line interruptions or failure of safety monitoring functions due to upgrades. This effectively enhances the continuous operation capability of industrial automation systems and ensures production efficiency and equipment safety in highly sensitive scenarios such as smart manufacturing and smart mines.
[0018] When the feature similarity value reaches a preset threshold, a switching operation is triggered, which significantly improves the decision reliability of the new version of the AI model in the production environment, avoids control logic deviations caused by model version iteration, and provides more stable intelligent decision support for scenarios such as water conservancy, water affairs, tunnels and pipe corridors.
[0019] When resource status is abnormal or model differences are too large, the switching process is automatically terminated, effectively preventing defective model versions from entering the production environment. At the same time, a manual confirmation step is introduced through prompts, enhancing the system's proactive defense against model upgrade risks.
[0020] The hot standby PLC's model fine-tuning mechanism optimizes model parameters online through the backpropagation algorithm, completing model iterations without requiring a complete firmware flashing. This significantly reduces the frequency of write operations to the PLC's storage media, extends equipment lifespan, and meets the compliance requirements for long-term stable operation of industrial automation equipment. Attached Figure Description
[0021] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0022] Figure 1 A flowchart illustrating an AI model upgrade method based on dual PLCs, provided for an embodiment of this application;
[0023] Figure 2 This is a schematic diagram of the internal structure of an AI model upgrade device based on dual PLCs, provided as an embodiment of this application. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0025] This application provides an AI model upgrade method, device, and medium based on dual PLCs to solve the following technical problem: how to achieve dynamic upgrades and switching of AI models while ensuring the continuous and stable operation of industrial automation systems.
[0026] The technical solutions proposed in the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0027] Figure 1 This document provides a flowchart for upgrading an AI model based on dual PLCs, as an embodiment of this application. Figure 1 As shown in the figure, the AI model upgrade method based on dual PLCs provided in this application embodiment specifically includes the following steps:
[0028] Step 1: Load the new version of the AI model via the hot standby PLC.
[0029] A hot standby PLC refers to a PLC in a dual-PLC redundancy system that is in standby mode. It synchronizes data with the main PLC in real time but does not execute control commands, ensuring rapid takeover in the event of a main PLC failure. A new version AI model refers to an updated algorithm model (such as a neural network model) used to improve decision-making accuracy (such as anomaly detection or control optimization).
[0030] For example, the hot standby PLC downloads a new version of the AI model (version 2.0, optimized for grain temperature and humidity prediction) from the central server. This model is stored in a containerized format (such as TensorRT) and deployed to an isolated sandbox environment within the hot standby PLC's memory upon loading, avoiding interference with current operation. This ensures that the upgrade process does not affect the main PLC's real-time monitoring of warehouse sensors.
[0031] Step 2: Synchronize the input data of the main PLC with the hot standby PLC, and process the input data based on the new version of the AI model to generate new inference results.
[0032] Step 2.1: Establish a communication connection between the hot standby PLC and the main PLC to obtain input data from the main PLC; the input data includes at least monitoring data collected by sensors and equipment status data.
[0033] Input data includes monitoring data collected by sensors (such as temperature and vibration waveforms) and equipment status data (such as motor speed thresholds or equipment configuration parameters in the PLC register). Synchronization refers to real-time data transmission via communication connection to ensure that the hot standby PLC receives consistent input with the main PLC. The new inference result is the output after the new model processes the input, including alarm information (such as equipment abnormality warnings) or control commands (such as parameter adjustment instructions).
[0034] For example, in an assembly robot controlled by the main PLC, the hot standby PLC synchronizes data and runs a new model through this step. Specifically, the hot standby PLC establishes an Ethernet connection to read vibration waveform data and equipment status data (such as robot joint angle settings) from the main PLC in real time from the assembly line sensors. Then, it processes these inputs based on the new model to generate new inference results (such as a "bearing wear warning" alarm and a "reduce speed by 5%" control command).
[0035] Step 2.2: Use the new version of the AI model on the hot standby PLC to perform inference calculations on the input data to obtain intermediate inference results.
[0036] Inference refers to the computational process by which an AI model processes input data to generate output. Intermediate inference results are transitional data generated internally by the model (such as vectors after feature extraction or classification probabilities) used to generate the final result.
[0037] For example, a new version of the AI model (an optimized vibration analysis model) is used to process synchronous input data (such as accelerometer waveforms). The model first performs inference operations (such as convolutional layers to extract frequency domain features) and generates intermediate inference results (feature vectors [0.6, 0.3, 0.1], representing the probability distribution of different vibration modes).
[0038] Step 2.3: Generate new processing results based on the intermediate inference results; wherein, the new processing results include alarm information and / or control commands.
[0039] The new processing result is the executable decision (such as alarm information) or control command (device operation instruction) finally output by the AI model, which is derived based on the intermediate results of inference.
[0040] For example, the hot standby PLC generates new processing results based on the intermediate inference results (feature vectors). Specifically, the model determines that the feature vector [0.8, 0.1, 0.1] corresponds to "conveyor belt offset risk", and outputs the alarm message "conveyor belt offset" and the control command "conveyor belt offset 8 degrees to the left".
[0041] Step 3: Compare the new inference results with the old inference results generated by the main PLC based on the old version of the AI model to determine the feature similarity value.
[0042] The old inference results are the outputs (such as alarms or control commands) generated by the main PLC using the current AI model. The feature similarity value is a consistency index (ranging from -1 to 1) of the old and new results quantified by an algorithm (such as cosine similarity). The higher the value, the more similar the decisions are, and it is used to evaluate the reliability of the new model.
[0043] For example, the main PLC running the old model outputs a "normal water level" alarm, while the hot standby PLC generates a new inference result (such as a "water level fluctuation risk" alarm). By comparing these results, a feature similarity value (e.g., 0.85) is determined to assess whether the new model can be safely switched over. This step ensures that the upgraded decision-making is consistent with the old model, preventing accidents caused by control logic deviations.
[0044] Step 3.1: The hot standby PLC obtains the old processing results output by the main PLC; where the old processing results are alarm information and / or control commands generated based on the old version of the AI model.
[0045] The old processing results are outputs (such as alarm messages or control commands) generated in real time by the main PLC based on the old version of the AI model, and are used for comparison with the new results.
[0046] For example, the hot standby PLC reads old processing results (such as "motor temperature normal" alarm and "maintain speed" control command) from the main PLC via the OPCUA protocol. This result is obtained from the main PLC's system log interface, ensuring data timeliness and integrity, and avoiding comparison distortion caused by network latency.
[0047] Step 3.2: Extract the feature vectors of the new processing result and the old processing result to obtain the new feature vector and the old feature vector.
[0048] Feature vectors are a way of converting processing results (such as alarm type distribution) into numerical vector representations (e.g., [weight1, weight2, ...]) to facilitate algorithm processing. New feature vectors come from the output of the hot standby PLC, while old feature vectors come from the output of the main PLC.
[0049] For example, the feature vector of the old processing result is extracted as [0.1, 0.8, 0.1] (representing humidity, temperature, and pest alarm weights, respectively), and the feature vector of the new processing result is extracted as [0.2, 0.7, 0.1]. The extraction process uses a standardization algorithm (such as normalization) to ensure that the vector dimensions are consistent (such as three-dimensional vectors) in preparation for similarity calculation.
[0050] Step 3.3: Process the similarity between the new feature vector and the old feature vector based on the preset cosine similarity algorithm to obtain the feature similarity value.
[0051] The cosine similarity algorithm calculates the cosine of the angle between two feature vectors (the formula is the dot product divided by the modulus product) and outputs a feature similarity value (a value greater than 0.9 indicates high similarity), which is used for decision consistency evaluation.
[0052] For example, a pre-defined cosine similarity algorithm is used to process the new feature vector [0.3, 0.6, 0.1] and the old feature vector [0.2, 0.5, 0.3]. The calculated feature similarity value is 0.92 (close to 1), indicating that the new model's decision is highly consistent with the old model. This value is used for subsequent switching decisions (e.g., a value > 0.9 allows switching). The algorithm execution time is less than 5ms, meeting industrial real-time requirements.
[0053] Step 4: Determine the processing instructions based on the feature similarity value, the device status of the main PLC, and the device status of the hot standby PLC; among which, the processing instructions include prompt instructions, rollback instructions, and fine-tuning instructions.
[0054] Processing instructions are decision commands generated based on model consistency (feature similarity values) and system health (device status), including prompt instructions (manual confirmation), rollback instructions (restoring the old model), or fine-tuning instructions (optimizing the new model).
[0055] For example, the hot standby PLC runs a new vibration detection model. The feature similarity value (calculated based on step 3) is 0.88. The main PLC's device status is (CPU 40% / Memory 50% / Latency 3ms), and the hot standby PLC's device status is (CPU 55% / Memory 60% / Latency 5ms). After comprehensive comparison, the system generates a prompt instruction, triggering a manual review process to ensure uninterrupted conveyor belt control.
[0056] Step 4.1: Obtain the CPU utilization rate, memory utilization rate, and communication latency of the main PLC to determine the device status of the main PLC.
[0057] CPU utilization (%) refers to the proportion of computational load on the main PLC processing core; memory utilization (%) refers to the proportion of RAM resource consumption; communication latency (ms) refers to the time difference between data transmission and execution. Equipment status is a combined indicator of these three factors, reflecting the real-time health of the system.
[0058] For example, the main PLC monitors the assembly of a robotic arm. When acquiring the equipment status, the system reads internal registers: CPU utilization 35% (indicating low computational load), memory utilization 45% (indicating sufficient cache), and communication latency 2ms (indicating fast network response). This status indicates that the main PLC is operating stably, providing a fundamental guarantee for switching to a new model.
[0059] Step 4.2: Obtain the CPU utilization, memory usage, and communication latency of the hot standby PLC to determine the device status of the hot standby PLC.
[0060] The status of hot standby PLC devices is also based on CPU, memory, and latency metrics to assess whether their operating load can support the new model.
[0061] For example, after a hot-standby PLC loads a new AI model, the system checks its device status: CPU utilization 60% (temporary load caused by model inference calculations), memory utilization 65% (the new model occupies additional RAM), and communication latency 6ms (data synchronization overhead). This status helps determine whether the hot-standby PLC is overloaded, avoiding performance bottlenecks during switchover.
[0062] Step 4.3: Calculate the absolute difference between the device status of the main PLC and the device status of the hot standby PLC to generate the resource status difference value.
[0063] The resource status difference value is the sum of the absolute differences in the status indicators of the main PLC and the hot standby PLC, which quantifies the resource consistency between systems (the smaller the value, the better the status match).
[0064] For example, the main PLC status is (CPU 30% / Memory 40% / Latency 4ms), and the hot standby PLC status is (CPU 45% / Memory 50% / Latency 7ms). The resource status difference value = |30-45| + |40-50| + |4-7| = 15 + 10 + 3 = 28. This difference value is used for subsequent decisions (e.g., if the resource status difference value < 30, switching is allowed) to ensure conflict-free collaboration between the two PLCs.
[0065] Step 4.4: When the feature similarity value is greater than or equal to the first threshold, no instruction is generated.
[0066] The first threshold (e.g., 0.95) is a preset high standard for model consistency, indicating that the new / old model decisions are highly similar (cosine similarity ≥ 0.95). At this point, no instructions are generated, and subsequent switching is directly allowed, reducing intervention.
[0067] For example, if the feature similarity value is 0.97 (with the first threshold set to 0.95), the system determines that the model has strong consistency and does not require additional processing instructions, directly entering the switchover preparation stage to avoid redundant operations affecting real-time performance. It is understandable that when the feature similarity value is greater than or equal to the first threshold, it is not necessary to compare the current device status of the hot standby PLC with that of the main PLC.
[0068] Step 4.5: When the feature similarity value is less than the first threshold and greater than the second threshold, and the resource status difference value is less than the third threshold, generate a prompt instruction.
[0069] The second threshold (e.g., 0.8) is a moderate standard for model consistency (0.8 ≤ value < 0.95); the third threshold (e.g., 30) is the upper limit for resource discrepancies. The prompt instruction triggers manual review to compensate for the shortcomings of automated decision-making.
[0070] For example, the feature similarity value is 0.85 (first threshold 0.95, second threshold 0.8), and the resource status difference value is 20 (third threshold 30). The system generates a prompt requiring manual confirmation of the new model's reliability.
[0071] Step 4.5.1: Construct a notification message data packet containing feature similarity values, resource status difference values, and the current timestamp;
[0072] The notification message data packet is a structured data body containing key indicators (feature similarity values, resource status difference values) and timestamps (precise time stamps) to facilitate log traceability.
[0073] For example, the system automatically generates a JSON data packet, which provides a basis for decision-making and supports post-event auditing.
[0074] Step 4.5.2: Transmit the prompt message data packet to the monitoring terminal through the preset system log interface and / or human-computer interaction interface;
[0075] The system log interface is used for automatic logging; the human-machine interface (such as an HMI touchscreen) is used for operator interaction. Transmission ensures that data packets reach the monitoring terminal (such as a central control console).
[0076] For example, data packets are transmitted to the HMI interface (IP address 192.168.1.100) via Ethernet, alarm messages are displayed in real time, and the data is written to the system log file for easy double verification.
[0077] Step 4.5.3: Continuously monitor the user confirmation signal input within the preset delay time window.
[0078] The delay time window (e.g., 30 seconds) is a preset waiting period, during which the system continuously monitors user confirmation signals (e.g., button clicks or command input).
[0079] For example, the system starts a 30-second countdown, repeatedly checking for confirmation signals from the HMI terminal (such as when the operator presses the "Confirm" button). If no signal is received within the countdown, the process is aborted; if a signal is received, it continues.
[0080] Step 4.5.4: When a valid user confirmation signal is received, generate a switching permission flag.
[0081] The switching permission flag is a Boolean variable (e.g., 1 indicates permission), which is written to the PLC register to authorize subsequent switching operations.
[0082] For example, after operator confirmation, the system sets the flag value to 1 (binary 0001) at register address 0x3000, allowing the hot standby PLC to take over control.
[0083] Step 4.5.5: If no valid user confirmation signal is received within the delay time window, generate a handover abort command.
[0084] Switching abort commands are control commands (such as 0xFFFF) that terminate the upgrade process to prevent unauthorized switching.
[0085] For example, if no user confirmation is received after the delay window ends (30 seconds), the system outputs an abort command to the control bus (such as the CAN protocol), and the hot standby PLC remains in standby mode to avoid risky operations.
[0086] Step 4.6: When the feature similarity value is less than or equal to the second threshold, generate a rollback instruction or a fine-tuning instruction.
[0087] The second threshold (e.g., 0.8) is the minimum standard for model consistency (value ≤ 0.8). Rollback instructions unload the new model and restore the old version; fine-tuning instructions optimize model parameters based on differences.
[0088] For example, a feature similarity value of 0.75 (≤0.8) and a resource state difference value of 40. The system generates fine-tuning instructions (if the model is optimizable) or rollback instructions (if the risk is high) to ensure control stability to a certain extent.
[0089] Step 5: When the processing instruction is a fine-tuning instruction, fine-tune the new version of the AI model based on the difference between the new inference result and the old inference result, and regenerate the feature similarity value.
[0090] Fine-tuning refers to the process of optimizing the decision-making behavior of the new model by adjusting its weight parameters while keeping the overall structure of the new model unchanged. This step is triggered when the feature similarity value is too low (below the second threshold), and its purpose is to improve the consistency of decision-making between the new model and the old model, ensuring a safe transition.
[0091] For example, a feature similarity value of 0.75 (less than the second threshold of 0.8) triggers a fine-tuning instruction. The hot standby PLC optimizes the weights based on the differences between the old and new alarm results, increasing the similarity to 0.92.
[0092] Step 5.1: Analyze the alarm type distribution data and control parameter values in the new inference results to generate a new result data vector.
[0093] Alarm type distribution data refers to the statistical weight of each type of alarm (e.g., [temperature alarm: 0.6, vibration alarm: 0.3]); control parameter values refer to the numerical values of the executed commands (e.g., speed setpoint 1500 rpm). The new result data vector is a vector of these values converted into numerical values (e.g., [0.6, 0.3, 1500]).
[0094] For example, analyze the new inference result: alarm distribution {"Temperature exceeding limit": 0.7, Pressure abnormality: 0.2}, control parameter {Speed: 1200}. Generate a vector [0.7, 0.2, 1200], with a fixed vector dimension of 3 for easy subsequent calculations.
[0095] Step 5.2: Analyze the alarm type distribution data and control parameter values in the old inference results to generate an old result data vector.
[0096] The old result data vector is also generated based on the output of the main PLC, and its format is consistent with the new vector to ensure comparability.
[0097] For example, in the same production line, the old inference result is: alarm distribution {temperature exceeds limit: 0.5, pressure is abnormal: 0.4}, control parameter {speed: 1000}. Generate vector [0.5, 0.4, 1000].
[0098] Step 5.3: Calculate the difference vector between the new result data vector and the old result data vector.
[0099] The difference vector is the result of subtracting two vectors element by element, and it quantifies decision bias.
[0100] For example, given the new vector [0.7, 0.2, 1200] for production line A and the old vector [0.5, 0.4, 1000], the difference vector is calculated as [0.2, -0.2, 200]. This vector reveals that the new model is more sensitive to temperature alarms but more aggressive in speed control.
[0101] Step 5.4: Construct the model loss function based on the difference vector, and adjust the weight parameters of the new version of the AI model through the preset backpropagation algorithm.
[0102] The loss function converts the difference vector into a scalar loss value; the backpropagation algorithm updates the model weights (such as the parameters of fully connected layers) based on the gradient of the loss value.
[0103] For example, the difference vector is [0.15, -0.1, 50]. The loss function is constructed as (0.15). 2 +(-0.1) 2 +(50) 2 The weights of the new model are adjusted through two rounds of backpropagation (learning rate 0.001), which reduces the value of the loss function.
[0104] Step 5.5: Based on the new version of the AI model container with adjusted weight parameters, process the input data and generate the fine-tuned inference results.
[0105] A model container refers to the runtime environment (such as a Docker container) that encapsulates an AI model. After weight adjustments, the model needs to be reloaded for the changes to take effect. The post-adjustment inference result is the optimized output.
[0106] For example, after updating the model weights, the vibration sensor data (input waveform) is reprocessed to generate a fine-tuned inference result: alarm "Vibration normal" (original result "Vibration risk"), control command "Maintain speed" (original command "Reduce speed by 10%).
[0107] Step 5.6: Extract the feature vector of the fine-tuned inference result and execute the feature similarity value calculation process to regenerate the feature similarity value.
[0108] The process for calculating feature similarity values is the same as steps 3.1-3.3 (extracting feature vectors to calculate cosine similarity).
[0109] For example, the feature vector of the fine-tuned result is extracted as [0.5, 0.4, 0.1] (alarm weight), and the old result vector is [0.5, 0.3, 0.2]. The cosine similarity value is increased from 0.75 to 0.94 (> the first threshold of 0.95 requires further fine-tuning).
[0110] Step 5.7: Initialize the fine-tuning counter and set the maximum number of fine-tuning times threshold.
[0111] The fine-tuning counter records the current fine-tuning round; the maximum fine-tuning threshold (e.g., 100 times) prevents infinite loops.
[0112] For example, the system initializes the counter to 0 and sets the threshold to 100. If the similarity still does not meet the standard after the first round of fine-tuning, the fine-tuning counter increments.
[0113] Step 5.8: When the regenerated feature similarity value is less than the preset fine-tuning threshold, increment the count value of the fine-tuning counter.
[0114] The fine-tuning threshold (e.g., 0.95) is the target similarity for a single round of fine-tuning. If the threshold is not met, the fine-tuning counter is incremented by 1.
[0115] For example, if the fine-tuned feature similarity value is 0.92 (< fine-tuning threshold 0.95), the counter increases from 0 to 1, triggering the next round of optimization.
[0116] Step 5.9: Determine whether the count value of the fine-tuning counter has reached the maximum fine-tuning count threshold.
[0117] If the count value is greater than or equal to the threshold, the fine-tuning is deemed to have failed.
[0118] For example, when the counter reaches 100 (reaching the threshold), the system terminates fine-tuning and executes a rollback.
[0119] Step 5.10: If the count value of the fine-tuning counter reaches the maximum fine-tuning count threshold, a rollback instruction is triggered.
[0120] The rollback instruction is a control command that instructs the hot standby PLC to abandon the new model and revert to the old version.
[0121] For example, if the similarity is still less than 0.8 after 10 rounds of fine-tuning, continue fine-tuning; if the fine-tuning counter reaches 100, immediately trigger a rollback.
[0122] Step 5.11: Unload the currently loaded new version AI model container on the hot standby PLC.
[0123] Unloading refers to removing the model container from memory and releasing resources.
[0124] Step 5.12: Load the backup of the old version of the AI model container stored locally on the hot standby PLC.
[0125] Backups are pre-stored images of older models.
[0126] For example, a backup container can be loaded from the Flash storage of a hot standby PLC to restore the old model's operation and ensure control continuity.
[0127] Step 5.13: Output a rollback alarm message data packet containing the number of fine-tuning failures and the rollback status through the system log interface.
[0128] The rollback alert message data packet contains the number of fine-tuning failure rounds and the rollback result.
[0129] For example, data packets can be output to a central monitoring terminal to facilitate maintenance intervention.
[0130] Step 6: Switch the hot standby PLC to the main PLC and control the original main PLC to synchronize the new version of the AI model.
[0131] In a dual-PLC redundancy system, the process of transferring control from the original master PLC to the hot standby PLC involves the hot standby PLC becoming the new master PLC after the switchover, while the original master PLC enters a hot standby state. Synchronization refers to transmitting the new version of the AI model from the new master PLC to the original master PLC.
[0132] For example, when the feature similarity value reaches 0.95 and the resource status is normal, the system completes the master / standby switch. After the switch, the new master PLC (originally hot standby) controls the grain warehouse temperature and humidity control equipment, while the original master PLC synchronizes with the new model and switches to hot standby mode, ensuring uninterrupted monitoring of the entire grain warehouse.
[0133] Step 6.1: Send switching control signals to the control status registers of the main PLC and the hot standby PLC.
[0134] The control status register is a dedicated memory address in the PLC hardware that stores the operating mode. The switching control signal is a predefined instruction code, which is written to the register to trigger a mode change.
[0135] For example, the system writes instruction code 0x5AA5F00F to both the main PLC register address 0x2000 and the hot standby PLC register address 0x2000.
[0136] Step 6.2: Switch the hot standby PLC to master control mode to gain control of the equipment.
[0137] The master control mode grants the PLC control over the device, enabling it to output execution instructions (such as starting and stopping the device, and adjusting parameters).
[0138] Step 6.3: Switch the original main PLC's operating mode to hot standby mode and release control of the equipment.
[0139] Hot standby mode puts the PLC into standby mode, stopping the output of control commands but still synchronizing data, ready to take over in case of failure.
[0140] Step 6.4: Transfer the image file data of the new version AI model container to the original main PLC through a preset shared memory area or communication link.
[0141] The shared memory area is a high-speed memory space shared by both PLCs; the communication link refers to the network protocol channel. The model image is a complete file package containing the AI model's weights and configuration.
[0142] The above are embodiments of the method proposed in this application. Based on the same inventive concept, embodiments of this application also provide an AI model upgrade device based on dual PLCs, the structure of which is as follows: Figure 2 As shown.
[0143] Figure 2 This is a schematic diagram of the internal structure of an AI model upgrade device based on dual PLCs, provided as an embodiment of this application. Figure 2 As shown, the device includes:
[0144] At least one processor 201;
[0145] And a memory 202 that is communicatively connected to at least one processor;
[0146] The memory 202 stores instructions executable by at least one processor, which are executed by at least one processor 201 to enable at least one processor 201 to:
[0147] The new version of the AI model is loaded via a hot standby PLC; the input data of the main PLC is synchronized via the hot standby PLC, and the input data is processed based on the new version of the AI model to generate a new inference result; the new inference result is compared with the old inference result generated by the main PLC based on the old version of the AI model to determine the feature similarity value; the processing instructions are determined based on the feature similarity value, the device status of the main PLC, and the device status of the hot standby PLC; the processing instructions include prompt instructions, rollback instructions, and fine-tuning instructions; when the processing instruction is a fine-tuning instruction, the new version of the AI model is fine-tuned based on the difference between the new and old inference results, and the feature similarity value is regenerated; the hot standby PLC is switched to the main PLC, and the original main PLC is controlled to synchronize the new version of the AI model.
[0148] Some embodiments of this application provide corresponding to Figure 1 A non-volatile computer storage medium for upgrading AI models based on dual PLCs, storing computer-executable instructions, wherein the computer-executable instructions are configured as follows:
[0149] A new version of the AI model is loaded via a hot standby PLC; the input data of the main PLC is synchronized via the hot standby PLC, and the input data is processed based on the new version of the AI model to generate a new inference result; the new inference result is compared with the old inference result generated by the main PLC based on the old version of the AI model to determine the feature similarity value; processing instructions are determined based on the feature similarity value, the device status of the main PLC, and the device status of the hot standby PLC; the processing instructions include prompt instructions, rollback instructions, and fine-tuning instructions; when the processing instruction is a fine-tuning instruction, the new version of the AI model is fine-tuned based on the difference between the new and old inference results, and the feature similarity value is regenerated; the hot standby PLC is switched to the main PLC, and the original main PLC is controlled to synchronize the new version of the AI model. The various embodiments in this application are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the IoT device and media embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and relevant parts can be referred to the description of the method embodiments.
[0150] The systems, media, and methods provided in this application are one-to-one correspondences. Therefore, the systems and media also have similar beneficial technical effects as their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the systems and media will not be repeated here.
[0151] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0152] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0153] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0154] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0155] In a typical configuration, a computing device includes one or more processors (PLCs), input / output interfaces, network interfaces, and memory.
[0156] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0157] Computer-readable media include both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0158] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0159] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A dual-PLC-based AI model upgrading method applied to a PLC control system, the PLC control system comprising a master PLC and a hot-standby PLC which are hot standby to each other, characterized in that, The method comprises: loading a new version of an AI model by the hot backup PLC; synchronizing input data of the main PLC by the hot backup PLC, and processing the input data based on the new version of the AI model to generate a new inference result; comparing the new inference result with an old inference result generated by the main PLC based on an old version of the AI model to determine a feature similarity value; determining a processing instruction based on the feature similarity value, a device state of the main PLC, and a device state of the hot backup PLC; wherein the processing instruction comprises a prompt instruction, a rollback instruction, and a fine-tuning instruction; when the processing instruction is the fine-tuning instruction, fine-tuning the new version of the AI model based on a difference between the new inference result and the old inference result, and regenerating the feature similarity value; switching the hot backup PLC to the main PLC, and controlling the original main PLC to synchronize the new version of the AI model. 2.The AI model upgrading method based on double PLCs according to claim 1, wherein, synchronizing input data of the main PLC by the hot backup PLC, and processing the input data based on the new version of the AI model to generate a new inference result, specifically comprising: establishing a communication connection with the main PLC by the hot backup PLC to obtain input data of the main PLC; wherein the input data at least comprises monitoring data and device state data collected by a sensor; performing inference operation on the input data by the hot backup PLC using the new version of the AI model to obtain an inference intermediate result; generating a new processing result based on the inference intermediate result; wherein the new processing result comprises alarm information and / or a control command. 3.The AI model upgrading method based on double PLCs according to claim 1, wherein, comparing the new inference result with an old inference result generated by the main PLC based on an old version of the AI model to determine a feature similarity value, specifically comprising: obtaining an old processing result output by the main PLC; wherein the old processing result is alarm information and / or a control command generated based on the old version of the AI model; extracting feature vectors of the new processing result and the old processing result to obtain a new feature vector and an old feature vector; processing similarity of the new feature vector and the old feature vector based on a preset cosine similarity algorithm to obtain the feature similarity value. 4.The AI model upgrading method based on double PLCs according to claim 1, wherein, determining a processing instruction based on the feature similarity value, a device state of the main PLC, and a device state of the hot backup PLC, specifically comprising: obtaining CPU occupancy, memory usage, and communication delay of the main PLC to determine the device state of the main PLC; obtaining CPU occupancy, memory usage, and communication delay of the hot backup PLC to determine the device state of the hot backup PLC; calculating an absolute difference value of the device state of the main PLC and the device state of the hot backup PLC to generate a resource state difference value; when the feature similarity value is greater than or equal to a first threshold value, no instruction is generated; when the feature similarity value is less than the first threshold value and greater than a second threshold value, and the resource state difference value is less than a third threshold value, a prompt instruction is generated; when the feature similarity value is less than or equal to the second threshold value, a rollback instruction or a fine-tuning instruction is generated. 5.The AI model upgrading method based on double PLCs according to claim 4, wherein, generate a prompt instruction when the feature similarity value is less than a first threshold and greater than a second threshold, and the resource state difference value is less than a third threshold, specifically including: constructing a prompt message data packet containing the feature similarity value, the resource state difference value, and a current timestamp; transmitting the prompt message data packet to a monitoring terminal through a pre-set system log interface and / or a human-computer interaction interface; continuously monitoring user confirmation signal input within a pre-set delay time window; generating a switching permission flag when a valid user confirmation signal input is received; generating a switching termination instruction when a valid user confirmation signal input is not received within the delay time window.
6. The AI model upgrading method based on double PLCs according to claim 1, wherein when the processing instruction is a fine-tuning instruction, fine-tuning the new version AI model based on the difference between the new inference result and the old inference result, and re-generating a feature similarity value, specifically including: parsing the alarm type distribution data and control parameter values in the new inference result to generate a new result data vector; parsing the alarm type distribution data and control parameter values in the old inference result to generate an old result data vector; calculating a difference vector between the new result data vector and the old result data vector; constructing a model loss function based on the difference vector, and adjusting the weight parameters of the new version AI model container through a pre-set back propagation algorithm; processing the input data based on the new version AI model container with adjusted weight parameters to generate a fine-tuned inference result; extracting the feature vector of the fine-tuned inference result, and executing a feature similarity value calculation process to re-generate a feature similarity value.
7. The AI model upgrading method based on double PLCs according to claim 6, characterized in that, The method further includes: initializing a fine-tuning counter and setting a maximum fine-tuning number threshold; incrementing the count value of the fine-tuning counter when the re-generated feature similarity value is less than a pre-set fine-tuning threshold; determining whether the count value of the fine-tuning counter reaches the maximum fine-tuning number threshold; if the count value of the fine-tuning counter reaches the maximum fine-tuning number threshold, triggering a rollback instruction: unloading the new version AI model container currently loaded by the hot standby PLC; loading a backup of the old version AI model container stored locally by the hot standby PLC; outputting a rollback alarm message data packet containing the number of fine-tuning failures and the rollback state through a system log interface. 8.The AI model upgrading method based on double PLCs according to claim 1, wherein, switching the hot standby PLC to the main PLC, and controlling the original main PLC to synchronize the new version AI model, specifically including: sending a switching control signal to the control state registers of the main PLC and the hot standby PLC; switching the operating mode of the hot standby PLC to a master mode to obtain device control; switching the operating mode of the original main PLC to a hot standby mode to release device control; transmitting the image file data of the new version AI model container to the original main PLC through a pre-set shared memory area or communication link. 9.A dual-PLC based AI model upgrading device, comprising: The device includes: at least one processor; and a memory in communication connection with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to: Load a new version of an AI model through a hot-standby PLC; Synchronize input data of the main PLC through the hot-standby PLC, and process the input data based on the new version of the AI model to generate a new inference result; Compare the new inference result with an old inference result generated by the main PLC based on an old version of the AI model to determine a feature similarity value; Determine a processing instruction based on the feature similarity value, a device state of the main PLC, and a device state of the hot-standby PLC; wherein the processing instruction comprises a prompt instruction, a rollback instruction, and a fine-tuning instruction; When the processing instruction is the fine-tuning instruction, fine-tune the new version of the AI model based on a difference between the new inference result and the old inference result, and regenerate the feature similarity value; Switch the hot-standby PLC to the main PLC, and control the original main PLC to synchronize the new version of the AI model. 10.A non-transitory computer storage medium storing computer-executable instructions for AI model upgrading based on dual-PLC, the computer-executable instructions comprising: The computer executable instructions are configured to: Load a new version of an AI model through a hot-standby PLC; Synchronize input data of the main PLC through the hot-standby PLC, and process the input data based on the new version of the AI model to generate a new inference result; Compare the new inference result with an old inference result generated by the main PLC based on an old version of the AI model to determine a feature similarity value; Determine a processing instruction based on the feature similarity value, a device state of the main PLC, and a device state of the hot-standby PLC; wherein the processing instruction comprises a prompt instruction, a rollback instruction, and a fine-tuning instruction; When the processing instruction is the fine-tuning instruction, fine-tune the new version of the AI model based on a difference between the new inference result and the old inference result, and regenerate the feature similarity value; Switch the hot-standby PLC to the main PLC, and control the original main PLC to synchronize the new version of the AI model.
Citation Information
Patent Citations
Switching scheme of PLC dual system, switching method of PLC dual system
JP2019219894A
Dual-machine hot standby management method and computing device
WO2025092543A1