iCub-main
springyFingers.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 
56 #ifndef __PERCEPTIVEMODELS_SPRINGYFINGERS_H__
57 #define __PERCEPTIVEMODELS_SPRINGYFINGERS_H__
58 
59 #include <mutex>
60 
61 #include <yarp/os/all.h>
62 #include <yarp/dev/all.h>
63 #include <yarp/sig/all.h>
64 
68 #include <iCub/perception/nodes.h>
69 #include <iCub/perception/models.h>
70 
71 
72 namespace iCub
73 {
74 
75 namespace perception
76 {
77 
84 class SpringyFinger : public Node
85 {
86 protected:
90  double outputGain;
91  bool calibrated;
92 
93  bool extractSensorsData(yarp::sig::Vector &in, yarp::sig::Vector &out) const;
94 
95 public:
118  bool fromProperty(const yarp::os::Property &options);
119 
125  void toProperty(yarp::os::Property &options) const;
126 
135  bool toStream(std::ostream &str) const;
136 
149  bool calibrate(const yarp::os::Property &options);
150 
158  bool getSensorsData(yarp::os::Value &data) const;
159 
166  bool getOutput(yarp::os::Value &out) const;
167 
172  bool isCalibrated() const
173  {
174  return calibrated;
175  }
176 
181  void setCalibVel(const double vel)
182  {
184  }
185 
190  double getCalibVel() const
191  {
192  return calibratingVelocity;
193  }
194 };
195 
196 
204 class SpringyFingersModel : public virtual Model
205 {
206 private:
207  std::string type;
208  std::string robot;
209  std::string carrier;
210 
211  SensorEncoders sensEncs[5];
212  SensorPort sensPort[12];
213  SpringyFinger fingers[5];
214  bool configured;
215 
216  yarp::os::BufferedPort<yarp::os::Bottle> *port;
217  yarp::dev::PolyDriver driver;
218 
219  std::mutex mtx;
220 
221  class CalibThread : public yarp::os::Thread
222  {
223  SpringyFingersModel *model;
224  SpringyFinger *finger;
225  double min;
226  double max;
227  int joint;
228  bool done;
229 
230  public:
231  CalibThread() : model(NULL), done(false) { }
232 
233  void setInfo(SpringyFingersModel *model, SpringyFinger &finger,
234  const int joint, const double min, const double max)
235  {
236  this->model=model;
237  this->finger=&finger;
238  this->joint=joint;
239  this->min=min;
240  this->max=max;
241  }
242 
243  void run()
244  {
245  if (!done && (model!=NULL))
246  {
247  model->calibrateFinger(*finger,joint,min,max);
248  done=true;
249  }
250 
251  yarp::os::Time::delay(0.1);
252  }
253 
254  bool isDone() const { return done; }
255  };
256  friend class CalibThread;
257 
258  void calibrateFinger(SpringyFinger &finger, const int joint,
259  const double min, const double max);
260  void close();
261 
262 public:
267 
284  bool fromProperty(const yarp::os::Property &options);
285 
291  void toProperty(yarp::os::Property &options) const;
292 
301  bool toStream(std::ostream &str) const;
302 
318  bool calibrate(const yarp::os::Property &options);
319 
324  bool isCalibrated() const;
325 
334  bool getOutput(yarp::os::Value &out) const;
335 
339  virtual ~SpringyFingersModel();
340 };
341 
342 
343 }
344 
345 }
346 
347 #endif
348 
349 
sensors.h
iCub::perception::SpringyFinger::getOutput
bool getOutput(yarp::os::Value &out) const
Retrieve the finger output.
Definition: springyFingers.cpp:211
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::SpringyFinger::getCalibVel
double getCalibVel() const
Return the finger actuation velocity used while calibrating.
Definition: springyFingers.h:190
iCub::perception::SpringyFingersModel
Definition: springyFingers.h:204
iCub::perception::SpringyFinger::calibratingVelocity
double calibratingVelocity
Definition: springyFingers.h:89
iCub::perception::SpringyFinger::isCalibrated
bool isCalibrated() const
Return the internal status of the calibration.
Definition: springyFingers.h:172
out
out
Definition: sine.m:8
strain::dsp::fsc::min
const FSC min
Definition: strain.h:49
iCub::perception::SpringyFinger::scaler
iCub::learningmachine::FixedRangeScaler scaler
Definition: springyFingers.h:87
LSSVMLearner.h
FixedRangeScaler.h
iCub::perception::SpringyFinger::toProperty
void toProperty(yarp::os::Property &options) const
Return a Property representation of all the node parameters.
Definition: springyFingers.cpp:99
iCub::perception::SpringyFinger
Definition: springyFingers.h:84
iCub::perception::SpringyFinger::fromProperty
bool fromProperty(const yarp::os::Property &options)
Configure the finger taking its parameters from a Property object.
Definition: springyFingers.cpp:43
data
@ data
Definition: ST_M1_dataType.h:64
iCub::perception::SensorEncoders
Definition: sensors.h:166
iCub::perception::SpringyFinger::outputGain
double outputGain
Definition: springyFingers.h:90
iCub::perception::SpringyFinger::calibrated
bool calibrated
Definition: springyFingers.h:91
iCub::perception::SpringyFingersModel::getOutput
bool getOutput(yarp::os::Value &out) const
Retrieve the complete output of the model.
Definition: springyFingers.cpp:688
strain::dsp::fsc::max
const FSC max
Definition: strain.h:48
iCub::perception::SpringyFingersModel::toStream
bool toStream(std::ostream &str) const
Similar to the toProperty() method but it operates on output streams (e.g.
Definition: springyFingers.cpp:461
iCub::perception::SpringyFinger::lssvm
iCub::learningmachine::LSSVMLearner lssvm
Definition: springyFingers.h:88
iCub::perception::SpringyFingersModel::SpringyFingersModel
SpringyFingersModel()
Constructor.
Definition: springyFingers.cpp:261
iCub::perception::SensorPort
Definition: sensors.h:200
iCub::perception::Node
Definition: nodes.h:93
iCub::perception::SpringyFingersModel::isCalibrated
bool isCalibrated() const
Return the internal status of the calibration.
Definition: springyFingers.cpp:800
iCub::perception::SpringyFinger::toStream
bool toStream(std::ostream &str) const
Similar to the toProperty() method but it operates on output streams (e.g.
Definition: springyFingers.cpp:112
string
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}") include_directories($
Definition: CMakeLists.txt:9
iCub::learningmachine::FixedRangeScaler
Definition: FixedRangeScaler.h:39
iCub::perception::SpringyFingersModel::~SpringyFingersModel
virtual ~SpringyFingersModel()
Destructor.
Definition: springyFingers.cpp:828
models.h
iCub::perception::SpringyFinger::extractSensorsData
bool extractSensorsData(yarp::sig::Vector &in, yarp::sig::Vector &out) const
Definition: springyFingers.cpp:179
nodes.h
done
bool done
Definition: main.cpp:42
iCub::perception::Model
Definition: models.h:61
iCub::learningmachine::LSSVMLearner
Definition: LSSVMLearner.h:121
iCub::perception::SpringyFingersModel::CalibThread
friend class CalibThread
Definition: springyFingers.h:256
iCub::perception::SpringyFingersModel::fromProperty
bool fromProperty(const yarp::os::Property &options)
Configure the model taking its parameters from a Property object.
Definition: springyFingers.cpp:269
iCub::perception::SpringyFinger::setCalibVel
void setCalibVel(const double vel)
Set the finger actuation velocity used while calibrating.
Definition: springyFingers.h:181
iCub::perception::SpringyFinger::getSensorsData
bool getSensorsData(yarp::os::Value &data) const
Retrieve data finger from the joints used both for calibration and normal operation.
Definition: springyFingers.cpp:126
iCub::perception::SpringyFingersModel::calibrate
bool calibrate(const yarp::os::Property &options)
Execute the fingers calibration.
Definition: springyFingers.cpp:498
iCub::perception::SpringyFinger::calibrate
bool calibrate(const yarp::os::Property &options)
Allow to send calibration commands to the finger.
Definition: springyFingers.cpp:230
iCub::perception::SpringyFingersModel::toProperty
void toProperty(yarp::os::Property &options) const
Return a Property representation of all the model parameters.
Definition: springyFingers.cpp:418