iCub-main
main.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3  * Author: Ugo Pattacini
4  * email: ugo.pattacini@iit.it
5  * Permission is granted to copy, distribute, and/or modify this program
6  * under the terms of the GNU General Public License, version 2 or any
7  * later version published by the Free Software Foundation.
8  *
9  * A copy of the license can be found at
10  * http://www.robotcub.org/icub/license/gpl.txt
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details
16 */
17 
18 #include <yarp/os/all.h>
19 #include <yarp/dev/all.h>
20 #include <fakeMotorDevice.h>
21 
22 #include <iostream>
23 #include <iomanip>
24 #include <string>
25 
26 using namespace std;
27 using namespace yarp::os;
28 using namespace yarp::dev;
29 
33 class ServerModule: public RFModule
34 {
35 protected:
36  PolyDriver partDrv;
37  PolyDriver server;
38 
39 public:
40  /**********************************************************/
41  bool configure(ResourceFinder &rf)
42  {
43  // grab parameters from the configuration file
44  string robot=rf.find("robot").asString();
45  string part=rf.find("part").asString();
46  string local=rf.find("local").asString();
47  string pathToKin=rf.findFile("kinematics_file");
48 
49  // prepare the option to open up the device driver to
50  // access the fake robot
51  Property optPart;
52  optPart.put("device","fakeyClient");
53  optPart.put("remote","/"+robot+"/"+part);
54  optPart.put("local","/"+local+"/"+part);
55  optPart.put("part",part);
56 
57  // open the device driver
58  if (!partDrv.open(optPart))
59  {
60  cout<<"Error: Device driver not available!"<<endl;
61  close();
62  return false;
63  }
64 
65  // now go on with the server driver
66  PolyDriverList list;
67  list.push(&partDrv,part.c_str());
68 
69  // take the parameters and fill the kinematic description
70  Property optServer("(device cartesiancontrollerserver)");
71  optServer.fromConfigFile(rf.findFile("from"),false);
72  if (!server.open(optServer))
73  {
74  cout<<"Error: Unable to open the Cartesian Controller Server!"<<endl;
75  close();
76  return false;
77  }
78 
79  // attach the device driver to the server
80  IMultipleWrapper *wrapper;
81  server.view(wrapper);
82  if (!wrapper->attachAll(list))
83  {
84  cout<<"Error: Unable to attach device drivers!"<<endl;
85  close();
86  return false;
87  }
88 
89  return true;
90  }
91 
92  /**********************************************************/
93  bool close()
94  {
95  if (server.isValid())
96  server.close();
97 
98  if (partDrv.isValid())
99  partDrv.close();
100 
101  return true;
102  }
103 
104  /**********************************************************/
105  double getPeriod() { return 1.0; }
106  bool updateModule() { return true; }
107 };
108 
109 
110 /**********************************************************/
111 int main(int argc, char *argv[])
112 {
113  Network yarp;
114  if (!yarp.checkNetwork())
115  {
116  cout<<"Error: yarp server does not seem available"<<endl;
117  return 1;
118  }
119 
120  // register here the new yarp devices
121  // for dealing with the fake robot
123 
124  ResourceFinder rf;
125  rf.setDefaultConfigFile("server.ini");
126  rf.setDefault("robot","fake_robot");
127  rf.setDefault("part","fake_part");
128  rf.setDefault("local","server");
129  rf.setDefault("kinematics_file","kinematics.ini");
130  rf.configure(argc,argv);
131 
132  ServerModule server;
133  return server.runModule(rf);
134 }
135 
136 
This class launches the server.
Definition: main.cpp:34
bool close()
Definition: main.cpp:93
PolyDriver partDrv
Definition: main.cpp:36
PolyDriver server
Definition: main.cpp:37
double getPeriod()
Definition: main.cpp:105
bool updateModule()
Definition: main.cpp:106
bool configure(ResourceFinder &rf)
Definition: main.cpp:41
void registerFakeMotorDevices()
Register new yarp devices for fake motor handling.
int main(int argc, char *argv[])
Definition: main.cpp:31
Copyright (C) 2008 RobotCub Consortium.