2014年11月28日 星期五

另一個使用加速計與低解析度編碼器的位置估測法則 A method for estimating position with accelerometer and low resolution encoders


以下的方法,可以和 Kojima 先生的做法比較 The following method could be compared with the one proposed by Kojima san.

假設位置資料是 $x_1$,速度資料是 $x_2$,加速度資料是 $a$。那麼以狀態空間的方式來描述的話,就會是以下形式 Assume that $x_1$, $x_2$, and $a$ stand for position, velocity, and acceleration, respectively.  The following state equation describes their relationship.

$\left[ \begin{matrix} \dot{x_1} \\ \dot{x_2} \end{matrix} \right]=\left[ \begin{matrix} 0 & 1 \\ 0 & 0 \end{matrix} \right]\left[ \begin{matrix} x_1 \\ x_2 \end{matrix} \right] + \left[ \begin{matrix} 0 \\ 1 \end{matrix} \right] a$

如果位置資料的估測值是 $\hat{x}_1$,速度資料的估測值是 $\hat{x}_2$。那麼以下的狀態空間動態方程式,就可以用來估測位置資料,並且具備較高的解析度。這是利用 Luenberger observer 的概念來做的。Assume that $\hat{x}_1$, and $\hat{x}_2$, stand for position, and velocity estimations, respectively.  The following dynamic equation derived from the idea of state observer could be used to estimate the position and velocity signals with better resolution and accuracy.

$\frac{d}{dt} \left[ \begin{matrix} \hat{x}_1 \\ \hat{x}_2 \end{matrix} \right]=\left[ \begin{matrix} 0 & 1 \\ 0 & 0 \end{matrix} \right]\left[ \begin{matrix} \hat{x}_1 \\ \hat{x}_2 \end{matrix} \right] + \left[ \begin{matrix} 0 \\ 1 \end{matrix} \right] a + \left[ \begin{matrix} g_1 \\ g_2 \end{matrix} \right] (x_1 - \hat{x}_1)$

$g_1$ 與 $g_2$ 的設計可以用 $g_1=2\zeta \omega_n$,$g_2=\omega_n^2$,來設計,$\zeta$ 是 damping ratio ,$\omega_n$ 可以看成頻寬,$\zeta$ 可以選擇 [0.7, 1] 的範圍。Gains of $g_1$ and $g_2$ can be adjusted by using second order systems.

以下就是假設編碼器的解析度是 16 pulses/r 的模擬結果。其中加速度的資料來自加速規,而且我加了一些雜訊已接近真實情況。目前看起來還不錯。接下來就是數位化的工作。The following SIMULINK behavior model assumes that the resolution of a encoder is 16 pulses/r, and acceleration signal is added some white noise.


當我把編碼器輸出信號的單位弄錯時,下圖是錯誤的模擬結果,速度信號不對。The following incorrect results come from the wrong setting of the unit of position signals.  The estimated velocity signal does not match the true one.

修正過後的結果,可以看出位置與速度都正確的跟上了。The followings are correct results.

放大來看,可以看出位置信號的解析度的確增加了,加速規雜訊的影響也不大。

整個估測器的 SIMULINK 行為模型。

產生模擬信號的SIMULINK 行為模型。

離散時間的模擬看起來也可以了,取樣時間設定為 $T_s$ = 1ms, Discrete time simulations with $T_s$ = 1ms seems OK now.



2014年11月11日 星期二

一個電腦鼠運與自走車運動控制的新方法 A new method for the motion control of micromouse and robotracers

為了解決因編碼器解析度帶來差分的雜訊問題,我做了一個二階的位置與速度估測器,並且用這一些估測值來控制電腦鼠運與自走車的位置與速度。
A second order filter is devised in this article to estimate the position and velocity of wheeled mobile robots such that the noise effect arose from difference methods can be lessened.




我在 MPLAB 中利用以下的副程式實現了這樣一個演算法 The algorithm is implemented in the MPLAB environment

