Friday we had extra time to work on some things. We spent most of the time programming again and spent a little bit of the time working on our final build.
Saturday was the competition and TC and I were worried because our design had been working about 80% as much as we wanted it to and saturday morning it was about 70%.
We started working on it as soon as we got to Cal State Fullerton. We eventually decided to go with the less complex code from the day before because all of the new changes that came into our build only slowed us down and reduced the robot's total performance.
We decided to go with a name chosen by one of our classmates with respect to the robot's appearance.
Name: BABY SCORPION.
This is the latest code I have.. which is 95% similar to the code we used on the day of the competition... Minor changes were made by my partner TC and I did not get a chance to get that from him.
#pragma config(Sensor, in1, linesensor, sensorLineFollower)
#pragma config(Sensor, in2, colorsensor, sensorReflection)
#pragma config(Sensor, in3, encoder, sensorRotation)
#pragma config(Sensor, in4, sonar, sensorSONAR, int1)
#pragma config(Motor, port2, leftmotor, tmotorNormal, openLoop)
#pragma config(Motor, port3, rightmotor, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port4, rightarm, tmotorServoStandard, openLoop)
#pragma config(Motor, port5, leftarm, tmotorServoStandard, openLoop)
#pragma config(Motor, port8, platform, tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
void checkline()
{
if (SensorValue[linesensor] > 450)
{
motor[leftmotor]=-40;
motor[rightmotor]=-40;
wait1Msec(1000);
motor[leftmotor]=40;
motor[rightmotor]=-40;
wait1Msec(1000);
motor[leftmotor]=0;
motor[rightmotor]=0;
wait1Msec(50);
}
}
void goforward(int gotime) //go forward function
{
motor[rightmotor]=45;
motor[leftmotor]=45;
checkline();
wait1Msec(gotime);
checkline();
motor[rightmotor]=0;
motor[leftmotor]=0;
checkline();
}
void pause(int gotime) //pause function
{
motor[rightmotor]=0;
motor[leftmotor]=0;
checkline();
wait1Msec(gotime);
}
void goback(int gotime)
{
motor[rightmotor]=-40;
motor[leftmotor]=-40;
checkline();
wait10Msec(gotime);
pause(100);
}
void turn(int gotime) //turn function
{
motor[rightmotor]=35;
motor[leftmotor]=-35;
checkline();
wait1Msec(gotime);
checkline();
motor[leftmotor]=0;
motor[rightmotor]=0;
}
void tilt(int gotime) //tilt color sensor function
{
motor[platform]=35;
wait10Msec(gotime);
motor[platform]=0;
wait10Msec(20);
motor[platform]=-25;
wait10Msec(gotime);
motor[platform]=0;
}
short given1=0; //variable for first given color
short given2=0; //variable for second given color
short mission=0; //variable for defining what mission robot is on
int count=0; //counter for loop assigning colors to givens
short carry=0;
bool go;
bool finish;
void closeclaw()
{
motor[leftarm]=10;
motor[rightarm]=10;
wait10Msec(200);
}
void openclaw()
{
motor[leftarm]=160;
motor[rightarm]=160;
wait10Msec(20);
}
void check(int gotime1,int gotime2,int gotime3)
{
pause(gotime1);
tilt(gotime2);//tilt color sensor
pause(gotime3);
count ++;
}
void rightcolor()
{
//Move to color zone that matches color of can
finish=true;
carry=1;
}
void wrongcolor()
{
//Get rid of can
openclaw();
goback(200);
turn(100);
finish=false;
}
void checkcolor()
{
closeclaw();
wait10Msec(200);
int color1 = SensorValue[colorsensor];
if (color1 <> 18) //Is it red
{
if (given1==8) //red is the target color?
{
rightcolor();
}
else
{
wrongcolor();
}
}//check to see if color is green
if (color1 <> 328) //Is it green and is green the target color?
{
if (given1==6) //green is the target color?
{
rightcolor();
}
else
{
wrongcolor();
}
}//check to see if color is blue
if (color1 <> 628) //Is it blue and the target color is blue?
{
if (given1==7) //blue is the target color?
{
rightcolor();
}
else
{
wrongcolor();
}
}
if (color1 > 1000) //Not one of the above Maybe we should sense again
{
openclaw();
}
}
void search()
{
while(go==true)//search for can
{
openclaw();
if (SensorValue[sonar] <=-1 || SensorValue[sonar] >=20)
{
goforward(200);
pause(50);
checkline();
goforward(100);
pause(50);
checkline();
turn(100);
checkline();
pause(150);
}
if (SensorValue[sonar]>=3 && SensorValue[sonar]<20)>
{
goforward(150);
pause(50);
}
if (SensorValue[sonar] <3>=1) //if something is in close range
{
goforward(40);
pause(100);
go=false;
checkcolor();//closeclaw();
}
}
}
void end()
{
pause(200000);
}
void searchfloor()
{
if (SensorValue[colorsensor] >1000)
{
pause(1000);
goforward(20);
checkline();
pause(150);
int color2=SensorValue[colorsensor];
if (color2 <> 18) //Is it red
{
if (given1==8) //red is the target color?
{
openclaw();
end();
}
else
{
goforward(50);
}
}//check to see if color is green
if (color2 <> 328) //Is it green and is green the target color?
{
if (given1==6) //green is the target color?
{
openclaw();
end();
}
else
{
goforward(50);
}
}//check to see if color is blue
if (color2 <> 628) //Is it blue and the target color is blue?
{
if (given1==7) //blue is the target color?
{
openclaw();
end();
}
else
{
goforward(50);
}
}
pause(250);
}
}
void goforever()
{
while(true)
{
checkline();
motor[rightmotor]=40;
motor[leftmotor]=40;
wait1Msec(50);
checkline();
searchfloor();
}
}
task main()
{
bMotorReflected[leftarm]=1;
while(true)
{
if (carry==0)
{
openclaw();
}
do
{ //look forward for first color given1
//check to see if color is red
if (SensorValue[colorsensor] <> 18)
{
if (given1==0) //if given1 has not been set, set to red
{
given1=8;//red
check(500,30,750); //pause,tilt,pause,count++
}
else //else set given2 to red
{
given2=8;//red
check(500,0,0); //pause,no tilt, no 2nd pause, count++
}
}//check to see if color is green
if (SensorValue[colorsensor] <> 328)
{
if (given1==0) //if given1 has not been set, set to green
{
given1=6;//green
check(500,30,750); //pause,tilt,pause,count++
}
else //else set given2 to green
{
given2=6;
check(500,0,0);
}
}//check to see if color is blue
if (SensorValue[colorsensor] <> 628)
{
if (given1==0) //if given1 has not been set, set to blue
{
given1=7;//blue
check(500,30,750);
}
else //else set given2 to blue
{
given2=7;//blue
check(500,0,0);
}
}//end color sense
} while(count<=2);
pause(100);
motor[leftmotor]=40;
motor[rightmotor]=40;
wait10Msec(50);
pause(20);
if(count>=2 && count <=4)
{
go=true; //allow for next loop
count++;
}
search(); //search for can
if (finish==true)
{
motor[platform]=30;
wait10Msec(25);
motor[platform]=0;
wait10Msec(10);
pause(100);
goforever();
checkline();
}
if (finish==false)
{
search();
}
}
}