YARP
Yet Another Robot Platform
ControlBoardWrapperEncodersTimed.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  size_t off;
16  try {
17  off = device.lut.at(j).offset;
18  } catch (...) {
19  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
20  return false;
21  }
22  size_t subIndex = device.lut[j].deviceEntry;
23 
24  SubDevice* p = device.getSubdevice(subIndex);
25  if (!p) {
26  return false;
27  }
28 
29  if (p->iJntEnc) {
30  return p->iJntEnc->resetEncoder(static_cast<int>(off + p->base));
31  }
32  return false;
33 }
34 
35 
37 {
38  bool ret = true;
39 
40  for (size_t l = 0; l < controlledJoints; l++) {
41  int off = device.lut[l].offset;
42  size_t subIndex = device.lut[l].deviceEntry;
43 
44  SubDevice* p = device.getSubdevice(subIndex);
45  if (!p) {
46  return false;
47  }
48 
49  if (p->iJntEnc) {
50  ret = ret && p->iJntEnc->resetEncoder(static_cast<int>(off + p->base));
51  } else {
52  ret = false;
53  }
54  }
55  return ret;
56 }
57 
58 
60 {
61  size_t off;
62  try {
63  off = device.lut.at(j).offset;
64  } catch (...) {
65  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
66  return false;
67  }
68  size_t subIndex = device.lut[j].deviceEntry;
69 
70  SubDevice* p = device.getSubdevice(subIndex);
71  if (!p) {
72  return false;
73  }
74 
75  if (p->iJntEnc) {
76  return p->iJntEnc->setEncoder(static_cast<int>(off + p->base), val);
77  }
78  return false;
79 }
80 
81 
83 {
84  bool ret = true;
85 
86  for (size_t l = 0; l < controlledJoints; l++) {
87  int off = device.lut[l].offset;
88  size_t subIndex = device.lut[l].deviceEntry;
89 
90  SubDevice* p = device.getSubdevice(subIndex);
91  if (!p) {
92  return false;
93  }
94 
95  if (p->iJntEnc) {
96  ret = ret && p->iJntEnc->setEncoder(static_cast<int>(off + p->base), vals[l]);
97  } else {
98  ret = false;
99  }
100  }
101  return ret;
102 }
103 
104 
106 {
107  size_t off;
108  try {
109  off = device.lut.at(j).offset;
110  } catch (...) {
111  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
112  return false;
113  }
114  size_t subIndex = device.lut[j].deviceEntry;
115 
116  SubDevice* p = device.getSubdevice(subIndex);
117  if (!p) {
118  return false;
119  }
120 
121  if (p->iJntEnc) {
122  return p->iJntEnc->getEncoder(static_cast<int>(off + p->base), v);
123  }
124  *v = 0.0;
125  return false;
126 }
127 
128 
130 {
131  auto* encValues = new double[device.maxNumOfJointsInDevices];
132  bool ret = true;
133  for (size_t d = 0; d < device.subdevices.size(); d++) {
134  SubDevice* p = device.getSubdevice(d);
135  if (!p) {
136  ret = false;
137  break;
138  }
139 
140  if ((p->iJntEnc) && (ret = p->iJntEnc->getEncoders(encValues))) {
141  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
142  encs[juser] = encValues[jdevice];
143  }
144  } else {
145  printError("getEncoders", p->id, ret);
146  ret = false;
147  break;
148  }
149  }
150 
151  delete[] encValues;
152  return ret;
153 }
154 
155 
157 {
158  auto* encValues = new double[device.maxNumOfJointsInDevices];
159  auto* tValues = new double[device.maxNumOfJointsInDevices];
160  bool ret = true;
161  for (size_t d = 0; d < device.subdevices.size(); d++) {
162  SubDevice* p = device.getSubdevice(d);
163  if (!p) {
164  ret = false;
165  break;
166  }
167 
168  if ((p->iJntEnc) && (ret = p->iJntEnc->getEncodersTimed(encValues, tValues))) {
169  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
170  encs[juser] = encValues[jdevice];
171  t[juser] = tValues[jdevice];
172  }
173  } else {
174  printError("getEncodersTimed", p->id, ret);
175  ret = false;
176  break;
177  }
178  }
179 
180  delete[] encValues;
181  delete[] tValues;
182  return ret;
183 }
184 
185 
187 {
188  size_t off;
189  try {
190  off = device.lut.at(j).offset;
191  } catch (...) {
192  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
193  return false;
194  }
195  size_t subIndex = device.lut[j].deviceEntry;
196 
197  SubDevice* p = device.getSubdevice(subIndex);
198  if (!p) {
199  return false;
200  }
201 
202  if (p->iJntEnc) {
203  return p->iJntEnc->getEncoderTimed(static_cast<int>(off + p->base), v, t);
204  }
205  *v = 0.0;
206  return false;
207 }
208 
209 
211 {
212  size_t off;
213  try {
214  off = device.lut.at(j).offset;
215  } catch (...) {
216  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
217  return false;
218  }
219  size_t subIndex = device.lut[j].deviceEntry;
220 
221  SubDevice* p = device.getSubdevice(subIndex);
222  if (!p) {
223  return false;
224  }
225 
226  if (p->iJntEnc) {
227  return p->iJntEnc->getEncoderSpeed(static_cast<int>(off + p->base), sp);
228  }
229  *sp = 0.0;
230  return false;
231 }
232 
233 
235 {
236  auto* sValues = new double[device.maxNumOfJointsInDevices];
237  bool ret = true;
238  for (size_t d = 0; d < device.subdevices.size(); d++) {
239  SubDevice* p = device.getSubdevice(d);
240  if (!p) {
241  ret = false;
242  break;
243  }
244 
245  if ((p->iJntEnc) && (ret = p->iJntEnc->getEncoderSpeeds(sValues))) {
246  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
247  spds[juser] = sValues[jdevice];
248  }
249  } else {
250  printError("getEncoderSpeeds", p->id, ret);
251  ret = false;
252  break;
253  }
254  }
255 
256  delete[] sValues;
257  return ret;
258 }
259 
260 
262 {
263  size_t off;
264  try {
265  off = device.lut.at(j).offset;
266  } catch (...) {
267  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
268  return false;
269  }
270  size_t subIndex = device.lut[j].deviceEntry;
271 
272  SubDevice* p = device.getSubdevice(subIndex);
273  if (!p) {
274  return false;
275  }
276 
277  if (p->iJntEnc) {
278  return p->iJntEnc->getEncoderAcceleration(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->iJntEnc) && (ret = p->iJntEnc->getEncoderAccelerations(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("getEncoderAccelerations", p->id, ret);
302  ret = false;
303  break;
304  }
305  }
306 
307  delete[] aValues;
308  return ret;
309 }
ControlBoardWrapperLogComponent.h
ControlBoardWrapperEncodersTimed::setEncoders
bool setEncoders(const double *vals) override
Set the value of all encoders.
Definition: ControlBoardWrapperEncodersTimed.cpp:82
ControlBoardWrapperEncodersTimed::getEncoders
bool getEncoders(double *encs) override
Read the position of all axes.
Definition: ControlBoardWrapperEncodersTimed.cpp:129
t
float t
Definition: FfmpegWriter.cpp:74
ControlBoardWrapperEncodersTimed::getEncoderAcceleration
bool getEncoderAcceleration(int j, double *acc) override
Read the instantaneous acceleration of an axis.
Definition: ControlBoardWrapperEncodersTimed.cpp:261
yarp::dev::IEncodersTimed::getEncodersTimed
virtual bool getEncodersTimed(double *encs, double *time)=0
Read the instantaneous acceleration of all axes.
ControlBoardWrapperEncodersTimed::getEncoderTimed
bool getEncoderTimed(int j, double *v, double *t) override
Read the instantaneous acceleration of all axes.
Definition: ControlBoardWrapperEncodersTimed.cpp:186
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
ControlBoardWrapperEncodersTimed::resetEncoder
bool resetEncoder(int j) override
Reset encoder, single joint.
Definition: ControlBoardWrapperEncodersTimed.cpp:13
ControlBoardWrapperEncodersTimed::setEncoder
bool setEncoder(int j, double val) override
Set the value of the encoder for a given joint.
Definition: ControlBoardWrapperEncodersTimed.cpp:59
ControlBoardWrapperEncodersTimed::getEncoder
bool getEncoder(int j, double *v) override
Read the value of an encoder.
Definition: ControlBoardWrapperEncodersTimed.cpp:105
CONTROLBOARDWRAPPER
const yarp::os::LogComponent & CONTROLBOARDWRAPPER()
Definition: ControlBoardWrapperLogComponent.cpp:11
ControlBoardWrapperEncodersTimed::resetEncoders
bool resetEncoders() override
Reset encoders.
Definition: ControlBoardWrapperEncodersTimed.cpp:36
ControlBoardWrapperCommon::partName
std::string partName
Definition: ControlBoardWrapperCommon.h:24
yarp::dev::IEncoders::resetEncoder
virtual bool resetEncoder(int j)=0
Reset encoder, single joint.
ControlBoardWrapperCommon::controlledJoints
size_t controlledJoints
Definition: ControlBoardWrapperCommon.h:23
SubDevice::id
std::string id
Definition: SubDevice.h:57
ControlBoardWrapperEncodersTimed::getEncoderSpeed
bool getEncoderSpeed(int j, double *sp) override
Read the istantaneous speed of an axis.
Definition: ControlBoardWrapperEncodersTimed.cpp:210
WrappedDevice::getSubdevice
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:129
yarp::dev::IEncoders::getEncoderAcceleration
virtual bool getEncoderAcceleration(int j, double *spds)=0
Read the instantaneous acceleration of an axis.
WrappedDevice::subdevices
SubDeviceVector subdevices
Definition: SubDevice.h:125
ControlBoardWrapperEncodersTimed::getEncoderSpeeds
bool getEncoderSpeeds(double *spds) override
Read the instantaneous speed of all axes.
Definition: ControlBoardWrapperEncodersTimed.cpp:234
ControlBoardWrapperEncodersTimed::getEncoderAccelerations
bool getEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all axes.
Definition: ControlBoardWrapperEncodersTimed.cpp:285
ControlBoardWrapperEncodersTimed.h
ControlBoardWrapperCommon::device
WrappedDevice device
Definition: ControlBoardWrapperCommon.h:22
yarp::dev::IEncoders::getEncoderAccelerations
virtual bool getEncoderAccelerations(double *accs)=0
Read the instantaneous acceleration of all axes.
yCError
#define yCError(component,...)
Definition: LogComponent.h:157
yarp::dev::IEncoders::getEncoder
virtual bool getEncoder(int j, double *v)=0
Read the value of an encoder.
SubDevice::base
size_t base
Definition: SubDevice.h:58
WrappedDevice::lut
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:126
SubDevice::wbase
size_t wbase
Definition: SubDevice.h:60
yarp::dev::IEncoders::setEncoder
virtual bool setEncoder(int j, double val)=0
Set the value of the encoder for a given joint.
yarp::dev::IEncodersTimed::getEncoderTimed
virtual bool getEncoderTimed(int j, double *encs, double *time)=0
Read the instantaneous acceleration of all axes.
SubDevice
Definition: SubDevice.h:55
yarp::dev::IEncoders::getEncoderSpeeds
virtual bool getEncoderSpeeds(double *spds)=0
Read the instantaneous speed of all axes.
WrappedDevice::maxNumOfJointsInDevices
size_t maxNumOfJointsInDevices
Definition: SubDevice.h:127
yarp::dev::IEncoders::getEncoderSpeed
virtual bool getEncoderSpeed(int j, double *sp)=0
Read the istantaneous speed of an axis.
ControlBoardWrapperEncodersTimed::getEncodersTimed
bool getEncodersTimed(double *encs, double *t) override
Read the instantaneous acceleration of all axes.
Definition: ControlBoardWrapperEncodersTimed.cpp:156
SubDevice::iJntEnc
yarp::dev::IEncodersTimed * iJntEnc
Definition: SubDevice.h:73
ControlBoardWrapperCommon::printError
void printError(const std::string &func_name, const std::string &info, bool result)
Definition: ControlBoardWrapperCommon.h:72
yarp::dev::IEncoders::getEncoders
virtual bool getEncoders(double *encs)=0
Read the position of all axes.