勇闖新世界︰ W!o《卡夫卡村》變形祭︰感知自然‧幽夢‧二

從牛頓力學來講,假使我們知道一個物體的『加速度』 \vec{a} (t) ,而且如果『初始條件』︰該物位置在原點,速度為零。那麼任意時刻的『速度』是 \vec{v} (t)  = \int \limits_{0}^{t} \vec{a} (t) dt ,『位置』為 \vec{r} (t) = \int \limits_{0}^{t} \int \limits_{0}^{t} \vec{a} (t) dt 。這麼簡易的算術有什麼重要嗎?若是我們可以『追跡物體 』,舉凡相機拍照的防震、手腳運動之練習、肢體平衡復健的監督﹐…… 實有著不勝枚舉之『用途』。然而『微機電』所作的『慣性感測器』 IMU ,一有免不了的『加速度』之『度量誤差』,此誤差在長『時間』的『積累』下將越來『錯誤』越大!再者那個『量測值』只能是『加速度』的『時間序列』 \vec{a} ( t_i ) ,因此 t_mt_n 時刻間之事也就不得不有『假設』的了!!就像此處問答所說的一樣︰

Tracking 2D positioning with IMU Sensor

I am using a miniature car and I want to estimate the position. We can not use GPS modules and most of the tracking systems that I saw, are using IMU senson with the GPS module. In our car we are able to find our exact correct location with image processing but for some parts that dont have enough markings we can not do this. So we want to use the IMU as backup for our positioning. so as long as the positioning is close is good for us.

And we are only interested in our 2D position since the car is on a flat ground.

I am using a IMU 9DOF sensor and I want to calculate my movement. I have seen some amazing works with IMU for tracking body movements but no code or simple explanation is anywhere about it. So basically I have the reading from accelerometer, gyro and magnetometer. I also have orientation in quarternions. From the device I am getting also the linear acceleration but even when I am not moving it in any direction the values are not 0 which is really confusing.

Can you please help me how to approach this?

Thanks in advance

Update :

So right now we are getting the perfect heading from the quaternion values. We also have the delta_time between each heading. So what I believe we need right now is the velocity. either as a vector or as a total value.

shareimprove this question

───

Non-zero rates are normal for MEMS accelerometers and gyros. This is persistent error. It is eliminated by somehow making sure that the device is stationary for a couple of seconds (so the output can stabilize), then getting a reading. Henceforth, subtracting this steady-state error from all future measurements. Look up the datasheet of your sensor – there will be maximum values for this and other types of measurement tolerances.

Now, the much more complex subject of fusing the accelerometer, gyro and compass data. This can get hugely complicated, using Kalman filter, like Apolo once did. It can, however, be quite simple as well.

The general idea is that the magnetic sensor has slow response, low accuracy, but the error does not increase. On the other hand, a gyro’s output is velocity, which is integrated to get angular position. The error grows very fast – generally you can’t do dead reckoning for more than a minute with only a giro. The accelerometer is worse – it outputs acceleration, which gets integrated twice!

So, a simple fusing filter would be some linear combination of the readings of the accelerometer and compass, with the coefficient in front of the gyro descreasing over tyme.

Here is a discussion by much more knowledgeable people than me on the topic.

Note: What you are trying to do is called dead reckoning.

shareimprove this answer

───

 

於是為了能夠更好的『應用』 IMU ,終將走入『數據處理』之路。『卡爾曼濾波Kalman filter

Kalman filtering, also known as linear quadratic estimation (LQE), is an algorithm that uses a series of measurements observed over time, containing statistical noise and other inaccuracies, and produces estimates of unknown variables that tend to be more precise than those based on a single measurement alone. The filter is named after Rudolf E. Kálmán, one of the primary developers of its theory.

The Kalman filter has numerous applications in technology. A common application is for guidance, navigation and control of vehicles, particularly aircraft and spacecraft. Furthermore, the Kalman filter is a widely applied concept in time series analysis used in fields such as signal processing and econometrics. Kalman filters also are one of the main topics in the field of robotic motion planning and control, and they are sometimes included in trajectory optimization. The multi-fractional order estimator is a simple and practical alternative to the Kalman filter for tracking targets.

The algorithm works in a two-step process. In the prediction step, the Kalman filter produces estimates of the current state variables, along with their uncertainties. Once the outcome of the next measurement (necessarily corrupted with some amount of error, including random noise) is observed, these estimates are updated using a weighted average, with more weight being given to estimates with higher certainty. The algorithm is recursive. It can run in real time, using only the present input measurements and the previously calculated state and its uncertainty matrix; no additional past information is required.

