Program Won't work

That was what we tried.

so what happened

It didn’t work. aaaa

what didnt work? please be specific

same thing. aaaaaaaa

The same thing happened. It skipped the function altogether.

try printing out values of white and black, and also print something in the linecount function to check if it is called

We know that it is the while loops.

Also, I tested printing the sensorvalue of the sensor and the variables. “Black” was 14, “White” was 170, and the color value over black was 14 and the color value over white was 168.

i think you are misunderstanding whiles. the while loop will continue if the statement is true, the statement is not the break condition

so maybe do a while true loop, and add a if statement which breaks the loop when the condition is satisfied. A simpler way is to add a ! in the statement

Okay. The battery was an issue. It was too low to spin the wheels. The thing is, now it just acts as a forward for forever command.

Try this

while(!(SensorValue(lineTrack)<=(White+10))&&(SensorValue(lineTrack)>=(White-10)))
{
setMotor(lDrive,30);
setMotor(rDrive,30);
}
while(!(SensorValue(lineTrack)<=(Black+10))&&(SensorValue(lineTrack)>=(Black-10)))
{
setMotor(lDrive,30);
setMotor(rDrive,30);
}

and you will have to stop the motors afterwards. if the line tracker is white or black, it will set it to 30 power. even if it reaches anything else, it will still be 30 power. Even after the function because after u set it to 30 speed u have to stop it. Also i am assuming you want the robot to reverse after getting to white to go to black.

yup, that may be it.

#pragma config(Sensor, port10, touchLED, sensorVexIQ_LED)
#pragma config(Sensor, port11, gyroSense, sensorVexIQ_Gyro)
#pragma config(Sensor, port12, lineTrack, sensorVexIQ_ColorGrayscale)
#pragma config(Motor, motor1, lDrive, tmotorVexIQ, PIDControl, encoder)
#pragma config(Motor, motor2, arm, tmotorVexIQ, PIDControl, reversed, encoder)
#pragma config(Motor, motor3, tray, tmotorVexIQ, PIDControl, encoder)
#pragma config(Motor, motor4, convey, tmotorVexIQ, PIDControl, encoder)
#pragma config(Motor, motor5, cube2, tmotorVexIQ, PIDControl, encoder)
#pragma config(Motor, motor6, rDrive, tmotorVexIQ, PIDControl, reversed, encoder)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

int White = 0;
int Black = 0;

void gyroturn(string type,string direction,int degrees)
{
if(strcmp(type,“wide”) == 0)
{
if(strcmp(direction,“left”) == 0)
{
setMotor(lDrive,15);
waitUntil(SensorValue(gyroSense)==degrees);
}
if(strcmp(direction,“right”) == 0)
{
setMotor(rDrive,15);
waitUntil(SensorValue(gyroSense)==degrees);
}
}
if(strcmp(type,“tight”) == 0)
{
if(strcmp(direction,“right”) == 0)
{
setMotor(lDrive,15);
setMotor(rDrive,-15);
waitUntil(SensorValue(gyroSense)==degrees);
}
if(strcmp(direction,“right”) == 0)
{
setMotor(rDrive,15);
setMotor(lDrive,-15);
waitUntil(SensorValue(gyroSense)==degrees);
}
}
}

void linecount(int var, int black, int white)
{
int var2 = 0;
repeatUntil(var2 == var)
{
while((SensorValue(lineTrack)<=(white+10))&&(SensorValue(lineTrack)>=(white-10)))
{
setMotor(lDrive,30);
setMotor(rDrive,30);
}
while((SensorValue(lineTrack)<=(black+10))&&(SensorValue(lineTrack)>=(black-10)))
{
setMotor(lDrive,30);
setMotor(rDrive,30);
}
int var2 = var2+1;
}

	setMotor(lDrive,0);
	setMotor(rDrive,0);

}

task main()
{

//set colors
waitUntil(SensorValue(touchLED) == 1);
White = SensorValue(lineTrack);
sleep(1000);
waitUntil(SensorValue(touchLED) == 1);
Black = SensorValue(lineTrack);
sleep(1000);
waitUntil(SensorValue(touchLED) == 1);
sleep(1000);
//start move
linecount(2,Black,White);
sleep(60000);

}

I don’t know. I’m just going to check this after school tomorrow.

When you say it skipped the function all together, are you saying the linecount function is never called from the task main?

From a glance task main will call the linecount function. However, It seems like your robot just goes straight since both of the condition checks tell the robot to do the same thing of moving forward at 30% speed. Also, you’ve declared var2 all over again at the end of the repeat loop as you are incrementing the value. This will cause the var2 that was declared at the linecount function before the repeatuntil loop not to “see” it… so your repeatuntil should loop forever.

Thanks for that. I am going to rewrite it tomorrow. I’ll update then.

you may be shadowing the original declaration of var2, so the first var2 is never updated.