YARP
Yet Another Robot Platform
ControlBoardWrapperMotor.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->imotor) {
24  return p->imotor->getTemperature(static_cast<int>(off + p->base), val);
25  }
26  *val = 0.0;
27  return false;
28 }
29 
31 {
32  auto* temps = new double[device.maxNumOfJointsInDevices];
33  bool ret = true;
34  for (size_t d = 0; d < device.subdevices.size(); d++) {
36  if (!p) {
37  ret = false;
38  break;
39  }
40 
41  if ((p->imotor) && (ret = p->imotor->getTemperatures(temps))) {
42  for (size_t juser = p->wbase, jdevice = p->base; juser <= p->wtop; juser++, jdevice++) {
43  vals[juser] = temps[jdevice];
44  }
45  } else {
46  printError("getTemperatures", p->id, ret);
47  ret = false;
48  break;
49  }
50  }
51 
52  delete[] temps;
53  return ret;
54 }
55 
57 {
58  int off = device.lut[m].offset;
59  size_t subIndex = device.lut[m].deviceEntry;
60 
61  SubDevice* p = device.getSubdevice(subIndex);
62  if (!p) {
63  return false;
64  }
65 
66  if (p->imotor) {
67  return p->imotor->getTemperatureLimit(static_cast<int>(off + p->base), val);
68  }
69  *val = 0.0;
70  return false;
71 }
72 
73 bool ControlBoardWrapperMotor::setTemperatureLimit(int m, const double val)
74 {
75  int off = device.lut[m].offset;
76  size_t subIndex = device.lut[m].deviceEntry;
77 
78  SubDevice* p = device.getSubdevice(subIndex);
79  if (!p) {
80  return false;
81  }
82 
83  if (p->imotor) {
84  return p->imotor->setTemperatureLimit(static_cast<int>(off + p->base), val);
85  }
86  return false;
87 }
88 
90 {
91  int off = device.lut[m].offset;
92  size_t subIndex = device.lut[m].deviceEntry;
93 
94  SubDevice* p = device.getSubdevice(subIndex);
95  if (!p) {
96  return false;
97  }
98 
99  if (p->imotor) {
100  return p->imotor->getGearboxRatio(static_cast<int>(off + p->base), val);
101  }
102  *val = 0.0;
103  return false;
104 }
105 
106 bool ControlBoardWrapperMotor::setGearboxRatio(int m, const double val)
107 {
108  int off = device.lut[m].offset;
109  size_t subIndex = device.lut[m].deviceEntry;
110 
111  SubDevice* p = device.getSubdevice(subIndex);
112  if (!p) {
113  return false;
114  }
115 
116  if (p->imotor) {
117  return p->imotor->setGearboxRatio(static_cast<int>(off + p->base), val);
118  }
119  return false;
120 }
ControlBoardWrapperMotor::getTemperatureLimit
bool getTemperatureLimit(int m, double *val) override
Retreives the current temperature limit for a specific motor.
Definition: ControlBoardWrapperMotor.cpp:56
ControlBoardWrapperLogComponent.h
yarp::dev::IMotor::getTemperatures
virtual bool getTemperatures(double *vals)=0
Get temperature of all the motors.
yarp::dev::IMotor::getGearboxRatio
virtual bool getGearboxRatio(int m, double *val)
Get the gearbox ratio for a specific motor.
Definition: IMotor.h:152
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
ControlBoardWrapperMotor.h
SubDevice::id
std::string id
Definition: SubDevice.h:57
WrappedDevice::getSubdevice
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:129
WrappedDevice::subdevices
SubDeviceVector subdevices
Definition: SubDevice.h:125
ControlBoardWrapperMotor::setGearboxRatio
bool setGearboxRatio(int m, const double val) override
Set the gearbox ratio for a specific motor.
Definition: ControlBoardWrapperMotor.cpp:106
ControlBoardWrapperCommon::device
WrappedDevice device
Definition: ControlBoardWrapperCommon.h:22
yarp::dev::IMotor::setTemperatureLimit
virtual bool setTemperatureLimit(int m, const double temp)=0
Set the temperature limit for a specific motor.
yarp::dev::IMotor::getTemperature
virtual bool getTemperature(int m, double *val)=0
Get temperature of a motor.
SubDevice::base
size_t base
Definition: SubDevice.h:58
WrappedDevice::lut
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:126
ControlBoardWrapperMotor::getTemperature
bool getTemperature(int m, double *val) override
Get temperature of a motor.
Definition: ControlBoardWrapperMotor.cpp:13
yarp::dev::IMotor::getTemperatureLimit
virtual bool getTemperatureLimit(int m, double *temp)=0
Retreives the current temperature limit for a specific motor.
SubDevice::wbase
size_t wbase
Definition: SubDevice.h:60
SubDevice
Definition: SubDevice.h:55
WrappedDevice::maxNumOfJointsInDevices
size_t maxNumOfJointsInDevices
Definition: SubDevice.h:127
ControlBoardWrapperMotor::getTemperatures
bool getTemperatures(double *vals) override
Get temperature of all the motors.
Definition: ControlBoardWrapperMotor.cpp:30
ControlBoardWrapperMotor::getGearboxRatio
bool getGearboxRatio(int m, double *val) override
Get the gearbox ratio for a specific motor.
Definition: ControlBoardWrapperMotor.cpp:89
ControlBoardWrapperCommon::printError
void printError(const std::string &func_name, const std::string &info, bool result)
Definition: ControlBoardWrapperCommon.h:72
yarp::dev::IMotor::setGearboxRatio
virtual bool setGearboxRatio(int m, const double val)
Set the gearbox ratio for a specific motor.
Definition: IMotor.h:160
ControlBoardWrapperMotor::setTemperatureLimit
bool setTemperatureLimit(int m, const double val) override
Set the temperature limit for a specific motor.
Definition: ControlBoardWrapperMotor.cpp:73
SubDevice::imotor
yarp::dev::IMotor * imotor
Definition: SubDevice.h:85