-
Notifications
You must be signed in to change notification settings - Fork 1
/
encoder_test.cpp
48 lines (39 loc) · 1.29 KB
/
encoder_test.cpp
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
#include<Mahi/Daq.hpp>
#include<Mahi/Util.hpp>
#include<common.hpp>
using namespace mahi::daq;
using namespace mahi::util;
int main(int arc, char const *argv[])
{
Q8Usb q8;
if (!q8.is_open())
return -1;
std::vector<bool> active_joints = {true, // joint 1 (elbow)
true, // joint 2 (forearm ps)
true, // joint 3 (wrist fe)
true}; // joint 4 (wrist ru)
for (auto i = 0; i < moe_n_dof; i++){
q8.encoder.units[encoder_channel[i]] = (2.0*PI/encoder_cprs[i])*gear_ratios[i];
q8.encoder.zero(encoder_channel[i]);
}
q8.enable();
Timer timer(1_s);
Time t = 0_s;
auto test_time = 10_s;
while (t < test_time){
q8.read_all();
for (auto i = 0; i < moe_n_dof; i++){
if (active_joints[i]){
print("encoder[{}]: {} counts = {:+.2f} rad. -> {:+2f} rad/s",
i,
q8.encoder[encoder_channel[i]],
q8.encoder.positions[encoder_channel[i]],
q8.velocity.velocities[encoder_channel[i]]);
}
}
t = timer.wait();
}
q8.disable();
q8.close();
return 0;
}