Committer:
narshu
Date:
Thu Apr 26 19:11:11 2012 +0000
Revision:
0:e238496b8073
Child:
1:4964fa534202

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
narshu 0:e238496b8073 1 #ifndef KALMAN_H
narshu 0:e238496b8073 2 #define KALMAN_H
narshu 0:e238496b8073 3
narshu 0:e238496b8073 4 #include "globals.h"
narshu 0:e238496b8073 5
narshu 0:e238496b8073 6
narshu 0:e238496b8073 7 #include "rtos.h"
narshu 0:e238496b8073 8 //#include "Matrix.h"
narshu 0:e238496b8073 9 #include "motors.h"
narshu 0:e238496b8073 10 #include "RFSRF05.h"
narshu 0:e238496b8073 11 #include "IR.h"
narshu 0:e238496b8073 12
narshu 0:e238496b8073 13 #include <tvmet/Matrix.h>
narshu 0:e238496b8073 14 #include <tvmet/Vector.h>
narshu 0:e238496b8073 15 using namespace tvmet;
narshu 0:e238496b8073 16
narshu 0:e238496b8073 17
narshu 0:e238496b8073 18 class Kalman {
narshu 0:e238496b8073 19 public:
narshu 0:e238496b8073 20 enum measurement_t {SONAR1 = 0, SONAR2, SONAR3, IR1, IR2, IR3};
narshu 0:e238496b8073 21 static const measurement_t maxmeasure = IR3;
narshu 0:e238496b8073 22
narshu 0:e238496b8073 23 Kalman(Motors &motorsin);
narshu 0:e238496b8073 24
narshu 0:e238496b8073 25 void predict();
narshu 0:e238496b8073 26 void runupdate(measurement_t type, float value, float variance);
narshu 0:e238496b8073 27
narshu 0:e238496b8073 28 //State variables
narshu 0:e238496b8073 29 Vector<float, 3> X;
narshu 0:e238496b8073 30 Matrix<float, 3, 3> P;
narshu 0:e238496b8073 31 Mutex statelock;
narshu 0:e238496b8073 32
narshu 0:e238496b8073 33 float SonarMeasures[3];
narshu 0:e238496b8073 34 float IRMeasures[3];
narshu 0:e238496b8073 35 float SonarMeasure_Offset[3];
narshu 0:e238496b8073 36
narshu 0:e238496b8073 37 bool Kalman_init;
narshu 0:e238496b8073 38
narshu 0:e238496b8073 39 //The IR is public so it's possible to print the offset in the print function
narshu 0:e238496b8073 40 IR ir;
narshu 0:e238496b8073 41
narshu 0:e238496b8073 42 //Initialises the kalman filter
narshu 0:e238496b8073 43 void KalmanInit();
narshu 0:e238496b8073 44
narshu 0:e238496b8073 45 private:
narshu 0:e238496b8073 46
narshu 0:e238496b8073 47 //Sensor interfaces
narshu 0:e238496b8073 48 RFSRF05 sonararray;
narshu 0:e238496b8073 49 Motors& motors;
narshu 0:e238496b8073 50
narshu 0:e238496b8073 51 Thread predictthread;
narshu 0:e238496b8073 52 void predictloop();
narshu 0:e238496b8073 53 static void predictloopwrapper(void const *argument){ ((Kalman*)argument)->predictloop(); }
narshu 0:e238496b8073 54 RtosTimer predictticker;
narshu 0:e238496b8073 55
narshu 0:e238496b8073 56 // Thread sonarthread;
narshu 0:e238496b8073 57 // void sonarloop();
narshu 0:e238496b8073 58 // static void sonarloopwrapper(void const *argument){ ((Kalman*)argument)->sonarloop(); }
narshu 0:e238496b8073 59 // RtosTimer sonarticker;
narshu 0:e238496b8073 60
narshu 0:e238496b8073 61 struct measurmentdata{
narshu 0:e238496b8073 62 measurement_t mtype;
narshu 0:e238496b8073 63 float value;
narshu 0:e238496b8073 64 float variance;
narshu 0:e238496b8073 65 } ;
narshu 0:e238496b8073 66
narshu 0:e238496b8073 67 Mail <measurmentdata, 16> measureMQ;
narshu 0:e238496b8073 68
narshu 0:e238496b8073 69 Thread updatethread;
narshu 0:e238496b8073 70 void updateloop();
narshu 0:e238496b8073 71 static void updateloopwrapper(void const *argument){ ((Kalman*)argument)->updateloop(); }
narshu 0:e238496b8073 72
narshu 0:e238496b8073 73
narshu 0:e238496b8073 74 };
narshu 0:e238496b8073 75
narshu 0:e238496b8073 76 #endif //KALMAN_H