Go to the documentation of this file.00001
00012 #ifndef HARDWARESENSORADHOCSIMULATOR_HPP_
00013 #define HARDWARESENSORADHOCSIMULATOR_HPP_
00014
00015 #include "rtslam/simulator.hpp"
00016 #include "rtslam/hardwareSensorAbstract.hpp"
00017
00018 namespace jafar {
00019 namespace rtslam {
00020 namespace hardware {
00021
00022 class HardwareSensorAdhocSimulator: public HardwareSensorExteroAbstract
00023 {
00024 private:
00025 double dt;
00026 size_t n;
00027 boost::shared_ptr<simu::AdhocSimulator> simulator;
00028 size_t robId, senId;
00029 protected:
00030 virtual void getTimingInfos(double &data_period, double &arrival_delay) { data_period=dt; arrival_delay=0.; }
00031 public:
00032 HardwareSensorAdhocSimulator(kernel::VariableCondition<int> *condition, double freq, boost::shared_ptr<simu::AdhocSimulator> simulator, size_t robId, size_t senId):
00033 HardwareSensorExteroAbstract(condition, mOnline, 3),
00034 dt(1./freq), n(0), simulator(simulator), robId(robId), senId(senId) {}
00035 virtual void start() {}
00036 virtual void stop() {}
00037 virtual bool join(int timed_ms = -1) { return true; }
00038
00039 int getRawInfo(size_t m, RawInfo &info)
00040 {
00041 info.timestamp = m*dt;
00042 info.arrival = info.timestamp;
00043 info.id = m;
00044 if (simulator->hasEnded(robId, senId, info.timestamp)) return -2;
00045 return 0;
00046 }
00047
00048 virtual double getLastTimestamp() { return (n-1)*dt; }
00049
00050 virtual int getUnreadRawInfos(RawInfos &infos)
00051 {
00052 infos.available.clear();
00053 RawInfo info;
00054 int res = getRawInfo(n, info);
00055 if (res != -2) infos.available.push_back(info);
00056 infos.integrate_all = false;
00057 getRawInfo(n+1, info);
00058 infos.next = info;
00059 infos.process_time = 0;
00060 return res;
00061 }
00062
00063 virtual int getNextRawInfo(RawInfo &info)
00064 {
00065 return getRawInfo(n, info);
00066 }
00067
00068 virtual void getRaw(unsigned id, raw_ptr_t& raw)
00069 {
00070 double t = id*dt;
00071 raw = simulator->getRaw(robId, senId, t);
00072 n = id+1;
00073 return;
00074 }
00075
00076 virtual double getRawTimestamp(unsigned id)
00077 {
00078 return id*dt;
00079 }
00080
00081 virtual int getLastUnreadRaw(raw_ptr_t& raw)
00082 {
00083 getRaw(n++, raw);
00084 if (simulator->hasEnded(robId, senId, (n-1)*dt)) return -2;
00085 return 0;
00086 }
00087
00088 virtual void getLastProcessedRaw(raw_ptr_t& raw)
00089 {
00090 getRaw(n-1, raw);
00091 }
00092
00093 virtual void release() {}
00094
00095 };
00096
00097 }}}
00098
00099 #endif