-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsauter_helper_functions.h
77 lines (62 loc) · 1.39 KB
/
sauter_helper_functions.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef SAUTER_HELPER_H
#define SAUTER_HELPER_H
#include "config.h"
#include "console_helper_functions.h"
#include "motor_helper_functions.h"
int BUFFER_SIZE = 64;
// Function to read command from serial port
float get_sauter_one_measure(int BUFFER_SIZE) {
int i = 0, j = 0;
char data[BUFFER_SIZE];
while(i != 7){
//Serial1.write(0x39);
i = 0;
for (i = 0; i < BUFFER_SIZE; i++) {
data[i] = '\0';
}
i = 0;
j = 0;
while(Serial1.available() < 7){
if(j == 0) {
Serial1.write(0x39);
j++;
} else if (j == 2000) {
//Serial.println("Sauter probably disconnected");
j = 0;
} else j++;
}
while(Serial1.available()) {
data[i++] = Serial1.read();
if (i == BUFFER_SIZE) {
break;
}
}
}
// first digit is sign
if(data[0] == '0'){
data[0] = '-';
} else {
data[0] = '+';
}
return atof(data);
}
float get_sauter_force(int n, int BUFFER_SIZE){
if (n==1){
return get_sauter_one_measure(BUFFER_SIZE);
} else {
float mean = 0;
for(int i = 0; i < n; i++){
mean = mean + get_sauter_one_measure(BUFFER_SIZE)/n;
}
return mean;
}
}
//void test_force_sign(float x, bool wait){
// if (sign != (force > 0)){
// Serial.print("Sign changed at x: ");
// Serial.print(x);
// if (wait)
// wait_for_enter();
// }
//}
#endif