iCub-main
SimConfig.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4 * Copyright (C) 2010 RobotCub Consortium, European Commission FP6 Project IST-004370
5 * Author: Paul Fitzpatrick, Vadim Tikhanoff
6 * email: paulfitz@alum.mit.edu, vadim.tikhanoff@iit.it
7 * website: www.robotcub.org
8 * Permission is granted to copy, distribute, and/or modify this program
9 * under the terms of the GNU General Public License, version 2 or any
10 * later version published by the Free Software Foundation.
11 *
12 * A copy of the license can be found at
13 * http://www.robotcub.org/icub/license/gpl.txt
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details
19 */
20 
29 #ifndef SIMCONFIG_INC
30 #define SIMCONFIG_INC
31 
32 #include <yarp/os/ResourceFinder.h>
33 #include <yarp/os/Bottle.h>
34 #include <stdio.h>
35 #include <string>
36 #include <fstream>
37 #include <sstream>
38 
39 #include "RobotConfig.h"
40 
41 using namespace std;
42 using namespace yarp::os;
43 
44 class SimConfig : public yarp::os::ResourceFinder, public RobotConfig {
45 
46 public:
47 
49  odeParamRead = false;
50  }
51 
52  // can't actually configure from command line yet, since
53  // some config files get loaded before main() - this needs
54  // to be fixed.
55  std::string configure(int argc, char *argv[], std::string &moduleName, int &verbosity);
56 
57  //std::stringfind(const char *fileName);
58  //std::string findPath(const char *key);
59  //bool isActive();
60 
61  //void deleteFinder();
62 
63  // RobotConfig interface
64 
66  return moduleName.c_str();
67  }
68 
69  virtual int getVerbosity() {
70  return verbosity;
71  }
72 
73  virtual yarp::os::ResourceFinder& getFinder() {
74  return *this;
75  }
76 
78  return flags;
79  }
80 
81  virtual double getWorldCFM() {
82  readOdeParams();
83  return p.worldCFM;
84  }
85  virtual double getWorldERP() {
86  readOdeParams();
87  return p.worldERP;
88  }
89  virtual double getFudgeFactor(){
90  readOdeParams();
91  return p.fudgeFactor;
92  }
93  virtual double getStopCFM(){
94  readOdeParams();
95  return p.stopCFM;
96  }
97  virtual double getJointCFM(){
98  readOdeParams();
99  return p.jointCFM;
100  }
101  virtual double getStopERP(){
102  readOdeParams();
103  return p.stopERP;
104  }
105  virtual double getMaxContactCorrectingVel(){
106  readOdeParams();
107  return p.maxContactCorrectingVel;
108  }
110  readOdeParams();
111  return p.contactFrictionCoefficient;
112  }
113  virtual double getContactSurfaceLayer(){
114  readOdeParams();
115  return p.contactSurfaceLayer;
116  }
117  virtual double getMotorMaxTorque(){
118  readOdeParams();
119  return p.motorMaxTorque;
120  }
121  virtual double getMotorDryFriction(){
122  readOdeParams();
123  return p.motorDryFriction;
124  }
125  virtual double getJointStopBouncyness(){
126  readOdeParams();
127  return p.jointStopBouncyness;
128  }
129  virtual int getWorldTimestep(){
130  readOdeParams();
131  return p.worldTimestep;
132  }
134  readOdeParams();
135  return p;
136  }
137 
138 
139 private:
140  std::string moduleName;
141  int verbosity;
142  RobotFlags flags;
143 
144  bool odeParamRead;
145  OdeParams p;
146 
147 
148  void readOdeParams(){
149  if(odeParamRead==true)
150  return;
151 
152  Property bParams;
153  bParams.fromConfigFile(findFile(find("ode").asString().c_str()).c_str());
154  Bottle &bParamWorld = bParams.findGroup("WORLD");
155  Bottle &bParamContacts = bParams.findGroup("CONTACTS");
156  Bottle &bParamJoints = bParams.findGroup("JOINTS");
157 
158  p.worldTimestep = bParamWorld.check("timestep", Value(10)).asInt32();
159  p.worldCFM = bParamWorld.check("worldCFM", Value(0.00001)).asFloat64();
160  p.worldERP = bParamWorld.check("worldERP", Value(0.2)).asFloat64();
161 
162  p.maxContactCorrectingVel = bParamContacts.check("maxContactCorrectingVel", Value(1e6)).asFloat64();
163  p.contactFrictionCoefficient = bParamContacts.check("contactFrictionCoefficient",Value(1.0)).asFloat64();
164  p.contactSurfaceLayer = bParamContacts.check("contactSurfaceLayer", Value(0.0)).asFloat64();
165 
166  p.fudgeFactor = bParamJoints.check("fudgeFactor", Value(0.02)).asFloat64();
167  p.jointCFM = bParamJoints.check("jointCFM", Value(1e-5)).asFloat64();
168  p.stopCFM = bParamJoints.check("stopCFM", Value(1e-5)).asFloat64();
169  p.stopERP = bParamJoints.check("stopERP", Value(0.2)).asFloat64();
170  p.motorMaxTorque = bParamJoints.check("motorMaxTorque", Value(1e3)).asFloat64();
171  p.motorDryFriction = bParamJoints.check("motorDryFriction", Value(0.1)).asFloat64();
172  p.jointStopBouncyness = bParamJoints.check("jointStopBouncyness", Value(0.1)).asFloat64();
173 
174  odeParamRead = true;
175  }
176 };
177 
178 
179 #endif
180 
SimConfig::getJointStopBouncyness
virtual double getJointStopBouncyness()
Definition: SimConfig.h:125
SimConfig::getFudgeFactor
virtual double getFudgeFactor()
Definition: SimConfig.h:89
RobotConfig
Definition: RobotConfig.h:55
e
e
Definition: compute_ekf_fast.m:13
SimConfig::getWorldTimestep
virtual int getWorldTimestep()
Definition: SimConfig.h:129
SimConfig::getJointCFM
virtual double getJointCFM()
Definition: SimConfig.h:97
SimConfig::getStopCFM
virtual double getStopCFM()
Definition: SimConfig.h:93
verbosity
int verbosity
Definition: main.cpp:21
p
p
Definition: show_eyes_axes.m:23
OdeParams
Definition: RobotConfig.h:37
SimConfig::getFlags
RobotFlags & getFlags()
Definition: SimConfig.h:77
SimConfig::getStopERP
virtual double getStopERP()
Definition: SimConfig.h:101
SimConfig::getWorldCFM
virtual double getWorldCFM()
Definition: SimConfig.h:81
SimConfig::getFinder
virtual yarp::os::ResourceFinder & getFinder()
Definition: SimConfig.h:73
SimConfig::SimConfig
SimConfig()
Definition: SimConfig.h:48
SimConfig::getContactSurfaceLayer
virtual double getContactSurfaceLayer()
Definition: SimConfig.h:113
string
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}") include_directories($
Definition: CMakeLists.txt:9
SimConfig::getOdeParameters
virtual OdeParams getOdeParameters()
Definition: SimConfig.h:133
RobotConfig.h
SimConfig::getMotorDryFriction
virtual double getMotorDryFriction()
Definition: SimConfig.h:121
SimConfig::getContactFrictionCoefficient
virtual double getContactFrictionCoefficient()
Definition: SimConfig.h:109
scripting.argc
argc
Definition: scripting.py:184
SimConfig::getMotorMaxTorque
virtual double getMotorMaxTorque()
Definition: SimConfig.h:117
RobotFlags
Definition: RobotConfig.h:28
SimConfig::getModuleName
virtual std::string getModuleName()
Definition: SimConfig.h:65
SimConfig
Definition: SimConfig.h:44
SimConfig::getMaxContactCorrectingVel
virtual double getMaxContactCorrectingVel()
Definition: SimConfig.h:105
SimConfig::getVerbosity
virtual int getVerbosity()
Definition: SimConfig.h:69
SimConfig::getWorldERP
virtual double getWorldERP()
Definition: SimConfig.h:85