icub-client
main.cpp
Go to the documentation of this file.
1 /*
2 * Copyright(C) 2014 WYSIWYD Consortium, European Commission FP7 Project ICT - 612139
3 * Authors: Nguyen Dong Hai Phuong
4 * email : phuong.nguyen@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 * 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 <iostream>
19 #include <iomanip>
20 #include <yarp/os/all.h>
21 #include <yarp/sig/all.h>
22 #include <yarp/math/Math.h>
23 #include <yarp/math/SVD.h>
25 
26 using namespace std;
27 using namespace yarp::os;
28 using namespace yarp::sig;
29 using namespace yarp::math;
30 using namespace icubclient;
31 
32 int main()
33 {
34  Network yarp;
35  if (!yarp.checkNetwork())
36  {
37  yError()<<"[KARMA_OPC_Example] YARP network seems unavailable!";
38  return -1;
39  }
40 
41  ICubClient iCub("KARMA_OPC_Example","icubClient","example_KARMA_OPC.ini");
42 
43  ResourceFinder rfClient;
44  rfClient.setVerbose(true);
45  rfClient.setDefaultContext("icubClient");
46  rfClient.setDefaultConfigFile("example_KARMA_OPC.ini");
47  rfClient.configure(0, nullptr);
48 
49  string target;
50  if (rfClient.check("target"))
51  {
52  target = rfClient.find("target").asString();
53  yInfo("target name set to %s", target.c_str());
54  }
55  else
56  {
57  target = "octopus";
58  yInfo("target name set to default, i.e. %s", target.c_str());
59  }
60 
61 
62  // we connect just to ARE
63  // we need connect to KARMA also
64  if (!iCub.connectSubSystems())
65  {
66  yError()<<"[KARMA_OPC_Example] KARMA seems unavailabe!";
67  return -1;
68  }
69  // we then connect to OPC
70  bool connected = iCub.connectOPC();
71  yInfo()<<"connected to OPC port";
72  yInfo()<<(connected?"success":"failed");
73  bool ok = false;
74  iCub.home(); // Home by using ARE
75 
76  yInfo()<<"[KARMA_OPC_Example] try to pushLeft target with KARMA ...";
77  //iCub.look(target);
78  ok = iCub.pushKarmaLeft(target,-0.2);
79  yInfo()<<(ok?"success":"failed");
80  Time::delay(1.0);
81  iCub.home(); // Home by using ARE
82  Time::delay(10.0);
83 
84  yInfo()<<"[KARMA_OPC_Example] try to pushRight target with KARMA ...";
85  //iCub.look(target);
86  ok = iCub.pushKarmaRight(target, 0.2);
87  yInfo()<<(ok?"success":"failed");
88  Time::delay(1.0);
89  iCub.home(); // Home by using ARE
90  Time::delay(10.0);
91 
92  yInfo()<<"[KARMA_OPC_Example] try to pushFront target with KARMA ...";
93  //iCub.look(target);
94  ok = iCub.pushKarmaFront(target,-0.45);
95  yInfo()<<(ok?"success":"failed");
96  Time::delay(1.0);
97  iCub.home(); // Home by using ARE
98  Time::delay(10.0);
99 
100  yInfo()<<"[KARMA_OPC_Example] try to pullBack target with KARMA ...";
101  //iCub.look(target);
102  ok = iCub.pullKarmaBack(target,-0.25);
103  yInfo()<<(ok?"success":"failed");
104  Time::delay(1.0);
105  iCub.home(); // Home by using ARE
106  Time::delay(10.0);
107 
108  yInfo()<<"[KARMA_OPC_Example] shutting down ... ";
109  iCub.close();
110  return 0;
111 }
112 
113 
bool connectOPC(const std::string &opcName="OPC")
Try to connect to OPC.
Definition: icubClient.cpp:107
Grants access to high level motor commands (grasp, touch, look, goto, etc) of the robot as well as it...
Definition: icubClient.h:66
bool pushKarmaFront(const std::string &objName, const double &targetPosXFront, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pushKarmaFront: push an object by name to front See the SubSystem_KARMA::pushFront documentation for ...
STL namespace.
bool connectSubSystems()
Try to connect to all sub-systems.
Definition: icubClient.cpp:117
bool home(const std::string &part="all")
Go in home position.
int main()
Definition: main.cpp:32
bool pushKarmaRight(const std::string &objName, const double &targetPosYRight, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pushKarmaRight: push an object by name to right side See the SubSystem_KARMA::pushAside documentation...
void close()
Properly closes all ports which were opened.
Definition: icubClient.cpp:140
bool pullKarmaBack(const std::string &objName, const double &targetPosXBack, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pullKarmaBack: pull an object by name back See the SubSystem_KARMA::pullBack documentation for more d...
bool pushKarmaLeft(const std::string &objName, const double &targetPosYLeft, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pushKarmaLeft: push an object by name to left side See the SubSystem_KARMA::pushAside documentation f...