icub-client
agent.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_AGENT_H__
20 #define __ICUBCLIENT_AGENT_H__
21 
22 #include "object.h"
23 #include "relation.h"
24 
25 namespace icubclient{
26 
33 struct Body
34 {
35  std::map<std::string, yarp::sig::VectorOf<double>> m_parts;
36 
37  Body()
38  {
39  m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_HEAD].resize(3,0.0);
40  m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_SHOULDER_C].resize(3,0.0);
41  m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_SHOULDER_L].resize(3,0.0);
42  m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_SHOULDER_R].resize(3,0.0);
43  m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_SPINE].resize(3,0.0);
44  m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_HAND_R].resize(3,0.0);
45  m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_HAND_L].resize(3,0.0);
46  m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_ELBOW_R].resize(3,0.0);
47  m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_ELBOW_L].resize(3,0.0);
48  //m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_LEFT_HIP].resize(3,0.0);
49  //m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_LEFT_KNEE].resize(3,0.0);
50  //m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_LEFT_FOOT].resize(3,0.0);
51  //m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_RIGHT_HIP].resize(3,0.0);
52  //m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_RIGHT_KNEE].resize(3,0.0);
53  //m_parts[ICUBCLIENT_OPC_BODY_PART_TYPE_RIGHT_FOOT].resize(3,0.0);
54  }
55 
56  yarp::os::Bottle asBottle() const
57  {
58  yarp::os::Bottle b;
59  for(auto& part : m_parts)
60  {
61  yarp::os::Bottle sub;
62  sub.addString(part.first.c_str());
63  yarp::os::Bottle position;
64  position.addDouble(part.second[0]);
65  position.addDouble(part.second[1]);
66  position.addDouble(part.second[2]);
67  sub.addList() = position;
68  b.addList()= sub;
69  }
70  return b;
71  }
72 
73  bool fromBottle(const yarp::os::Bottle &b)
74  {
75  for(std::map<std::string,yarp::sig::VectorOf<double>>::iterator part = m_parts.begin(); part != m_parts.end(); part++)
76  {
77  yarp::os::Bottle* position = b.find(part->first.c_str()).asList();
78  part->second[0] = position->get(0).asDouble();
79  part->second[1] = position->get(1).asDouble();
80  part->second[2] = position->get(2).asDouble();
81  }
82  return true;
83  }
84 };
85 
93 class Agent : public Object
94 {
95  friend class OPCClient;
96 private:
97  std::list<Relation> m_belief;
98 public:
99  Agent();
100  Agent(const Agent &b);
101 
102  std::map<std::string, double> m_emotions_intrinsic;
104 
105  virtual bool isType(std::string _entityType) const
106  {
107  if (_entityType == ICUBCLIENT_OPC_ENTITY_AGENT)
108  return true;
109  else
110  return this->Object::isType(_entityType);
111  }
112 
113  virtual yarp::os::Bottle asBottle() const;
114  virtual bool fromBottle(const yarp::os::Bottle &b);
115  virtual std::string toString() const;
116 
121  bool addBelief(const Relation &r);
122 
127  bool removeBelief(const Relation &r);
128 
133  bool checkBelief(const Relation &r) const;
134 
138  const std::list<Relation> &beliefs() const;
139 };
140 
141 } //namespaces
142 
143 #endif
144 
145 
#define ICUBCLIENT_OPC_BODY_PART_TYPE_ELBOW_L
Definition: tags.h:83
#define ICUBCLIENT_OPC_BODY_PART_TYPE_SHOULDER_L
Definition: tags.h:86
#define ICUBCLIENT_OPC_BODY_PART_TYPE_SHOULDER_R
Definition: tags.h:87
std::map< std::string, double > m_emotions_intrinsic
Definition: agent.h:102
#define ICUBCLIENT_OPC_BODY_PART_TYPE_HAND_L
Definition: tags.h:79
#define ICUBCLIENT_OPC_BODY_PART_TYPE_HEAD
Definition: tags.h:78
Represent any physical entity (including objects and agents) that can be stored within the OPC...
Definition: object.h:35
virtual bool isType(std::string _entityType) const
Test if an entity is inheriting a given type.
Definition: object.h:86
#define ICUBCLIENT_OPC_BODY_PART_TYPE_SHOULDER_C
Definition: tags.h:85
Represent an agent.
Definition: agent.h:93
#define ICUBCLIENT_OPC_BODY_PART_TYPE_HAND_R
Definition: tags.h:80
An OPC client using the datastructures defined within the icub-client library.
Definition: opcClient.h:35
bool fromBottle(const yarp::os::Bottle &b)
Definition: agent.h:73
yarp::os::Bottle asBottle() const
Definition: agent.h:56
Represent a relation between two entities.
Definition: relation.h:31
Represent a the body of an agent.
Definition: agent.h:33
#define ICUBCLIENT_OPC_BODY_PART_TYPE_SPINE
Definition: tags.h:88
#define ICUBCLIENT_OPC_ENTITY_AGENT
Definition: tags.h:40
#define ICUBCLIENT_OPC_BODY_PART_TYPE_ELBOW_R
Definition: tags.h:84
std::map< std::string, yarp::sig::VectorOf< double > > m_parts
Definition: agent.h:35
virtual bool isType(std::string _entityType) const
Test if an entity is inheriting a given type.
Definition: agent.h:105