Newer
Older
13035516
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "ImpedanceControl.h"
#include <Arduino.h>
ImpedanceControl::ImpedanceControl() {
k_sel = ks1;
x = 0;
x0 = 0;
prev_x = 0;
current = 0;
torque = 0;
}
ImpedanceControl::~ImpedanceControl() { }
void ImpedanceControl::setSpringConst(bool kc) {
if (kc) {
k_sel = ks2;
} else {
k_sel = ks1;
}
}
void ImpedanceControl::setSpringZeroPos(bool kc) {
if (kc) {
x0 = zero2;
} else {
x0 = zero1;
}
}
float ImpedanceControl::getSpringConst() {
return k_sel;
}
float ImpedanceControl::getSpringZeroPos() {
return x0;
}
void ImpedanceControl::impedanceControllerUpdate(float x_, float dt) {
float torque = 0;
float delta_x = 0;
float v = 0;
x = x_;
delta_x = (x - prev_x) - x0;
if (delta_x >= 0) {
v = delta_x/dt; // delta_x in rads and dt in sec
torque = dampener*v + delta_x*k_sel;
current = torque/(kt*belt_ratio);
} else {
v = 0;
torque = 0;
current = 0;
}
}
float ImpedanceControl::getDesiredCurrent() {
return current*1000;
}
float ImpedanceControl::getDesiredTorque() {
return torque;
}