summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-06-17 15:47:44 +0200
committerPeter Wu <peter@lekensteyn.nl>2015-06-17 15:47:44 +0200
commit3bebd54178be8e896200eafe49933c9c0914517e (patch)
treedec8666fe4af2c75adc49d1eaca49fd73c7cf5c2
parenta3d4f7cb083449e67fce21f1067eb1c6da244c1e (diff)
downloadcode-3bebd54178be8e896200eafe49933c9c0914517e.tar.gz
Init turret sequence docs + logical
-rw-r--r--Venus_Skeleton/Venus_Skeleton.ino29
1 files changed, 15 insertions, 14 deletions
diff --git a/Venus_Skeleton/Venus_Skeleton.ino b/Venus_Skeleton/Venus_Skeleton.ino
index 87b8449..f061f0c 100644
--- a/Venus_Skeleton/Venus_Skeleton.ino
+++ b/Venus_Skeleton/Venus_Skeleton.ino
@@ -177,22 +177,23 @@ long microsecondsToCentimeters(long microseconds)
return microseconds / 29 / 2;
}
+/**
+ * Given the number of positions $n$, fills the lower half of the array with 0,
+ * 2, 4, ..., $n-1$, then continues filling the upper half with $n-2$, $n-4$,
+ * ..., 5, 3, 1.
+ */
void initTurretSequence(int array[], int numOfPositions) {
- int sign = 1;
- int x = 0;
-
- for (int i = 0; i < numOfPositions; i++) {
+ // for n=7, fill lower half of array with 0, 2, 4, 6
+ // for n=8, fill lower half of array with 0, 2, 4, 6
+ for (int i = 0; i < numOfPositions / 2; i++) {
+ array[i] = i * 2;
+ }
+ // for n=7, fill upper half of array with 5, 3, 1
+ // for n=8, fill upper half of array with 7, 5, 3, 1
+ int x = numOfPositions / 2 * 2 - 1;
+ for (int i = numOfPositions / 2 + 1; i < numOfPositions; i++) {
array[i] = x;
- x += sign * 2;
-
- if(x > numOfPositions) {
- sign = -1;
- x -= 3;
- }
- if(x == numOfPositions) {
- sign = -1;
- x -= 1;
- }
+ x -= 2;
}
}