久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1707|回復: 0
打印 上一主題 下一主題
收起左側

爾曼濾波器英文資料與C語言源程序

[復制鏈接]
跳轉到指定樓層
樓主
詳細介紹卡爾曼濾波器。
附有程序源碼


源程序如下:
  1. /***************************************************************************/
  2. /* kalman.c                                                                */
  3. /* 1-D Kalman filter Algorithm, using an inclinometer and gyro             */
  4. /* Author: Rich Chi Ooi                                                    */
  5. /* Version: 1.0                                                            */
  6. /* Date:30.05.2003                                                         */
  7. /* Adapted from Trammel Hudson(hudson@rotomotion.com)                      */  
  8. /* -------------------------------                                         */
  9. /* Compilation  procedure:                                                 */
  10. /*       Linux                                                             */
  11. /*      gcc68 -c  XXXXXX.c (to create object file)                         */
  12. /*      gcc68 -o  XXXXXX.hex XXXXXX.o ppwa.o                               */
  13. /*Upload data :                                                                   */
  14. /*        ul filename.txt                                                                 */
  15. /***************************************************************************/
  16. /* In this version:                                                        */
  17. /***************************************************************************/
  18. /* This is a free software; you can redistribute it and/or modify          */
  19. /* it under the terms of the GNU General Public License as published       */
  20. /* by the Free Software Foundation; either version 2 of the License,       */
  21. /* or (at your option) any later version.                                  */
  22. /*                                                                         */
  23. /* this code is distributed in the hope that it will be useful,            */
  24. /* but WITHOUT ANY WARRANTY; without even the implied warranty of          */
  25. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
  26. /* GNU General Public License for more details.                            */
  27. /*                                                                         */
  28. /* You should have received a copy of the GNU General Public License       */
  29. /* along with Autopilot; if not, write to the Free Software                */
  30. /* Foundation, Inc., 59 Temple Place, Suite 330, Boston,                   */
  31. /* MA  02111-1307  USA                                                     */
  32. /***************************************************************************/

  33. #include <math.h>
  34. #include "eyebot.h"

  35. /*
  36. * The state is updated with gyro rate measurement every 20ms
  37. * change this value if you update at a different rate.
  38. */

  39. static const float dt = 0.02;

  40. /*
  41. * The covariance matrix.This is updated at every time step to
  42. * determine how well the sensors are tracking the actual state.
  43. */
  44. static float P[2][2] = {{ 1, 0 },
  45.                         { 0, 1 }};

  46. /*
  47. * Our two states, the angle and the gyro bias.As a byproduct of computing
  48. * the angle, we also have an unbiased angular rate available.These are
  49. * read-only to the user of the module.
  50. */
  51. float angle;
  52. float q_bias;
  53. float rate;


  54. /*
  55. * The R represents the measurement covariance noise.R=E[vvT]
  56. * In this case,it is a 1x1 matrix that says that we expect
  57. * 0.1 rad jitter from the inclinometer.
  58. * for a 1x1 matrix in this case v = 0.1
  59. */
  60. static const float R_angle = 0.001 ;


  61. /*
  62. * Q is a 2x2 matrix that represents the process covariance noise.
  63. * In this case, it indicates how much we trust the inclinometer
  64. * relative to the gyros.
  65. */
  66. static const float Q_angle = 0.001;
  67. static const float Q_gyro  = 0.0015;


  68. /*
  69. * state_update is called every dt with a biased gyro measurement
  70. * by the user of the module.  It updates the current angle and
  71. * rate estimate.
  72. *
  73. * The pitch gyro measurement should be scaled into real units, but
  74. * does not need any bias removal.  The filter will track the bias.
  75. *
  76. *          A = [ 0 -1 ]
  77. *              [ 0  0 ]
  78. */
  79. void stateUpdate(const float q_m){

  80.         float q;
  81.         float Pdot[4];

  82.         /* Unbias our gyro */
  83.         q = q_m - q_bias;

  84.         /*
  85.          * Compute the derivative of the covariance matrix
  86.          * (equation 22-1)
  87.          *        Pdot = A*P + P*A' + Q
  88.          *
  89.          */
  90.         Pdot[0] = Q_angle - P[0][1] - P[1][0];        /* 0,0 */
  91.         Pdot[1] = - P[1][1];                        /* 0,1 */
  92.         Pdot[2] = - P[1][1];                         /* 1,0 */
  93.         Pdot[3] = Q_gyro;                        /* 1,1 */

  94.         /* Store our unbias gyro estimate */
  95.         rate = q;

  96.         /*
  97.          * Update our angle estimate
  98.          * angle += angle_dot * dt
  99.          *       += (gyro - gyro_bias) * dt
  100.          *       += q * dt
  101.          */
  102.         angle += q * dt;

  103.         /* Update the covariance matrix */
  104.         P[0][0] += Pdot[0] * dt;
  105.         P[0][1] += Pdot[1] * dt;
  106.         P[1][0] += Pdot[2] * dt;
  107.         P[1][1] += Pdot[3] * dt;
  108. }


  109. /*
  110. * kalman_update is called by a user of the module when a new
  111. * inclinoometer measurement is available.
  112. *
  113. * This does not need to be called every time step, but can be if
  114. * the accelerometer data are available at the same rate as the
  115. * rate gyro measurement.
  116. *
  117. *         H  = [ 1 0 ]
  118. *
  119. * because the angle measurement directly corresponds to the angle
  120. * estimate and the angle measurement has no relation to the gyro
  121. * bias.
  122. */
  123. void kalmanUpdate(const float incAngle)
  124. {
  125.         /* Compute our measured angle and the error in our estimate */
  126.         float angle_m = incAngle;
  127.         float angle_err = angle_m - angle;

  128.         /*
  129.          * h_0 shows how the state measurement directly relates to
  130.          * the state estimate.
  131.           *   
  132.          *      H = [h_0 h_1]
  133.          *
  134.          * The h_1 shows that the state measurement does not relate
  135.          * to the gyro bias estimate.  We don't actually use this, so
  136.          * we comment it out.
  137.          */
  138.         float h_0 = 1;
  139.         /* const float                h_1 = 0; */

  140.         /*
  141.          * Precompute PH' as the term is used twice
  142.          * Note that H[0,1] = h_1 is zero, so that term is not not computed
  143.          */
  144.         const float PHt_0 = h_0*P[0][0]; /* + h_1*P[0][1] = 0*/
  145.         const float PHt_1 = h_0*P[1][0]; /* + h_1*P[1][1] = 0*/

  146.         /*
  147.          * Compute the error estimate:
  148.          * (equation 21-1)
  149.          *
  150.          *        E = H P H' + R
  151.          */
  152.         float E = R_angle +(h_0 * PHt_0);

  153.         /*
  154.          * Compute the Kalman filter gains:
  155.          * (equation 21-2)
  156.          *
  157.          *        K = P H' inv(E)
  158.                 */
  159.         float K_0 = PHt_0 / E;
  160.         float K_1 = PHt_1 / E;
  161.                
  162.         /*
  163.          * Update covariance matrix:
  164.          * (equation 21-3)
  165.          *
  166.          *        P = P - K H P
  167.          * Let
  168.          *      Y = H P
  169.          */
  170.         float Y_0 = PHt_0;  /*h_0 * P[0][0]*/
  171.         float Y_1 = h_0 * P[0][1];
  172.          
  173.         P[0][0] -= K_0 * Y_0;
  174.         P[0][1] -= K_0 * Y_1;
  175.         P[1][0] -= K_1 * Y_0;
  176.         P[1][1] -= K_1 * Y_1;
  177.         
  178.         /*
  179.          * Update our state estimate:
  180.          *
  181.          *        Xnew = X + K * error
  182.          *
  183.          * err is a measurement of the difference in the measured state
  184.          * and the estimate state.  In our case, it is just the difference
  185.          * between the inclinometer measured angle and the estimated angle.
  186.          */
  187.         angle        += K_0 * angle_err;
  188.         q_bias        += K_1 * angle_err;
  189. }