The Kalman filter does not require any assumption that the errors are Gaussian.[1] However, the filter yields the exact conditional probability estimate in the special case that all errors are Gaussian-distributed.

Extensions and generalizations to the method have also been developed, such as the extended Kalman filter and the unscented Kalman filter which work on nonlinear systems. The underlying model is a Bayesian model similar to a hidden Markov model but where the state space of the latent variables is continuous and where all latent and observed variables have Gaussian distributions.

……

 

就是早年發展重要的一種『數據處理』方法。也許下面一篇論文的『摘要』

Displacement profile estimation using low cost inertial motion sensors with applications to sporting and rehabilitation exercises

Abstract
This paper investigates two methods of displacement estimation using sampled acceleration and orientation data from a 6 degrees of freedom (DOF) Inertial Measurement Unit (IMU), with the application to sporting training and rehabilitation. Currently, the use of low cost IMUs for this particular application is very impractical due to the accumulation of errors from various sources. Previous studies and projects that have applied IMUs to similar applications have used a lower number of DOF, or have used higher accuracy navigational grade IMUs. Solutions to the acceleration noise accumulation and gyroscope angle error problem are proposed in this paper. A zero velocity update algorithm (ZUPT) is also developed to improve the accuracy of displacement estimation with a low grade IMU. The experimental results from this study demonstrate the feasibility of using an IMU with loose tolerances to determine the displacement. Peak distances of a range of exercises are shown to be measured with accuracies within 5% for the numerical integration methods.

Keywords
estimation, profile, displacement, sporting, applications, sensors, motion, inertial, exercises, cost, rehabilitation, low

Disciplines
Engineering | Science and Technology Studies

Publication Details
J. Coyte, D. A. Stirling, M. Ros, H. Du & A. Gray, “Displacement profile estimation using low cost inertial motion sensors with applications to sporting and rehabilitation exercises,” in 2013 IEEE/ASME International Conference on Advanced Intelligent Mechatronics (AIM), 2013, pp. 1290-1295.

───

 

將引領我們走得更遠乎??終究莫忘那『微分』與『差分』方程式可以很不相同的耶!!

150px-Pierre_Francois_Verhulst

Logistic-curve.svg

P(t) = \frac{1}{1 + \mathrm e^{-t}}

350px-Logit.svg

\operatorname{logit}(p)=\log\left( \frac{p}{1-p} \right)

220px-Linear_regression.svg

Y \approx F(X, \Box)

Maple_logistic_plot_small

x_{n+1} = r x_n(1 - x_n)

Logistic_map_animation

Logistic_map_phase_plot_of_x-n+1--x-n-_vs_x-n-

相圖

512px-LogisticMap_BifurcationDiagram

Logistic_map

Logistic_map_scatterplots_large

LogisticCobwebChaos
定點震盪混沌

200px-Ganzhi001

300px-NewtonIteration_Ani

一八三八年,比利時數學家 Pierre François Verhulst 發表了一個『人口成長』方程式,

\frac{dN}{dt} = r N \left(1 - \frac {N}{K} \right)

,此處 N(t) 是某時的人口數,r 是自然成長率, K 是環境承載力。求解後得到

N(t) = \frac{K}{1+ C K e^{-rt}}

,此處 C = \frac{1}{N(0)} - \frac{1}{K} 是初始條件。 Verhulst 將這個函數稱作『logistic function』,於是那個微分方程式也就叫做『 logistic equation』。假使用 P = \frac{N}{K} 改寫成 \frac{dP}{dt} = r P \left(1 - P \right),將它『標準化』,取 CK = 1r = 1,從左圖的解答來看, 0 < P <1,也就是講人口數成長不可能超過環境承載力的啊!

如果求 P(t) 的反函數,得到 t = \ln{\frac {1 -P}{P}},這個反函數被稱之為『Logit』函數,定義為

\operatorname{logit}(p)=\log\left( \frac{p}{1-p} \right) , \ 0 < p < 1

,一般常用於『二元選擇』,比方說『To Be or Not To Be』的『機率分佈』,也用於『迴歸分析』 Regression Analysis 來看看兩個『變量』在統計上是『相干』還是『無干』的ㄡ!假使試著用『無窮小』 數來看 \log\left( \frac{\delta p}{1-\delta p} \right) = \log(\delta p) \approx - \infty\log\left( \frac{1-\delta p} {\delta p}\right) = \log(\frac{1}{\delta p}) = \log(H) \approx \infty,或許更能體會『兩極性』的吧!!

