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: 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 * 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  cout<<"YARP network seems unavailable!"<<endl;
38  return -1;
39  }
40 
41  ICubClient iCub("AREiCubClientExample","icubClient","example_ARE.ini");
42 
43  ResourceFinder rfClient;
44  rfClient.setVerbose(true);
45  rfClient.setDefaultContext("icubClient");
46  rfClient.setDefaultConfigFile("example_ARE.ini");
47  rfClient.configure(0, nullptr);
48 
49  // we connect to both ARE and OPC
50  if(!iCub.connect()) {
51  yError()<<"[ARE_KARMAiCubClientExample] ARE and/or OPC seems unavailabe!";
52  return -1;
53  }
54 
55  string target;
56  if (rfClient.check("target")) {
57  target = rfClient.find("target").asString();
58  yInfo("target name set to %s", target.c_str());
59  } else {
60  target = "octopus";
61  yInfo("target name set to default, i.e. %s", target.c_str());
62  }
63 
64  double radius=0.025;
65 
66  // object location in the iCub frame
67  Vector x(3);
68  x[0]=-0.35;
69  x[1]=-0.05;
70  x[2]=-0.05;
71 
72  iCub.home();
73  yInfo()<<"pointing at the object ... ";
74  Bottle options("right"); // force the use of the right hand
75  iCub.point(x, options); // automatic selection of the hand
76  Time::delay(2.0);
77 
78 
79  iCub.home();
80  yInfo("try to grasp %s", target.c_str());
81  bool ok=iCub.take(target,options);
82  yInfo()<<(ok?"grasped!":"missed!");
83  iCub.home();
84 
85  if (ok)
86  {
87  x[2]+=1.2*radius;
88  yInfo()<<"releasing ... ";
89  iCub.release(x);
90  iCub.home();
91  }
92 
93  yInfo()<<"shutting down ... ";
94  iCub.close();
95  return 0;
96 }
97 
98 
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 release(const std::string &oLocation, const yarp::os::Bottle &options=yarp::os::Bottle())
Release the hand-held object on a given location.
int main()
Definition: main.cpp:32
void close()
Properly closes all ports which were opened.
Definition: icubClient.cpp:140