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