YARP
Yet Another Robot Platform
ControlBoardWrapperMotor.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
7 
9 
11 {
12  int off = device.lut[m].offset;
13  size_t subIndex = device.lut[m].deviceEntry;
14 
15  SubDevice* p = device.getSubdevice(subIndex);
16  if (!p) {
17  return false;
18  }
19 
20  if (p->imotor) {
21  return p->imotor->getTemperature(static_cast<int>(off + p->base), val);
22  }
23  *val = 0.0;
24  return false;
25 }
26 
28 {
29  auto* temps = new double[device.maxNumOfJointsInDevices];
30  bool ret = true;
31  for (size_t d = 0; d < device.subdevices.size(); d++) {
33  if (!p) {
34  ret = false;
35  break;
36  }
37 
38  if ((p->imotor) && (ret = p->imotor->getTemperatures(temps))) {
39  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
40  vals[juser] = temps[jdevice];
41  }
42  } else {
43  printError("getTemperatures", p->id, ret);
44  ret = false;
45  break;
46  }
47  }
48 
49  delete[] temps;
50  return ret;
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->imotor) {
64  return p->imotor->getTemperatureLimit(static_cast<int>(off + p->base), val);
65  }
66  *val = 0.0;
67  return false;
68 }
69 
70 bool ControlBoardWrapperMotor::setTemperatureLimit(int m, const double val)
71 {
72  int off = device.lut[m].offset;
73  size_t subIndex = device.lut[m].deviceEntry;
74 
75  SubDevice* p = device.getSubdevice(subIndex);
76  if (!p) {
77  return false;
78  }
79 
80  if (p->imotor) {
81  return p->imotor->setTemperatureLimit(static_cast<int>(off + p->base), val);
82  }
83  return false;
84 }
85 
87 {
88  int off = device.lut[m].offset;
89  size_t subIndex = device.lut[m].deviceEntry;
90 
91  SubDevice* p = device.getSubdevice(subIndex);
92  if (!p) {
93  return false;
94  }
95 
96  if (p->imotor) {
97  return p->imotor->getGearboxRatio(static_cast<int>(off + p->base), val);
98  }
99  *val = 0.0;
100  return false;
101 }
102 
103 bool ControlBoardWrapperMotor::setGearboxRatio(int m, const double val)
104 {
105  int off = device.lut[m].offset;
106  size_t subIndex = device.lut[m].deviceEntry;
107 
108  SubDevice* p = device.getSubdevice(subIndex);
109  if (!p) {
110  return false;
111  }
112 
113  if (p->imotor) {
114  return p->imotor->setGearboxRatio(static_cast<int>(off + p->base), val);
115  }
116  return false;
117 }
bool ret
void printError(const std::string &func_name, const std::string &info, bool result)
bool getGearboxRatio(int m, double *val) override
Get the gearbox ratio for a specific motor.
bool getTemperatures(double *vals) override
Get temperature of all the motors.
bool setTemperatureLimit(int m, const double val) override
Set the temperature limit for a specific motor.
bool getTemperature(int m, double *val) override
Get temperature of a motor.
bool getTemperatureLimit(int m, double *val) override
Retreives the current temperature limit for a specific motor.
bool setGearboxRatio(int m, const double val) override
Set the gearbox ratio for a specific motor.
size_t base
Definition: SubDevice.h:55
std::string id
Definition: SubDevice.h:54
yarp::dev::IMotor * imotor
Definition: SubDevice.h:82
size_t wbase
Definition: SubDevice.h:57
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:122
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:125
size_t maxNumOfJointsInDevices
Definition: SubDevice.h:123
SubDeviceVector subdevices
Definition: SubDevice.h:121
virtual bool getTemperature(int m, double *val)=0
Get temperature of a motor.
virtual bool getTemperatures(double *vals)=0
Get temperature of all the motors.
virtual bool getTemperatureLimit(int m, double *temp)=0
Retreives the current temperature limit for a specific motor.
virtual bool getGearboxRatio(int m, double *val)
Get the gearbox ratio for a specific motor.
Definition: IMotor.h:149
virtual bool setTemperatureLimit(int m, const double temp)=0
Set the temperature limit for a specific motor.
virtual bool setGearboxRatio(int m, const double val)
Set the gearbox ratio for a specific motor.
Definition: IMotor.h:157