復制代碼

所有資料51hei提供下載:
卡爾曼.zip (580.13 KB, 下載次數: 14)



評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 一区二区三区精品 | 亚洲91精品 | 日韩av一区二区在线观看 | 日韩高清电影 | 日本在线精品视频 | 黑人一级黄色大片 | 日日操操 | 亚洲国产成人在线视频 | 天堂久久一区 | 亚洲aⅴ| 不卡一区| 国产aa| 久久久精品影院 | 国产一区二区三区 | 日韩在线视频观看 | av毛片| 久久久影院 | 欧美性生交大片免费 | 国产欧美日韩综合精品一区二区 | 欧美精品一区在线发布 | 欧美 日韩 国产 成人 在线 91 | 亚洲交性 | 免费一区二区三区在线视频 | 亚洲一区二区三区免费视频 | 中文字幕在线观看 | 欧美阿v| 91高清在线视频 | 欧美日韩在线一区二区 | 99久久免费精品国产男女高不卡 | 欧美国产日韩一区 | 国产精品美女久久久久久免费 | 人人艹人人 | 欧美国产亚洲一区二区 | 国产精品爱久久久久久久 | 在线观看国产视频 | 国产91丝袜在线熟 | 久久综合一区二区三区 | 久久不卡| 日韩久久网 | 伊人久久综合影院 | 精品二区 |