YARP
Yet Another Robot Platform
ControlBoardWrapperMotorEncoders.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
10 
12 
14 {
15  int off = device.lut[m].offset;
16  size_t subIndex = device.lut[m].deviceEntry;
17 
18  SubDevice* p = device.getSubdevice(subIndex);
19  if (!p) {
20  return false;
21  }
22 
23  if (p->iMotEnc) {
24  return p->iMotEnc->resetMotorEncoder(static_cast<int>(off + p->base));
25  }
26  return false;
27 }
28 
29 
31 {
32  bool ret = true;
33 
34  for (size_t l = 0; l < controlledJoints; l++) {
35  int off = device.lut[l].offset;
36  size_t subIndex = device.lut[l].deviceEntry;
37 
38  SubDevice* p = device.getSubdevice(subIndex);
39  if (!p) {
40  return false;
41  }
42 
43  if (p->iMotEnc) {
44  ret = ret && p->iMotEnc->resetMotorEncoder(static_cast<int>(off + p->base));
45  } else {
46  ret = false;
47  }
48  }
49  return ret;
50 }
51 
52 
54 {
55  int off = device.lut[m].offset;
56  size_t subIndex = device.lut[m].deviceEntry;
57 
58  SubDevice* p = device.getSubdevice(subIndex);
59  if (!p) {
60  return false;
61  }
62 
63  if (p->iMotEnc) {
64  return p->iMotEnc->setMotorEncoder(static_cast<int>(off + p->base), val);
65  }
66  return false;
67 }
68 
69 
71 {
72  bool ret = true;
73 
74  for (size_t l = 0; l < controlledJoints; l++) {
75  int off = device.lut[l].offset;
76  size_t subIndex = device.lut[l].deviceEntry;
77 
78  SubDevice* p = device.getSubdevice(subIndex);
79  if (!p) {
80  return false;
81  }
82 
83  if (p->iMotEnc) {
84  ret = ret && p->iMotEnc->setMotorEncoder(static_cast<int>(off + p->base), vals[l]);
85  } else {
86  ret = false;
87  }
88  }
89  return ret;
90 }
91 
92 
94 {
95  int off = device.lut[m].offset;
96  size_t subIndex = device.lut[m].deviceEntry;
97 
98  SubDevice* p = device.getSubdevice(subIndex);
99  if (!p) {
100  return false;
101  }
102 
103  if (p->iMotEnc) {
104  return p->iMotEnc->setMotorEncoderCountsPerRevolution(static_cast<int>(off + p->base), cpr);
105  }
106  return false;
107 }
108 
109 
111 {
112  int off = device.lut[m].offset;
113  size_t subIndex = device.lut[m].deviceEntry;
114 
115  SubDevice* p = device.getSubdevice(subIndex);
116  if (!p) {
117  return false;
118  }
119 
120  if (p->iMotEnc) {
121  return p->iMotEnc->getMotorEncoderCountsPerRevolution(static_cast<int>(off + p->base), cpr);
122  }
123  *cpr = 0.0;
124  return false;
125 }
126 
127 
129 {
130  int off = device.lut[m].offset;
131  size_t subIndex = device.lut[m].deviceEntry;
132 
133  SubDevice* p = device.getSubdevice(subIndex);
134  if (!p) {
135  return false;
136  }
137 
138  if (p->iMotEnc) {
139  return p->iMotEnc->getMotorEncoder(static_cast<int>(off + p->base), v);
140  }
141  *v = 0.0;
142  return false;
143 }
144 
145 
147 {
148 
149  auto* encValues = new double[device.maxNumOfJointsInDevices];
150  bool ret = true;
151  for (size_t d = 0; d < device.subdevices.size(); d++) {
152  SubDevice* p = device.getSubdevice(d);
153  if (!p) {
154  ret = false;
155  break;
156  }
157 
158  if ((p->iMotEnc) && (ret = p->iMotEnc->getMotorEncoders(encValues))) {
159  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
160  encs[juser] = encValues[jdevice];
161  }
162  } else {
163  printError("getMotorEncoders", p->id, ret);
164  ret = false;
165  break;
166  }
167  }
168 
169  delete[] encValues;
170  return ret;
171 }
172 
173 
175 {
176  auto* encValues = new double[device.maxNumOfJointsInDevices];
177  auto* tValues = new double[device.maxNumOfJointsInDevices];
178  bool ret = true;
179  for (size_t d = 0; d < device.subdevices.size(); d++) {
180  SubDevice* p = device.getSubdevice(d);
181  if (!p) {
182  ret = false;
183  break;
184  }
185 
186  if ((p->iMotEnc) && (ret = p->iMotEnc->getMotorEncodersTimed(encValues, tValues))) {
187  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
188  encs[juser] = encValues[jdevice];
189  t[juser] = tValues[jdevice];
190  }
191  } else {
192  printError("getMotorEncodersTimed", p->id, ret);
193  ret = false;
194  break;
195  }
196  }
197 
198  delete[] encValues;
199  delete[] tValues;
200  return ret;
201 }
202 
203 
205 {
206  int off = device.lut[m].offset;
207  size_t subIndex = device.lut[m].deviceEntry;
208 
209  SubDevice* p = device.getSubdevice(subIndex);
210  if (!p) {
211  return false;
212  }
213 
214  if (p->iMotEnc) {
215  return p->iMotEnc->getMotorEncoderTimed(static_cast<int>(off + p->base), v, t);
216  }
217  *v = 0.0;
218  return false;
219 }
220 
221 
223 {
224  int off = device.lut[m].offset;
225  size_t subIndex = device.lut[m].deviceEntry;
226 
227  SubDevice* p = device.getSubdevice(subIndex);
228  if (!p) {
229  return false;
230  }
231 
232  if (p->iMotEnc) {
233  return p->iMotEnc->getMotorEncoderSpeed(static_cast<int>(off + p->base), sp);
234  }
235  *sp = 0.0;
236  return false;
237 }
238 
239 
241 {
242  auto* sValues = new double[device.maxNumOfJointsInDevices];
243  bool ret = true;
244  for (size_t d = 0; d < device.subdevices.size(); d++) {
245  SubDevice* p = device.getSubdevice(d);
246  if (!p) {
247  ret = false;
248  break;
249  }
250 
251  if ((p->iMotEnc) && (ret = p->iMotEnc->getMotorEncoderSpeeds(sValues))) {
252  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
253  spds[juser] = sValues[jdevice];
254  }
255  } else {
256  printError("getMotorEncoderSpeeds", p->id, ret);
257  ret = false;
258  break;
259  }
260  }
261 
262  delete[] sValues;
263  return ret;
264 }
265 
266 
268 {
269  int off = device.lut[m].offset;
270  size_t subIndex = device.lut[m].deviceEntry;
271 
272  SubDevice* p = device.getSubdevice(subIndex);
273  if (!p) {
274  return false;
275  }
276 
277  if (p->iMotEnc) {
278  return p->iMotEnc->getMotorEncoderAcceleration(static_cast<int>(off + p->base), acc);
279  }
280  *acc = 0.0;
281  return false;
282 }
283 
284 
286 {
287  auto* aValues = new double[device.maxNumOfJointsInDevices];
288  bool ret = true;
289  for (size_t d = 0; d < device.subdevices.size(); d++) {
290  SubDevice* p = device.getSubdevice(d);
291  if (!p) {
292  ret = false;
293  break;
294  }
295 
296  if ((p->iMotEnc) && (ret = p->iMotEnc->getMotorEncoderAccelerations(aValues))) {
297  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
298  accs[juser] = aValues[jdevice];
299  }
300  } else {
301  printError("getMotorEncoderAccelerations", p->id, ret);
302  ret = false;
303  break;
304  }
305  }
306 
307  delete[] aValues;
308  return ret;
309 }
310 
311 
313 {
314  *num = controlledJoints;
315  return true;
316 }
SubDevice::iMotEnc
yarp::dev::IMotorEncoders * iMotEnc
Definition: SubDevice.h:74
ControlBoardWrapperMotorEncoders::getMotorEncoderAccelerations
bool getMotorEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all motor encoders.
Definition: ControlBoardWrapperMotorEncoders.cpp:285
ControlBoardWrapperLogComponent.h
t
float t
Definition: FfmpegWriter.cpp:74
yarp::dev::IMotorEncoders::setMotorEncoderCountsPerRevolution
virtual bool setMotorEncoderCountsPerRevolution(int m, const double cpr)=0
Sets number of counts per revolution for motor encoder m.
ControlBoardWrapperMotorEncoders::setMotorEncoderCountsPerRevolution
bool setMotorEncoderCountsPerRevolution(int m, const double cpr) override
Sets number of counts per revolution for motor encoder m.
Definition: ControlBoardWrapperMotorEncoders.cpp:93
yarp::dev::IMotorEncoders::resetMotorEncoder
virtual bool resetMotorEncoder(int m)=0
Reset motor encoder, single motor.
ControlBoardWrapperMotorEncoders::getMotorEncodersTimed
bool getMotorEncodersTimed(double *encs, double *t) override
Read the instantaneous position of all motor encoders.
Definition: ControlBoardWrapperMotorEncoders.cpp:174
ControlBoardWrapperMotorEncoders.h
ControlBoardWrapperMotorEncoders::getMotorEncoderCountsPerRevolution
bool getMotorEncoderCountsPerRevolution(int m, double *cpr) override
Gets number of counts per revolution for motor encoder m.
Definition: ControlBoardWrapperMotorEncoders.cpp:110
yarp::dev::IMotorEncoders::getMotorEncoder
virtual bool getMotorEncoder(int m, double *v)=0
Read the value of a motor encoder.
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
ControlBoardWrapperMotorEncoders::getMotorEncoderTimed
bool getMotorEncoderTimed(int m, double *v, double *t) override
Read the instantaneous position of a motor encoder.
Definition: ControlBoardWrapperMotorEncoders.cpp:204
ControlBoardWrapperMotorEncoders::getNumberOfMotorEncoders
bool getNumberOfMotorEncoders(int *num) override
Get the number of available motor encoders.
Definition: ControlBoardWrapperMotorEncoders.cpp:312
yarp::dev::IMotorEncoders::getMotorEncoderAccelerations
virtual bool getMotorEncoderAccelerations(double *accs)=0
Read the instantaneous acceleration of all motor encoders.
ControlBoardWrapperMotorEncoders::getMotorEncoderSpeeds
bool getMotorEncoderSpeeds(double *spds) override
Read the instantaneous speed of all motor encoders.
Definition: ControlBoardWrapperMotorEncoders.cpp:240
ControlBoardWrapperMotorEncoders::getMotorEncoderSpeed
bool getMotorEncoderSpeed(int m, double *sp) override
Read the istantaneous speed of a motor encoder.
Definition: ControlBoardWrapperMotorEncoders.cpp:222
ControlBoardWrapperMotorEncoders::setMotorEncoder
bool setMotorEncoder(int m, const double val) override
Set the value of the motor encoder for a given motor.
Definition: ControlBoardWrapperMotorEncoders.cpp:53
yarp::dev::IMotorEncoders::getMotorEncoders
virtual bool getMotorEncoders(double *encs)=0
Read the position of all motor encoders.
ControlBoardWrapperMotorEncoders::getMotorEncoders
bool getMotorEncoders(double *encs) override
Read the position of all motor encoders.
Definition: ControlBoardWrapperMotorEncoders.cpp:146
yarp::dev::IMotorEncoders::getMotorEncoderTimed
virtual bool getMotorEncoderTimed(int m, double *encs, double *time)=0
Read the instantaneous position of a motor encoder.
ControlBoardWrapperCommon::controlledJoints
size_t controlledJoints
Definition: ControlBoardWrapperCommon.h:23
SubDevice::id
std::string id
Definition: SubDevice.h:57
WrappedDevice::getSubdevice
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:129
yarp::dev::IMotorEncoders::getMotorEncoderSpeeds
virtual bool getMotorEncoderSpeeds(double *spds)=0
Read the instantaneous speed of all motor encoders.
WrappedDevice::subdevices
SubDeviceVector subdevices
Definition: SubDevice.h:125
ControlBoardWrapperMotorEncoders::getMotorEncoder
bool getMotorEncoder(int m, double *v) override
Read the value of a motor encoder.
Definition: ControlBoardWrapperMotorEncoders.cpp:128
ControlBoardWrapperCommon::device
WrappedDevice device
Definition: ControlBoardWrapperCommon.h:22
ControlBoardWrapperMotorEncoders::setMotorEncoders
bool setMotorEncoders(const double *vals) override
Set the value of all motor encoders.
Definition: ControlBoardWrapperMotorEncoders.cpp:70
SubDevice::base
size_t base
Definition: SubDevice.h:58
WrappedDevice::lut
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:126
ControlBoardWrapperMotorEncoders::resetMotorEncoder
bool resetMotorEncoder(int m) override
Reset motor encoder, single motor.
Definition: ControlBoardWrapperMotorEncoders.cpp:13
yarp::dev::IMotorEncoders::getMotorEncoderAcceleration
virtual bool getMotorEncoderAcceleration(int m, double *acc)=0
Read the instantaneous acceleration of a motor encoder.
yarp::dev::IMotorEncoders::setMotorEncoder
virtual bool setMotorEncoder(int m, const double val)=0
Set the value of the motor encoder for a given motor.
ControlBoardWrapperMotorEncoders::getMotorEncoderAcceleration
bool getMotorEncoderAcceleration(int m, double *acc) override
Read the instantaneous acceleration of a motor encoder.
Definition: ControlBoardWrapperMotorEncoders.cpp:267
ControlBoardWrapperMotorEncoders::resetMotorEncoders
bool resetMotorEncoders() override
Reset motor encoders.
Definition: ControlBoardWrapperMotorEncoders.cpp:30
yarp::dev::IMotorEncoders::getMotorEncoderCountsPerRevolution
virtual bool getMotorEncoderCountsPerRevolution(int m, double *cpr)=0
Gets number of counts per revolution for motor encoder m.
SubDevice::wbase
size_t wbase
Definition: SubDevice.h:60
SubDevice
Definition: SubDevice.h:55
WrappedDevice::maxNumOfJointsInDevices
size_t maxNumOfJointsInDevices
Definition: SubDevice.h:127
ControlBoardWrapperCommon::printError
void printError(const std::string &func_name, const std::string &info, bool result)
Definition: ControlBoardWrapperCommon.h:72
yarp::dev::IMotorEncoders::getMotorEncodersTimed
virtual bool getMotorEncodersTimed(double *encs, double *time)=0
Read the instantaneous position of all motor encoders.
yarp::dev::IMotorEncoders::getMotorEncoderSpeed
virtual bool getMotorEncoderSpeed(int m, double *sp)=0
Read the istantaneous speed of a motor encoder.