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  SensorEncoderArrays sensEncArrays[12];
213  SpringyFinger fingers[5];
214  bool configured;
215 
216  yarp::dev::PolyDriver drvEncs;
217  yarp::dev::PolyDriver drvMAIS;
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 
@ data
A class that implements preprocessing based on a fixed range of outputs to a fixed range of outputs.
This is basic implementation of the LSSVM algorithms.
Definition: LSSVMLearner.h:120
An abstract class that provides basic methods for interfacing with the data acquisition.
Definition: models.h:62
An abstract class that exposes the basic methods for the handling of data acquired through the attach...
Definition: nodes.h:94
This class implements the reading of encoders through MultipleAnalogSensors (MAS) interfaces.
Definition: sensors.h:202
This class implements the reading of joints encoders.
Definition: sensors.h:167
An implementation of the Node class that represents the springy finger.
bool fromProperty(const yarp::os::Property &options)
Configure the finger taking its parameters from a Property object.
bool getOutput(yarp::os::Value &out) const
Retrieve the finger output.
void toProperty(yarp::os::Property &options) const
Return a Property representation of all the node parameters.
bool toStream(std::ostream &str) const
Similar to the toProperty() method but it operates on output streams (e.g.
iCub::learningmachine::LSSVMLearner lssvm
double getCalibVel() const
Return the finger actuation velocity used while calibrating.
bool getSensorsData(yarp::os::Value &data) const
Retrieve data finger from the joints used both for calibration and normal operation.
void setCalibVel(const double vel)
Set the finger actuation velocity used while calibrating.
bool extractSensorsData(yarp::sig::Vector &in, yarp::sig::Vector &out) const
bool calibrate(const yarp::os::Property &options)
Allow to send calibration commands to the finger.
iCub::learningmachine::FixedRangeScaler scaler
bool isCalibrated() const
Return the internal status of the calibration.
A class that provides the user with a suitable framework to deal with the elastic approach for the pr...
void toProperty(yarp::os::Property &options) const
Return a Property representation of all the model parameters.
bool toStream(std::ostream &str) const
Similar to the toProperty() method but it operates on output streams (e.g.
bool isCalibrated() const
Return the internal status of the calibration.
bool calibrate(const yarp::os::Property &options)
Execute the fingers calibration.
bool fromProperty(const yarp::os::Property &options)
Configure the model taking its parameters from a Property object.
bool getOutput(yarp::os::Value &out) const
Retrieve the complete output of the model.
bool done
Definition: main.cpp:42
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
const FSC max
Definition: strain.h:48
const FSC min
Definition: strain.h:49
out
Definition: sine.m:8