icub-client
icubClient.h
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
4  * email: stephane.lallee@gmail.com
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 
19 #ifndef __ICUBCLIENT_ICUBCLIENT_H__
20 #define __ICUBCLIENT_ICUBCLIENT_H__
21 
22 #include <iostream>
23 #include <iomanip>
24 #include <fstream>
25 #include <tuple>
26 #include <typeindex>
27 #include <map>
28 #include <list>
29 
30 #include <yarp/sig/Vector.h>
31 
40 namespace icubclient{
41  // forward declarations
42  class OPCClient;
43 
44  class SubSystem;
46  class SubSystem_ARE;
47  class SubSystem_babbling;
48  class SubSystem_IOL2OPC;
49  class SubSystem_KARMA;
50  class SubSystem_Recog;
51  class SubSystem_Speech;
52  class SubSystem_SAM;
53  class SubSystem_emotion;
54 
55  class Action;
56  class Agent;
57  class Entity;
58  class Object;
59 
66  class ICubClient
67  {
68  protected:
69  std::map<std::string, SubSystem*> subSystems;
70  bool closed;
71  std::list<Action*> actionsKnown;
72 
73  //Reachability area
76 
77  std::string robot; // Name of robot
78 
79  public:
80  template <class T>
81  T* getSubSystem(const std::string &subSystemName) {
82  if (subSystems.find(subSystemName) == subSystems.end())
83  return nullptr;
84  else
85  return (T*)subSystems[subSystemName];
86  }
87 
92  template <class T>
93  T* getSubSystem(T) {
94  for(const auto subSystem : subSystems) {
95  if(std::type_index(typeid(T)) == std::type_index(typeid(subSystem))) {
96  return subSystem;
97  }
98  }
99  return nullptr;
100  }
101 
111 
114 
122  ICubClient(const std::string &moduleName, const std::string &context = "icubClient",
123  const std::string &clientConfigFile = "client.ini", bool isRFVerbose = false);
124 
130  bool connect(const std::string &opcName = "OPC");
131 
137  bool connectOPC(const std::string &opcName = "OPC");
138 
143  bool connectSubSystems();
144 
148  void updateAgent();
149 
153  void commitAgent();
154 
163  bool home(const std::string &part = "all");
164 
175  bool release(const std::string &oLocation, const yarp::os::Bottle &options = yarp::os::Bottle());
176 
188  bool release(const yarp::sig::VectorOf<double> &target, const yarp::os::Bottle &options = yarp::os::Bottle());
189 
201  bool point(const yarp::sig::VectorOf<double> &target, const yarp::os::Bottle &options = yarp::os::Bottle());
202 
203  bool point(const double x, const double y, const double z, const yarp::os::Bottle &options = yarp::os::Bottle()) {
204  yarp::sig::VectorOf<double> target(3);
205  target[0] = x;
206  target[1] = y;
207  target[2] = z;
208  return point(target, options);
209  }
210 
222  bool point(const std::string &oLocation, const yarp::os::Bottle &options = yarp::os::Bottle());
223 
230  bool waving(const bool sw);
231 
244  bool push(const std::string &oLocation, const yarp::os::Bottle &options = yarp::os::Bottle());
245 
257  bool take(const std::string &oName, const yarp::os::Bottle &options = yarp::os::Bottle());
258 
259 
269  bool pushKarmaLeft(const std::string &objName, const double &targetPosYLeft,
270  const std::string &armType = "selectable",
271  const yarp::os::Bottle &options = yarp::os::Bottle());
272 
282  bool pushKarmaRight(const std::string &objName, const double &targetPosYRight,
283  const std::string &armType = "selectable",
284  const yarp::os::Bottle &options = yarp::os::Bottle());
285 
295  bool pushKarmaFront(const std::string &objName, const double &targetPosXFront,
296  const std::string &armType = "selectable",
297  const yarp::os::Bottle &options = yarp::os::Bottle());
298 
308  bool pullKarmaBack(const std::string &objName, const double &targetPosXBack,
309  const std::string &armType = "selectable",
310  const yarp::os::Bottle &options = yarp::os::Bottle());
311 
321  bool pushKarma(const yarp::sig::VectorOf<double> &targetCenter, const double &theta, const double &radius,
322  const yarp::os::Bottle &options = yarp::os::Bottle());
323 
334  bool drawKarma(const yarp::sig::VectorOf<double> &targetCenter, const double &theta,
335  const double &radius, const double &dist,
336  const yarp::os::Bottle &options = yarp::os::Bottle());
337 
345  bool look(const std::string &target, const yarp::os::Bottle &options = yarp::os::Bottle());
346 
354  bool look(const yarp::sig::VectorOf<double> &target, const yarp::os::Bottle &options = yarp::os::Bottle());
355 
359  bool lookAtPartner();
360 
365  bool lookAtBodypart(const std::string &sBodypartName);
366 
372  std::string getPartnerName(bool verbose = true);
373 
379  yarp::sig::VectorOf<double> getPartnerBodypartLoc(std::string sBodypartName);
380 
389  bool babbling(int jointNumber, const std::string &babblingArm, double train_dur = -1.0);
390 
400  bool babbling(const std::string &bpName, const std::string &babblingArm, double train_dur = -1.0);
401 
402 
409  bool say(const std::string &text, bool shouldWait = true);
410 
417  bool changeName(Entity *e, const std::string &newName);
418 
423  std::tuple<std::string, double> getHighestEmotion();
424 
429  std::list<Action*> getKnownActions();
430 
436  std::list<Object*> getObjectsInSight();
437 
443  std::list<Object*> getObjectsInRange();
444 
450  bool isTargetInRange(const yarp::sig::VectorOf<double> &target) const;
451 
456  void close();
457 
461  virtual ~ICubClient();
462  };
463 }//Namespace
464 #endif
bool point(const yarp::sig::VectorOf< double > &target, const yarp::os::Bottle &options=yarp::os::Bottle())
Point at a specified location from the iCub.
SubSystem_babbling * getBabblingClient()
Definition: icubClient.cpp:459
void commitAgent()
Commit the local definition of iCub agent to the OPC.
Definition: icubClient.cpp:245
Abstract subSystem for speech management (Text to Speech)
std::list< Action * > actionsKnown
Definition: icubClient.h:71
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
SubSystem for SAM.
Definition: subSystem_SAM.h:33
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 connect(const std::string &opcName="OPC")
Try to connect all functionalities.
Definition: icubClient.cpp:132
SubSystem_emotion * getEmotionClient()
Definition: icubClient.cpp:501
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 ...
SubSystem to deal with the experimental affordance learning module (a.k.a.
bool lookAtPartner()
Looks at the agent if present in the scene.
Definition: icubClient.cpp:307
Represent any physical entity (including objects and agents) that can be stored within the OPC...
Definition: object.h:35
bool take(const std::string &oName, const yarp::os::Bottle &options=yarp::os::Bottle())
Take (grasp) an object.
T * getSubSystem(const std::string &subSystemName)
Definition: icubClient.h:81
SubSystem_Speech * getSpeechClient()
Definition: icubClient.cpp:484
Represents an action, whether composite or not.
Definition: action.h:33
Represent an agent.
Definition: agent.h:93
std::list< Object * > getObjectsInSight()
Get the list of object that are in front of the iCub Warning: this will update the local icubAgent...
Definition: icubClient.cpp:399
bool changeName(Entity *e, const std::string &newName)
Change the name of a given entity.
Definition: icubClient.cpp:183
bool babbling(int jointNumber, const std::string &babblingArm, double train_dur=-1.0)
Babbling using a single joint.
Definition: icubClient.cpp:344
bool connectSubSystems()
Try to connect to all sub-systems.
Definition: icubClient.cpp:117
SubSystem for iol2opc.
bool home(const std::string &part="all")
Go in home position.
bool isTargetInRange(const yarp::sig::VectorOf< double > &target) const
Check if a given cartesian position is within the reach of the robot This can be adjusted using the r...
Definition: icubClient.cpp:444
std::tuple< std::string, double > getHighestEmotion()
Get the strongest emotion.
Definition: icubClient.cpp:354
bool release(const std::string &oLocation, const yarp::os::Bottle &options=yarp::os::Bottle())
Release the hand-held object on a given location.
T * getSubSystem(T)
get a subsystem by just providing the type untested, just to play around with C++11 ...
Definition: icubClient.h:93
Abstract class to handle sub-systems of the icub-client.
Definition: subSystem.h:43
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.
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...
An OPC client using the datastructures defined within the icub-client library.
Definition: opcClient.h:35
ICubClient(const std::string &moduleName, const std::string &context="icubClient", const std::string &clientConfigFile="client.ini", bool isRFVerbose=false)
Create an iCub client.
Definition: icubClient.cpp:37
bool look(const std::string &target, const yarp::os::Bottle &options=yarp::os::Bottle())
Look at a specified target object.
void close()
Properly closes all ports which were opened.
Definition: icubClient.cpp:140
bool lookAtBodypart(const std::string &sBodypartName)
Looks at the agent specific bodypart if present in the scene.
Abstract subSystem for speech recognizer.
std::list< Action * > getKnownActions()
Get the list of actions known the iCub.
Definition: icubClient.cpp:387
virtual ~ICubClient()
Destructor.
Definition: icubClient.cpp:161
bool waving(const bool sw)
Enable/disable arms waving.
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...
SubSystem for emotion.
SubSystem_IOL2OPC * getIOL2OPCClient()
Definition: icubClient.cpp:464
yarp::sig::VectorOf< double > getPartnerBodypartLoc(std::string sBodypartName)
Extract the location of the bodypart name of the partner.
Definition: icubClient.cpp:274
std::string getPartnerName(bool verbose=true)
Extract the name of the agent interaction with the iCub (present, not iCub nor &#39;unnamed&#39; partner) ...
Definition: icubClient.cpp:251
void updateAgent()
Retrieve fresh definition of the iCub agent from the OPC.
Definition: icubClient.cpp:169
SubSystem for babbling.
std::list< Object * > getObjectsInRange()
Get the list of objects that are graspable by the iCub See isTargetInRange() for a definition of how ...
Definition: icubClient.cpp:422
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...
bool point(const double x, const double y, const double z, const yarp::os::Bottle &options=yarp::os::Bottle())
Definition: icubClient.h:203
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...
SubSystem_SAM * getSAMClient()
Definition: icubClient.cpp:496
std::map< std::string, SubSystem * > subSystems
Definition: icubClient.h:69
bool say(const std::string &text, bool shouldWait=true)
Ask the robot to perform speech synthesis of a given sentence.
Definition: icubClient.cpp:374
SubSystem_KARMA * getKARMA()
Definition: icubClient.cpp:479
SubSystem_agentDetector * getAgentDetectorClient()
Definition: icubClient.cpp:454
SubSystem_ARE * getARE()
Definition: icubClient.cpp:474
SubSystem_Recog * getRecogClient()
Definition: icubClient.cpp:469