一九七六年,澳洲科學家 Robert McCredie May 發表了一篇《Simple mathematical models with very complicated dynamics》文章,提出了一個『單峰映象』 logistic map 遞迴關係式 x_{n+1} = r x_n(1 - x_n), \ 0\leq x_n <1。這個遞迴關係式很像是『差分版』的『 logistic equation』,竟然是產生『混沌現象』的經典範例。假使說一個『遞迴關係式』有『極限值x_{\infty} = x_H 的話,此時 x_H = r x_H(1-x_H),可以得到 r{x_H}^2 = (r - 1) x_H,於是 x_H \approx 0 或者 x_H \approx \frac{r - 1}{r}。在 r < 1 之時,『單峰映象』或快或慢的收斂到『』; 當 1 < r < 2 之時,它很快的逼近 \frac{r - 1}{r};於 2 < r < 3 之時,線性的上下震盪趨近 \frac{r - 1}{r};雖然 r=3 也收斂到 \frac{r - 1}{r},然而已經是很緩慢而且不是線性的了;當 r > 1 + \sqrt{6} \approx 3.45 時,對幾乎各個『初始條件』而言,系統開始發生兩值『震盪現象』,而後變成四值、八值、十六值…等等的『持續震盪』;最終於大約 r = 3.5699 時,這個震盪現象消失了,系統就步入了所謂的『混沌狀態』的了!!

連續的』微分方程式沒有『混沌性』,『離散的』差分方程式反倒發生了『混沌現象』,那麼這個『量子』的『宇宙』到底是不是『混沌』的呢??回想之前『λ 運算』裡的『遞迴函式』,與數學中的『定點』定義,『單峰映象』可以看成函數 f(x) = r \cdot x(1 - x) 的『迭代求值』︰x_1 = f(x_0), x_2 = f(x_1), \cdots x_{k+1} = f(x_k) \cdots。當 f^{(p)} (x_f) = f \cdots p -2 times f \cdots f(x_f) = x_f,這個 x_f 就是『定點』,左圖中顯示出不同的 r 值的求解現象,從有『定點』向『震盪』到『混沌』。如果我們將『 logistic equation』 改寫成 \Delta P(t) = P(t + \Delta t) - P(t) = \left( r P(t) \left[ 1 - P(t) \right]  \right) \cdot \Delta t,假使取 t = n \Delta t, \Delta t = 1,可以得到 P(n + 1) - P(n) =  r P(n) \left[ 1 - P(n) \right],它的『極限值P(H) \approx 0, 1,根本與 r 沒有關係,這也就說明了兩者的『根源』是不同的啊!然而這卻建議著一種『時間序列』的觀點,如將 x_n 看成 x(n \Delta t), \ \Delta t = 1,這樣 \frac{x[(n+1) \Delta t]  - x[n \Delta t]}{\Delta t} = x_{n+1} - x_n 就說是『速度』的了,於是 (x_n, x_{n+1} - x_n) 便構成了假想的『相空間』,這可就把一個『遞迴關係式』轉譯成了一種『符號動力學』的了!!

在某些特定的 r 值,這個『遞迴關係式』有『正確解』 exact solution,比方說 r=2 時,x_n = \frac{1}{2} - \frac{1}{2}(1-2x_0)^{2^{n}},因為 x_0 \in [0,1),所以 (1-2x_0)\in (-1,1),於是 n \approx \infty \Longrightarrow (1-2x_0)^{2^{n}} \approx 0,因此 x_H \approx \frac{1}{2}。再者由於『指數項2^n 是『偶數』,所以此『符號動力系統』不等速 ── 非線性 ── 而且不震盪的逼近『極限值』的啊。

對於 r=4 來講,它的解是

x_{n}=\sin^{2}(2^{n} \theta \pi)

,此處 \theta 是『初始條件』參數,可由 \theta = \tfrac{1}{\pi}\sin^{-1}(x_0^{1/2}) 來決定。假使 \theta 是『有理數』,那麼 \sin^{2}(2^{n} \theta \pi) 這個『周期函數』,多次『迭代』後就可能產生『極限循環』;要是 \theta 是『無理數』,它有一個『不循環』的無窮小數成份,這個『符號動力系統』就彷彿是『隨機亂動』一般,因此才說它是『混沌』的啊!假使思考 \theta = \tfrac{1}{\pi}\sin^{-1}(x_0^{1/2}) 是一個『有理數』的機會,怕是很渺茫的吧!!

── 引自《【Sonic π】電路學之補充《四》無窮小算術‧中下上