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: Tobias Fischer, Maxime Petit (Based on ARE/KARMA iCubClient examples of Ugo Pattacini and Nguyen Dong Hai Phuong)
4 * email : t.fischer@imperial.ac.uk, m.petit@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 <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()<<"YARP network seems unavailable!";
38  return -1;
39  }
40 
41  ICubClient iCub("ARE_KARMAiCubClientExample","icubClient","example_ARE_KARMA.ini");
42 
43  if(!iCub.connect()) { // we connect to ARE, KARMA and OPC
44  yError()<<"[ARE_KARMAiCubClientExample] ARE and/or KARMA and/or OPC seems unavailabe!";
45  return -1;
46  }
47 
48  ResourceFinder rfClient;
49  rfClient.setVerbose(true);
50  rfClient.setDefaultContext("icubClient");
51  rfClient.setDefaultConfigFile("example_ARE_KARMA.ini");
52  rfClient.configure(0, nullptr);
53 
54  // object location in the iCub frame
55  Vector x(3);
56  x[0]=-0.25;
57  x[1]=-0.20;
58  x[2]=-0.05;
59 
60  string target;
61  if (rfClient.check("target")) {
62  target = rfClient.find("target").asString();
63  yInfo("target name set to %s", target.c_str());
64  } else {
65  target = "octopus";
66  yInfo("target name set to default, i.e. %s", target.c_str());
67  }
68  bool ok;
69 
70  iCub.home(); // Home by using ARE
71  yInfo()<<"try to pushFront with KARMA ...";
72  ok = iCub.pushKarma(x,-90,0.1); //WARNING: second argument is the desired x[0] that we want and should be less than original x[0]
73  yInfo()<<(ok?"success":"failed");
74  Time::delay(4.0);
75 
76  iCub.home(); // Home by using ARE
77  x[1] =x[1] - 0.1; //offset on lateral to draw?
78  yInfo()<<"try to pull with KARMA...";
79  ok = iCub.drawKarma(x,0,0.1,0.1); //draw of 0.1m but the objects is considered as -0.35 so final: -0.25
80  yInfo()<<(ok?"success":"failed");
81  Time::delay(4.0);
82  x[1] = x[1] + 0.1; //go back to original value
83 
84 
85 
86  //----------------------------> ARE related action
87  iCub.home(); // Home by using ARE
88  yInfo()<<"try to point using ARE...";
89  ok = iCub.point(x); // automatic selection of the hand
90  yInfo()<<(ok?"success":"failed");
91  Time::delay(4.0);
92 
93  iCub.home(); // Home by using ARE
94  yInfo()<<"try to take from side using ARE...";
95  Bottle bOptions("side"); // param1: side
96  ok = iCub.take(target, bOptions); // automatic selection of the hand
97  yInfo()<<(ok?"success":"failed");
98  Time::delay(4.0);
99 
100  iCub.home(); // Home by using ARE
101  yInfo()<<"try to take from above using ARE...";
102  bOptions.clear();
103  bOptions.addString("above");
104  ok = iCub.take(target, bOptions); // automatic selection of the hand
105  yInfo()<<(ok?"success":"failed");
106  Time::delay(4.0);
107 
108  iCub.home(); // Home by using ARE
109  yInfo()<<"try to push using ARE...";
110  ok = iCub.push(target); // automatic selection of the hand
111  yInfo()<<(ok?"success":"failed");
112  Time::delay(4.0);
113 
114  iCub.home(); // Home by using ARE
115  yInfo()<<"try to push away using ARE...";
116  bOptions.clear();
117  bOptions.addString("away");
118  ok = iCub.push(target,bOptions); // automatic selection of the hand
119  yInfo()<<(ok?"success":"failed");
120  Time::delay(4.0);
121  iCub.home();
122 
123 
124  yInfo()<<"shutting down ... ";
125  iCub.close();
126  return 0;
127 }
128 
129 
bool point(const yarp::sig::VectorOf< double > &target, const yarp::os::Bottle &options=yarp::os::Bottle())
Point at a specified location from the iCub.
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
STL namespace.
bool take(const std::string &oName, const yarp::os::Bottle &options=yarp::os::Bottle())
Take (grasp) an object.
bool home(const std::string &part="all")
Go in home position.
bool pushKarma(const yarp::sig::VectorOf< double > &targetCenter, const double &theta, const double &radius, const yarp::os::Bottle &options=yarp::os::Bottle())
pushKarma (KARMA): push to certain position, along a direction See the SubSystem_KARMA::push document...
bool push(const std::string &oLocation, const yarp::os::Bottle &options=yarp::os::Bottle())
Push at a specified location.
int main()
Definition: main.cpp:32
void close()
Properly closes all ports which were opened.
Definition: icubClient.cpp:140
bool drawKarma(const yarp::sig::VectorOf< double > &targetCenter, const double &theta, const double &radius, const double &dist, const yarp::os::Bottle &options=yarp::os::Bottle())
drawKarma (KARMA): draw action, along the positive direction of the x-axis (in robot FoR) See the Sub...