Program Won't work

This function is just skipped over. I need help. When I run it, linecount does nothing.

#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);

}

When you say it doesn’t work, what does it do? Looks like it will drive forward for quite a long time. You don’t have any turn code and you don’t tell it to stop.

2 Likes

you assigned 0 to var2. var is assigned 2. They you repeat until 2 == 0. it is forever looped there and will be stuck forever.

It completely skips the function.

I tried it so it displays text after the function and it displayed the text before even moving.

i think the thread is stuck inside the function

What do you mean Eden?

im sorry i read it incorrectly because of the indentation

where did you declare black and white? is it a global variable?

I think it is an issue with the repeat command.
I have done the exact same code outside of a void command and it worked like a charm.

since you declared it in int main(), i dont think the function can access it

isusse

img

firstly, declare white and black outside of any scope (so they become a global)

It already is. It is outside of taskmain.

I changed it.
Im going to try it out.

normally linecount cant acces white and black and should result in an error, but idk how you got it to compile

Oh!! Do I need to do something like SensorValue or VEXRT?

#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 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;
}

}

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);
sleep(60000);

}

since you declared white and black globally, and then declare it again locally, it means that main() will edit the value of the local one not the global one. To solve this remove the declaration part (the int) in main()