﻿ XGBoost机器学习在光电编码器误差补偿中的应用
 光学仪器  2023, Vol. 45 Issue (1): 32-37 PDF
XGBoost机器学习在光电编码器误差补偿中的应用

Application of XGBoost machine learning in error compensation of photoelectric encoder
LI Yingzheng, LI Zhibin, JIN Lei, HU Zhenzhen, KANG Yefei, LI Gengbai
Department of Automation, Shanghai University of Electric Power, Shanghai 200082, China
Abstract: The error of photoelectric encoder detection system is mainly affected by the angle measurement error of the reference photoelectric encoder, data acquisition error and coaxial error. The angle measurement error can be compensated. In this paper, an algorithm based on extreme gradient boosting (XGBoost) machine learning is designed to compensate the error of the reference photoelectric encoder. After compensation, the static accuracy is improved by 35 times. The standard deviation is decreased from 3.62" to 0.13", and the maximum error value is reduced from 5.53" to 0.39". Compared with the traditional back progagation (BP) neural network algorithm and radial basis function (RBF) neural network algorithm, XGBoost's compensation is better than the others. XGBoost machine learning algorithm compensation effectively reduces the measurement error of the reference photoelectric encoder and improves the detection accuracy of the photoelectric encoder detection system.
Key words: photoelectric encoder    error compensation    XGBoost    accuracy of detection

1 光电编码器检测系统的误差构成

 图 1 编码器精度检测装置 Figure 1 Precision measurement system for photoelectric encoder

 $\varepsilon =\frac{\sum _{i=1}^{n}\left|{e}_{i}\right|}{n}，\;\;i=\mathrm{1,2},3,\cdots,n$ (1)

 $\sigma =\sqrt{\frac{\sum _{i=1}^{n}{\left({e}_{i}-\overline{e}\right)}^{2}}{n-1}}，\;\;i=\mathrm{1,2},3,\cdots,n$ (2)

 ${e}_{\rm{{max}}}={\rm{max}}\left|{\theta }_{i,{\rm{T}}}-{\theta }_{i,{\rm{L}}}\right|，\;\;i=\mathrm{1,2},3,\cdots,n$ (3)

2 XGBoost基本原理以及补偿方法

XGBoost算法是在梯度提升决策树（gradient boosting decision tree，GBDT）的基础上提出的机器学习系统，具有防过拟合性好、计算效率高、样本适应度高等特点。其学习器包括分类树以及线性分类器。本文利用分类树作为学习器。其核心为根据样本特征生长出新的叶子节点，分裂生长出新的树。每次添加一棵树，就学习一个新函数，去拟合上次预测的残差[14]。如训练完成的系统由 K棵树组成，当预测某个样本的值时，就根据这个样本的特征，在每棵树中落到对应的叶子节点处。每个叶子节点有唯一的权重值，即分数对应。一棵树的得分用F表示，将样本值在每棵树的得分加起来就是该样本的预测值 $\widehat{y}$ ，其表达式为：

 $\widehat{y}=\mathrm{\varPhi }\left({x}_{i}\right)=\sum\nolimits _{k=1}^{K}{f}_{k}\left({x}_{i}\right)$ (4)
 $F=\left\{f\left(x\right)={\omega }_{q\left(x\right)}\right\}\left(q：{{\boldsymbol{R}}}^{m}\to T,\omega \in {{\boldsymbol{R}}}^{T}\right)$ (5)

 $Obj={\sum }_{i=1}^{n}l\left({y}_{i},{\widehat{y}}_{i}\right)+{\sum }_{k=1}^{K}{\varOmega}\left({f}_{k}\right)$ (6)

 $\mathrm{\varOmega }\left(f\right)=\gamma T+\frac{1}{2}\lambda {‖\omega ‖}^{2}$ (7)

 ${g}_{i}={\partial }_{{\widehat{y}_{i}}^{\left(t-1\right)}}l\left({y}_{i}\text{，}{\widehat{y}}_i^{\left(t-1\right)}\right)$ (8)
 ${h}_{i}={\partial }_{{\widehat{y}_{i}}^{\left(t-1\right)}}^{2}l\left({y}_{i}\text{，}{\widehat{y}}_i^{\left(t-1\right)}\right)$ (9)

 $Gain=\frac{1}{2}\left[\frac{{G}_{{\rm{L}}}^{2}}{{H}_{{\rm{L}}}+\lambda }+\frac{{G}_{{\rm{R}}}^{2}}{{H}_{{\rm{R}}}+\lambda }-\frac{{\left({G}_{{\rm{L}}}+{G}_{{\rm{R}}}\right)}^{2}}{{H}_{{\rm{L}}}+{H}_{{\rm{R}}}+\lambda }\right]-\gamma$ (10)

