-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEvil-Minion.ino
136 lines (103 loc) · 2.22 KB
/
Evil-Minion.ino
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//--------------------------------------------------------
// Evil Minion 5 Axis robot firmware
// dan@marginallyclever.com
// 2015 September 3
// see http://evilminion.info/ for more information.
//--------------------------------------------------------
#include "config.h"
#include "pid.h"
#include "sensor.h"
#include "flash.h"
#include "motor.h"
// movement control
float destination[NUM_AXIES];
char move_active[NUM_AXIES];
// timing
long m0, m1;
// misc
long robot_uid=0;
char continuous_reporting;
char compliant_mode;
float compliance_limit;
void setup() {
comms_setup();
loadConfig();
motor_setup();
setup_sensors();
int i;
for(i=0;i<NUM_AXIES;++i) {
// PIDs
PID_init(pid[i]);
move_active[i]=0;
}
compliant_mode = 0;
continuous_reporting = 0;
compliance_limit = COMPLIANCE_DEFAULT_EPSILON;
help();
ready();
m0 = millis();
}
void loop() {
tick_comms();
tick_sensors();
// post a position update every 50ms. No need to overdo it...
m1 = millis();
float dt = ((m1-m0)*0.001);
if(dt >= 0.05) {
m0 = m1;
if(continuous_reporting==1) {
where();
}
}
char can_comply=comply();
if( is_target_set() ) {
if( can_comply ) {
// move motors
tick_motors(dt);
} else {
// collision!
Serial.println(F("Collision"));
motor_all_stop();
}
} else {
// no target set
if( can_comply==0 ) {
// pushed
Serial.println(F("Pushed"));
respond_to_push();
}
}
}
void respond_to_push() {
int i;
for(i=0;i<NUM_AXIES;++i) {}
}
char is_target_set() {
int i;
for(i=0;i<NUM_AXIES;++i) {
if( move_active[i]!=0 ) return 1;
}
return 0;
}
/**
* Compliance test.
*/
char comply() {
// if compliance test is off, allow movement
if(compliant_mode==0) return 1;
int i;
float ds;
char can_comply=1;
for(i=0;i<NUM_AXIES;++i) {
// if expected sensor too far from actual sensor then interference
ds = sensors_expected[i] - sensors_filtered[i];
if(fabs(ds) > compliance_limit) {
Serial.print(i);
Serial.print('=');
Serial.println(ds);
can_comply=0;
}
}
if(can_comply==0) Serial.println(F("Can't comply"));
return can_comply;
}