// script.hh #ifndef SCRIPT_LOADED #define SCRIPT_LOADED #include #include #include #include #include #include #include "Timer.hh" #include "P_Motion.hh" #include "O_LaserScan.hh" #include "O_SonarScan.hh" const int maxStringLength = 4096; const int maxNumberOfProximityReadings = 1024; #define origScriptOpenMark "@OPEN" #define origScriptPosMark "#ROBOT" #define origScriptBumperMark "#BUMP" #define origScriptSonarMark "#SONAR" #define origScriptLaserMark "#LASER" #define origScriptMarkerMark "#MARKER:" #define origScriptTimeMark "@SENS" #define origScriptImageMark "#IMAGE" const int origScriptTimeOffset = 9; //#define newScriptOpenMark "begin(patternset)" #define newScriptOpenMark "begin(pattern)" #define newScriptPosMark "position:" #define newScriptBumperMark "" #define newScriptSonarMark "sonars" #define newScriptLaserMark "lasers" #define newScriptMarkerMark "marker:" #define newScriptTimeMark "time:" #define newScriptImageMark "image" const int newScriptTimeOffset = 0; #define scriptBumpMark "#BUMP" const int NO_ITEM_TYPE = -1; const int LASER_ITEM_TYPE = 0; const int SONAR_ITEM_TYPE = 1; #define SCRIPT_TYPE_NOT_SET 0 #define OLD_SCRIPT_TYPE 1 #define NEW_SCRIPT_TYPE 2 typedef struct { State position; float timeStamp; } refPos; ///////////////////////////////////////////////////////////////// // Reads a script and sends the data via tcx. ///////////////////////////////////////////////////////////////// class script { public: script( string& fileName, string& refPosFile, bool useSonar = true, bool useLaser = false, float timeFactor = 1.0, float skipDistance = 20.0, int startTime = 0, int numberOfLaserScanners = 1, int scriptType = SCRIPT_TYPE_NOT_SET); void readReferencePositions( string& fileName); inline State getRefPos(); inline void setTimeFactor( float timeFactor); bool updateObservation( O_SonarScan* scan); bool updateObservation( O_LaserScan* scan); inline bool useSonar() const; inline bool useLaser() const; protected: bool getNextItem(); inline bool getNextLine( char* line); inline bool readingLine(char *line, char *mark); inline Timer getTime(char *line, char *mark, int offset); inline State extractPosition( char* line, char *mark); inline bool extractLaserScan( char* line, O_LaserScan& scan); inline bool extractSonarScan( char* line, O_SonarScan& scan); private: char *fileName; O_LaserScan _laser; O_SonarScan _sonar; State _scriptPosition; bool _useSonar; bool _useLaser; bool _realTimeMode; char *timeMark; char *positionMark; char *laserMark; char *sonarMark; char *imageMark; int timeOffset; int _scriptType; Timer _startTime; Timer _previousTime; #ifdef USE_ZLIB gzFile _zFile; #else FILE* _file; #endif FILE* _stdin; Timer _realTime; float _elapsedTime; float _elapsedTimeSinceLastMeasurement; float _timeFactor; float _timeSkipped; float _skipDistance; float _skipTime; vector _referencePositions; }; extern State referencePosition; #endif