iCub-main
sensors.cpp
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 
18 #include <yarp/os/Bottle.h>
19 #include <yarp/os/BufferedPort.h>
20 #include <yarp/dev/ControlBoardInterfaces.h>
21 #include <yarp/sig/Vector.h>
22 
25 
26 using namespace std;
27 using namespace yarp::os;
28 using namespace yarp::dev;
29 using namespace yarp::sig;
30 using namespace iCub::perception;
31 
32 
33 /************************************************************************/
34 Sensor::Sensor()
35 {
36  name="";
37  source=NULL;
38  configured=false;
39 }
40 
41 
42 /************************************************************************/
43 bool SensorEncoders::configure(void *source, const Property &options)
44 {
45  if ((source==NULL) || !options.check("name") ||
46  !options.check("size") || !options.check("index"))
47  return false;
48 
49  this->source=source;
50  name=options.find("name").asString();
51  size=options.find("size").asInt32();
52  index=options.find("index").asInt32();
53 
54  return configured=true;
55 }
56 
57 
58 /************************************************************************/
59 bool SensorEncoders::getOutput(Value &in) const
60 {
61  if (!configured)
62  return false;
63 
64  Vector vect(size);
65  static_cast<IEncoders*>(source)->getEncoders(vect.data());
66  in=Value(vect[index]);
67 
68  return true;
69 }
70 
71 
72 /************************************************************************/
73 bool SensorPort::configure(void *source, const Property &options)
74 {
75  if ((source==NULL) || !options.check("name") || !options.check("index"))
76  return false;
77 
78  this->source=source;
79  name=options.find("name").asString();
80  index=options.find("index").asInt32();
81 
82  return configured=true;
83 }
84 
85 
86 /************************************************************************/
87 bool SensorPort::getOutput(Value &in) const
88 {
89  if (configured)
90  {
91  in=static_cast<iCub::perception::Port*>(source)->getValue(index);
92  return true;
93  }
94  else
95  return false;
96 }
97 
98 
99 
100 
sensors.h
yarp::dev
Definition: DebugInterfaces.h:52
iCub::perception::Port
Definition: ports.h:34
ports.h
iCub::perception
Definition: models.h:52