1010 P % Process Covariance matrix
1111 A % Position/Velocity Transformation Matrix
1212 B % Acceleration Transformation Position Matrix
13+ y % Observeration Data Gathered For Specific Simulation Step
14+ vel % Current Velocity
15+ changed % Indication of change in observeration
1316 end
1417
1518 %% Main Functions that Run the Kalman Filter
2427 obj.P = pt * transpose(pt );
2528 obj.A = eye(6 ,6 );
2629 obj.pos = pos ;
30+ obj.vel = 0 ;
31+ obj.y = [];
32+ obj.changed = false ;
2733 end
28- function UpdateModel(obj , telemetry , sensory , del_t )
34+ function UpdateModel(obj , del_t )
2935 % UpdateModel - Predicts the next position given the next
3036 % simulation step.
3137 % Input:
3238 % telemetry (table) : Telemetry information
3339 % sensory (table) : sensory informaiton
3440 % del_t (float) : The change in time;
3541
36- acceration = (transpose(telemetry .speed) - obj .pos(4 : 6 ))/del_t ;
42+ if (~obj .changed)
43+ return ;
44+ end
45+
46+ acceration = (obj .vel - obj .pos(4 : 6 ))/del_t ;
3747
3848 % New Predicted State
3949 obj .PredictNextState(del_t , obj .pos, acceration );
@@ -49,31 +59,33 @@ function UpdateModel(obj, telemetry, sensory, del_t)
4959 k = (obj .P* H )/(H * obj .P* H + R );
5060
5161 % Grab Observeration Data
52- y = obj .CalculateAverageInformaiton(telemetry , sensory );
5362 z = mvnrnd([0 ,0 ,0 , 0 , 0 ,0 ], eye(6 )*.5 );
54- obj.pos = eye(6 )*y + transpose(z );
63+ obj.pos = eye(6 )*obj . y + transpose(z );
5564
5665 % Calculate the current state
57- obj.pos = obj .pos + k *(y - obj .pos);
66+ obj.pos = obj .pos + k *(obj . y - obj .pos);
5867
5968 % Update the Process Covariance matrix
6069 obj.P = (eye(6 ) - k )*obj .P;
70+ obj.changed = false ;
6171 end
6272
63- function y = CalculateAverageInformaiton (obj , telemetry , sensory )
73+ function RecieveObservationData (obj , telemetry , sensory )
6474 % CalculateAverageInformation - Calculate the mean observed
6575 % position from the sensory information for the kalman filter
6676 % Input
6777 % sensory (table): Sensory information tied to the Object
6878 % being tracked
69- y = [];
79+ cur_y = [];
7080 if (~isempty(sensory ))
7181 obs = height(sensory );
72- y = zeros(obs + 1 , 6 );
73- y (1 : obs , : ) = [sensory .pos, sensory .speed];
82+ cur_y = zeros(obs + 1 , 6 );
83+ cur_y (1 : obs , : ) = [sensory .pos, sensory .speed];
7484 end
75- y(end , : ) = [telemetry .pos, telemetry .speed];
76- y = transpose(mean(y ));
85+ cur_y(end , : ) = [telemetry .pos, telemetry .speed];
86+ obj.vel = transpose(telemetry .speed);
87+ obj.y = transpose(mean(cur_y ));
88+ obj.changed = true ;
7789 end
7890
7991 function PredictNextState(obj , del_t , prev_pos ,accerlation )
0 commit comments