CN104009735B - Implementation method of the Kalman filter in 300 series of PLC of S7 - Google Patents
Implementation method of the Kalman filter in 300 series of PLC of S7 Download PDFInfo
- Publication number
- CN104009735B CN104009735B CN201410230791.7A CN201410230791A CN104009735B CN 104009735 B CN104009735 B CN 104009735B CN 201410230791 A CN201410230791 A CN 201410230791A CN 104009735 B CN104009735 B CN 104009735B
- Authority
- CN
- China
- Prior art keywords
- matrix
- kalman filter
- data block
- plc
- calculated
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
- 238000000034 method Methods 0.000 title claims abstract description 15
- 239000011159 matrix material Substances 0.000 claims abstract description 96
- 238000004364 calculation method Methods 0.000 claims abstract description 12
- 238000003860 storage Methods 0.000 claims abstract description 10
- 239000013598 vector Substances 0.000 claims description 10
- 238000001914 filtration Methods 0.000 claims description 4
- 238000005259 measurement Methods 0.000 claims description 3
- 230000014759 maintenance of location Effects 0.000 claims 1
- 230000006870 function Effects 0.000 abstract description 3
- 238000005070 sampling Methods 0.000 abstract 1
- 230000008569 process Effects 0.000 description 4
- 230000000694 effects Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 3
- 238000004519 manufacturing process Methods 0.000 description 3
- 238000004891 communication Methods 0.000 description 2
- 238000010586 diagram Methods 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 230000001934 delay Effects 0.000 description 1
- 238000003745 diagnosis Methods 0.000 description 1
- 238000009826 distribution Methods 0.000 description 1
- 230000004927 fusion Effects 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 230000008520 organization Effects 0.000 description 1
- 238000004886 process control Methods 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 238000011160 research Methods 0.000 description 1
- 230000009466 transformation Effects 0.000 description 1
- 230000007704 transition Effects 0.000 description 1
Landscapes
- Complex Calculations (AREA)
- Feedback Control In General (AREA)
Abstract
本发明公开了一种卡尔曼滤波器在S7‑300系列PLC中的实现方法和具体的实现步骤。在S7‑300系列PLC系统中定义16个数据块,其中的14个数据块和卡尔曼滤波器迭代算式中的各个矩阵变量一一对应,余下两个数据块用于矩阵运算的暂存。将卡尔曼滤波器迭代算式中若干变量的存取操作转化为S7‑300系列PLC系统对应数据块中变量的存取操作。使用PLC系统的指令系统,直接实现矩阵的加减运算、乘法运算、逆运算和卡尔曼滤波器迭代算式。卡尔曼滤波器的计算时间相对确定,且实际应用中的每个采样周期多为单次迭代,通过合理设置PLC系统的警戒定时器,扩充的卡尔曼滤波器功能不会影响PLC系统的正常扫描功能,并为其高级应用提供了新的手段。
The invention discloses a realization method and specific realization steps of a Kalman filter in an S7-300 series PLC. In the S7-300 series PLC system, 16 data blocks are defined, 14 of which correspond to each matrix variable in the Kalman filter iterative formula, and the remaining two data blocks are used for temporary storage of matrix operations. The access operation of several variables in the Kalman filter iterative formula is transformed into the access operation of variables in the corresponding data block of the S7‑300 series PLC system. Using the command system of the PLC system, directly realize matrix addition and subtraction operations, multiplication operations, inverse operations and Kalman filter iterative calculations. The calculation time of the Kalman filter is relatively fixed, and each sampling period in practical applications is mostly a single iteration. By setting the alarm timer of the PLC system reasonably, the expanded Kalman filter function will not affect the normal scanning of the PLC system. functions and provide new means for its advanced applications.
Description
技术领域technical field
本发明属于自动化技术领域,涉及卡尔曼滤波器在S7-300系列PLC中的实现方法。The invention belongs to the technical field of automation and relates to a realization method of a Kalman filter in an S7-300 series PLC.
背景技术Background technique
可编程序控制器(PLC),工业控制微机(主要是IPC)、集散控制系统(DCS)/现场总线控制系统(FCS)和智能控制仪表,是工业自动化领域常用的四大类控制装置。其中,PLC凭借其高可靠性和易用性,在工业自动化工程中的应用最为广泛。大中型PLC主要用于复杂生产线控制、顺序控制、批量控制和流程工业控制。在众多的大中型PLC系统中,西门子的S7-300或S7-400系列PLC凭借其良好的体系结构、网络功能、集成技术和技术支持,已成为我国广泛应用的大中型PLC系统之一。Programmable logic controller (PLC), industrial control microcomputer (mainly IPC), distributed control system (DCS)/field bus control system (FCS) and intelligent control instrument are the four major types of control devices commonly used in the field of industrial automation. Among them, PLC is most widely used in industrial automation engineering due to its high reliability and ease of use. Large and medium-sized PLCs are mainly used for complex production line control, sequence control, batch control and process industry control. Among many large and medium-sized PLC systems, Siemens' S7-300 or S7-400 series PLC has become one of the large and medium-sized PLC systems widely used in my country by virtue of its good architecture, network functions, integrated technology and technical support.
卡尔曼(Kalman)于1960年提出了一种滤波和预报算法,即卡尔曼滤波器,该算法提供了一种高效可计算的方法来估计过程的状态,并使估计值均方误差最小,现已广泛应用于机器人导航、过程控制、数据融合、雷达系统、导弹追踪等,用于解决参数估计、状态预报和工业过程故障诊断等问题。In 1960, Kalman proposed a filtering and forecasting algorithm, the Kalman filter, which provides an efficient and computable method to estimate the state of the process and minimize the mean square error of the estimated value. It has been widely used in robot navigation, process control, data fusion, radar system, missile tracking, etc., to solve problems such as parameter estimation, state prediction and industrial process fault diagnosis.
当前广泛使用的PLC系统按照IEC61131-3国际标准提供编程语言和指令系统,各PLC系统厂家尚未提供卡尔曼滤波器模块或指令库。卡尔曼滤波器涉及到复杂的矩阵运算,当今的研究或应用多采用基于PC的Matlab平台或C语言平台。现有技术必须先从PLC系统等控制设备中获取观测数据,接着通过PC机的Matlab平台,完成卡尔曼滤波器的复杂计算,最后将计算结果形成控制量再回传到PLC,由PLC系统实现工业过程的控制。现有技术需要周而复始地从PLC系统获取数据和传输优化信息到PLC系统,需要借助于通信网络和PC平台,协同完成先进控制系统中的状态估计或优化控制等。The currently widely used PLC system provides programming language and command system according to the IEC61131-3 international standard, and each PLC system manufacturer has not yet provided the Kalman filter module or command library. The Kalman filter involves complex matrix operations, and today's research or application mostly uses the PC-based Matlab platform or C language platform. In the existing technology, observation data must be obtained from PLC system and other control equipment first, and then the complex calculation of the Kalman filter is completed through the Matlab platform of the PC, and finally the calculation result is formed into a control quantity and then sent back to the PLC, which is realized by the PLC system Control of industrial processes. The existing technology needs to repeatedly obtain data from the PLC system and transmit optimization information to the PLC system. It needs to rely on the communication network and the PC platform to cooperate to complete the state estimation or optimal control in the advanced control system.
现有技术方案需要PC系统和PLC系统之间周而复始地交换数据,需要配备PC机、Windows平台、Matlab平台和通信网络。网络故障,尤其是固有存在的网络时延都将影响卡尔曼滤波器的应用效果。此外,工业环境的高要求也对PC平台的运行环境提出了挑战,增加的PC平台还会导致系统的成本的增加。The prior art solution needs to exchange data repeatedly between the PC system and the PLC system, and needs to be equipped with a PC, a Windows platform, a Matlab platform and a communication network. Network faults, especially inherent network delays, will affect the application effect of the Kalman filter. In addition, the high requirements of the industrial environment also pose challenges to the operating environment of the PC platform, and the increased PC platform will also lead to an increase in the cost of the system.
因此,如何直接在PLC系统中实现卡尔曼滤波器是自动化工程界一直追求的目标。Therefore, how to directly realize the Kalman filter in the PLC system is the goal that the automation engineering circles have been pursuing.
发明内容Contents of the invention
本发明提供了卡尔曼滤波器在S7-300系列PLC中的实现方法,解决了目前卡尔曼滤波器在PLC中实现的方法复杂的问题。The invention provides a method for realizing the Kalman filter in the S7-300 series PLC, and solves the problem that the method for realizing the Kalman filter in the PLC is complicated at present.
借助于西门子S7-300系列PLC中的数据块,将卡尔曼滤波器矩阵之间的各类存取和运算,转换为数据块之间各个元素的存取和运算,使用西门子S7-300系列PLC的指令系统实现矩阵的加、减、乘和逆运算,再依据卡尔曼滤波器的迭代算式和S7-300系列PLC提供的模块程序设计方法,按步骤在PLC中实现卡尔曼滤波器。With the help of data blocks in Siemens S7-300 series PLC, various accesses and operations between Kalman filter matrices are converted into accesses and operations of each element between data blocks, using Siemens S7-300 series PLC The instruction system realizes the addition, subtraction, multiplication and inverse operation of the matrix, and then implements the Kalman filter in the PLC step by step according to the iterative formula of the Kalman filter and the module programming method provided by the S7-300 series PLC.
本发明采用的技术方案为将卡尔曼滤波器迭代算式中若干矩阵变量的存取操作转化为S7-300系列PLC系统对应数据块中变量的存取操作,并在PLC系统中实现了矩阵的加减运算、乘法运算和逆运算。The technical solution adopted by the present invention is to convert the access operations of several matrix variables in the Kalman filter iterative formula into the access operations of the variables in the corresponding data blocks of the S7-300 series PLC system, and realize the addition and retrieval of the matrix in the PLC system. Subtraction, multiplication and inverse operations.
进一步,卡尔曼滤波器在S7-300系列PLC中的实现方法的步骤为:Further, the steps for implementing the Kalman filter in the S7-300 series PLC are:
步骤1:定义数据块DB1~DB14,存放卡尔曼滤波器算式中的变量;DB1~DB6分别存放卡尔曼滤波器迭代算式中的矩阵变量X(k)、Φ(k)、Η(k)、y(k)、ω(k)和v(k),数据块DB7存放状态估计值向量DB8存放状态一步预测值向量DB9存放滤波增益矩阵K(k),DB10存放估计误差的协方差矩阵P(k-1,k-1),DB11存放协方差矩阵的一步预测值P(k,k-1),DB12存放Q,DB13存放R,DB14存放单位矩阵I;Step 1: define data block DB1~DB14, store the variable in the Kalman filter formula; DB1~DB6 respectively store the matrix variable X(k), Φ(k), Η(k), y(k), ω(k) and v(k), the data block DB7 stores the state estimation value vector DB8 stores state one-step predicted value vector DB9 stores the filter gain matrix K(k), DB10 stores the covariance matrix P(k-1,k-1) of the estimated error, DB11 stores the one-step predicted value P(k,k-1) of the covariance matrix, and DB12 stores Q , DB13 stores R, and DB14 stores the identity matrix I;
步骤2:计算卡尔曼滤波器的一步预测值,分别从数据块DB7和DB2中取出和Φ(k),按下式计算卡尔曼滤波器的一步预测值 Step 2: Calculate the one-step predicted value of the Kalman filter, which is taken from the data blocks DB7 and DB2 respectively and Φ(k), calculate the one-step predicted value of the Kalman filter as follows
将存于数据块DB8;Will Stored in data block DB8;
步骤3:计算状态估计值,分别从数据块DB8、DB9、DB3、DB4中取出K(k)、H(k)和y(k),按下式计算状态估计值 Step 3: Calculate the estimated value of the state and take it out from the data blocks DB8, DB9, DB3, and DB4 respectively K(k), H(k) and y(k), calculate the state estimation value according to the following formula
使用更新DB7中的 use Update DB7 in
步骤4:计算滤波增益矩阵,分别从数据块DB11、DB3和DB13中取出P(k,k-1)、H(k)和R,按下式计算滤波增益矩阵K(k):Step 4: Calculate the filter gain matrix, take out P(k,k-1), H(k) and R from the data blocks DB11, DB3 and DB13 respectively, and calculate the filter gain matrix K(k) as follows:
K(k)=P(k,k-1)HT(k)[H(k)P(k,k-1)HT(k)+R]-1 K(k)=P(k,k-1) HT (k)[H(k)P(k,k-1) HT (k)+R] -1
将K(k)存于数据块DB9;Store K(k) in data block DB9;
步骤5:计算误差协方差阵的一步预测值,分别从数据块DB2、DB10、DB12取出Φ(k)、P(k-1,k-1)和Q,按下式计算误差协方差阵的一步预测值P(k,k-1):Step 5: Calculate the one-step predicted value of the error covariance matrix, take out Φ(k), P(k-1,k-1) and Q from the data blocks DB2, DB10, and DB12 respectively, and calculate the error covariance matrix by the following formula One-step predictive value P(k,k-1):
P(k,k-1)=Φ(k)P(k-1,k-1)ΦT(k)+QP(k,k-1)=Φ(k)P(k-1,k-1) ΦT (k)+Q
将P(k,k-1)存于数据块DB11;Store P(k,k-1) in data block DB11;
步骤6:计算估计误差的协方差矩阵,分别从数据块DB14、DB9、DB3和DB11中取出I、K(k)、H(k)和P(k,k-1),按下式计算估计误差的协方差矩阵P(k,k):Step 6: Calculate the covariance matrix of the estimation error, take out I, K(k), H(k) and P(k,k-1) from the data blocks DB14, DB9, DB3 and DB11 respectively, and calculate the estimation according to the following formula Error covariance matrix P(k,k):
P(k,k)=[I-K(k)H(k)]P(k,k-1)P(k,k)=[I-K(k)H(k)]P(k,k-1)
使用P(k,k)更新DB10中的P(k-1,k-1),至此,完成卡尔曼滤波器的一次迭代运算。Use P(k,k) to update P(k-1,k-1) in DB10, so far, an iterative operation of the Kalman filter is completed.
本发明的有益效果是方法简单,成本低。The beneficial effect of the invention is that the method is simple and the cost is low.
附图说明Description of drawings
图1是PLC系统进行加减运算的两矩阵元素的存放示例图;Fig. 1 is a storage example diagram of two matrix elements for addition and subtraction in the PLC system;
图2是PLC系统进行乘法运算的两矩阵元素的存放示例图;Fig. 2 is the storage example figure of two matrix elements that PLC system carries out multiplication operation;
图3是PLC系统中的矩阵元素存取流程图;Fig. 3 is a matrix element access flow chart in the PLC system;
图4是PLC系统中的矩阵加减运算流程图;Fig. 4 is the flow chart of matrix addition and subtraction in the PLC system;
图5是PLC系统中的矩阵乘法运算流程图;Fig. 5 is a flow chart of matrix multiplication in the PLC system;
图6是PLC系统中的矩阵行列式计算流程图;Fig. 6 is the matrix determinant calculation flowchart in PLC system;
图7是PLC系统中的伴随矩阵计算流程图;Fig. 7 is the accompanying matrix calculation flowchart in the PLC system;
图8是PLC系统中的矩阵逆运算流程图;Fig. 8 is the flow chart of matrix inverse operation in the PLC system;
图9是PLC系统中的卡尔曼滤波器用到的程序块和数据块图;Fig. 9 is a program block and a data block diagram used by the Kalman filter in the PLC system;
图10是PLC系统中的卡尔曼滤波器跟踪小球运动轨迹图;Fig. 10 is a Kalman filter in the PLC system to track the motion trajectory of the ball;
图11是Matlab提供的卡尔曼滤波器跟踪小球运动轨迹图。Figure 11 is a Kalman filter provided by Matlab to track the trajectory of the ball.
具体实施方式detailed description
下面结合附图和具体实施方式对本发明进行详细说明。The present invention will be described in detail below in conjunction with the accompanying drawings and specific embodiments.
本发明首先使用S7-300系列PLC系统中的数据块定义矩阵,实现卡尔曼滤波器的迭代运算需要定义14个矩阵或向量,考虑到矩阵运算还需要暂存,共定义16个矩阵,对应PLC系统的16个数据块,数据块编号为DB1~DB16。其次,将矩阵的加、减、乘和逆运算转换为基本的矩阵元素的四则运算,通过存取对应的数据块访问参与运算的矩阵,使用S7-300系列PLC的浮点数运算指令分别实现矩阵的加、减、乘和逆运算。最后,按下列六个步骤实现卡尔曼滤波器的迭代运算,其中第一步只进行一次,后续五步为每进行一次卡尔曼滤波器迭代计算的步骤。The present invention first uses the data blocks in the S7-300 series PLC system to define the matrix, and to realize the iterative operation of the Kalman filter needs to define 14 matrices or vectors. Considering that the matrix operation needs to be temporarily stored, a total of 16 matrices are defined, corresponding to the PLC There are 16 data blocks in the system, and the data block numbers are DB1~DB16. Secondly, the addition, subtraction, multiplication and inverse operations of the matrix are converted into the four arithmetic operations of basic matrix elements, and the matrices involved in the operation are accessed by accessing the corresponding data block, and the matrix is respectively realized by using the floating-point operation instructions of the S7-300 series PLC addition, subtraction, multiplication and inverse operations. Finally, implement the iterative calculation of the Kalman filter according to the following six steps, in which the first step is performed only once, and the subsequent five steps are steps for each Kalman filter iterative calculation.
卡尔曼滤波器在S7-300系列PLC系统中的实现步骤如下:The implementation steps of the Kalman filter in the S7-300 series PLC system are as follows:
步骤1:定义数据块DB1~DB14,存放卡尔曼滤波器算式中的变量。Step 1: Define data blocks DB1~DB14 to store the variables in the Kalman filter formula.
1.使用PLC系统中的数据块定义矩阵:1. Use the data blocks in the PLC system to define the matrix:
S7-300系列PLC系统内部数量最多的软元件是数据块,其数量可达1024个,每个数据块的容量最大为64KB。S7-300系列PLC支持单精度浮点数(占用4字节,类型为Real),如果使用每个数据块对应一个矩阵,则矩阵最大可定义128×128的方阵,足够满足多数实际工程系统的需求。将每个数据块对应一个矩阵后,矩阵之间的相互操作则转为数据块之间的操作。The largest number of soft components in the S7-300 series PLC system are data blocks, the number of which can reach 1024, and the maximum capacity of each data block is 64KB. The S7-300 series PLC supports single-precision floating-point numbers (occupies 4 bytes, and the type is Real). If each data block corresponds to a matrix, the matrix can define a square matrix of 128×128 at most, which is enough to meet the needs of most practical engineering systems. need. After each data block corresponds to a matrix, the mutual operation between matrices is transformed into the operation between data blocks.
(1)参与加减运算的两个矩阵具有相同的行数和列数,两个矩阵的各元素在两个数据块中的结构完全相同,均采用按行依次定义,如图1所示(以3×3维矩阵为例)。两个m×n矩阵的元素aij和bij的地址指针均按下述公式进行计算:(1) The two matrices participating in the addition and subtraction operations have the same number of rows and columns, and the structures of the elements of the two matrices in the two data blocks are exactly the same, and they are all defined by row, as shown in Figure 1 ( Take a 3×3 dimensional matrix as an example). The address pointers of the elements ai j and bi j of the two m×n matrices are calculated according to the following formula:
ptr=[(i-1)n+(j-1)]×4ptr=[(i-1)n+(j-1)]×4
(2)如果参与乘法运算的两个矩阵仍然按行依次进行元素存放,则需要分别计算地址指针,导致计算量翻倍;为此,将乘数矩阵按列依次进行数据元素的存放,如图2所示(以3×3维矩阵为例)。一个m×n维矩阵A乘以一个n×p维矩阵B,获得一个m×p维矩阵C。(2) If the elements of the two matrices involved in the multiplication operation are still stored sequentially by row, the address pointers need to be calculated separately, resulting in double the amount of calculation; for this reason, the multiplier matrix is stored sequentially by column, as shown in the figure 2 (taking a 3×3 dimensional matrix as an example). An m×n dimensional matrix A is multiplied by an n×p dimensional matrix B to obtain an m×p dimensional matrix C.
按图2所示的数据结构存放两个矩阵时,则元素aik和bkj在两个数据块中的地址指针相同,只需按(1)所述的公式计算1次。When the two matrices are stored according to the data structure shown in Figure 2, the address pointers of the elements a ik and bk j in the two data blocks are the same, and it only needs to be calculated once according to the formula described in (1).
2.在S7-300系列PLC系统中实现矩阵的运算:2. Realize matrix operation in S7-300 series PLC system:
在S7-300系列PLC系统中实现矩阵运算,需解决矩阵元素的存取,矩阵的加减运算、矩阵乘法运算和矩阵的逆运算等问题。To realize the matrix operation in the S7-300 series PLC system, it is necessary to solve the access of matrix elements, the addition and subtraction of the matrix, the multiplication of the matrix and the inverse operation of the matrix.
(1)矩阵元素的存取:(1) Access to matrix elements:
矩阵元素的存取包括矩阵元素的读和写操作,都是针对给定的矩阵进行操作,因此,矩阵元素的读写操作可以由同一个程序模块实现,其实现流程如图3所示。程序编号为FC1,其输入参数为:数据块编号DBno,矩阵行数m,列数n,读写元素所在行i和列j,读写标志WR(1为写操作,0为读操作);输入输出参数为:dat(WR=1,dat为待写数据;WR=0时,dat为所读到的数据)。The access of matrix elements includes the read and write operations of matrix elements, which are all operated on a given matrix. Therefore, the read and write operations of matrix elements can be realized by the same program module, and its implementation process is shown in Figure 3. The program number is FC1, and its input parameters are: data block number DBno, matrix row number m, column number n, row i and column j of read and write elements, read and write flag WR (1 is write operation, 0 is read operation); The input and output parameters are: dat (WR=1, dat is the data to be written; when WR=0, dat is the read data).
(2)矩阵的加减运算:(2) Matrix addition and subtraction:
矩阵的加减运算规则相似,因此可以将矩阵的加减运算设计为一个模块,其名称为FC2,其实现流程如图4所示。输入参数为:数据块编号DBNo1、DBNo2、DBNo3,矩阵的行数m,列数n;加减标志PorM(1:加法,0:减法);无输出参数。The addition and subtraction operation rules of matrix are similar, so the addition and subtraction operation of matrix can be designed as a module, its name is FC2, and its implementation process is shown in Figure 4. The input parameters are: data block numbers DBNo1, DBNo2, DBNo3, the number of rows of the matrix m, the number of columns n; addition and subtraction flag PorM (1: addition, 0: subtraction); no output parameters.
(3)矩阵的乘法运算:(3) Matrix multiplication:
矩阵的乘法运算的流程如图5所示,模块名称为FC3。输入参数为:数据块编号DBNo1、DBNo2、DBNo3,被乘数矩阵的行数m、列数n,乘数矩阵的行数n、列数p;无输出参数。一个m×n维矩阵A乘以一个n×p维矩阵B,获得一个m×p维矩阵C,矩阵C中的每个元素cij按下列公式进行计算:The flow of matrix multiplication operation is shown in Figure 5, and the module name is FC3. The input parameters are: data block numbers DBNo1, DBNo2, DBNo3, the number of rows m and the number of columns of the multiplicand matrix, the number of rows n and the number of columns of the multiplier matrix; no output parameters. An m×n dimensional matrix A is multiplied by an n×p dimensional matrix B to obtain an m×p dimensional matrix C, and each element ci j in the matrix C is calculated according to the following formula:
共需要n次乘法和(n-1)次加法运算,因此,矩阵的乘法运算需要较大的运算处理量,需要合理设置S7-300系列PLC系统的警戒定时器。A total of n times of multiplication and (n-1) times of addition are required. Therefore, the multiplication of the matrix requires a large amount of computing processing, and the alarm timer of the S7-300 series PLC system needs to be set reasonably.
(4)矩阵的逆运算:(4) Inverse operation of matrix:
矩阵的逆运算程序模块名称为FC4,输入参数:数据块DBno1、DBNo2,矩阵行数m、列数n;无输出参数。PLC系统的矩阵逆运算按如下步骤进行:The name of the matrix inverse operation program module is FC4, input parameters: data blocks DBno1, DBNo2, matrix row number m, column number n; no output parameters. The matrix inverse operation of the PLC system is carried out as follows:
第一步:通过初等变换角计算矩阵A的行列式A,程序流程如图6所示;The first step: Calculate the determinant A of the matrix A through the elementary transformation angle, and the program flow is shown in Figure 6;
第二步:利用代数余子式计算A的伴随矩阵A*,程序流程如图7所示;The second step: use the algebraic remainder to calculate the adjoint matrix A * of A, the program flow is shown in Figure 7;
第三步:按下列公式计算A的逆矩阵A-1,程序流程如图8所示。Step 3: Calculate the inverse matrix A -1 of A according to the following formula, and the program flow is shown in FIG. 8 .
基于上述已经实现的矩阵定义及其运算,按照卡尔曼滤波器的迭代公式,循环调用上述已经实现的矩阵运算类程序模块,即可在PLC系统中实现卡尔曼滤波器。首先定义数据块DB1~DB14,存放卡尔曼滤波器算式中的变量Based on the above-mentioned realized matrix definition and its operation, according to the iteration formula of the Kalman filter, the Kalman filter can be realized in the PLC system by cyclically calling the above-mentioned realized matrix operation program module. First define the data blocks DB1~DB14 to store the variables in the Kalman filter formula
按下列所示线性系统离散状态方程,DB1~DB6分别存放其对应的矩阵变量X(k)、Φ(k)、Η(k)、y(k)、ω(k)和v(k)。According to the discrete state equation of the linear system shown below, DB1~DB6 store their corresponding matrix variables X(k), Φ(k), Η(k), y(k), ω(k) and v(k) respectively.
X(k)是状态向量;y(k)是观测向量;ω(k)是系统噪声;v(k)是观测噪声向量;Φ(k)是非奇异状态转移矩阵;H(k)是观测矩阵。ω(k)和v(k)为互不相关的零均值、方差分别为Q和R的高斯白噪声。X(k) is the state vector; y(k) is the observation vector; ω(k) is the system noise; v(k) is the observation noise vector; Φ(k) is the non-singular state transition matrix; H(k) is the observation matrix . ω(k) and v(k) are uncorrelated Gaussian white noise with zero mean and variance Q and R respectively.
数据块DB7存放状态估计值向量DB8存放状态一步预测值向量DB9存放滤波增益矩阵K(k),DB10存放估计误差的协方差矩阵P(k-1,k-1),DB11存放协方差矩阵的一步预测值P(k,k-1),DB12存放Q,DB13存放R,DB14存放单位矩阵I。Data block DB7 stores state estimation value vector DB8 stores state one-step predicted value vector DB9 stores the filter gain matrix K(k), DB10 stores the covariance matrix P(k-1,k-1) of the estimated error, DB11 stores the one-step predicted value P(k,k-1) of the covariance matrix, and DB12 stores Q , DB13 stores R, and DB14 stores the identity matrix I.
步骤2:计算卡尔曼滤波器的一步预测值:Step 2: Compute the one-step forecast of the Kalman filter:
分别从数据块DB7和DB2中取出和Φ(k),按下式计算卡尔曼滤波器的一步预测值 Take out from the data block DB7 and DB2 respectively and Φ(k), calculate the one-step predicted value of the Kalman filter as follows
将存于数据块DB8。Will Stored in data block DB8.
步骤3:计算状态估计值:Step 3: Calculate the state estimate:
分别从数据块DB8、DB9、DB3、DB4中取出K(k)、H(k)和y(k),按下式计算状态估计值 Take out from the data blocks DB8, DB9, DB3, DB4 respectively K(k), H(k) and y(k), calculate the state estimation value according to the following formula
使用更新DB7中的 use Update DB7 in
步骤4:计算滤波增益矩阵:Step 4: Calculate the filter gain matrix:
分别从数据块DB11、DB3和DB13中取出P(k,k-1)、H(k)和R,按下式计算滤波增益矩阵K(k):Take out P(k,k-1), H(k) and R from the data blocks DB11, DB3 and DB13 respectively, and calculate the filter gain matrix K(k) as follows:
K(k)=P(k,k-1)HT(k)[H(k)P(k,k-1)HT(k)+R]-1 K(k)=P(k,k-1) HT (k)[H(k)P(k,k-1) HT (k)+R] -1
将K(k)存于数据块DB9。Store K(k) in data block DB9.
步骤5:计算误差协方差阵的一步预测值:Step 5: Calculate the one-step predictor of the error covariance matrix:
分别从数据块DB2、DB10、DB12取出Φ(k)、P(k-1,k-1)和Q,按下式计算误差协方差阵的一步预测值P(k,k-1):Take out Φ(k), P(k-1,k-1) and Q from the data blocks DB2, DB10, and DB12 respectively, and calculate the one-step predicted value P(k,k-1) of the error covariance matrix according to the following formula:
P(k,k-1)=Φ(k)P(k-1,k-1)ΦT(k)+QP(k,k-1)=Φ(k)P(k-1,k-1) ΦT (k)+Q
将P(k,k-1)存于数据块DB11。Store P(k,k-1) in the data block DB11.
步骤6:计算估计误差的协方差矩阵Step 6: Calculate the covariance matrix of the estimation errors
分别从数据块DB14、DB9、DB3和DB11中取出I、K(k)、H(k)和P(k,k-1),按下式计算估计误差的协方差矩阵P(k,k):Take out I, K(k), H(k) and P(k,k-1) from the data blocks DB14, DB9, DB3 and DB11 respectively, and calculate the covariance matrix P(k,k) of the estimation error according to the following formula :
P(k,k)=[I-K(k)H(k)]P(k,k-1)P(k,k)=[I-K(k)H(k)]P(k,k-1)
使用P(k,k)更新DB10中的P(k-1,k-1)。Use P(k,k) to update P(k-1,k-1) in DB10.
至此,完成卡尔曼滤波器的一次迭代运算,程序模块、数据块的组织及其关联关系如图9所示。So far, an iterative operation of the Kalman filter is completed, and the organization of program modules and data blocks and their associations are shown in Figure 9 .
下面列举具体实施例对本发明进行说明:List specific embodiment below and illustrate the present invention:
实施例1:PLC系统中的卡尔曼滤波器应用实例,为了验证PLC系统中实现的卡尔曼滤波器,拟用卡尔曼滤波算法估计一个自由落体运动的小球的高度和速度。小球高度的20次测量值如表1所示。设高度的测量误差是零均值方差为1的高斯白噪声,该物体的初始高度h0和速度V0也是高斯分布的随机变量,即Embodiment 1: The Kalman filter application example in the PLC system, in order to verify the Kalman filter realized in the PLC system, it is proposed to use the Kalman filter algorithm to estimate the height and velocity of a free-falling ball. The 20 measurements of the ball height are shown in Table 1. Assuming that the measurement error of height is Gaussian white noise with zero mean and variance of 1, the initial height h 0 and velocity V 0 of the object are also random variables of Gaussian distribution, namely
小球运动的状态方程如下:The state equation of the ball motion is as follows:
式中, In the formula,
滤波初值: Filter initial value:
为了直观显示PLC中卡尔曼滤波器的执行效果,使用WinCC组态软件的趋势控件将其数据导出到EXCEL绘制成曲线,如图10所示。左上图为高度估计值,右上图为速度估计值,左下图为高度估计协方差,右下图为速度估计协方差。表1为小球自由落体运动的高度变化值。In order to visually display the execution effect of the Kalman filter in the PLC, use the trend control of the WinCC configuration software to export its data to EXCEL to draw a curve, as shown in Figure 10. The upper left panel is the altitude estimate, the upper right panel is the velocity estimate, the lower left panel is the height estimate covariance, and the lower right panel is the velocity estimate covariance. Table 1 shows the height change value of the free fall of the ball.
表1Table 1
为了进一步验证PLC系统中所实现的卡尔曼滤波器,图11给出了Matlab提供的卡尔曼滤波器实现小球运动跟踪的高度和速度估计值、均方误差曲线。图11中左上图为高度估计值,右上图为速度估计值,左下图为高度估计协方差,右下图为速度估计协方差。In order to further verify the Kalman filter implemented in the PLC system, Figure 11 shows the height and velocity estimation values and mean square error curves of the Kalman filter provided by Matlab to realize the ball motion tracking. In Figure 11, the upper left figure is the estimated height, the upper right figure is the estimated velocity, the lower left figure is the estimated covariance of the height, and the lower right figure is the estimated covariance of the velocity.
通过比较可以得知,PLC系统中实现的卡尔曼滤波器和Matlab提供的卡尔曼滤波器在估计小球速度和高度时具有相似效果。It can be seen from the comparison that the Kalman filter implemented in the PLC system and the Kalman filter provided by Matlab have similar effects in estimating the velocity and height of the ball.
以上所述,仅为本发明较佳的具体实施方式,本发明的保护范围不限于此,任何熟悉本技术领域的技术人员在本发明披露的技术范围内,可显而易见地得到的技术方案的简单变化或等效替换均落入本发明的保护范围内。The above is only a preferred specific embodiment of the present invention, and the scope of protection of the present invention is not limited thereto. Any person familiar with the technical field within the technical scope disclosed in the present invention can obviously obtain the simplicity of the technical solution. Changes or equivalent replacements all fall within the protection scope of the present invention.
Claims (2)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410230791.7A CN104009735B (en) | 2014-05-28 | 2014-05-28 | Implementation method of the Kalman filter in 300 series of PLC of S7 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410230791.7A CN104009735B (en) | 2014-05-28 | 2014-05-28 | Implementation method of the Kalman filter in 300 series of PLC of S7 |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104009735A CN104009735A (en) | 2014-08-27 |
CN104009735B true CN104009735B (en) | 2017-04-05 |
Family
ID=51370252
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410230791.7A Expired - Fee Related CN104009735B (en) | 2014-05-28 | 2014-05-28 | Implementation method of the Kalman filter in 300 series of PLC of S7 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104009735B (en) |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2991170B2 (en) * | 1997-10-01 | 1999-12-20 | 日本電気株式会社 | CDMA receiver and method |
JP5504175B2 (en) * | 2008-01-31 | 2014-05-28 | フィッシャー−ローズマウント システムズ,インコーポレイテッド | Robust adaptive model predictive controller with tuning to compensate for model mismatch |
CN102931946B (en) * | 2012-10-25 | 2016-02-17 | 苏州有色金属研究院有限公司 | Based on the plate shape measurement signal processing method of Kalman filter |
-
2014
- 2014-05-28 CN CN201410230791.7A patent/CN104009735B/en not_active Expired - Fee Related
Also Published As
Publication number | Publication date |
---|---|
CN104009735A (en) | 2014-08-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Ge et al. | Stable adaptive neural network control | |
CN108789417B (en) | Reconfigurable mechanical arm cost-preserving decentralized control method based on self-adaptive dynamic programming | |
CN112119409A (en) | Neural network with relational memory | |
JP5349478B2 (en) | Inverse kinematics | |
CN104331547B (en) | Space mechanical arm structure parameter optimization method based on operability | |
Zhang et al. | A penalty strategy combined varying-parameter recurrent neural network for solving time-varying multi-type constrained quadratic programming problems | |
CN111880412B (en) | A Zero-Sum Neural Optimal Control Method for Reconfigurable Robot Based on Single Judgment Network | |
Balakirsky | Ontology based action planning and verification for agile manufacturing | |
Zhao et al. | Extended Kalman filter-based Elman networks for industrial time series prediction with GPU acceleration | |
CN104834216B (en) | A kind of circuit and method that PI controller parameters are adjusted based on BP neural network | |
Lv et al. | Wsbp function activated Zhang dynamic with finite-time convergence applied to Lyapunov equation | |
Tsai et al. | A strictly convergent real‐time solution for inverse kinematics of robot manipulators | |
CN118780434A (en) | Welding unit optimization scheduling method, medium and equipment based on improved simulated annealing particle swarm algorithm | |
CN117359639A (en) | Robot cluster cooperative control method and system | |
CN117245640A (en) | Robot control methods, devices, equipment and storage media | |
CN104009735B (en) | Implementation method of the Kalman filter in 300 series of PLC of S7 | |
JP7083703B2 (en) | Computer mounting method for simulation of whole electrical circuit | |
Bahrpeyma et al. | Application of Reinforcement Learning to UR10 Positioning for Prioritized Multi-Step Inspection in NVIDIA Omniverse | |
Su et al. | Incremental learning with balanced update on receptive fields for multi-sensor data fusion | |
Van Khang et al. | On the sliding mode control of redundant parallel robots using neural networks | |
Dai et al. | Research on deep learning methods of UUV maneuvering target tracking | |
Chen et al. | Robot kinematics learning computations using polynomial neural networks | |
CN204695010U (en) | A kind of circuit regulating PI controller parameter based on BP neural network | |
CN108021393A (en) | A kind of computational methods and Related product | |
CN115170666A (en) | Robot navigation method and system based on external memory |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20170405 |