XGBoost在原有的决策树上进行优化，使用梯度提升算法来确保较小的损失值，若构成一棵新的树模型损失值要大于原有的树模型，则停止生成新的树。XGBoost每进行一次迭代就是增加一棵树， $K$ 棵树的线性组合可以表示为

 ${\widehat{y}}_{i}^{\left(t\right)}=\sum\nolimits _{K=1}^{K}{f}_{k}\left({x}_{i}\right)={\widehat{y}}_{i}^{\left(t-1\right)}+{f}_{t}\left({x}_{i}\right)\text{，}{f}_{k}\in F$ (11)

3 基准编码器误差补偿实验 3.1 编码器检测系统装置

 图 2 基准光电编码器误差检测系统结构 Figure 2 Structure of error detection system for reference photoelectric encoder

3.2 基于XGBoost误差补偿建模及数据处理

 图 3 XGBoost机器学习训练能力 Figure 3 XGBoost machine learning training ability

 图 4 XGBoost机器学习泛化能力 Figure 4 XGBoost machine learning generalization ability

 图 5 补偿前后编码器误差对比 Figure 5 Comparison of encoder error before and after compensation

 图 6 BP神经网络补偿对比图 Figure 6 Comparison diagram of BP neural network compensation

 图 7 RBF神经网络补偿对比图 Figure 7 Comparison diagram of RBF neural network compensation

4 结　论

 [1] 汤天瑾, 曹向群, 林斌. 光电轴角编码器发展现状分析及展望[J]. 光学仪器, 2005, 27(1): 90–96. [2] INCZE I I, SZABÓ C, IMECS M. Incremental encoder in electrical drives: modeling and simulation[M]// RUDAS I J, FODOR J, KACPRZYK J. Computational Intelligence and Informatics: Principles and Practice. Berlin, Heidelberg: Springer, 2010: 287 − 300. [3] 吴文峰, 李志斌, 杨勇, 等. 基于LabVIEW的光栅编码器动态特性检测系统[J]. 微特电机, 2019, 47(3): 25–28. [4] LU L, WANG L, WANG W, et al. A self-calibration method for error of photoelectric encoder based on gyro in rotational inertial navigation system[J]. Microsystem Technologies, 2019, 25(6): 2145–2152. DOI:10.1007/s00542-018-4139-0 [5] BHANGU B S, RAJASHEKARA K. Control strategy for electric starter generators embedded in gas turbine engine for aerospace applications[C]//Energy Conversion Congress & Exposition. Phoenix: IEEE, 2011: 1461 − 1467. [6] HOU B, ZHOU B, LI X, et al. Periodic nonlinear error analysis and compensation of a single-excited petal-shaped capacitive encoder to achieve high-accuracy measurement[J]. Sensors, 2019, 19(10): 2412. DOI:10.3390/s19102412 [7] 陈洪月, 张坤, 刘治翔, 等. 基于PSO-BP神经网络光电编码器误差补偿研究[J]. 传感技术学报, 2017, 30(8): 1182–1186. [8] 洪喜, 续志军, 杨宁, 等. RBF网络在编码器误差补偿中的应用[J]. 光电工程, 2009, 36(8): 139–142. [9] 董凯炎, 史姝倩, 刘杰, 等. 一种光电编码器精度自动检测系统[J]. 传感技术学报, 2019, 32(3): 463–468. [10] 刘丰文, 邓文和. 25位绝对式编码器[J]. 光电工程, 2000, 27(6): 66–68. [11] JIA H K, YU L D, ZHAO H N, et al. A new method of angle measurement error analysis of rotary encoders[J]. Applied Sciences, 2019, 9(16): 3415. DOI:10.3390/app9163415 [12] YU H. Angle measurement based on in-line digital holographic reconstruction[J]. Optics and Lasers in Engineering, 2021, 137: 106385. DOI:10.1016/j.optlaseng.2020.106385 [13] 王义文, 焦环宇, 刘献礼, 等. 绝对式编码器输出信号的误差自动补偿[J]. 光电工程, 2015, 42(1): 89–94. [14] 李占山, 刘兆赓. 基于XGBoost的特征选择算法[J]. 通信学报, 2019, 40(10): 101–108. DOI:10.11959/j.issn.1000-436x.2019154 [15] 李叶紫, 王振友, 周怡璐, 等. 基于贝叶斯最优化的Xgboost算法的改进及应用[J]. 广东工业大学学报, 2018, 35(1): 23–28. [16] 杨金利, 魏晓蓉. 绝对式光电编码器测角误差自动检测系统[J]. 光学与光电技术, 2021, 19(5): 30–35. [17] 董静, 万秋华, 于海, 等. 小型绝对式光电编码器误码自动检测系统[J]. 中国光学, 2016, 9(6): 695–703.