YARP
Yet Another Robot Platform
ControlBoardWrapperAmplifierControl.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 
11 #include <yarp/os/LogStream.h>
12 
14 
15 
17 {
18  size_t off;
19  try {
20  off = device.lut.at(j).offset;
21  } catch (...) {
22  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
23  return false;
24  }
25  size_t subIndex = device.lut[j].deviceEntry;
26 
27  SubDevice* p = device.getSubdevice(subIndex);
28  if (!p) {
29  return false;
30  }
31 
32  if (p->amp) {
33  return p->amp->enableAmp(static_cast<int>(off + p->base));
34  }
35  return false;
36 }
37 
38 
40 {
41  size_t off;
42  try {
43  off = device.lut.at(j).offset;
44  } catch (...) {
45  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
46  return false;
47  }
48  size_t subIndex = device.lut[j].deviceEntry;
49 
50  bool ret = true;
51  SubDevice* p = device.getSubdevice(subIndex);
52  if (!p) {
53  return false;
54  }
55 
56  // Use the newer interface if available, otherwise fallback on the old one.
57  if (p->iMode) {
58  ret = p->iMode->setControlMode(static_cast<int>(off + p->base), VOCAB_CM_IDLE);
59  } else {
60  if (p->pos) {
61  ret = p->amp->disableAmp(static_cast<int>(off + p->base));
62  } else {
63  ret = false;
64  }
65  }
66  return ret;
67 }
68 
69 
71 {
72  int* status = new int[device.maxNumOfJointsInDevices];
73  bool ret = true;
74  for (size_t d = 0; d < device.subdevices.size(); d++) {
76  if (!p) {
77  ret = false;
78  break;
79  }
80 
81  if ((p->amp) && (ret = p->amp->getAmpStatus(status))) {
82  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
83  st[juser] = status[jdevice];
84  }
85  } else {
86  printError("getAmpStatus", p->id, ret);
87  ret = false;
88  break;
89  }
90  }
91 
92  delete[] status;
93  return ret;
94 }
95 
96 
98 {
99  size_t off;
100  try {
101  off = device.lut.at(j).offset;
102  } catch (...) {
103  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
104  return false;
105  }
106  size_t subIndex = device.lut[j].deviceEntry;
107 
108  SubDevice* p = device.getSubdevice(subIndex);
109  if (p && p->amp) {
110  return p->amp->getAmpStatus(static_cast<int>(off + p->base), v);
111  }
112  *v = 0;
113  return false;
114 }
115 
116 
118 {
119  size_t off;
120  try {
121  off = device.lut.at(j).offset;
122  } catch (...) {
123  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
124  return false;
125  }
126  size_t subIndex = device.lut[j].deviceEntry;
127 
128  SubDevice* p = device.getSubdevice(subIndex);
129  if (!p) {
130  return false;
131  }
132 
133  if (p->amp) {
134  return p->amp->setMaxCurrent(static_cast<int>(off + p->base), v);
135  }
136  return false;
137 }
138 
139 
141 {
142  size_t off;
143  try {
144  off = device.lut.at(j).offset;
145  } catch (...) {
146  yCError(CONTROLBOARDWRAPPER, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
147  return false;
148  }
149  size_t subIndex = device.lut[j].deviceEntry;
150 
151  SubDevice* p = device.getSubdevice(subIndex);
152  if (!p) {
153  *v = 0.0;
154  return false;
155  }
156 
157  if (p->amp) {
158  return p->amp->getMaxCurrent(static_cast<int>(off + p->base), v);
159  }
160  *v = 0.0;
161  return false;
162 }
163 
164 
166 {
167  int off = device.lut[m].offset;
168  size_t subIndex = device.lut[m].deviceEntry;
169 
170  SubDevice* p = device.getSubdevice(subIndex);
171  if (!p) {
172  *val = 0.0;
173  return false;
174  }
175 
176  if (!p->amp) {
177  *val = 0.0;
178  return false;
179  }
180  return p->amp->getNominalCurrent(static_cast<int>(off + p->base), val);
181 }
182 
183 
185 {
186  int off = device.lut[m].offset;
187  size_t subIndex = device.lut[m].deviceEntry;
188 
189  SubDevice* p = device.getSubdevice(subIndex);
190  if (!p) {
191  *val = 0.0;
192  return false;
193  }
194 
195  if (!p->amp) {
196  *val = 0.0;
197  return false;
198  }
199  return p->amp->getPeakCurrent(static_cast<int>(off + p->base), val);
200 }
201 
202 
204 {
205  int off = device.lut[m].offset;
206  size_t subIndex = device.lut[m].deviceEntry;
207 
208  SubDevice* p = device.getSubdevice(subIndex);
209  if (!p) {
210  return false;
211  }
212 
213  if (!p->amp) {
214  return false;
215  }
216  return p->amp->setPeakCurrent(static_cast<int>(off + p->base), val);
217 }
218 
219 
221 {
222  int off = device.lut[m].offset;
223  size_t subIndex = device.lut[m].deviceEntry;
224 
225  SubDevice* p = device.getSubdevice(subIndex);
226  if (!p) {
227  return false;
228  }
229 
230  if (!p->amp) {
231  return false;
232  }
233  return p->amp->setNominalCurrent(static_cast<int>(off + p->base), val);
234 }
235 
236 
238 {
239  int off = device.lut[m].offset;
240  size_t subIndex = device.lut[m].deviceEntry;
241  SubDevice* p = device.getSubdevice(subIndex);
242 
243  yCTrace(CONTROLBOARDWRAPPER) << "CBW2::getPWMlimit j" << static_cast<int>(off + p->base) << " p " << (p ? "1" : "0") << " amp " << (p->amp ? "1" : "0");
244  if (!p) {
245  *val = 0.0;
246  return false;
247  }
248 
249  if (!p->amp) {
250  *val = 0.0;
251  return false;
252  }
253  return p->amp->getPWM(static_cast<int>(off + p->base), val);
254 }
255 
256 
258 {
259  int off = device.lut[m].offset;
260  size_t subIndex = device.lut[m].deviceEntry;
261 
262  SubDevice* p = device.getSubdevice(subIndex);
263  yCTrace(CONTROLBOARDWRAPPER) << "CBW2::getPWMlimit j" << static_cast<int>(off + p->base) << " p " << (p ? "1" : "0") << " amp " << (p->amp ? "1" : "0");
264 
265  if (!p) {
266  *val = 0.0;
267  return false;
268  }
269 
270  if (!p->amp) {
271  *val = 0.0;
272  return false;
273  }
274  return p->amp->getPWMLimit(static_cast<int>(off + p->base), val);
275 }
276 
277 
279 {
280  int off = device.lut[m].offset;
281  size_t subIndex = device.lut[m].deviceEntry;
282 
283  SubDevice* p = device.getSubdevice(subIndex);
284  if (!p) {
285  return false;
286  }
287 
288  if (!p->amp) {
289  return false;
290  }
291  return p->amp->setPWMLimit(static_cast<int>(off + p->base), val);
292 }
293 
294 
296 {
297  int off = device.lut[m].offset;
298  size_t subIndex = device.lut[m].deviceEntry;
299 
300  SubDevice* p = device.getSubdevice(subIndex);
301  if (!p) {
302  *val = 0.0;
303  return false;
304  }
305 
306  if (!p->amp) {
307  *val = 0.0;
308  return false;
309  }
310  return p->amp->getPowerSupplyVoltage(static_cast<int>(off + p->base), val);
311 }
LogStream.h
ControlBoardWrapperAmplifierControl::getAmpStatus
bool getAmpStatus(int *st) override
Definition: ControlBoardWrapperAmplifierControl.cpp:70
ControlBoardWrapperAmplifierControl::setNominalCurrent
bool setNominalCurrent(int m, const double val) override
Definition: ControlBoardWrapperAmplifierControl.cpp:220
yarp::dev::IAmplifierControl::setMaxCurrent
virtual bool setMaxCurrent(int j, double v)=0
ControlBoardWrapperLogComponent.h
yarp::dev::IAmplifierControl::enableAmp
virtual bool enableAmp(int j)=0
Enable the amplifier on a specific joint.
ControlBoardWrapperAmplifierControl.h
yarp::dev::IAmplifierControl::getAmpStatus
virtual bool getAmpStatus(int *st)=0
ControlBoardWrapperAmplifierControl::getPowerSupplyVoltage
bool getPowerSupplyVoltage(int m, double *val) override
Definition: ControlBoardWrapperAmplifierControl.cpp:295
SubDevice::iMode
yarp::dev::IControlMode * iMode
Definition: SubDevice.h:81
SubDevice::pos
yarp::dev::IPositionControl * pos
Definition: SubDevice.h:71
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
ControlBoardWrapperAmplifierControl::setMaxCurrent
bool setMaxCurrent(int j, double v) override
Definition: ControlBoardWrapperAmplifierControl.cpp:117
yarp::dev::IAmplifierControl::getPeakCurrent
virtual bool getPeakCurrent(int m, double *val)
Definition: IAmplifierControl.h:129
yarp::dev::IAmplifierControl::setPWMLimit
virtual bool setPWMLimit(int j, const double val)
Definition: IAmplifierControl.h:164
ControlBoardWrapperAmplifierControl::getPeakCurrent
bool getPeakCurrent(int m, double *val) override
Definition: ControlBoardWrapperAmplifierControl.cpp:184
yarp::dev::IAmplifierControl::getPWMLimit
virtual bool getPWMLimit(int j, double *val)
Definition: IAmplifierControl.h:156
ControlBoardWrapperAmplifierControl::getMaxCurrent
bool getMaxCurrent(int j, double *v) override
Returns the maximum electric current allowed for a given motor.
Definition: ControlBoardWrapperAmplifierControl.cpp:140
yarp::dev::IAmplifierControl::getPWM
virtual bool getPWM(int j, double *val)
Definition: IAmplifierControl.h:148
ControlBoardWrapperAmplifierControl::enableAmp
bool enableAmp(int j) override
Enable the amplifier on a specific joint.
Definition: ControlBoardWrapperAmplifierControl.cpp:16
CONTROLBOARDWRAPPER
const yarp::os::LogComponent & CONTROLBOARDWRAPPER()
Definition: ControlBoardWrapperLogComponent.cpp:11
yarp::dev::IAmplifierControl::setPeakCurrent
virtual bool setPeakCurrent(int m, const double val)
Definition: IAmplifierControl.h:140
ControlBoardWrapperCommon::partName
std::string partName
Definition: ControlBoardWrapperCommon.h:24
ControlBoardWrapperAmplifierControl::disableAmp
bool disableAmp(int j) override
Disable the amplifier on a specific joint.
Definition: ControlBoardWrapperAmplifierControl.cpp:39
ControlBoardWrapperCommon::controlledJoints
size_t controlledJoints
Definition: ControlBoardWrapperCommon.h:23
SubDevice::id
std::string id
Definition: SubDevice.h:57
yarp::dev::IAmplifierControl::getPowerSupplyVoltage
virtual bool getPowerSupplyVoltage(int j, double *val)
Definition: IAmplifierControl.h:171
ControlBoardWrapperAmplifierControl::getPWM
bool getPWM(int m, double *val) override
Definition: ControlBoardWrapperAmplifierControl.cpp:237
WrappedDevice::getSubdevice
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:129
WrappedDevice::subdevices
SubDeviceVector subdevices
Definition: SubDevice.h:125
ControlBoardWrapperAmplifierControl::getNominalCurrent
bool getNominalCurrent(int m, double *val) override
Definition: ControlBoardWrapperAmplifierControl.cpp:165
VOCAB_CM_IDLE
constexpr yarp::conf::vocab32_t VOCAB_CM_IDLE
Definition: IControlMode.h:126
yarp::dev::IAmplifierControl::getNominalCurrent
virtual bool getNominalCurrent(int m, double *val)
Definition: IAmplifierControl.h:107
yarp::dev::IAmplifierControl::disableAmp
virtual bool disableAmp(int j)=0
Disable the amplifier on a specific joint.
ControlBoardWrapperAmplifierControl::setPeakCurrent
bool setPeakCurrent(int m, const double val) override
Definition: ControlBoardWrapperAmplifierControl.cpp:203
yarp::dev::IAmplifierControl::getMaxCurrent
virtual bool getMaxCurrent(int j, double *v)=0
Returns the maximum electric current allowed for a given motor.
yarp::dev::IAmplifierControl::setNominalCurrent
virtual bool setNominalCurrent(int m, const double val)
Definition: IAmplifierControl.h:118
ControlBoardWrapperCommon::device
WrappedDevice device
Definition: ControlBoardWrapperCommon.h:22
yCError
#define yCError(component,...)
Definition: LogComponent.h:157
ControlBoardWrapperAmplifierControl::getPWMLimit
bool getPWMLimit(int m, double *val) override
Definition: ControlBoardWrapperAmplifierControl.cpp:257
yarp::dev::IControlMode::setControlMode
virtual bool setControlMode(const int j, const int mode)=0
Set the current control mode.
SubDevice::base
size_t base
Definition: SubDevice.h:58
WrappedDevice::lut
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:126
yCTrace
#define yCTrace(component,...)
Definition: LogComponent.h:88
SubDevice::wbase
size_t wbase
Definition: SubDevice.h:60
SubDevice
Definition: SubDevice.h:55
WrappedDevice::maxNumOfJointsInDevices
size_t maxNumOfJointsInDevices
Definition: SubDevice.h:127
ControlBoardWrapperAmplifierControl::setPWMLimit
bool setPWMLimit(int m, const double val) override
Definition: ControlBoardWrapperAmplifierControl.cpp:278
SubDevice::amp
yarp::dev::IAmplifierControl * amp
Definition: SubDevice.h:75
ControlBoardWrapperCommon::printError
void printError(const std::string &func_name, const std::string &info, bool result)
Definition: ControlBoardWrapperCommon.h:72