My partner and I set the Squarebot to traverse through a maze autonomously. We began on the bot by taking away the radio receiver and then writing a program to traverse though the maze. This program is written in RobotC:
#pragma config(Sensor, in7, rEncoder, sensorRotation)
#pragma config(Sensor, in8, lEncoder, sensorRotation)
#pragma config(Motor, port2, rMotor, tmotorNormal, openLoop)
#pragma config(Motor, port3, lMotor, tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
int left = 98;
int right = 70;
int wt = 250;
void goForward(int length)
{
//wait1Msec(2000);
bMotorReflected[port2]=1;
SensorValue[lEncoder] = 0;
while(SensorValue[lEncoder]< length)
{
motor[port3]=127;
motor[port2]=95;
}
}
void goleft(int length)
{
//wait1Msec(2000);
bMotorReflected[port2]=1;
SensorValue[lEncoder] = 0;
while(SensorValue[lEncoder]< length)
{
motor[port3]=-127;
motor[port2]=80;
}
}
void goright(int length)
{
//wait1Msec(2000);
bMotorReflected[port2]=1;
SensorValue[lEncoder] = 0;
while(SensorValue[lEncoder]< length)
{
motor[port3]=127;
motor[port2]=-80;
}
}
void w(int wt)
{
while(SensorValue[lEncoder]< wt)
{
motor[port3]=0;
motor[port2]=0;
wait1Msec(wt);
}
}
task main()
{
goForward(570);
goleft(left);
goForward(280);
goleft(left);
goForward(550);
goRight(right);
goForward(280);
goRight(right);
goForward(740);
goRight(right);
goRight(3000);
}
No comments:
Post a Comment