iCub-main
fakeMotorDeviceComponents.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 
18 #ifndef __FAKEMOTORDEVICECOMPONENTS_H__
19 #define __FAKEMOTORDEVICECOMPONENTS_H__
20 
21 #include <mutex>
22 
23 #include <yarp/os/all.h>
24 #include <yarp/dev/all.h>
25 #include <yarp/sig/all.h>
26 
27 #include <iCub/ctrl/pids.h>
28 
33 class fakeMotorDeviceServer : public yarp::dev::DeviceDriver,
34  public yarp::os::PeriodicThread,
35  public yarp::os::PortReader,
36  public yarp::dev::IControlLimits,
37  public yarp::dev::IEncoders,
38  public yarp::dev::IVelocityControl
39 {
40 protected:
41  yarp::os::BufferedPort<yarp::sig::Vector> statePort;
42  yarp::os::BufferedPort<yarp::os::Bottle> cmdPort;
43  yarp::os::Port rpcPort;
44 
45  std::mutex mtx;
46 
48  yarp::sig::Vector vel;
49  bool configured;
50 
51  void run();
56  bool read(yarp::os::ConnectionReader &connection);
57 
58 public:
60  bool open(yarp::os::Searchable &config);
61  bool close();
62 
67  /**********************************************************/
68  bool getLimits(int axis, double *min, double *max);
69 
70  // not implemented
71  /**********************************************************/
72  bool setLimits(int,double,double) { return false; }
73  bool setVelLimits(int,double,double) { return false; }
74  bool getVelLimits(int,double*,double*) { return false; }
75 
80  /**********************************************************/
81  bool getAxes(int *ax);
82 
83  // not implemented
84  /**********************************************************/
85  bool getEncoder(int,double*) { return false; }
86  bool getEncoders(double*) { return false; }
87  bool resetEncoder(int) { return false; }
88  bool resetEncoders() { return false; }
89  bool setEncoder(int,double) { return false; }
90  bool setEncoders(const double*) { return false; }
91  bool getEncoderSpeed(int,double*) { return false; }
92  bool getEncoderSpeeds(double*) { return false; }
93  bool getEncoderAcceleration(int,double*) { return false; }
94  bool getEncoderAccelerations(double*) { return false; }
95 
100  /**********************************************************/
101  bool velocityMove(int j, double sp);
102  bool setRefAcceleration(int j, double acc);
103  bool stop(int j);
104 
105  // not implemented
106  /**********************************************************/
107  bool velocityMove(const int,const int*,const double*) { return false; }
108  bool velocityMove(const double*) { return false; }
109  bool setRefAccelerations(const int,const int*,const double*) { return false; }
110  bool setRefAccelerations(const double*) { return false; }
111  bool getRefAccelerations(const int,const int*,double*) { return false; }
112  bool getRefAcceleration(int,double*) { return false; }
113  bool getRefAccelerations(double*) { return false; }
114  bool stop(const int,const int*) { return false; }
115  bool stop() { return false; }
116 };
117 
122 class fakeMotorDeviceClient : public yarp::dev::DeviceDriver,
123  public yarp::dev::IControlLimits,
124  public yarp::dev::IEncoders,
125  public yarp::dev::IVelocityControl
126 {
127 protected:
128  class StatePort : public yarp::os::BufferedPort<yarp::sig::Vector>
129  {
130  fakeMotorDeviceClient *owner;
131  void onRead(yarp::sig::Vector &encs)
132  {
133  if (owner!=NULL)
134  {
135  std::lock_guard<std::mutex> lg(owner->mtx);
136  owner->encs=encs;
137  }
138  }
139  public:
140  StatePort() : owner(NULL) { useCallback(); }
141  void setOwner(fakeMotorDeviceClient *owner) { this->owner=owner; }
142  };
143 
145  yarp::os::BufferedPort<yarp::os::Bottle> cmdPort;
146  yarp::os::RpcClient rpcPort;
147 
148  std::mutex mtx;
149 
150  yarp::sig::Vector encs;
152 
153  friend class StatePort;
154 
155 public:
157  bool open(yarp::os::Searchable &config);
158  bool close();
159 
164  /**********************************************************/
165  bool getLimits(int axis, double *min, double *max);
166 
167  // not implemented
168  /**********************************************************/
169  bool setLimits(int,double,double) { return false; }
170  bool setVelLimits(int,double,double) { return false; }
171  bool getVelLimits(int,double*,double*) { return false; }
172 
177  /**********************************************************/
178  bool getAxes(int *ax);
179  bool getEncoders(double *encs);
180 
181  // not implemented
182  /**********************************************************/
183  bool getEncoder(int,double*) { return false; }
184  bool resetEncoder(int) { return false; }
185  bool resetEncoders() { return false; }
186  bool setEncoder(int,double) { return false; }
187  bool setEncoders(const double*) { return false; }
188  bool getEncoderSpeed(int,double*) { return false; }
189  bool getEncoderSpeeds(double*) { return false; }
190  bool getEncoderAcceleration(int,double*) { return false; }
191  bool getEncoderAccelerations(double*) { return false; }
192 
197  /**********************************************************/
198  bool velocityMove(int j, double sp);
199  bool setRefAcceleration(int j, double acc);
200  bool stop(int j);
201 
202  // not implemented
203  /**********************************************************/
204  bool velocityMove(const int,const int*,const double*) { return false; }
205  bool velocityMove(const double*) { return false; }
206  bool setRefAccelerations(const int,const int*,const double*) { return false; }
207  bool setRefAccelerations(const double*) { return false; }
208  bool getRefAccelerations(const int,const int*,double*) { return false; }
209  bool getRefAcceleration(int,double*) { return false; }
210  bool getRefAccelerations(double*) { return false; }
211  bool stop(const int,const int*) { return false; }
212  bool stop() { return false; }
213 };
214 
215 #endif
216 
217 
void setOwner(fakeMotorDeviceClient *owner)
This class implements the client part of the fake motor device driver.
bool getRefAccelerations(const int, const int *, double *)
bool getEncoderAcceleration(int, double *)
bool open(yarp::os::Searchable &config)
bool getRefAcceleration(int, double *)
bool setEncoders(const double *)
bool setRefAccelerations(const double *)
bool setRefAcceleration(int j, double acc)
bool getEncoderSpeed(int, double *)
bool getEncoders(double *encs)
bool getLimits(int axis, double *min, double *max)
bool velocityMove(const double *)
yarp::os::BufferedPort< yarp::os::Bottle > cmdPort
bool velocityMove(const int, const int *, const double *)
bool setRefAccelerations(const int, const int *, const double *)
bool stop(const int, const int *)
bool getVelLimits(int, double *, double *)
bool velocityMove(int j, double sp)
bool setLimits(int, double, double)
bool setVelLimits(int, double, double)
This class implements the server part of the fake motor device driver.
yarp::os::BufferedPort< yarp::sig::Vector > statePort
yarp::os::BufferedPort< yarp::os::Bottle > cmdPort
bool getVelLimits(int, double *, double *)
bool getLimits(int axis, double *min, double *max)
bool getRefAccelerations(const int, const int *, double *)
bool read(yarp::os::ConnectionReader &connection)
This method decodes the requests forwarded by the client and responds with corresponding replies.
bool velocityMove(int j, double sp)
bool getEncoderSpeed(int, double *)
bool velocityMove(const double *)
bool setVelLimits(int, double, double)
iCub::ctrl::Integrator * motors
bool open(yarp::os::Searchable &config)
bool getRefAcceleration(int, double *)
bool getEncoder(int, double *)
bool stop(const int, const int *)
bool setRefAcceleration(int j, double acc)
bool setRefAccelerations(const double *)
bool setEncoders(const double *)
bool setRefAccelerations(const int, const int *, const double *)
bool setLimits(int, double, double)
bool getEncoderAcceleration(int, double *)
bool velocityMove(const int, const int *, const double *)
A class for defining a saturated integrator based on Tustin formula: .
Definition: pids.h:48
_3f_vect_t acc
Definition: dataTypes.h:1
const FSC max
Definition: strain.h:48
const FSC min
Definition: strain.h:49