We were given a maze and had to program the squarebot to navigate through it. The fisrt time, we simply used timing commands, and saw how inacurate it was. We were put into groups, given rotary encoders and did it again. Programming the robot with shaft encoders results in much more accurate results. The video shows the results of the encoders, and my code posted afterwards.
#pragma config(Sensor, in3, eleft, sensorRotation) #pragma config(Sensor, in4, eright, sensorRotation) #pragma config(Motor, port1, right, tmotorNormal, openLoop, reversed) #pragma config(Motor, port2, left, tmotorNormal, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// #define sec 10000 #define rev 12.56 #define inch 8 //counts #define foot 105 //counts //1 count = .1256 void reset() { SensorValue[eleft]=0; SensorValue[eright]=0; } void goforward(int power, int dist) { while((SensorValue[eleft] < dist*105-100)&& (SensorValue[eright] < dist*105-100)) { motor[right] = 60; motor[left] = 60; } while((SensorValue[eleft] < dist*105)&& (SensorValue[eright] < dist*105)) { motor[right] = 30; motor[left] = 30; } motor[right] = -1; motor[left] = -1; wait10Msec(10); motor[right] = 0; motor[left] = 0; wait1Msec(1000); } void turnleft() { while((SensorValue[eright]<110) && (SensorValue[eleft]<110)) { motor[right] = 50; motor[left] = -50; } motor[right] = 0; motor[left] = 0; wait1Msec(1000); } void turnright() { while((SensorValue[eright]<110) && (SensorValue[eleft]<110)) { motor[right] = -50; motor[left] = 50; } motor[right] = 0; motor[left] = 0; wait1Msec(1000); } task main() { SensorValue[eleft]=0; SensorValue[eright]=0; while(true) { goforward(80,4.5); reset(); turnright(); reset(); goforward(80,1.8); reset(); turnright(); reset(); goforward(80, 3.5); reset(); turnleft(); reset(); goforward(80,1.5); reset(); turnleft(); reset(); goforward(80,3.5); reset(); turnright(); reset(); goforward(80,1.5); reset(); turnright(); reset(); goforward(80,5); reset(); turnright(); reset(); goforward(80,1.8); wait10Msec(800); //goforward(100,1000); } }