Robotsystem from Robot Group Leipzig: odeconfig.h Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# odeconfig.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *                                                                         *
    00007  *   This program is free software; you can redistribute it and/or modify  *
    00008  *   it under the terms of the GNU General Public License as published by  *
    00009  *   the Free Software Foundation; either version 2 of the License, or     *
    00010  *   (at your option) any later version.                                   *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00015  *   GNU General Public License for more details.                          *
    00016  *                                                                         *
    00017  *   You should have received a copy of the GNU General Public License     *
    00018  *   along with this program; if not, write to the                         *
    00019  *   Free Software Foundation, Inc.,                                       *
    00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00021  *                                                                         *
    00022  *   $Log: odeconfig.h,v $
    00023  *   Revision 1.12.4.5  2006/03/28 09:55:12  robot3
    00024  *   -main: fixed snake explosion bug
    00025  *   -odeconfig.h: inserted cameraspeed
    00026  *   -camermanipulator.cpp: fixed setbyMatrix,
    00027  *    updateFactor
    00028  *
    00029  *   Revision 1.12.4.4  2006/02/08 16:14:28  martius
    00030  *   no namespace using
    00031  *
    00032  *   Revision 1.12.4.3  2006/01/10 15:08:15  martius
    00033  *   controlinterval is 1 by default
    00034  *
    00035  *   Revision 1.12.4.2  2005/12/06 10:13:23  martius
    00036  *   openscenegraph integration started
    00037  *
    00038  *   Revision 1.12.4.1  2005/11/14 17:37:00  martius
    00039  *   changed makefile structure to have and include directory
    00040  *   mode to selforg
    00041  *
    00042  *   Revision 1.12  2005/11/09 13:29:19  martius
    00043  *   GPL'ised
    00044  *
    00045  ***************************************************************************/
    00046 #ifndef __ODECONFIG_H
    00047 #define __ODECONFIG_H
    00048
    00049 #include <ode/ode.h>
    00050 #include <selforg/configurable.h>
    00051 #include "odehandle.h"
    00052
    00053 namespace lpzrobots {
    00054
    00055 class OdeConfig : public Configurable {
    00056 public:
    00057   OdeConfig() :
    00058     name ("Simulation Environment: ")
    00059   {
    00060     simStepSize=0.01;
    00061     controlInterval=1;
    00062     realTimeFactor=1.0;
    00063     noise=0.1;
    00064     gravity=-9.81;
    00065     drawInterval=calcDrawInterval();
    00066     cameraSpeed=100;
    00067       // prepare name;
    00068     Configurable::insertCVSInfo(name, "$RCSfile: odeconfig.h,v $", "$Revision: 1.12.4.5 $");
    00069   }
    00070
    00071   virtual ~OdeConfig(){}
    00072
    00073   virtual paramkey getName() const {
    00074     return name;
    00075   }
    00076
    00077   virtual paramlist getParamList() const{
    00078     paramlist list;
    00079     list.push_back(std::pair<paramkey, paramval> (std::string("noise"), noise));
    00080     list.push_back(std::pair<paramkey, paramval> (std::string("simstepsize"), simStepSize));
    00081     list.push_back(std::pair<paramkey, paramval> (std::string("realtimefactor"), realTimeFactor));
    00082     list.push_back(std::pair<paramkey, paramval> (std::string("drawinterval"), drawInterval));
    00083     list.push_back(std::pair<paramkey, paramval> (std::string("controlinterval"), controlInterval));
    00084     list.push_back(std::pair<paramkey, paramval> (std::string("cameraspeed"), cameraSpeed));
    00085     list.push_back(std::pair<paramkey, paramval> (std::string("gravity"), gravity));
    00086     return list;
    00087   }
    00088
    00089
    00090   paramval getParam(const paramkey& key) const {
    00091     if(key == "noise") return noise;
    00092     else if(key == "simstepsize") return simStepSize;
    00093     else if(key == "realtimefactor") return realTimeFactor;
    00094     else if(key == "drawinterval") return drawInterval;
    00095     else if(key == "controlinterval") return controlInterval;
    00096     else if(key == "cameraspeed") return cameraSpeed;
    00097     else if(key == "gravity") return gravity;
    00098     else  return 0.0;
    00099   }
    00100
    00101   bool setParam(const paramkey& key, paramval val){
    00102     if(key == "noise") noise = val;
    00103     else if(key == "simstepsize") {
    00104       simStepSize=std::max(0.0000001,val);
    00105       drawInterval=calcDrawInterval();
    00106     }else if(key == "realtimefactor"){
    00107       realTimeFactor=std::max(0.0,val);
    00108       drawInterval=calcDrawInterval();
    00109     }
    00110     else if(key == "drawinterval") drawInterval=(int)val;
    00111     else if(key == "controlinterval") controlInterval=(int)val;
    00112     else if(key == "cameraspeed") cameraSpeed=(int)val;
    00113     else if(key == "gravity") {
    00114       gravity=val;
    00115       dWorldSetGravity ( odeHandle.world , 0 , 0 , gravity );
    00116     }
    00117     else return false;
    00118     return true;
    00119   }
    00120
    00121   void setOdeHandle(const OdeHandle& odeHandle){
    00122     this->odeHandle = odeHandle;
    00123   }
    00124
    00125 private:
    00126   /// calculates the draw interval with simStepSize and realTimeFactor so that we have 25 frames/sec
    00127   int calcDrawInterval(){
    00128     if(realTimeFactor>0 && simStepSize>0){
    00129       return int(ceil(1/(25.0*simStepSize/realTimeFactor)));
    00130     }else return 50;
    00131   }
    00132
    00133
    00134 public:
    00135   double simStepSize;
    00136   double realTimeFactor;
    00137   int drawInterval;
    00138   int controlInterval;
    00139   double noise;
    00140   double gravity;
    00141   double cameraSpeed;
    00142   std::string name;
    00143   OdeHandle odeHandle;
    00144 };
    00145
    00146 }
    00147
    00148 #endif