Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LoggedDataDriver.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LoggedDataDriver_h_
00003 #define INCLUDED_LoggedDataDriver_h_
00004 
00005 #include "local/DeviceDriver.h"
00006 #include "local/DataSources/FileSystemSensorSource.h"
00007 #include "local/DataSources/FileSystemImageSource.h"
00008 
00009 //! description of LoggedDataDriver
00010 class LoggedDataDriver : public virtual DeviceDriver, public virtual plist::PrimitiveListener {
00011 public:
00012   LoggedDataDriver(const std::string& name) : DeviceDriver(autoRegisterLoggedDataDriver,name),
00013     path("logged"), fsSensorSrc(*this, ".*\\.pos$"), fsImageSrc(*this, ".*\\.(jpg|jpeg|png)$")
00014   {
00015     addEntry("Path",path,"The directory from which data samples should be loaded, or a single specific file.\nA single file can be either a single data file (e.g. sensor or camera image), or an index file as output by VisionGUI, or in the format 'filename <tab> time', where 'filename' is an absolute path or relative to the directory containing the index file, and 'time' is in milliseconds, relative to the time at which the index file is loaded.\nIn the future, this could also be network addresses for teleoperation and remote processing.");
00016     addEntry("Sensors",fsSensorSrc,"Settings for loading logged sensor readings (stored in PostureEngine format)");
00017     addEntry("Camera",fsImageSrc,"Settings for loading logged camera images (stored as either JPEG or PNG)");
00018     path.addPrimitiveListener(this);
00019     fsSensorSrc.path.addPrimitiveListener(this);
00020     fsImageSrc.path.addPrimitiveListener(this);
00021   }
00022   
00023   virtual std::string getClassName() const { return autoRegisterLoggedDataDriver; }
00024   
00025   virtual void getSensorSources(std::map<std::string,DataSource*>& sources) {
00026     sources.clear();
00027     sources["Sensors"]=&fsSensorSrc;
00028   }
00029   virtual void getImageSources(std::map<std::string,DataSource*>& sources) {
00030     sources.clear();
00031     sources["Camera"]=&fsImageSrc;
00032   }
00033   
00034   virtual void plistValueTouched(const plist::PrimitiveBase& pl) {
00035     plistValueChanged(pl);
00036   }
00037   virtual void plistValueChanged(const plist::PrimitiveBase& pl) {
00038     if(&pl==&path) {
00039       // reload file lists for data sources which aren't overriding the common path
00040       bool good=true;
00041       if(fsSensorSrc.path.size()==0 && fsSensorSrc.isRegistered())
00042         good=fsSensorSrc.loadFileList();
00043       if(fsImageSrc.path.size()==0 && fsImageSrc.isRegistered()) {
00044         if(good)
00045           fsImageSrc.loadFileList();
00046         else // already got (and reported) an error on the path, don't try again
00047           fsImageSrc.clearFiles();
00048       }
00049     }
00050     if(&pl==&fsSensorSrc.path || &pl==&fsImageSrc.path || &pl==&path) {
00051       // if both streams are using the same source...
00052       if(fsSensorSrc.getUsedPath()==fsImageSrc.getUsedPath()) {
00053         //keep them in sync across loops, smooth offset between end times
00054         //std::cout << "SYNCING LOOP TIMES" << std::endl;
00055         double looptime=std::max(fsSensorSrc.getLoopTime(false),fsImageSrc.getLoopTime(false));
00056         if(looptime>0) { // if negative, indicates neither in use, framerates are unknown
00057           fsSensorSrc.setLoopTime(looptime);
00058           fsImageSrc.setLoopTime(looptime);
00059         }
00060       }
00061     } else {
00062       std::cerr << "LoggedDataDriver didn't handle call to plistValueChanged for " << pl.get() << std::endl;
00063     }
00064   }
00065   
00066   plist::Primitive<std::string> path;
00067   
00068 protected:
00069   FileSystemSensorSource fsSensorSrc;
00070   FileSystemImageSource fsImageSrc;
00071   
00072 private:
00073   //! holds the class name, set via registration with the DeviceDriver registry
00074   static const std::string autoRegisterLoggedDataDriver;
00075 };
00076 
00077 /*! @file
00078  * @brief 
00079  * @author Ethan Tira-Thompson (ejt) (Creator)
00080  */
00081 
00082 #endif

Tekkotsu Hardware Abstraction Layer 5.1CVS
Generated Mon May 9 05:01:38 2016 by Doxygen 1.6.3