RoboCatz.com

Spring 2015 Program Code in RobotC

#include "Library2012.c";
/*------
Date: April 13
Description: Walk
-------*/
task main() {
  startup();
  setPowerLevel(25);
  configureRobotDimensions(70, 4);
  //calibrateLightSensor();
  motor[motorA]=20;
  SensorType[S3] = sensorLightActive;      // Turn light 'on' if it is currently 'off'
  float LowestRecordedValue = 99;
  long LowestRecordedDegree = -1;
  int LastTurnMade = 0;
  while(true) {                            // Run Forever
    if(SensorValue(touchSensor) == 1) {    // Button was pressed.  Now act on it.
      nxtDisplayCenteredTextLine(2, "Degree: %5d", LowestRecordedDegree);
      nxtDisplayCenteredTextLine(3, "Lowest: %5.2f", LowestRecordedValue);
      if(LowestRecordedDegree>315) {       // turn right
        motor[motorB] = 0;
        motor[motorC] = powerLevel;
        LastTurnMade=COUNTERCLOCKWISE;
        nxtDisplayCenteredTextLine(6, "****      " );
        nxtDisplayCenteredTextLine(7, "****      " );
      } else {
        if(LowestRecordedDegree>135 && LowestRecordedDegree<235) {
          motor[motorC] = 0;               // turn left
          motor[motorB] = powerLevel;
          LastTurnMade=CLOCKWISE;
          nxtDisplayCenteredTextLine(6, "      ****" );
          nxtDisplayCenteredTextLine(7, "      ****" );
//                             //
        } else {                           // go straight
          motor[motorC] = powerLevel;
          motor[motorB] = powerLevel;
          nxtDisplayCenteredTextLine(6, "   ****   " );
          nxtDisplayCenteredTextLine(7, "   ****   " );
        }
      }
      LowestRecordedValue = 99;            // Reset the lowest value
      nMotorEncoder[motorA] = 0;           // Reset the sensor rotation indicator
      while(SensorValue(touchSensor) == 1) { wait10Msec(2); }
                                           // Wait until the button is released
    }
    int thisLightValue = getLightPercent();// Get the current light value
    nxtDisplayCenteredTextLine(4, "Degree:%5d", nMotorEncoder[motorA]);
    nxtDisplayCenteredTextLine(5, "Light: %5d", thisLightValue);
                                           // Compare Current light value to recorded light value
    if(LowestRecordedValue*1 > thisLightValue*1 && thisLightValue*1>0 && nMotorEncoder[motorA]>180) {
       LowestRecordedValue = thisLightValue*1; // Set new values
       LowestRecordedDegree = nMotorEncoder[motorA];  // Store this degree value
                                           // This degree will be used later to decide if should turn or go straight
    }
  }
}