pose_ekf
SlowFastAggregator.hpp
Go to the documentation of this file.
1 #ifndef SLOWFASTAGGREGATOR_HPP
2 #define SLOWFASTAGGREGATOR_HPP
3 
4 #include <aggregator/StreamAligner.hpp>
5 
6 namespace pose_ekf {
8 {
9 
10 
11  private:
13  aggregator::StreamAligner *slow_aggr;
14  aggregator::StreamAligner *fast_aggr;
15 
17  int stream_size;
18 
20  size_t *prev_num_processed_streams_slow;
22  bool copy;
23 
24  public:
25 
27 
28  void configureSlowFastAggr( aggregator::StreamAligner& slow_aggr, aggregator::StreamAligner& fast_aggr )
29  {
30 
31  this->slow_aggr = &slow_aggr;
32  this->fast_aggr = &fast_aggr;
33 
34  stream_size = slow_aggr.getStreamSize();
35 
36  prev_num_processed_streams_slow = new size_t[stream_size];
37  for(int i = 0; i < stream_size; i++)
38  {
39  prev_num_processed_streams_slow[i] = 0;
40  }
41 
42  copy = false;
43 
44  }
45 
49  virtual void copyState()=0;
50 
56  void step()
57  {
58 
59  // call the slow aggregator streams in the relevant order
60  while( slow_aggr->step() );
61 
62  //this logic is for determining if a copy is needed, so only triggered if there is no pending copy
63  if(!copy)
64  {
65  //Check which streams were dropped by the fast filter, but weren't dropped by the slow filter.
66  for( int i = 0; i < stream_size; i++)
67  {
68  const aggregator::StreamStatus &status_fast( fast_aggr->getBufferStatus(i) );
69  const aggregator::StreamStatus &status_slow( slow_aggr->getBufferStatus(i) );
70 
71  int total_stream_dropped_fast = status_fast.samples_dropped_buffer_full + status_fast.samples_dropped_late_arriving;
72  int total_stream_dropped_slow = status_slow.samples_dropped_buffer_full + status_slow.samples_dropped_late_arriving;
73  int current_dif = total_stream_dropped_fast - total_stream_dropped_slow;
74  //verify if a stream was dropped by the fast filter, but wasen't dropped by the slow filter
75  if( current_dif > 0 )
76  {
77  //verify if that stream of that type was procces by the slow filter
78  if( prev_num_processed_streams_slow[i] < status_slow.samples_processed)
79  {
80  //if the stream process was of a type dropped by the fast filter there need to be a copy
81  copy = true;
82  break;
83  }
84  }
85 
86  prev_num_processed_streams_slow[i] = status_slow.samples_processed;
87 
88  }
89 
90  }
91 
92  //std::cout << " MUST COPY " << copy << std::endl;
93  //verify if there is a need to procces the fast aggregator
94  if ( slow_aggr->getLatency().toSeconds() > fast_aggr->getTimeOut().toSeconds() )
95  {
96  if( copy )
97  {
98  copy = false;
99  fast_aggr->copyState( *slow_aggr );
100  copyState();
101 
102  //since there was a copy this get the new ammount of stream dropped
103  for( int i = 0; i < stream_size; i++)
104  {
105  const aggregator::StreamStatus &status_slow( slow_aggr->getBufferStatus(i) );
106  prev_num_processed_streams_slow[i] = status_slow.samples_processed;
107  }
108  }
109  while( fast_aggr->step() );
110 
111  }
112 
113  }
114 
115 
116 };
117 }
118 
119 #endif // SLOWFASTAGGREGATOR_H
void configureSlowFastAggr(aggregator::StreamAligner &slow_aggr, aggregator::StreamAligner &fast_aggr)
Definition: SlowFastAggregator.hpp:28
void step()
Definition: SlowFastAggregator.hpp:56
Definition: EKFPosYawBiasT.hpp:11
SlowFastAggregator()
Definition: SlowFastAggregator.hpp:26
virtual void copyState()=0
Definition: SlowFastAggregator.hpp:7