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:
63 
64 public:
68  EventCallback();
69 
75  {
76  return name;
77  }
78 
83  virtual void execute(void* ptr) = 0;
84 };
85 
86 
93 class Node
94 {
95 protected:
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 
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 
iCub::perception::EventCallback::getName
std::string getName() const
Retrieve the node name.
Definition: nodes.h:74
iCub::perception::EventCallback::EventCallback
EventCallback()
Constructor.
Definition: nodes.cpp:26
sensors.h
iCub
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Definition: emotionInterface.h:17
iCub::perception::Node::calibrate
virtual bool calibrate(const yarp::os::Property &options)=0
Some kinds of nodes need to be calibrated to properly operate.
iCub::perception::Node::addNeighbor
void addNeighbor(Node &node)
Add a node as a neighbor for the process of building the architecture.
Definition: nodes.cpp:54
iCub::perception::Node::getNeighbor
Node * getNeighbor(const std::string &name) const
Retrieve a neighbor node by its name.
Definition: nodes.cpp:75
iCub::perception::Node::getSensorsData
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.
iCub::perception::Node::toStream
virtual bool toStream(std::ostream &str) const =0
Similar to the toProperty() method but it operates on output streams (e.g.
iCub::perception::Sensor
Definition: sensors.h:115
out
out
Definition: sine.m:8
iCub::perception::Node::removeNeighbor
bool removeNeighbor(const std::string &name)
Remove a node previously added as neighbor.
Definition: nodes.cpp:61
iCub::perception::Node::sensors
std::map< std::string, Sensor * > sensors
Definition: nodes.h:98
iCub::perception::EventCallback::name
std::string name
Definition: nodes.h:62
iCub::perception::Node::getOutput
virtual bool getOutput(yarp::os::Value &out) const =0
Retrieve the node output computed over the sensors data.
data
@ data
Definition: ST_M1_dataType.h:64
iCub::perception::Node::toProperty
virtual void toProperty(yarp::os::Property &options) const =0
Return a Property representation of all the node parameters.
iCub::perception::Node::attachSensor
void attachSensor(Sensor &sensor)
Attach a sensor object to the node.
Definition: nodes.cpp:40
iCub::perception::EventCallback::execute
virtual void execute(void *ptr)=0
The callback routine.
iCub::perception::Node::isCalibrated
virtual bool isCalibrated() const =0
Return the internal status of the calibration.
iCub::perception::Node::neighbors
std::map< std::string, Node * > neighbors
Definition: nodes.h:100
iCub::perception::Node
Definition: nodes.h:93
iCub::perception::Node::getName
std::string getName() const
Retrieve the node name.
Definition: nodes.h:112
iCub::perception::Node::name
std::string name
Definition: nodes.h:96
iCub::perception::Node::fromProperty
virtual bool fromProperty(const yarp::os::Property &options)=0
Configure the node taking its parameters from a Property object.
iCub::perception::Node::Node
Node()
Constructor.
Definition: nodes.cpp:33
string
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}") include_directories($
Definition: CMakeLists.txt:9
iCub::perception::Node::attachCallback
void attachCallback(EventCallback &callback)
Attach an event callback to the node.
Definition: nodes.cpp:47
iCub::perception::Node::~Node
virtual ~Node()
Destructor.
Definition: nodes.h:217
iCub::perception::Node::callbacks
std::map< std::string, EventCallback * > callbacks
Definition: nodes.h:99
iCub::perception::EventCallback
Definition: nodes.h:59