From 56990d37ecc3221d56cb5417f2c50562cfed3e44 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 10 Jun 2015 18:52:48 +0200 Subject: 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?). --- Venus_Skeleton/Venus_Skeleton.ino | 32 +++++++++++++++----------------- 1 file 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; } } } -- cgit v1.2.1