//--------- Functions -----------------------------------------
// Function Name : EST_FILTER
// Description   : 2nd order filter for vc and w
// input              : struct ESTIMATOR_S est_ps, or est_ths
// output            : struct ESTIMATOR_S est_ps, or est_ths
//-------------------------------------------------------------
struct ESTIMATOR_S EST_FILTER(struct ESTIMATOR_S states, long ref)
{
//long er_estp2;

states.yv.n = states.yv.n1 + states.erv.n1;
states.yp.n = states.yp.n1 + states.yv.n1;
states.er = ref - states.yp.n;
states.erv.n = (states.er>>2) - states.yv.n;
states.erv.n1 = states.erv.n;
states.yv.n1 = states.yv.n;
states.yp.n1 = states.yp.n;

return (states);
}

struct ESTIMATOR_S { union POSITION yp; struct FILTER_S yv; struct FILTER_S erv; long er; };

struct FILTER_S { int n; int n1; };

union POSITION { struct { long n; // in pulses, 81 pulses ~ 1mm, Q26.5 long n1; }; struct { unsigned int Ln; unsigned int Hn; unsigned int Ln1; unsigned int Hn1; }; } ;

其中 ref 代表真實的編碼器位置信號,states.yp.n 與 states.yp.n1 分別表示現在與過去一個取樣時間的編碼器位置信號估測值,states.yv.n 與 states.yv.n1 分別表示現在與過去一個取樣時間的編碼器速度信號估測值,states.er 是編碼器位置信號真實值與估測值之間的誤差。

states.erv.n = (states.er>>2) - states.yv.n;

上述方程式中的 states.erv.n 是使用編碼器位置信號真實值與估測值之間的誤差乘以 P 增益 0.25,加上編碼器速度信號估測值乘以 D 增益 1的結果,然後再積分得到編碼器速度信號估測值。

states.yv.n = states.yv.n1 + states.erv.n1; $\leftarrow y_v[n] = y_v[n-1] + erv[n-1]*T_s$

真正執行程式時,為了提高解析度,我將編碼器位置信號真實值放大 32 倍。

est_psR = EST_FILTER(est_psR, (out_pR.n<<5));
est_psL = EST_FILTER(est_psL, (out_pL.n<<5));

做位置控制的程式段

// find feedback variables
POS_con.pQEI = ((est_psR.yp.n + est_psL.yp.n)>>1);
ANG_con.pQEI = (est_psR.yp.n - est_psL.yp.n);

// find controlled errors
POS_con.perr = POS_con.pcom - POS_con.pQEI;
ANG_con.perr = ANG_con.pcom - ANG_con.pQEI;

// find motor command ->  $K_pe_p - K_v v_c^e$, and $K_p\theta_p - K_v \omega_c^e$
POS_PWM = (POS_con.perr>>1) - 9*((est_psL.yv.n+est_psR.yv.n)>>1);
ANG_PWM = (ANG_con.perr>>2) - 4*(est_psR.yv.n-est_psL.yv.n);

// find right and left motor commands
R_PWM = POS_PWM + ANG_PWM;
if (R_PWM>PWM_100) R_PWM = PWM_100;
else if (R_PWM<-PWM_100) R_PWM = -PWM_100;
//
L_PWM = POS_PWM - ANG_PWM;
if (L_PWM>PWM_100) L_PWM = PWM_100;
else if (L_PWM<-PWM_100) L_PWM = -PWM_100;

實驗結果 Experimental results for center and angular velocity




迴圈線迷宮(looped line maze)的搜尋與路徑簡化

迴圈線迷宮(如下圖),專指一個由直交線段組成的迷宮中,包含「迴圈」的路徑。在每年教育部主辦的「 電腦鼠暨智慧輪型機器人競賽 」中,屬於高中職與大專組的「 線迷宮鼠 」競賽活動。規則請參考以下連結  https://sites.google.com/gm.lhu.edu.tw/20...