icub-client
icubClient_KARMArelated.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 yarp::dev;
26 using namespace icubclient;
27 
28 
29 // Left push
30 bool ICubClient::pushKarmaLeft(const std::string &objName, const double &targetPosYLeft,
31  const std::string &armType,
32  const yarp::os::Bottle &options)
33 {
34  SubSystem_KARMA *karma = getKARMA();
35  if (karma == nullptr)
36  {
37  yError() << "[iCubClient] Called pushKarmaLeft() but KARMA subsystem is not available.";
38  return false;
39  }
40 
41  if (opc->isConnected())
42  {
43  Entity *target = opc->getEntity(objName, true);
44  if (!target || !target->isType(ICUBCLIENT_OPC_ENTITY_OBJECT))
45  {
46  yWarning() << "[iCubClient] Called pushKarmaLeft() on a unallowed entity: \"" << objName << "\"";
47  return false;
48  }
49 
50  Object *oTarget = dynamic_cast<Object*>(target);
51  if (!oTarget || oTarget->m_present != 1.0)
52  {
53  yWarning() << "[iCubClient] Called pushKarmaLeft() on an unavailable entity: \"" << objName << "\"";
54  return false;
55  }
56 
57  yInfo("[icubClient pushKarmaLeft] object %s position from OPC (no calibration): %s", oTarget->name().c_str(),
58  oTarget->m_ego_position.toString().c_str());
59  return karma->pushAside(objName, oTarget->m_ego_position, targetPosYLeft, 0, armType, options);
60  }
61  else
62  {
63  yWarning() << "[iCubClient] There is no OPC connection";
64  return false;
65  }
66 }
67 
68 // Right push
69 bool ICubClient::pushKarmaRight(const std::string &objName, const double &targetPosYRight,
70  const std::string &armType,
71  const yarp::os::Bottle &options)
72 {
73  SubSystem_KARMA *karma = getKARMA();
74  if (karma == nullptr)
75  {
76  yError() << "[iCubClient] Called pushKarmaRight() but KARMA subsystem is not available.";
77  return false;
78  }
79 
80  if (opc->isConnected())
81  {
82  Entity *target = opc->getEntity(objName, true);
83  if (!target || !target->isType(ICUBCLIENT_OPC_ENTITY_OBJECT))
84  {
85  yWarning() << "[iCubClient] Called pushKarmaRight() on a unallowed entity: \"" << objName << "\"";
86  return false;
87  }
88 
89  Object *oTarget = dynamic_cast<Object*>(target);
90  if (!oTarget || oTarget->m_present != 1.0)
91  {
92  yWarning() << "[iCubClient] Called pushKarmaRight() on an unavailable entity: \"" << objName << "\"";
93  return false;
94  }
95 
96  yInfo("[icubClient pushKarmaRight] object %s position from OPC (no calibration): %s", oTarget->name().c_str(),
97  oTarget->m_ego_position.toString().c_str());
98  return karma->pushAside(objName, oTarget->m_ego_position, targetPosYRight, 180, armType, options);
99  }
100  else
101  {
102  yWarning() << "[iCubClient] There is no OPC connection";
103  return false;
104  }
105 }
106 
107 // Front push
108 bool ICubClient::pushKarmaFront(const std::string &objName, const double &targetPosXFront,
109  const std::string &armType,
110  const yarp::os::Bottle &options)
111 {
112  SubSystem_KARMA *karma = getKARMA();
113  if (karma == nullptr)
114  {
115  yError() << "[iCubClient] Called pushKarmaFront() but KARMA subsystem is not available.";
116  return false;
117  }
118 
119  if (opc->isConnected())
120  {
121  Entity *target = opc->getEntity(objName, true);
122  if (!target || !target->isType(ICUBCLIENT_OPC_ENTITY_OBJECT))
123  {
124  yWarning() << "[iCubClient] Called pushKarmaFront() on a unallowed entity: \"" << objName << "\"";
125  return false;
126  }
127 
128  Object *oTarget = dynamic_cast<Object*>(target);
129  if (!oTarget || oTarget->m_present != 1.0)
130  {
131  yWarning() << "[iCubClient] Called pushKarmaFront() on an unavailable entity: \"" << objName << "\"";
132  return false;
133  }
134 
135  yInfo("[icubClient pushKarmaFront] object %s position from OPC (no calibration): %s", oTarget->name().c_str(),
136  oTarget->m_ego_position.toString().c_str());
137  return karma->pushFront(objName, oTarget->m_ego_position, targetPosXFront, armType, options);
138  }
139  else
140  {
141  yWarning() << "[iCubClient] There is no OPC connection";
142  return false;
143  }
144 }
145 
146 // Pure push in KARMA
147 bool ICubClient::pushKarma(const yarp::sig::VectorOf<double> &targetCenter, const double &theta, const double &radius,
148  const yarp::os::Bottle &options)
149 {
150  SubSystem_KARMA *karma = getKARMA();
151  if (karma == nullptr)
152  {
153  yError() << "[iCubClient] Called pushKarma() but KARMA subsystem is not available.";
154  return false;
155  }
156  return karma->push(targetCenter, theta, radius, options);
157 }
158 
159 // Back pull
160 bool ICubClient::pullKarmaBack(const std::string &objName, const double &targetPosXBack,
161  const std::string &armType,
162  const yarp::os::Bottle &options)
163 {
164  SubSystem_KARMA *karma = getKARMA();
165  if (karma == nullptr)
166  {
167  yError() << "[iCubClient] Called pullKarmaBack() but KARMA subsystem is not available.";
168  return false;
169  }
170 
171  if (opc->isConnected())
172  {
173  Entity *target = opc->getEntity(objName, true);
174  if (!target || !target->isType(ICUBCLIENT_OPC_ENTITY_OBJECT))
175  {
176  yWarning() << "[iCubClient] Called pushKarmaFront() on a unallowed entity: \"" << objName << "\"";
177  return false;
178  }
179 
180  Object *oTarget = dynamic_cast<Object*>(target);
181  if (!oTarget || oTarget->m_present != 1.0)
182  {
183  yWarning() << "[iCubClient] Called pushKarmaFront() on an unavailable entity: \"" << objName << "\"";
184  return false;
185  }
186 
187  yInfo("[icubClient pullKarmaBack] object %s position from OPC (no calibration): %s", oTarget->name().c_str(),
188  oTarget->m_ego_position.toString().c_str());
189  return karma->pullBack(objName, oTarget->m_ego_position, targetPosXBack, armType, options);
190  }
191  else
192  {
193  yWarning() << "[iCubClient] There is no OPC connection";
194  return false;
195  }
196 }
197 
198 // Pure pull (draw) in KARMA
199 bool ICubClient::drawKarma(const yarp::sig::VectorOf<double> &targetCenter, const double &theta,
200  const double &radius, const double &dist,
201  const yarp::os::Bottle &options)
202 {
203  SubSystem_KARMA *karma = getKARMA();
204  if (karma == nullptr)
205  {
206  yError() << "[iCubClient] Called drawKarma() but KARMA subsystem is not available.";
207  return false;
208  }
209  return karma->draw(targetCenter, theta, radius, dist, options);
210 }
211 
bool pullBack(const std::string &objName, const yarp::sig::VectorOf< double > &objCenter, const double &targetPosXBack, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pullBack (KARMA): pull an object to a certain location along x-axis of robot RoF
Represent any entity that can be stored within the OPC.
Definition: entity.h:40
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
SubSystem to deal with the experimental affordance learning module (a.k.a.
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
bool draw(const yarp::sig::VectorOf< double > &targetCenter, const double theta, const double radius, const double dist, const yarp::os::Bottle &options=yarp::os::Bottle())
draw (KARMA): draw action, along the positive direction of the x-axis (in robot FoR) ...
std::string name() const
Return the name of an entity (which has to be unique within the OPC)
Definition: entity.h:93
#define ICUBCLIENT_OPC_ENTITY_OBJECT
Definition: tags.h:38
bool pushFront(const std::string &objName, const yarp::sig::VectorOf< double > &objCenter, const double &targetPosXFront, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pushFront (KARMA): push an object to a certain location along x-axis of robot RoF ...
bool push(const yarp::sig::VectorOf< double > &targetCenter, const double theta, const double radius, const yarp::os::Bottle &options=yarp::os::Bottle())
push (KARMA): push to certain position, along a defined direction
bool pushAside(const std::string &objName, const yarp::sig::VectorOf< double > &objCenter, const double &targetPosY, const double &theta, const std::string &armType="selectable", const yarp::os::Bottle &options=yarp::os::Bottle())
pushAside (KARMA): push an object to a certain location along y-axis of robot RoF ...