@@ -18,8 +18,8 @@ int betaPin = 36;
18
18
int gammaPin = 29 ;
19
19
int EDFPin = 8 ;
20
20
21
- float vane_min = -12 ;
22
- float vane_max = 12 ;
21
+ float vane_min = -15 ;
22
+ float vane_max = 15 ;
23
23
float alpha1_0 = 140 ; // Initial Vane setting in degrees
24
24
float alpha2_0 = 145 ;
25
25
@@ -29,7 +29,7 @@ float throttle_min = 0;
29
29
float throttle_max = 100 ;
30
30
31
31
int delta = high_endpoint - low_endpoint;
32
- int arm_tries = 10 ;
32
+ int arm_tries = 100 ;
33
33
bool startFlag = false ;
34
34
35
35
int segment = 0 ;
@@ -45,44 +45,49 @@ float forcenm1 = 1e6;
45
45
float forcenm2;
46
46
float currentAvg;
47
47
float lastAvg;
48
- float forceConvergenceThreshold = 0.01 ;
48
+ float forceConvergenceThreshold = 0.03 ;
49
49
50
50
float currentTorque = 1e3 ;
51
51
float torquenm1 = 1e6 ;
52
52
float torquenm2;
53
53
float currentTorqueAvg;
54
54
float lastTorqueAvg;
55
- float torqueConvergenceThreshold = 0.01 ;
55
+ float torqueConvergenceThreshold = 0.03 ;
56
56
57
57
double sum = 0 ;
58
58
int count = 0 ;
59
59
60
60
void setup () {
61
61
// put your setup code here, to run once:
62
- while (!Serial.available ()) {
63
- }
64
62
FreqMeasure.begin ();
65
63
Serial.begin (9600 );
66
64
Serial1.begin (115200 );
65
+
66
+ while (!Serial.available ()) {
67
+ }
68
+
67
69
vane1.attach (vane1Pin);
68
70
vane2.attach (vane2Pin);
69
71
betaServo.attach (betaPin);
70
72
gammaServo.attach (gammaPin);
71
73
EDF.attach (EDFPin);
72
74
vane1.write (alpha1_0);
73
75
vane2.write (alpha2_0);
74
- betaServo.write (100 );
76
+ betaServo.write (90 );
75
77
gammaServo.write (100 );
76
78
77
79
newestForce = 0 ;
78
80
newestTorque = 0 ;
79
81
82
+ delay (15 );
80
83
EDF.writeMicroseconds (1020 );
81
84
for (byte i = 0 ; i < arm_tries; i++) {
82
85
EDF.writeMicroseconds (1000 );
83
86
}
84
87
88
+ delay (15 );
85
89
EDF.writeMicroseconds (1020 );
90
+ delay (5000 );
86
91
87
92
lastSegmentTime = millis () / 1000.0 ;
88
93
@@ -102,35 +107,44 @@ void loop() {
102
107
switch (segment) {
103
108
case 0 :
104
109
105
- unitStep (lastSegmentTime, 20 , ' t' );
110
+ unitStep (lastSegmentTime, 40 , ' t' );
106
111
unitStep (lastSegmentTime, 0 , ' 1' );
107
112
unitStep (lastSegmentTime, 0 , ' 2' );
108
113
109
- if (forceConvergence () && torqueConvergence ()) {
114
+ currentForce = newestForce;
115
+ currentTorque = newestTorque;
116
+
117
+ if ((millis () / 1000.0 ) > lastSegmentTime + 10 ) {
110
118
segment++;
111
119
lastSegmentTime = millis () / 1000.0 ;
112
120
}
113
121
114
122
break ;
115
123
case 1 :
116
124
117
- unitStep (lastSegmentTime, 50 , ' t' );
125
+ unitStep (lastSegmentTime, 70 , ' t' );
118
126
unitStep (lastSegmentTime, 0 , ' 1' );
119
127
unitStep (lastSegmentTime, 0 , ' 2' );
120
128
121
- if (forceConvergence () && torqueConvergence ()) {
129
+ currentForce = newestForce;
130
+ currentTorque = newestTorque;
131
+
132
+ if ((millis () / 1000.0 ) > lastSegmentTime + 10 ) {
122
133
segment++;
123
134
lastSegmentTime = millis () / 1000.0 ;
124
135
}
125
136
126
137
break ;
127
138
case 2 :
128
139
129
- unitStep (lastSegmentTime, 70 , ' t' );
140
+ unitStep (lastSegmentTime, 100 , ' t' );
130
141
unitStep (lastSegmentTime, 0 , ' 1' );
131
142
unitStep (lastSegmentTime, 0 , ' 2' );
132
143
133
- if (forceConvergence () && torqueConvergence ()) {
144
+ currentForce = newestForce;
145
+ currentTorque = newestTorque;
146
+
147
+ if ((millis () / 1000.0 ) > lastSegmentTime + 10 ) {
134
148
segment++;
135
149
lastSegmentTime = millis () / 1000.0 ;
136
150
}
@@ -142,7 +156,10 @@ void loop() {
142
156
unitStep (lastSegmentTime, 0 , ' 1' );
143
157
unitStep (lastSegmentTime, 0 , ' 2' );
144
158
145
- if (forceConvergence () && torqueConvergence ()) {
159
+ currentForce = newestForce;
160
+ currentTorque = newestTorque;
161
+
162
+ if ((millis () / 1000.0 ) > lastSegmentTime + 10 ) {
146
163
segment++;
147
164
lastSegmentTime = millis () / 1000.0 ;
148
165
}
@@ -153,7 +170,10 @@ void loop() {
153
170
unitStep (lastSegmentTime, vane_max, ' 1' );
154
171
unitStep (lastSegmentTime, vane_max, ' 2' );
155
172
156
- if (forceConvergence () && torqueConvergence ()) {
173
+ currentForce = newestForce;
174
+ currentTorque = newestTorque;
175
+
176
+ if ((millis () / 1000.0 ) > lastSegmentTime + 10 ) {
157
177
segment++;
158
178
lastSegmentTime = millis () / 1000.0 ;
159
179
}
@@ -163,7 +183,10 @@ void loop() {
163
183
unitStep (lastSegmentTime, vane_min, ' 1' );
164
184
unitStep (lastSegmentTime, vane_min, ' 2' );
165
185
166
- if (forceConvergence () && torqueConvergence ()) {
186
+ currentForce = newestForce;
187
+ currentTorque = newestTorque;
188
+
189
+ if ((millis () / 1000.0 ) > lastSegmentTime + 10 ) {
167
190
segment++;
168
191
lastSegmentTime = millis () / 1000.0 ;
169
192
}
@@ -173,7 +196,10 @@ void loop() {
173
196
unitStep (lastSegmentTime, 0 , ' 1' );
174
197
unitStep (lastSegmentTime, 0 , ' 2' );
175
198
176
- if (forceConvergence () && torqueConvergence ()) {
199
+ currentForce = newestForce;
200
+ currentTorque = newestTorque;
201
+
202
+ if ((millis () / 1000.0 ) > lastSegmentTime + 10 ) {
177
203
segment++;
178
204
lastSegmentTime = millis () / 1000.0 ;
179
205
}
@@ -275,23 +301,23 @@ void loop() {
275
301
}
276
302
277
303
Serial.print (segment);
278
- Serial.print (" \t " );
304
+ Serial.print (" , \t " );
279
305
Serial.print (millis () / 1000.0 );
280
- Serial.print (" \t " );
306
+ Serial.print (" , \t " );
281
307
Serial.print (throttle_command);
282
- Serial.print (" \t " );
308
+ Serial.print (" , \t " );
283
309
Serial.print (vane_command);
284
- Serial.print (" \t " );
285
- Serial.print (currentForce);
286
- Serial.print (" \t " );
287
- Serial.print (currentTorque);
288
- Serial.print (" \t " );
310
+ Serial.print (" , \t " );
311
+ Serial.print (currentForce, 5 );
312
+ Serial.print (" , \t " );
313
+ Serial.print (currentTorque, 5 );
314
+ Serial.print (" , \t " );
289
315
290
316
if (FreqMeasure.available ()) {
291
317
// average several reading together
292
318
sum = sum + FreqMeasure.read ();
293
319
count = count + 1 ;
294
- if (count > 30 ) {
320
+ if (count > 10 ) {
295
321
float frequency = 60 / 2 * FreqMeasure.countToFrequency (sum / count);
296
322
Serial.print (frequency);
297
323
sum = 0 ;
@@ -312,7 +338,7 @@ void loop() {
312
338
}
313
339
}
314
340
315
- bool forceConvergence () {
341
+ bool forceConvergence (char id ) {
316
342
forcenm2 = forcenm1;
317
343
forcenm1 = currentForce;
318
344
currentForce = newestForce;
@@ -344,8 +370,8 @@ void unitStep(float t, float end, char identifier) {
344
370
345
371
void sineInput (float t, float angularRate, char identifier) {
346
372
if (identifier == ' t' ) {
347
- int pwm_out = (int )(((25 + 25 * sin ((t - lastSegmentTime) * angularRate) - throttle_min) / (throttle_max - throttle_min)) * (float )(high_endpoint - low_endpoint) + low_endpoint);
348
- throttle_command = 25 + 25 * sin ((t - lastSegmentTime) * angularRate);
373
+ int pwm_out = (int )(((50 + 50 * sin ((t - lastSegmentTime) * angularRate) - throttle_min) / (throttle_max - throttle_min)) * (float )(high_endpoint - low_endpoint) + low_endpoint);
374
+ throttle_command = 50 + 50 * sin ((t - lastSegmentTime) * angularRate);
349
375
EDF.writeMicroseconds (pwm_out);
350
376
} else if (identifier == ' 1' ) {
351
377
vane1.write (alpha1_0 + vane_max * sin ((t - lastSegmentTime) * angularRate));
0 commit comments