robotc

college code of robotc

git clone https://9o.is/git/robotc.git

deadreckoning.c

(693B)


      1 // circumference with 56 mm diameter wheel
      2 float revolution = 3.1415 * 56; //175.924
      3 float meter = revolution * 5.6842;
      4 
      5 
      6 void turn90() {
      7   nMotorEncoder[motorB] = 0;
      8   nMotorEncoder[motorC] = 0;
      9  while(nMotorEncoder[motorC] < revolution * 3.2) {
     10          motor[motorC] = 100;
     11          motor[motorB] = 0;
     12  }
     13 }
     14 
     15 
     16 void move(int distance) {
     17   nMotorEncoder[motorB] = 0;
     18   nMotorEncoder[motorC] = 0;
     19  while(nMotorEncoder[motorB] < distance) {
     20          motor[motorC] = 100;
     21          motor[motorB] = 100;
     22         }
     23 }
     24 
     25 
     26 task main() {
     27 
     28 
     29  // complete 4 sides of square
     30  for(int i=0; i < 4; i++) {
     31           move(meter/2); //move half a meter
     32           turn90();
     33  }
     34 }