simulation.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __SIMULATION_H
00025 #define __SIMULATION_H
00026
00027
00028 #include "base.h"
00029
00030 #include <osgViewer/Viewer>
00031 #include <osgViewer/ViewerEventHandlers>
00032 #include <osgGA/KeySwitchMatrixManipulator>
00033 #include <osg/Camera>
00034
00035
00036 #include <cmath>
00037 #define PI M_PI // (3.14159265358979323846)
00038 #include <vector>
00039 #include <iterator>
00040 #include <string>
00041
00042 #include "globaldata.h"
00043 #include "grabframe.h"
00044 #include "pos.h"
00045 #include "camerahandle.h"
00046
00047
00048 class PlotOption;
00049
00050 namespace lpzrobots {
00051 class LPZViewer;
00052 }
00053
00054
00055
00056 namespace lpzrobots {
00057
00058 class Simulation : public Base, public osgGA::GUIEventHandler
00059 {
00060 public:
00061
00062 enum SimulationState { none, initialised, running, closed };
00063 enum CameraMode {Static=0, Follow, TV, Race};
00064
00065 Simulation();
00066 virtual ~Simulation();
00067
00068
00069
00070
00071
00072 bool run(int argc, char** argv);
00073
00074
00075
00076
00077 virtual void start(const OdeHandle&, const OsgHandle&, GlobalData& globalData) = 0;
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 virtual bool restart(const OdeHandle&, const OsgHandle&, GlobalData& globalData);
00090
00091
00092 virtual void end(GlobalData& globalData);
00093
00094
00095
00096 virtual bool config(GlobalData& globalData);
00097
00098
00099
00100
00101 virtual bool command(const OdeHandle&, const OsgHandle&, GlobalData& globalData,
00102 int key, bool down) { return false; };
00103
00104
00105
00106 virtual void bindingDescription(osg::ApplicationUsage & au) const {};
00107
00108
00109
00110 virtual void usage() const {};
00111
00112
00113
00114
00115
00116 virtual bool collCallback(const OdeHandle&, void* data, dGeomID o1, dGeomID o2) { return false;};
00117
00118
00119
00120
00121
00122
00123
00124 virtual void addCallback(GlobalData& globalData, bool draw, bool pause, bool control) {};
00125
00126
00127
00128
00129 virtual void addPaletteFile(const std::string& filename, bool verbose = false);
00130
00131
00132
00133 virtual void addColorAliasFile(const std::string& filename, bool verbose = false);
00134
00135 virtual void odeStep();
00136
00137 virtual void osgStep();
00138
00139 protected:
00140
00141 virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
00142 virtual void getUsage (osg::ApplicationUsage & au) const;
00143 virtual void accept(osgGA::GUIEventHandlerVisitor& v);
00144 virtual bool init(int argc, char** argv);
00145
00146 virtual void updateGraphics();
00147
00148
00149
00150
00151
00152 void setCameraHomePos(const osg::Vec3& eye, const osg::Vec3& view);
00153
00154
00155
00156
00157
00158 void setCameraMode(CameraMode mode);
00159
00160
00161
00162
00163
00164 void setWatchedAgent(OdeAgent* agent);
00165
00166 static void nearCallback_TopLevel(void *data, dGeomID o1, dGeomID o2);
00167 static void nearCallback(void *data, dGeomID o1, dGeomID o2);
00168 bool control_c_pressed();
00169
00170
00171
00172
00173 std::list<PlotOption>& plotoptions;
00174
00175
00176
00177
00178
00179
00180 __attribute__ ((deprecated)) void showParams(const ConfigList& configs) {}
00181
00182 private:
00183 void insertCmdLineOption(int& argc,char**& argv);
00184 bool loop();
00185
00186 void tidyUp(GlobalData& globalData);
00187
00188 protected:
00189
00190 virtual bool processCmdLine(int argc, char** argv);
00191 void resetSyncTimer();
00192 long timeOfDayinMS();
00193
00194 private:
00195 static void control_c(int i);
00196 static void cmd_handler_exit();
00197 static void cmd_handler_init();
00198 static void cmd_begin_input();
00199 static void cmd_end_input();
00200
00201
00202 static void main_usage(const char* progname);
00203
00204 bool storeOdeRobotsCFG();
00205
00206
00207 protected:
00208 GlobalData globalData;
00209 osg::ref_ptr<VideoStream> videostream;
00210
00211 int nextLeakAnnounce;
00212 int leakAnnCounter;
00213 long realtimeoffset;
00214 long simtimeoffset;
00215 double truerealtimefactor;
00216 bool justresettimes;
00217
00218 paramint windowWidth;
00219 paramint windowHeight;
00220
00221 paramint defaultFPS;
00222
00223 bool pause;
00224 bool simulation_time_reached;
00225 long int simulation_time;
00226 bool noGraphics;
00227 bool useKeyHandler;
00228
00229
00230
00231
00232 int guiloggerinterval;
00233 int filelogginginterval;
00234 int matrixvizinterval;
00235
00236 char odeRobotsCfg[256];
00237
00238
00239
00240
00241
00242 int currentCycle;
00243
00244 CameraHandle cameraHandle;
00245
00246 parambool useOdeThread;
00247 parambool useOsgThread;
00248 parambool useQMPThreads;
00249 parambool inTaskedMode;
00250
00251 std::string windowName;
00252
00253 protected:
00254 SimulationState state;
00255 osg::ArgumentParser* arguments;
00256 LPZViewer* viewer;
00257 osgGA::KeySwitchMatrixManipulator* keyswitchManipulator;
00258
00259 static int ctrl_C;
00260 char** orig_argv;
00261
00262 std::list<std::string> paletteFiles;
00263 std::list<std::string> colorAliasFiles;
00264 bool verboseColorLoading;
00265
00266
00267
00268 bool startConfigurator;
00269
00270
00271 pthread_t odeThread;
00272 pthread_t osgThread;
00273 bool odeThreadCreated;
00274 bool osgThreadCreated;
00275
00276 };
00277
00278
00279
00280 void createNewDir(const char* base, char *newdir);
00281 }
00282
00283 #endif