diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-06-10 18:52:48 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2015-06-10 18:52:48 +0200 |
commit | 56990d37ecc3221d56cb5417f2c50562cfed3e44 (patch) | |
tree | 73f6e38a047cc024c9a029a50815c0bb50e9e3cc /Venus_Skeleton | |
parent | fba17464f5cd5c8f9fb8eb8c9c9bd5947489df69 (diff) | |
download | code-56990d37ecc3221d56cb5417f2c50562cfed3e44.tar.gz |
Fix compile errors+warnings, fix compass edge case
Fix signed vs. unsigned millis() comparison, remove unused vars, change
functions where the return value is not checked to void.
Fix edge case in senseCompass, if the reading somehow fails, then it
should not change the compass value (right?).
Diffstat (limited to 'Venus_Skeleton')
-rw-r--r-- | Venus_Skeleton/Venus_Skeleton.ino | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/Venus_Skeleton/Venus_Skeleton.ino b/Venus_Skeleton/Venus_Skeleton.ino index f15848d..6bb8a4a 100644 --- a/Venus_Skeleton/Venus_Skeleton.ino +++ b/Venus_Skeleton/Venus_Skeleton.ino @@ -96,10 +96,10 @@ int currValDirection = 0; int currValDirectionDegree = 0; // Timers -long timerMovementStart = 0; -long timerMovementStop = 0; -long timerInitialSequence = 0; -long timerTurret = 0; +unsigned long timerMovementStart = 0; +unsigned long timerMovementStop = 0; +//unsigned long timerInitialSequence = 0; // TODO unused? +unsigned long timerTurret = 0; // Counters int counterInit = 0; @@ -267,20 +267,17 @@ float sensMagnetometer() { return(north); // Returns angle difference } void sensCompass() { - int degree = -1; - float reading[NUM_COMPASS_CHECKS]; + int degree; float readingtotal = 0; + // take multiple samples and use the average for(int i = 0; i < NUM_COMPASS_CHECKS; i++){ readingtotal += sensMagnetometer(); } - readingtotal /= NUM_COMPASS_CHECKS; - - if (readingtotal >= 0 && readingtotal <= 360) - degree = (int) readingtotal; - - if (data.compass != degree) { + // if compass reading is sane, save it. + degree = readingtotal / NUM_COMPASS_CHECKS; + if (degree >= 0 && degree <= 360 && data.compass != degree) { data.compass = degree; // mark as changed dataToPiChangedBits |= CHANGED_SENS_COMPASS; @@ -387,7 +384,7 @@ void sensSampleGripper() { } // sensor IR, beacon detection and recognition -int sensBeaconTurret() { +void sensBeaconTurret() { // BE AWARE, LOCALISATION OF OBSTACLE IS y DISTANCE FROM CENTER OF ROBOT // (creates triangle with centerOfRobot, centerOfSensor and Obstacle as its corners) @@ -439,9 +436,9 @@ void stopAllServos() { timerMovementStop = 0; } -bool moveTurnTo(int direction) { +void moveTurnTo(int direction) { if (direction == 0 || direction == NUM_DIRECTIONS) { - return true; + return; } // Make sure turret doesn't move @@ -760,7 +757,8 @@ void checkSample() { } } -bool confirmSample(int turretVal) { +void confirmSample(int turretVal) { + // TODO use turretVal if (!counterSampleConfirm) { stopAllServos(); // Turret direction in degrees calculated from forward. (negative is left, positive is right) @@ -796,7 +794,7 @@ bool confirmSample(int turretVal) { if (!counterMovement && counterSampleConfirm == 1) { int sign = currValDirectionDegree < 0 ? 1 : -1; currValDirectionDegree = 60 * sign; - counterSampleConfirm = 3 + counterSampleConfirm = 3; } } } |