iCub-main
RobotConfig.cpp
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 
21 #include "RobotConfig.h"
22 
23 #include <yarp/os/Property.h>
24 #include <yarp/os/LogStream.h>
25 #include <iostream>
26 #include <cstdlib>
27 #include <string>
28 
29 using namespace yarp::os;
30 using namespace std;
31 
32 static void set_flag(bool& flag,const string& str) {
33  flag = (str=="on" || str=="1" || str=="ON" || str=="true" || str=="TRUE");
34 }
35 #define FLAGIFY(flags,name) set_flag(flags.name,name)
36 
38  string parts = getFinder().findFile("parts");
39  if (parts == ""){
40  parts = getFinder().findFile("general");
41  }
42 
43  Property options;
44  options.fromConfigFile(parts.c_str());
45 
46  RobotFlags& flags = getFlags();
47  //bool proceed = false;
48 
49  string actElevation = options.findGroup("SETUP").check("elevation",Value(1),"what did the user select?").asString();
50  if ( actElevation.length()<1 ) stopConfig("actElevation");//, proceed);
51  FLAGIFY(flags,actElevation);
52 
53  string actStartHomePos = options.findGroup("SETUP").check("startHomePos",Value(1),"what did the user select?").asString();
54  if (actStartHomePos.length()<1 ) stopConfig("actStartHomePos");//, proceed);
55  FLAGIFY(flags, actStartHomePos);
56 
57  string actLegs = options.findGroup("PARTS").check("legs",Value(1),"what did the user select?").asString();
58  if (actLegs.length()<1 ) stopConfig("actLegs");//, proceed);
59  FLAGIFY(flags,actLegs);
60 
61  string actTorso = options.findGroup("PARTS").check("torso",Value(1),"what did the user select?").asString();
62  if (actTorso.length()<1 ) stopConfig("actTorso");//, proceed);
63  FLAGIFY(flags,actTorso);
64 
65  string actLArm = options.findGroup("PARTS").check("left_arm",Value(1),"what did the user select?").asString();
66  if (actLArm.length()<1 ) stopConfig("actLArm");//, proceed);
67  FLAGIFY(flags,actLArm);
68 
69  string actRArm = options.findGroup("PARTS").check("right_arm",Value(1),"what did the user select?").asString();
70  if (actRArm.length()<1 ) stopConfig("actRArm");//, proceed);
71  FLAGIFY(flags,actRArm);
72 
73  string actLHand = options.findGroup("PARTS").check("left_hand",Value(1),"what did the user select?").asString();
74  if (actLHand.length()<1 ) stopConfig("actLHand");//, proceed);
75  FLAGIFY(flags,actLHand);
76 
77  string actRHand = options.findGroup("PARTS").check("right_hand",Value(1),"what did the user select?").asString();
78  if (actRHand.length()<1 ) stopConfig("actRHand");//, proceed);
79  FLAGIFY(flags,actRHand);
80 
81  string actHead = options.findGroup("PARTS").check("head",Value(1),"what did the user select?").asString();
82  if (actHead.length()<1 ) stopConfig("actHead");//, proceed);
83  FLAGIFY(flags,actHead);
84 
85  string actfixedHip = options.findGroup("PARTS").check("fixed_hip",Value(1),"what did the user select?").asString();
86  if (actfixedHip.length()<1 ) stopConfig("actfixedHip");//, proceed);
87  FLAGIFY(flags,actfixedHip);
88 
89  string actSelfCol = options.findGroup("COLLISIONS").check("self_collisions",Value(1),"what did the user select?").asString();
90  if (actSelfCol.length()<1 ) stopConfig("actSelfCol");//, proceed);
91  FLAGIFY(flags,actSelfCol);
92 
93  string actCoversCol = options.findGroup("COLLISIONS").check("covers_collisions",Value(1),"what did the user select?").asString();
94  if (actCoversCol.length()<1 ) stopConfig("actCoversCol");//, proceed);
95  FLAGIFY(flags,actCoversCol);
96 
97  string actVision = options.findGroup("VISION").check("cam",Value(1),"What did the user select?").asString();
98  if (actVision.length()<1 ) stopConfig("actVision");//, proceed);
99  FLAGIFY(flags,actVision);
100 
101  string actPressure = options.findGroup("SENSORS").check("pressure",Value(1),"What did the user select?").asString();
102  if (actPressure.length()<1 ) stopConfig("actPressure");//, proceed);
103  FLAGIFY(flags,actPressure);
104 
105  string actSkinEmul = options.findGroup("SENSORS").check("whole_body_skin_emul",Value(1),"What did the user select?").asString();
106  if (actSkinEmul.length()<1 ) stopConfig("actSkinEmul");//, proceed);
107  FLAGIFY(flags,actSkinEmul);
108 
109  string actWorld = options.findGroup("RENDER").check("objects",Value(1),"What did the user select?").asString();
110  if (actWorld.length()<1 ) stopConfig("actWorld");//, proceed);
111  FLAGIFY(flags,actWorld);
112 
113  string actScreen = options.findGroup("RENDER").check("screen",Value(1),"What did the user select?").asString();
114  if (actScreen.length()<1 ) stopConfig("actScreen");//, proceed);
115  FLAGIFY(flags,actScreen);
116 
117  string actHeadCover = options.findGroup("RENDER").check("head_cover",Value(1),"What did the user select?").asString();
118  if (actHeadCover.length()<1 ) stopConfig("actHeadCover");//, proceed);
119  FLAGIFY(flags,actHeadCover);
120 
121  string actLegsCovers = options.findGroup("RENDER").check("legs_covers",Value(1),"What did the user select?").asString();
122  if (actLegsCovers.length()<1 ) stopConfig("actLegsCovers");//, proceed);
123  FLAGIFY(flags,actLegsCovers);
124 
125  string actLeftArmCovers = options.findGroup("RENDER").check("left_arm_covers",Value(1),"What did the user select?").asString();
126  if (actLeftArmCovers.length()<1 ) stopConfig("actLeftArmCovers");//, proceed);
127  FLAGIFY(flags,actLeftArmCovers);
128 
129  string actRightArmCovers = options.findGroup("RENDER").check("right_arm_covers",Value(1),"What did the user select?").asString();
130  if (actRightArmCovers.length()<1 ) stopConfig("actRightArmCovers");//, proceed);
131  FLAGIFY(flags,actRightArmCovers);
132 
133  string actTorsoCovers = options.findGroup("RENDER").check("torso_covers",Value(1),"What did the user select?").asString();
134  if ( actTorsoCovers.length()<1 ) stopConfig("actTorsoCovers");//, proceed);
135  FLAGIFY(flags,actTorsoCovers);
136 
137  //if (proceed)
138  flags.valid = true;
139  //else
140  //flags.valid = false;
141 
142  yInfo() << "The iCub simulator will start with the following configuration: \n\n" <<
143  "Elevation : " << actElevation << "\n" <<
144  "startHomePos : " << actStartHomePos << "\n" <<
145  "Legs : " << actLegs << "\n" <<
146  "Torso : " << actTorso << "\n" <<
147  "Left arm : " << actLArm << "\n" <<
148  "Left hand : " << actLHand << "\n" <<
149  "Right arm : " << actRArm << "\n" <<
150  "Right hand : " << actRHand << "\n" <<
151  "Head : " << actHead << "\n" <<
152  "Fixed Hip : " << actfixedHip << "\n" << "\n" <<
153  "Self-collisions : " << actSelfCol << "\n" <<
154  "Collisions for covers : " << actCoversCol << "\n" << "\n" <<
155  "Pressure sensors: " << actPressure << "\n" <<
156  "Whole body skin emulation: " << actSkinEmul << "\n" <<
157  "Cameras :" << actVision << "\n" <<
158  "Objects : " << actWorld << "\n" <<
159  "Head Cover : " << actHeadCover << "\n" <<
160  "Legs Cover : " << actLegsCovers << "\n" <<
161  "Left arm Covers : " << actLeftArmCovers << "\n" <<
162  "Right arm Covers : " << actRightArmCovers << "\n" <<
163  "Torso Cover : " << actTorsoCovers << "\n" <<
164  "Screen : " << actScreen << "\n" << "\n";
165 
166 }
167 
168 
169 //bool RobotConfig::stopConfig(string error, bool proceed){
170 void RobotConfig::stopConfig( string error ){
171 
172  yError() << "\n\n\nThere seems to be a conflict with the " << error << " configuration file";
173  yError() << "Check the iCub_parts_activation.ini under $ICUB_ROOT/app/simConfig ";
174  yError() << "If it still does not work (update svn) and re-install the app folder\n\n";
175  yError() << "The iCub simulator will not start..\n\n\n";
176  std::exit(1); // we can do this as no port has been created yet
177  //return false;
178 }
179 
RobotFlags::valid
bool valid
Definition: RobotConfig.h:30
RobotConfig::stopConfig
void stopConfig(std::string error)
Definition: RobotConfig.cpp:170
RobotConfig::setFlags
void setFlags()
Definition: RobotConfig.cpp:37
RobotConfig.h
RobotFlags
Definition: RobotConfig.h:28
set_flag
static void set_flag(bool &flag, const string &str)
Definition: RobotConfig.cpp:32
FLAGIFY
#define FLAGIFY(flags, name)
Definition: RobotConfig.cpp:35