00001
00002 #ifndef DDF_SENSORBASE_HPP
00003 #define DDF_SENSORBASE_HPP
00004
00005 #include <iostream>
00006 #include <fstream>
00007 #include <deque>
00008 #include <BayesFilter/allFilters.hpp>
00009 #include <BayesFilter/schemeFlt.hpp>
00010 #include "ddf/definitions.hpp"
00011 #include "ddfsimu/measureitem.hpp"
00012
00013
00014 namespace jafar
00015 {
00016 namespace ddfsimu
00017 {
00018
00019 typedef enum {SENSOR_ACCEL, SENSOR_GPS, SENSOR_VEL, SENSOR_TRACK, SENSOR_TRACK_ROBOT, SENSOR_EVENT, SENSOR_VOID} SENSOR_TYPE;
00020 typedef enum {MODEL_LINRZ_CORRELATED, MODEL_LINRZ_UNCORRELATED, MODEL_ADDATIVE_CORRELATED, MODEL_ADDATIVE_UNCORRELATED, MODEL_VOID} OBS_MODEL_TYPE;
00021
00022 const char SENSOR_DESCRIPTION[][30] =
00023 {"Accelerometer", "GPS_sensor", "Velocity_sensor", "Tracker_sensor", "Track_robot", "Event_trigger", "void"};
00024
00030 class SensorBase
00031 {
00032 typedef std::deque<MeasureItem> Measurements;
00033
00034 static unsigned short m_static_id;
00035 unsigned short m_id;
00036 time m_period;
00037 time m_proc_time;
00038 unsigned short m_size;
00039 unsigned short m_current;
00040 virtual void Dynamic_Cast() {}
00041
00042 protected:
00044 Measurements m_data;
00045 SENSOR_TYPE m_type_name;
00046 OBS_MODEL_TYPE m_obs_model_type;
00047
00048
00049
00050
00051 public:
00052
00053 SensorBase(unsigned short measSize);
00054 SensorBase(SensorBase const& sensor);
00055 virtual ~SensorBase();
00056
00057 SensorBase & operator =(SensorBase const &sensor) {
00058 JFR_PRECOND(m_size == sensor.m_size, "bad sizes");
00059 m_period = sensor.m_period;
00060
00061 return *this;
00062 }
00063
00065 unsigned short GetID() { return m_id; }
00066 SENSOR_TYPE GetTypeName() { return m_type_name; }
00067 char const* GetName() { return SENSOR_DESCRIPTION[m_type_name]; }
00068 OBS_MODEL_TYPE GetObservationType() { return m_obs_model_type; }
00069
00070 void SetPeriod(const time& t) { m_period = t; }
00071 void SetPeriod(double period) { JFR_PRECOND(period > 0.0, "period <= 0.0"); SetPeriod(time(period)); }
00072 time const& GetPeriod() const { return m_period; }
00073 double GetPeriodSec() const { return m_period.to_double(); }
00074 void SetFrequency(double freq) { JFR_PRECOND (freq > 0.0, "freq <= 0.0"); m_period = time(1.0 / freq); }
00075 double GetFrequencySec() const { return 1.0 / m_period.to_double(); }
00076 void SetProcTime(const time& t) { JFR_PRECOND(t < m_period, "proc time >= period"); m_proc_time = t; }
00077 void SetProcTime(double ptime) { JFR_PRECOND (ptime >= 0.0, "proc time < 0.0"); SetProcTime(time(ptime)); }
00078 double GetProcTimeSec() const { return m_proc_time.to_double(); }
00079 time GetProcTime() const { return m_proc_time; }
00080
00081 unsigned short GetMeasureSize() const { return m_size; }
00082 void AddMeasurement(time sensed, time available, VEC &data);
00083 void AddMeasurementWithNoise(time sensed, time available, VEC &data);
00084 void ClearMeasurements() { m_data.clear(); }
00085 void SortMeasurements_AvailableTime();
00086 void SortMeasurements_SensedTime();
00087 unsigned short GetMeasurementsNr() { return (unsigned short) m_data.size();}
00088 void PrintData();
00089 double GetMinTimeSlice() const;
00090 MeasureItem const& GetMeasurement(unsigned short idx) const { JFR_PRECOND(idx < m_data.size(), "index"); return m_data[idx]; }
00091 time GetSensedTime(unsigned short idx) { JFR_PRECOND(idx < m_data.size(), "index"); return m_data[idx].GetSensedTime(); }
00092 time GetAvailableTime(unsigned short idx) { JFR_PRECOND(idx < m_data.size(), "index"); return m_data[idx].GetAvailableTime(); }
00093 double GetNextSensedTimeSec();
00094 bool EndBuf() const { return m_current == m_data.size(); }
00095 double GetNextAvailableTimeSec();
00096 time GetNextAvailableTime();
00097 time GetNextSensedTime();
00098 time GetCurrentSensedTime();
00099 int GetNextMeasurement(MeasureItem &meas);
00100 MeasureItem const& GetNextMeasurement();
00101 MeasureItem const& GetCurrentMeasurement() const;
00102 bool IncCounter() { m_current++; if (m_current < m_data.size()) return true; else return false;}
00103
00104 VEC GetNextData();
00105 void ResetGetNext() { m_current = 0; }
00106 unsigned short GetCurrent() const { return m_current; }
00107 void DumpMeasurements(const char* fname);
00108
00109 friend std::ostream& operator << (std::ostream &stream, SensorBase const& pd);
00110
00111 private:
00112 void DumpMeasure(unsigned short nb, MeasureItem const& meas, std::ofstream &stream) const;
00113 static bool compare_available(MeasureItem const& t1, MeasureItem const &t2) { return t1.compare_available(t2) == -1; }
00114 static bool compare_sensed(MeasureItem const& t1, MeasureItem const &t2) { return t1.compare_sensed(t2) == -1; }
00115 };
00116
00117 std::ostream& operator << (std::ostream &stream, SensorBase const& pd);
00118
00119 } // namespace ddfsimu
00120 } // namespace jafar
00121 #endif