YARP
Yet Another Robot Platform
ControlBoardWrapperImpedanceControl.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 
10 
11 bool ControlBoardWrapperImpedanceControl::setImpedance(int j, double stiff, double damp)
12 {
13  size_t off;
14  try {
15  off = device.lut.at(j).offset;
16  } catch (...) {
17  yCError(CONTROLBOARD, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
18  return false;
19  }
20  size_t subIndex = device.lut[j].deviceEntry;
21 
22  SubDevice* p = device.getSubdevice(subIndex);
23  if (!p) {
24  return false;
25  }
26 
27  if (p->iImpedance) {
28  return p->iImpedance->setImpedance(static_cast<int>(off + p->base), stiff, damp);
29  }
30 
31  return false;
32 }
33 
34 
36 {
37  size_t off;
38  try {
39  off = device.lut.at(j).offset;
40  } catch (...) {
41  yCError(CONTROLBOARD, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
42  return false;
43  }
44  size_t subIndex = device.lut[j].deviceEntry;
45 
46  SubDevice* p = device.getSubdevice(subIndex);
47  if (!p) {
48  return false;
49  }
50 
51  if (p->iImpedance) {
52  return p->iImpedance->setImpedanceOffset(static_cast<int>(off + p->base), offset);
53  }
54 
55  return false;
56 }
57 
58 
59 bool ControlBoardWrapperImpedanceControl::getImpedance(int j, double* stiff, double* damp)
60 {
61  size_t off;
62  try {
63  off = device.lut.at(j).offset;
64  } catch (...) {
65  yCError(CONTROLBOARD, "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->iImpedance) {
76  return p->iImpedance->getImpedance(static_cast<int>(off + p->base), stiff, damp);
77  }
78 
79  return false;
80 }
81 
82 
84 {
85  size_t off;
86  try {
87  off = device.lut.at(j).offset;
88  } catch (...) {
89  yCError(CONTROLBOARD, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
90  return false;
91  }
92  size_t subIndex = device.lut[j].deviceEntry;
93 
94  SubDevice* p = device.getSubdevice(subIndex);
95  if (!p) {
96  return false;
97  }
98 
99  if (p->iImpedance) {
100  return p->iImpedance->getImpedanceOffset(static_cast<int>(off + p->base), offset);
101  }
102 
103  return false;
104 }
105 
106 
107 bool ControlBoardWrapperImpedanceControl::getCurrentImpedanceLimit(int j, double* min_stiff, double* max_stiff, double* min_damp, double* max_damp)
108 {
109  size_t off;
110  try {
111  off = device.lut.at(j).offset;
112  } catch (...) {
113  yCError(CONTROLBOARD, "Joint number %d out of bound [0-%zu] for part %s", j, controlledJoints, partName.c_str());
114  return false;
115  }
116  size_t subIndex = device.lut[j].deviceEntry;
117 
118  SubDevice* p = device.getSubdevice(subIndex);
119  if (!p) {
120  return false;
121  }
122 
123  if (p->iImpedance) {
124  return p->iImpedance->getCurrentImpedanceLimit(static_cast<int>(off + p->base), min_stiff, max_stiff, min_damp, max_damp);
125  }
126 
127  return false;
128 }
const yarp::os::LogComponent & CONTROLBOARD()
bool getImpedance(int j, double *stiff, double *damp) override
Get current impedance gains (stiffness,damping,offset) for a specific joint.
bool getImpedanceOffset(int j, double *offset) override
Get current force Offset for a specific joint.
bool getCurrentImpedanceLimit(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp) override
Get the current impedandance limits for a specific joint.
bool setImpedanceOffset(int j, double offset) override
Set current force Offset for a specific joint.
bool setImpedance(int j, double stiff, double damp) override
Set current impedance gains (stiffness,damping) for a specific joint.
yarp::dev::IImpedanceControl * iImpedance
Definition: SubDevice.h:77
size_t base
Definition: SubDevice.h:55
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:122
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:125
virtual bool setImpedance(int j, double stiffness, double damping)=0
Set current impedance gains (stiffness,damping) for a specific joint.
virtual bool getImpedanceOffset(int j, double *offset)=0
Get current force Offset for a specific joint.
virtual bool setImpedanceOffset(int j, double offset)=0
Set current force Offset for a specific joint.
virtual bool getImpedance(int j, double *stiffness, double *damping)=0
Get current impedance gains (stiffness,damping,offset) for a specific joint.
virtual bool getCurrentImpedanceLimit(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp)=0
Get the current impedandance limits for a specific joint.
#define yCError(component,...)
Definition: LogComponent.h:154