state-observation 1.8.0
General implementation of observers.
Loading...
Searching...
No Matches
delayed-measurements-observer.hpp
1
12
13#ifndef DelayedMeasurementObserverHPP
14#define DelayedMeasurementObserverHPP
15
16#include <boost/circular_buffer.hpp>
17#include <map>
18#include <state-observation/api.h>
20
21namespace stateObservation
22{
23
24class AsynchronousDataBase
25{
26protected:
27 AsynchronousDataBase() {}
28
29public:
30 virtual ~AsynchronousDataBase() {}
31 virtual void merge(const AsynchronousDataBase & input2) = 0;
32};
33
34class AsynchronousDataMapBase
35{
36protected:
37 AsynchronousDataMapBase() {}
38
39public:
40 virtual ~AsynchronousDataMapBase() {}
41 virtual bool checkIndex(TimeIndex k) = 0;
42 virtual void pushValue(const AsynchronousDataBase & v, TimeIndex k) = 0;
43 virtual bool empty() const = 0;
44 virtual void erase(TimeIndex k) = 0;
45 virtual void clear() = 0;
46 virtual AsynchronousDataBase & getElement(TimeIndex k) = 0;
47 virtual TimeIndex getFirstIndex() = 0;
48};
49
50template<typename DataType>
51struct AsynchronousDataMapT : public AsynchronousDataMapBase
52{
53public:
54 inline bool checkIndex(TimeIndex k) override;
55 inline void pushValue(const AsynchronousDataBase & v, TimeIndex k) override;
56 inline void clear() override;
57 inline void erase(TimeIndex k) override;
58 inline bool empty() const override;
59 inline AsynchronousDataBase & getElement(TimeIndex k) override;
60 inline TimeIndex getFirstIndex() override;
61
62protected:
63 std::map<TimeIndex, DataType> v_;
64};
65
66template<typename DataType>
67inline DataType & convert_async_data(AsynchronousDataBase & u);
68
69template<typename DataType>
70inline const DataType & convert_async_data(const AsynchronousDataBase & u);
71
77class STATE_OBSERVATION_DLLAPI DelayedMeasurementObserver : public ObserverBase
78{
79
80public:
87 Index n,
88 Index m,
89 unsigned long bufferCapacity,
90 const std::shared_ptr<IndexedInputArrayInterface> input = nullptr,
91 const std::shared_ptr<AsynchronousDataMapBase> async_input = nullptr,
92 const std::shared_ptr<AsynchronousDataMapBase> async_meas = nullptr);
93
96
99
102 DelayedMeasurementObserver & operator=(const DelayedMeasurementObserver &) = delete;
103
104 // inline const IndexedVector & getPastState(size_t nbIters)
105 // {
106 // return xBuffer_.at(nbIters);
107 // }
108
112
115 virtual void initEstimator(const Vector & x);
116
124 virtual void setState(const ObserverBase::StateVector & x_k, TimeIndex k) override;
125
129 virtual const ObserverBase::StateVector & getEstimatedState(TimeIndex k) override;
130
134 void setMeasurement(const Vector & y, TimeIndex k) override;
135
136 void pushAsyncMeasurement(const AsynchronousDataBase & asyncMeas, TimeIndex k);
137
139 Vector getMeasurement(TimeIndex k) const;
140
142 virtual TimeIndex getMeasurementTime() const;
143
145 virtual void clearMeasurements() override;
146
149
150 // void pushInput(const InputBase & u_k);
151
152 void pushAsyncInput(const AsynchronousDataBase & asyncMeas, TimeIndex k);
153
156 virtual void setInput(const InputBase & u_k, TimeIndex k) override;
157
160 virtual void clearInputs() override;
161
164 virtual void clearDelayedInputs();
165
176
179 virtual void clearStates() override;
180
182 inline virtual void setStateCapacity(unsigned long stateCapacity)
183 {
184 xBuffer_.set_capacity(stateCapacity);
185 }
186
188 inline void setSamplingTime(const double dt)
189 {
190 dt_ = dt;
191 }
192 inline double getSamplingTime()
193 {
194 return dt_;
195 }
196
197 TimeIndex getAsynchronousFirstIndex();
198
200 virtual TimeIndex getCurrentTime() const;
201
202protected:
203 typedef boost::circular_buffer<IndexedVector>::iterator StateIterator;
204
207 virtual StateVector oneStepEstimation_(StateIterator it) = 0;
208 virtual void startNewIteration_() = 0;
209
210 inline const boost::circular_buffer<IndexedVector> & getStateVectorBuffer() const
211 {
212 return xBuffer_;
213 }
214
215 bool stateIsSet() const;
216
217protected:
219 double dt_;
221 boost::circular_buffer<IndexedVector> xBuffer_;
223 IndexedVectorArray y_;
225 std::shared_ptr<IndexedInputArrayInterface> u_;
226
227 // Iteration from which the next estimation iteration must be run. In general, simply corresponds to the time of the
228 // latest estimation, but if asynchronous data is received, it will correspond to the oldest data.
229 TimeIndex currentIterIndex_;
231 std::shared_ptr<AsynchronousDataMapBase> y_asynchronous_;
233 std::shared_ptr<AsynchronousDataMapBase> u_asynchronous_;
234};
235
236} // namespace stateObservation
237
238#include <state-observation/observer/delayed-measurements-observer.hxx>
239
240#endif // DelayedMeasurementObserverHPP
void setCurrentState(const ObserverBase::StateVector &x_k)
Modify the value of the state vector at the current time.
void setSamplingTime(const double dt)
set the sampling time of the measurements
const ObserverBase::StateVector & getCurrentEstimatedState()
Get the Current Estimated State.
virtual StateVector oneStepEstimation_(StateIterator it)=0
Runs one loop of the estimator.
boost::circular_buffer< IndexedVector > xBuffer_
The state estimation of the observer (only one state is recorded).
virtual void initEstimator(const Vector &x)
initializes the state vector.
virtual void clearStates() override
Removes the state estimation.
virtual void setStateCapacity(unsigned long stateCapacity)
set the sampling time of the measurements
DelayedMeasurementObserver(const DelayedMeasurementObserver &)=delete
Not copyable: the copy would share the buffers of inputs and measurements.
DelayedMeasurementObserver()=delete
Default constructor.
virtual TimeIndex getMeasurementTime() const
Get the time index of the last given measurement.
std::shared_ptr< AsynchronousDataMapBase > y_asynchronous_
Container for the asynchronous measurements.
IndexedVectorArray y_
Container for the measurements.
virtual void setState(const ObserverBase::StateVector &x_k, TimeIndex k) override
Set the value of the state vector at time index k.
virtual void setInput(const InputBase &u_k, TimeIndex k) override
Vector getMeasurement(TimeIndex k) const
Get the measurement of the time index k.
std::shared_ptr< IndexedInputArrayInterface > u_
Container for the inputs.
virtual TimeIndex getCurrentTime() const
Get the value of the time index of the current state estimation.
virtual const ObserverBase::StateVector & getEstimatedState(TimeIndex k) override
getestimated State
std::shared_ptr< AsynchronousDataMapBase > u_asynchronous_
Container for the asynchronous inputs.
virtual void clearMeasurements() override
Remove all the given values of the measurements.
DelayedMeasurementObserver(double dt, Index n, Index m, unsigned long bufferCapacity, const std::shared_ptr< IndexedInputArrayInterface > input=nullptr, const std::shared_ptr< AsynchronousDataMapBase > async_input=nullptr, const std::shared_ptr< AsynchronousDataMapBase > async_meas=nullptr)
virtual void clearDelayedMeasurements()
Remove all the given values of the measurements.
void setMeasurement(const Vector &y, TimeIndex k) override
sets the measurement
Base class for inputs, necessary to do polymorphism.
Vector StateVector
StateVector is the type of state vector.
ObserverBase(Index n, Index m)
InputVector is the type of the input vector.
Filtering of divergent component of motion (DCM) and estimation of a bias betweeen the DCM and the co...
Eigen::VectorXd Vector
Dynamic sized scalar vector.
Defines the base class of a state observer. The observer is destinated to any dynamical system with a...