YARP
Yet Another Robot Platform
ImplementImpedanceControl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #include <cstdio>
11 
14 #include <yarp/os/LogStream.h>
15 #include <cmath>
16 
17 using namespace yarp::dev;
18 #define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
19 
22 {
23  iImpedanceRaw=r;
24  helper=nullptr;
25 }
26 
27 bool ImplementImpedanceControl::initialize(int size, const int *amap, const double *enc, const double *zos, const double *nw)
28 {
29  if (helper!=nullptr)
30  return false;
31 
32  helper=(void *)(new ControlBoardHelper(size, amap, enc, zos, nw));
33  yAssert (helper != nullptr);
34 
35  return true;
36 }
37 
39 {
40  uninitialize();
41 }
42 
44 {
45  if (helper!=nullptr)
46  {
47  delete castToMapper(helper);
48  helper=nullptr;
49  }
50 
51  return true;
52 }
53 
55 {
56  return iImpedanceRaw->getAxes(axes);
57 }
58 
59 bool ImplementImpedanceControl::setImpedance(int j, double stiffness, double damping)
60 {
62  int k;
63  double stiff;
64  double damp;
65  castToMapper(helper)->impN2S(stiffness,j,stiff,k);
66  castToMapper(helper)->impN2S(damping,j,damp,k);
67  return iImpedanceRaw->setImpedanceRaw(k, stiff, damp);
68 }
69 
70 bool ImplementImpedanceControl::getImpedance(int j, double *stiffness, double *damping)
71 {
73  int k;
74  k=castToMapper(helper)->toHw(j);
75  bool ret=iImpedanceRaw->getImpedanceRaw(k, stiffness, damping);
76  *stiffness = (castToMapper(helper)->impS2N(*stiffness, k));
77  *damping = (castToMapper(helper)->impS2N(*damping, k));
78  //prevent negative stiffness
79  *stiffness = fabs (*stiffness);
80  *damping = fabs (*damping);
81  return ret;
82 }
83 
85 {
87  int k;
88  double off;
89  castToMapper(helper)->trqN2S(offset,j,off,k);
90  return iImpedanceRaw->setImpedanceOffsetRaw(k, off);
91 }
92 
94 {
96  int k;
97  k=castToMapper(helper)->toHw(j);
98  bool ret = iImpedanceRaw->getImpedanceOffsetRaw(k, offset);
99  *offset = (castToMapper(helper)->trqS2N(*offset,k));
100  return ret;
101 }
102 
103 bool ImplementImpedanceControl::getCurrentImpedanceLimit(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp)
104 {
106  int k;
107  k=castToMapper(helper)->toHw(j);
108  return iImpedanceRaw->getCurrentImpedanceLimitRaw(k, min_stiff, max_stiff, min_damp, max_damp);
109 }
ImplementImpedanceControl.h
LogStream.h
yarp::dev::ControlBoardHelper::toHw
int toHw(int axis)
Definition: ControlBoardHelper.cpp:245
yarp::dev::IImpedanceControlRaw::getCurrentImpedanceLimitRaw
virtual bool getCurrentImpedanceLimitRaw(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::ImplementImpedanceControl::iImpedanceRaw
yarp::dev::IImpedanceControlRaw * iImpedanceRaw
Definition: ImplementImpedanceControl.h:24
yarp::dev::IImpedanceControlRaw::getImpedanceOffsetRaw
virtual bool getImpedanceOffsetRaw(int j, double *offset)=0
Get current force Offset for a specific joint.
yarp::dev::ImplementImpedanceControl::getAxes
bool getAxes(int *ax) override
Get the number of controlled axes.
Definition: ImplementImpedanceControl.cpp:54
yarp::dev::ImplementImpedanceControl::setImpedanceOffset
bool setImpedanceOffset(int j, double offset) override
Set current force Offset for a specific joint.
Definition: ImplementImpedanceControl.cpp:84
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::dev::ImplementImpedanceControl::getImpedance
bool getImpedance(int j, double *stiffness, double *damping) override
Get current impedance gains (stiffness,damping,offset) for a specific joint.
Definition: ImplementImpedanceControl.cpp:70
yarp::dev::IImpedanceControlRaw::getAxes
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::IImpedanceControlRaw::setImpedanceRaw
virtual bool setImpedanceRaw(int j, double stiffness, double damping)=0
Set current impedance parameters (stiffness,damping) for a specific joint.
yarp::dev::IImpedanceControlRaw
Interface for control boards implementing impedance control.
Definition: IImpedanceControl.h:28
yarp::dev::ImplementImpedanceControl::~ImplementImpedanceControl
virtual ~ImplementImpedanceControl()
Destructor.
Definition: ImplementImpedanceControl.cpp:38
JOINTIDCHECK
#define JOINTIDCHECK
Definition: ImplementImpedanceControl.cpp:18
yarp::dev::ControlBoardHelper::impS2N
void impS2N(const double *sens, double *newtons)
Definition: ControlBoardHelper.cpp:373
yarp::dev::IImpedanceControlRaw::setImpedanceOffsetRaw
virtual bool setImpedanceOffsetRaw(int j, double offset)=0
Set current force Offset for a specific joint.
yarp::dev::ImplementImpedanceControl::uninitialize
bool uninitialize()
Clean up internal data and memory.
Definition: ImplementImpedanceControl.cpp:43
ControlBoardHelper.h
yarp::dev::ControlBoardHelper::impN2S
void impN2S(double newtons, int j, double &sens, int &k)
Definition: ControlBoardHelper.cpp:304
yarp::dev::ImplementImpedanceControl::initialize
bool initialize(int size, const int *amap, const double *enc, const double *zos, const double *nw)
Initialize the internal data and alloc memory.
Definition: ImplementImpedanceControl.cpp:27
yarp::dev::ControlBoardHelper::trqN2S
void trqN2S(double newtons, int j, double &sens, int &k)
Definition: ControlBoardHelper.cpp:326
yarp::dev::ImplementImpedanceControl::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: ImplementImpedanceControl.cpp:103
castToMapper
yarp::dev::ControlBoardHelper * castToMapper(void *p)
Definition: ControlBoardHelper.h:180
yarp::dev::ImplementImpedanceControl::setImpedance
bool setImpedance(int j, double stiffness, double damping) override
Set current impedance gains (stiffness,damping) for a specific joint.
Definition: ImplementImpedanceControl.cpp:59
yarp::dev::ControlBoardHelper
Definition: ControlBoardHelper.h:60
yarp::dev::ControlBoardHelper::trqS2N
void trqS2N(const double *sens, double *newtons)
Definition: ControlBoardHelper.cpp:350
yarp::dev::ImplementImpedanceControl::ImplementImpedanceControl
ImplementImpedanceControl(yarp::dev::IImpedanceControlRaw *y)
Definition: ImplementImpedanceControl.cpp:21
yarp::dev::IImpedanceControlRaw::getImpedanceRaw
virtual bool getImpedanceRaw(int j, double *stiffness, double *damping)=0
Get current impedance parameters (stiffness,damping,offset) for a specific joint.
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::dev::ImplementImpedanceControl::getImpedanceOffset
bool getImpedanceOffset(int j, double *offset) override
Get current force Offset for a specific joint.
Definition: ImplementImpedanceControl.cpp:93
yarp::dev::ImplementImpedanceControl::helper
void * helper
Definition: ImplementImpedanceControl.h:25