icub-client
main.cpp
Go to the documentation of this file.
1 /*
2 * Copyright(C) 2017 WYSIWYD Consortium, European Commission FP7 Project ICT - 612139
3 * Authors: Tobias Fischer
4 * email : t.fischer@imperial.ac.uk
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 * icub-client / 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 <string>
19 #include <list>
20 
21 #include <yarp/os/all.h>
22 #include <icubclient/all.h>
23 
24 using namespace yarp::os;
25 using namespace icubclient;
26 
27 /*******************************************************/
28 class ExampleDependency : public RFModule
29 {
30  double period;
31  RpcServer rpcPort;
33 
34 public:
35  /*******************************************************/
36  ExampleDependency() : icubclient("exampleDependency", "exampleDependency") { }
37 
38  /*******************************************************/
39  bool configure(ResourceFinder &rf)
40  {
41  period=rf.check("period",Value(0.05)).asDouble();
42 
43  if (!icubclient.connect()) {
44  yError() << " iCubClient : Some dependencies are not running (OPC?)...";
45  return false;
46  }
47 
48  rpcPort.open("/exampleDependency/rpc");
49  attach(rpcPort);
50 
51  return true;
52  }
53 
54  /*******************************************************/
55  double getPeriod()
56  {
57  return period;
58  }
59 
60  /*******************************************************/
61  bool updateModule()
62  {
63  return true;
64  }
65 
66  /*******************************************************/
67  bool respond(const Bottle &command, Bottle &reply)
68  {
69  int cmd=command.get(0).asVocab();
70  int ack=Vocab::encode("ack");
71  int nack=Vocab::encode("nack");
72 
73  if (cmd==Vocab::encode("lookAtPartner"))
74  {
75  icubclient.lookAtPartner();
76  reply.addVocab(ack);
77  return true;
78  }
79  else
80  return RFModule::respond(command,reply);
81  }
82 
83  /*******************************************************/
84  bool close()
85  {
86  rpcPort.interrupt();
87  rpcPort.close();
88  icubclient.close();
89  return true;
90  }
91 
93  {
94  rpcPort.interrupt();
95  icubclient.opc->interrupt();
96  return true;
97  }
98 };
99 
100 
101 /*******************************************************/
102 int main(int argc, char *argv[])
103 {
104  Network yarp;
105  if (!yarp.checkNetwork()) {
106  yError()<<"YARP network seems unavailable!";
107  return 1;
108  }
109 
110  ResourceFinder rf;
111  rf.configure(argc,argv);
112 
113  ExampleDependency example;
114  return example.runModule(rf);
115 }
bool close()
Definition: main.cpp:84
Grants access to high level motor commands (grasp, touch, look, goto, etc) of the robot as well as it...
Definition: icubClient.h:66
bool connect(const std::string &opcName="OPC")
Try to connect all functionalities.
Definition: icubClient.cpp:132
bool respond(const Bottle &command, Bottle &reply)
Definition: main.cpp:67
bool lookAtPartner()
Looks at the agent if present in the scene.
Definition: icubClient.cpp:307
bool configure(ResourceFinder &rf)
Definition: main.cpp:39
int main()
Definition: main.cpp:32
bool interruptModule()
Definition: main.cpp:92
bool updateModule()
Definition: main.cpp:61
void close()
Properly closes all ports which were opened.
Definition: icubClient.cpp:140
void interrupt()
Interrupt communications of the client ports.
Definition: opcClient.cpp:64
double getPeriod()
Definition: main.cpp:55