icub-client
icubClient_ARErelated.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 WYSIWYD Consortium, European Commission FP7 Project ICT-612139
3  * Authors: Stéphane Lallée, Tobias Fischer
4  * email: stephane.lallee@gmail.com, t.fischer@imperial.ac.uk
5  * website: https://github.com/robotology/icub-client/
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * icub-client/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
21 
22 using namespace std;
23 using namespace yarp::os;
24 using namespace yarp::sig;
25 using namespace icubclient;
26 
27 bool ICubClient::home(const string &part)
28 {
29  SubSystem_ARE *are = getARE();
30  if (are == nullptr)
31  {
32  yError() << "[iCubClient] Called home() but ARE subsystem is not available.";
33  return false;
34  }
35 
36  return are->home(part);
37 }
38 
39 bool ICubClient::release(const std::string &oLocation, const yarp::os::Bottle &options)
40 {
41  Entity *target = opc->getEntity(oLocation, true);
42  if (!target || !target->isType(ICUBCLIENT_OPC_ENTITY_OBJECT))
43  {
44  yError() << "[iCubClient] Called release() on a unallowed location: \"" << oLocation << "\"";
45  return false;
46  }
47 
48  Object *oTarget = dynamic_cast<Object*>(target);
49  if (!oTarget || oTarget->m_present != 1.0)
50  {
51  yWarning() << "[iCubClient] Called release() on an unavailable entity: \"" << oLocation << "\"";
52  return false;
53  }
54 
55  return release(oTarget->m_ego_position, options);
56 }
57 
58 
59 bool ICubClient::release(const yarp::sig::VectorOf<double> &target, const yarp::os::Bottle &options)
60 {
61  SubSystem_ARE *are = getARE();
62  if (are == nullptr)
63  {
64  yError() << "[iCubClient] Called release() but ARE subsystem is not available.";
65  return false;
66  }
67 
68  if (isTargetInRange(target))
69  return are->dropOn(target, options);
70  else
71  {
72  yWarning() << "[iCubClient] Called release() on a unreachable location: (" << target.toString(3, 3).c_str() << ")";
73  return false;
74  }
75 }
76 
77 bool ICubClient::waving(const bool sw) {
78  SubSystem_ARE *are = getARE();
79  if (are == nullptr)
80  {
81  yError() << "[iCubClient] Called waving() but ARE subsystem is not available.";
82  return false;
83  }
84 
85  return are->waving(sw);
86 }
87 
88 
89 bool icubclient::ICubClient::point(const yarp::sig::VectorOf<double> &target, const yarp::os::Bottle &options)
90 {
91  SubSystem_ARE *are = getARE();
92  if (are == nullptr)
93  {
94  yError() << "[iCubClient] Called pointfar() but ARE subsystem is not available.";
95  return false;
96  }
97 
98  Bottle opt(options);
99  opt.addString("still"); // always avoid automatic homing after point
100  return are->point(target, opt);
101 }
102 
103 
104 bool icubclient::ICubClient::point(const std::string &sName, const yarp::os::Bottle &options)
105 {
106  Entity *target = opc->getEntity(sName, true);
107  if (!target || (!target->isType(ICUBCLIENT_OPC_ENTITY_OBJECT) && !target->isType(ICUBCLIENT_OPC_ENTITY_BODYPART)))
108  {
109  yWarning() << "[iCubClient] Called point() on a unallowed location: \"" << sName << "\"";
110  return false;
111  }
112 
113  Object *oTarget = dynamic_cast<Object*>(target);
114  if(oTarget!=nullptr) {
115  SubSystem_ARE *are = getARE();
116  if(are) {
117  Vector target = oTarget->m_ego_position;
118  are->selectHandCorrectTarget(const_cast<Bottle&>(options), target, sName);
119  return point(target, options);
120  } else {
121  yError() << "[iCubClient] Called point() but ARE subsystem is not available.";
122  return false;
123  }
124  } else {
125  yError() << "[iCubClient] pointfar: Could not cast Entity to Object";
126  return false;
127  }
128 }
129 
130 
131 bool ICubClient::push(const string &oLocation, const Bottle &options)
132 {
133  SubSystem_ARE *are = getARE();
134  if (are == nullptr)
135  {
136  yError() << "[iCubClient] Called push() but ARE subsystem is not available.";
137  return false;
138  }
139 
140  Bottle opt(options);
141  opt.addString("still"); // always avoid automatic homing after point
142 
143  return are->push(oLocation, opt);
144 }
145 
146 
147 bool ICubClient::take(const std::string& oName, const Bottle &options)
148 {
149  SubSystem_ARE *are = getARE();
150  if (are == nullptr)
151  {
152  yError() << "[iCubClient] Called take() but ARE subsystem is not available.";
153  return false;
154  }
155 
156  Bottle opt(options);
157  opt.addString("still"); // always avoid automatic homing after point
158  return are->take(oName, opt);
159 }
160 
161 
162 bool ICubClient::look(const std::string &target, const yarp::os::Bottle &options)
163 {
164  if (SubSystem_ARE *are = getARE())
165  {
166  if (Object *oTarget = dynamic_cast<Object*>(opc->getEntity(target, true)))
167  if (oTarget->m_present == 1.0)
168  return are->look(oTarget->m_ego_position, options);
169 
170  yWarning() << "[iCubClient] Called look() on an unavailable target: \"" << target << "\"";
171  return false;
172  }
173 
174  yError() << "Error, neither Attention nor ARE are running...";
175  return false;
176 }
177 
178 bool ICubClient::look(const yarp::sig::VectorOf<double> &target, const yarp::os::Bottle &options)
179 {
180  if (SubSystem_ARE *are = getARE())
181  {
182  return are->look(target, options);
183  }
184 
185  yError() << "Error, ARE not running...";
186  return false;
187 }
188 
189 bool ICubClient::lookAtBodypart(const std::string &sBodypartName)
190 {
191  if (SubSystem_ARE *are = getARE())
192  {
193  Vector vLoc;
194  vLoc = getPartnerBodypartLoc(sBodypartName);
195  if (vLoc.size() == 3){
196  return are->look(vLoc, yarp::os::Bottle());
197  }
198 
199  yWarning() << "[iCubClient] Called lookAtBodypart() on an unvalid/unpresent agent or bodypart (" << sBodypartName << ")";
200  return false;
201  }
202  return false;
203 }
bool point(const yarp::sig::VectorOf< double > &target, const yarp::os::Bottle &options=yarp::os::Bottle())
Point at a specified location from the iCub.
Represent any entity that can be stored within the OPC.
Definition: entity.h:40
SubSystem to deal with the actionsRenderingEngine module (a.k.a.
Definition: subSystem_ARE.h:41
bool push(const std::string &sName, const yarp::os::Bottle &options=yarp::os::Bottle())
Reach the specified [target] from one side and then push it laterally.
virtual bool isType(std::string _entityType) const
Test if an entity is inheriting a given type.
Definition: entity.h:67
double m_present
Is the object present in the scene A value of 1.0 means that the object currently is in the scene A v...
Definition: object.h:69
STL namespace.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
Definition: object.h:35
yarp::sig::VectorOf< double > m_ego_position
Position of the Object, in the initial ego-centered reference frame of the agent mainting the OPC (in...
Definition: object.h:46
#define ICUBCLIENT_OPC_ENTITY_BODYPART
Definition: tags.h:39
bool point(const yarp::sig::VectorOf< double > &targetUnsafe, const yarp::os::Bottle &options=yarp::os::Bottle())
Point at the specified [target] with the index finger.
bool home(const std::string &part="all")
Put the specified part ih home position.
bool take(const std::string &sName, const yarp::os::Bottle &options=yarp::os::Bottle())
Reach the specified [target] and grasp it.
void selectHandCorrectTarget(yarp::os::Bottle &options, yarp::sig::VectorOf< double > &target, const std::string &objName, const std::string handToUse="")
#define ICUBCLIENT_OPC_ENTITY_OBJECT
Definition: tags.h:38
bool dropOn(const yarp::sig::VectorOf< double > &targetUnsafe, const yarp::os::Bottle &options=yarp::os::Bottle())
Drop the object on a given target.
bool waving(const bool sw)
Enable/disable arms waving.