From 2677462887e2dfa777e2487e928449202d3cd9e6 Mon Sep 17 00:00:00 2001 From: Peter de Kok Date: Wed, 3 Jun 2015 14:18:03 +0200 Subject: Indents fixed --- Venus_Skeleton/Venus_Skeleton.ino | 240 +++++++++++++++++++------------------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/Venus_Skeleton/Venus_Skeleton.ino b/Venus_Skeleton/Venus_Skeleton.ino index 5fe4610..b4a7571 100644 --- a/Venus_Skeleton/Venus_Skeleton.ino +++ b/Venus_Skeleton/Venus_Skeleton.ino @@ -108,20 +108,20 @@ void errorSequence(int errorCode) { long microsecondsToInches(long microseconds) { - // According to Parallax's datasheet for the PING))), there are - // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per - // second). This gives the distance travelled by the ping, outbound - // and return, so we divide by 2 to get the distance of the obstacle. - // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf - return microseconds / 74 / 2; + // According to Parallax's datasheet for the PING))), there are + // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per + // second). This gives the distance travelled by the ping, outbound + // and return, so we divide by 2 to get the distance of the obstacle. + // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf + return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) { - // The speed of sound is 340 m/s or 29 microseconds per centimeter. - // The ping travels out and back, so to find the distance of the - // object we take half of the distance travelled. - return microseconds / 29 / 2; + // The speed of sound is 340 m/s or 29 microseconds per centimeter. + // The ping travels out and back, so to find the distance of the + // object we take half of the distance travelled. + return microseconds / 29 / 2; } void initTurretSequence(int array, int numOfPositions) { @@ -155,20 +155,20 @@ void sendData(pi_datatype_t method, int data, int data1 = NULL, int data2 = NULL } void interpretData(pi_datatype_t dataType, int message) { - switch(dataType) { - case PI_DATATYPE_MOVETO: + switch(dataType) { + case PI_DATATYPE_MOVETO: - break; - case PI_DATATYPE_GRIPPER: + break; + case PI_DATATYPE_GRIPPER: - break; - case PI_DATATYPE_TURRET: + break; + case PI_DATATYPE_TURRET: - break; - default: + break; + default: // ignore ???? - break; - } + break; + } } // receive data from Raspberry Pi @@ -191,81 +191,81 @@ void readData() { // sensor Compass, orientation float sensMagnetometer() { MagnetometerRaw raw = compass.ReadRawAxis(); - float heading = atan2(raw.YAxis, raw.XAxis); - - if(heading < 0){ - heading += 2*PI; - } - - float headingDegrees = heading * 180/M_PI; // Convert to angles - headingDegrees = headingDegrees + 90; // Adjust angle to be relative to front of robot instead of X-direction of sensor - if(headingDegrees>360){ - headingDegrees=headingDegrees-360; - } - float north; - if(headingDegrees<165){ // When heading is negative (left) of north with 15 degree margin - north=headingDegrees-180; // Set angle between north and heading angle - } - else if(headingDegrees>195){ // When heading is positive (right) of north with 15 degree margin - north=headingDegrees-180; // Set angle between north and heading angle - } - else{ // Else heading is towards north with 15 degree margin both sides - north=0; // Set angle between north and heading angle to be 0 - } - return(north); // Returns angle difference + float heading = atan2(raw.YAxis, raw.XAxis); + + if(heading < 0){ + heading += 2*PI; + } + + float headingDegrees = heading * 180/M_PI; // Convert to angles + headingDegrees = headingDegrees + 90; // Adjust angle to be relative to front of robot instead of X-direction of sensor + if(headingDegrees>360){ + headingDegrees=headingDegrees-360; + } + float north; + if(headingDegrees<165){ // When heading is negative (left) of north with 15 degree margin + north=headingDegrees-180; // Set angle between north and heading angle + } + else if(headingDegrees>195){ // When heading is positive (right) of north with 15 degree margin + north=headingDegrees-180; // Set angle between north and heading angle + } + else{ // Else heading is towards north with 15 degree margin both sides + north=0; // Set angle between north and heading angle to be 0 + } + return(north); // Returns angle difference } int sensCompass() { float reading[NUM_COMPASS_CHECKS]; - float readingtotal = 0; + float readingtotal = 0; - for(int i = 0; i < NUM_COMPASS_CHECKS; i++){ - reading[i] = readcompass(); + for(int i = 0; i < NUM_COMPASS_CHECKS; i++){ + reading[i] = readcompass(); readingtotal + i++; + reading[i] = readcompass(); i++; - reading[i] = readcompass(); - i++; - reading[i] = readcompass(); - } - if(i==NUM_COMPASS_CHECKS){ - for(int j = 0; j < NUM_COMPASS_CHECKS; j++){ - readingtotal = readingtotal + reading[j]; // Total readings - } - readingtotal = readingtotal / NUM_COMPASS_CHECKS; // Average reading - Serial.print("Readingtotal: "); // Print average reading (CAN BE REMOVED) - Serial.println(readingtotal); - } - return readingtotal; + reading[i] = readcompass(); + } + if(i==NUM_COMPASS_CHECKS){ + for(int j = 0; j < NUM_COMPASS_CHECKS; j++){ + readingtotal = readingtotal + reading[j]; // Total readings + } + readingtotal = readingtotal / NUM_COMPASS_CHECKS; // Average reading + Serial.print("Readingtotal: "); // Print average reading (CAN BE REMOVED) + Serial.println(readingtotal); + } + return readingtotal; // average for last x ???????? - int degree = 359; - sendData(PI_DATATYPE_COMPASS, degree); - return degree; + int degree = 359; + sendData(PI_DATATYPE_COMPASS, degree); + return degree; } // sensor Ultrasound, distance measurement long sensPing(int pin) { - long duration; + long duration; // Sets pin to OUTPUT and send start signal: pulse (Low-High-Low for clean signal) - pinMode(pin, OUTPUT); - digitalWrite(pin, 0); - delayMicroseconds(2); - digitalWrite(pin, 255); - delayMicroseconds(5); - digitalWrite(pin, 0); + pinMode(pin, OUTPUT); + digitalWrite(pin, 0); + delayMicroseconds(2); + digitalWrite(pin, 255); + delayMicroseconds(5); + digitalWrite(pin, 0); // Sets pin to INPUT and measure time from the echo - pinMode(pin, INPUT); - duration = pulseIn(pin, 255); + pinMode(pin, INPUT); + duration = pulseIn(pin, 255); // Convert from us to cm - duration = microsecondsToCentimeters(duration); - return duration; + duration = microsecondsToCentimeters(duration); + return duration; } void sensObstacleTurret() { @@ -279,7 +279,7 @@ void sensObstacleTurret() { // mark as changed dataToPiChangedBits |= CHANGED_SENS_OBSTACLETURRET; } - } + } } @@ -289,16 +289,16 @@ bool sensIRLine(lr_t LorR) { // BE AWARE, LOCALISATION OF LINE IS y DISTANCE and z DEGREE FROM CENTER OF ROBOT, // calculate by RPi?? - int i; + int i; bool inaccessible = false; int pinNo = LorR == L ? PIN_SENS_IR_LEFT : PIN_SENS_IR_RIGHT; int threshold = LorR == L ? CAL_IR_LEFT_THRESHOLD : CAL_IR_RIGHT_THRESHOLD; bool *dataField = LorR == L ? &data.IR_left_detected : &data.IR_right_detected; int changeBit = LorR == L ? CHANGED_SENS_IRLEFT : CHANGED_SENS_IRRIGHT; - i = analogRead(pinNo); - if (i > threshold) - inaccessible = true; + i = analogRead(pinNo); + if (i > threshold) + inaccessible = true; if (*dataField != inaccessible) { *dataField = inaccessible; @@ -306,7 +306,7 @@ bool sensIRLine(lr_t LorR) { dataToPiChangedBits |= changeBit; } - return inaccessible; + return inaccessible; } // sensor IR, sample detection @@ -325,15 +325,15 @@ void sensSampleTurret() { if (data.sample_turret_detected[counterTurret] != sample) { opMode(OPMODE_WAIT); - stopAllServos(); + stopAllServos(); data.sample_turret_detected[counterTurret] = sample; // mark as changed dataToPiChangedBits |= CHANGED_SENS_SAMPLETURRET; } - } + } } void sensSampleGripper() { - int i; + int i; bool sample = false; i = false; // SENSORDATA HERE @@ -365,12 +365,12 @@ int sensBeaconTurret() { // mark as changed dataToPiChangedBits |= CHANGED_SENS_SAMPLETURRET; } - } + } } // sensor IR, lab detection int sensLab() { - return 0; + return 0; } // ************************ @@ -435,10 +435,10 @@ void turnTurretToNext() { } int deg; - deg = turretSequence[counterTurret] * 10; + deg = turretSequence[counterTurret] * 10; timerTurret = millis(); - turnTurretTo(deg) + turnTurretTo(deg) } if ((timerTurret + 100) < millis()) { timerTurret = 0; @@ -520,9 +520,9 @@ int eliminateDirections(int directionArray[]) { // Implement PI's choices (if still possible) // if (numPossibleDirectionsPi) { - //for (int i = 0; i < NUM_DIRECTIONS * 2; i++) { - // if(!PIarray[i]) {directionArray[i] = 0} - // } + //for (int i = 0; i < NUM_DIRECTIONS * 2; i++) { + // if(!PIarray[i]) {directionArray[i] = 0} + // } // } return numPossibleDirections; @@ -568,19 +568,19 @@ void setup() { // initialise compass communication compass = HMC5883L(); // Gauss scale 1.3 - int error = compass.SetScale(1.3); - if(error != 0){ - // Serial.println(compass.GetErrorText(error)); - } - error = compass.SetMeasurementMode(Measurement_Continuous); - if(error != 0){ - // Serial.println(compass.GetErrorText(error)); - } + int error = compass.SetScale(1.3); + if(error != 0){ + // Serial.println(compass.GetErrorText(error)); + } + error = compass.SetMeasurementMode(Measurement_Continuous); + if(error != 0){ + // Serial.println(compass.GetErrorText(error)); + } servoLeft.attach(PIN_SERVO_LEFT); servoRight.attach(PIN_SERVO_RIGHT); servoTurret.attach(PIN_SERVO_TURRET); - servoGrabber.attach(PIN_SERVO_GRIPPER); + servoGrabber.attach(PIN_SERVO_GRIPPER); turnTurretTo(0); @@ -608,42 +608,42 @@ void loop() { switch(operationMode) { case OPMODE_WAIT: - counterMovement = 0; - timerMovement = 0; - break; + counterMovement = 0; + timerMovement = 0; + break; case OPMODE_INITIALSEQUENCE: - initialSequence(); - break; + initialSequence(); + break; case OPMODE_RANDOM: - break; + break; case OPMODE_MAPPING: - turnTurretToNext(); - checkBestRoute(); - moveTurnTo(currValDirection); - moveStraight(currValDirection, 1); // 1 is supposed to be some distance / time - break; + turnTurretToNext(); + checkBestRoute(); + moveTurnTo(currValDirection); + moveStraight(currValDirection, 1); // 1 is supposed to be some distance / time + break; case OPMODE_CHECKSAMPLE: - break; + break; case OPMODE_GRABSAMPLE: - break; + break; case OPMODE_GOTOLABLOCATION: - sensBeaconTurret(); - break; + sensBeaconTurret(); + break; case OPMODE_WAITFORLAB: - break; + break; case OPMODE_FINDMAGNET: - break; + break; case OPMODE_LABSEQUENCE: - break; + break; default: - // ?? - break; + // ?? + break; } // Delay for stability. @@ -698,9 +698,9 @@ if (data.left_detected != val) { // 2. read whetehr you have hit a block / line sensor if ((changedBits & (CHANGED_IR_LEFT | CHANGED_IR_RIGHT))) && - (data.left_detected || data.right_detected)) { - // panic! - stopMotor(); +(data.left_detected || data.right_detected)) { + // panic! + stopMotor(); } // 3. send to pi or other calculations (and clear bits) -- cgit v1.2.1