iCub-main
nodes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3  * Author: 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  * http://www.robotcub.org/icub/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 
36 #ifndef __PERCEPTIVEMODELS_NODES_H__
37 #define __PERCEPTIVEMODELS_NODES_H__
38 
39 #include <map>
40 #include <ostream>
41 
42 #include <yarp/os/Value.h>
43 #include <yarp/os/Property.h>
44 
46 
47 
48 namespace iCub
49 {
50 
51 namespace perception
52 {
53 
60 {
61 protected:
62  std::string name;
63 
64 public:
68  EventCallback();
69 
74  std::string getName() const
75  {
76  return name;
77  }
78 
83  virtual void execute(void* ptr) = 0;
84 };
85 
86 
93 class Node
94 {
95 protected:
96  std::string name;
97 
98  std::map<std::string,Sensor*> sensors;
99  std::map<std::string,EventCallback*> callbacks;
100  std::map<std::string,Node*> neighbors;
101 
102 public:
106  Node();
107 
112  std::string getName() const
113  {
114  return name;
115  }
116 
122  void attachSensor(Sensor &sensor);
123 
129  void attachCallback(EventCallback &callback);
130 
136  void addNeighbor(Node &node);
137 
143  bool removeNeighbor(const std::string &name);
144 
150  Node* getNeighbor(const std::string &name) const;
151 
159  virtual bool fromProperty(const yarp::os::Property &options) = 0;
160 
166  virtual void toProperty(yarp::os::Property &options) const = 0;
167 
176  virtual bool toStream(std::ostream &str) const = 0;
177 
187  virtual bool calibrate(const yarp::os::Property &options) = 0;
188 
195  virtual bool isCalibrated() const = 0;
196 
205  virtual bool getSensorsData(yarp::os::Value &data) const = 0;
206 
212  virtual bool getOutput(yarp::os::Value &out) const = 0;
213 
217  virtual ~Node() { }
218 };
219 
220 
221 }
222 
223 }
224 
225 #endif
226 
227 
@ data
An abstract class that provides basic events handling.
Definition: nodes.h:60
virtual void execute(void *ptr)=0
The callback routine.
std::string getName() const
Retrieve the node name.
Definition: nodes.h:74
EventCallback()
Constructor.
Definition: nodes.cpp:26
An abstract class that exposes the basic methods for the handling of data acquired through the attach...
Definition: nodes.h:94
std::map< std::string, EventCallback * > callbacks
Definition: nodes.h:99
std::map< std::string, Node * > neighbors
Definition: nodes.h:100
virtual ~Node()
Destructor.
Definition: nodes.h:217
std::map< std::string, Sensor * > sensors
Definition: nodes.h:98
virtual void toProperty(yarp::os::Property &options) const =0
Return a Property representation of all the node parameters.
virtual bool fromProperty(const yarp::os::Property &options)=0
Configure the node taking its parameters from a Property object.
void addNeighbor(Node &node)
Add a node as a neighbor for the process of building the architecture.
Definition: nodes.cpp:54
bool removeNeighbor(const std::string &name)
Remove a node previously added as neighbor.
Definition: nodes.cpp:61
void attachCallback(EventCallback &callback)
Attach an event callback to the node.
Definition: nodes.cpp:47
void attachSensor(Sensor &sensor)
Attach a sensor object to the node.
Definition: nodes.cpp:40
virtual bool isCalibrated() const =0
Return the internal status of the calibration.
virtual bool calibrate(const yarp::os::Property &options)=0
Some kinds of nodes need to be calibrated to properly operate.
std::string name
Definition: nodes.h:96
Node * getNeighbor(const std::string &name) const
Retrieve a neighbor node by its name.
Definition: nodes.cpp:75
std::string getName() const
Retrieve the node name.
Definition: nodes.h:112
virtual bool getSensorsData(yarp::os::Value &data) const =0
Retrieve data from the whole set of attached sensors, giving back a standard representation of it.
virtual bool toStream(std::ostream &str) const =0
Similar to the toProperty() method but it operates on output streams (e.g.
Node()
Constructor.
Definition: nodes.cpp:33
virtual bool getOutput(yarp::os::Value &out) const =0
Retrieve the node output computed over the sensors data.
An abstract class that exposes the basic methods for sensors handling.
Definition: sensors.h:116
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
out
Definition: sine.m:8