ROBOTC.net forums
http://www.robotc.net/forums/

I need help fixing errors
http://www.robotc.net/forums/viewtopic.php?f=63&t=13787
Page 1 of 1

Author:  Kodman [ Thu Mar 31, 2016 8:49 pm ]
Post subject:  I need help fixing errors

So for a school project we need our robot to follow a U-shaped line and stop at the end. We compile this code and it says that there is internal failure in expression evaluation for 'two()'. We really just need it to stop when it reaches the end of the tape. The tape is blue and the ground in concrete. The blue tape is lighter than 200 ( <200) and the concrete is darker than 200 (>200).

#pragma config(Sensor, in3, rline, sensorLineFollower)
#pragma config(Sensor, in5, lline, sensorLineFollower)
#pragma config(Sensor, in6, line, sensorLineFollower)
#pragma config(Motor, port1, rightmotor, tmotorVex269, openLoop)
#pragma config(Motor, port10, leftmotor, tmotorVex269, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
void two()
{
if (SensorValue(line) >200 && SensorValue(rline) > 200)
{

}
}

task main()
{
wait1Msec(3000);

while(true)
{

if (SensorValue(line) >= 200)
{
}


if (SensorValue(line) < 199)
{
motor[leftmotor] = 63;
motor[rightmotor] = 63;
}



if (SensorValue(rline) <= 200)
{
motor[leftmotor] = 63;
motor[rightmotor] = -63;
}


if (SensorValue(rline) > 201)
{

}


if (SensorValue(lline) >= 200)
{

}


if (SensorValue(lline) < 199)
{
motor[leftmotor] = -63;
motor[rightmotor] = 63;
}

if (two() && SensorValue(lline) >200)
{
motor[leftmotor] = 0;
motor[rightmotor] = 0;
}
}
}

Author:  CARBOT [ Fri Apr 01, 2016 12:24 pm ]
Post subject:  Re: I need help fixing errors

You have four if statements that do nothing. I have seen some issues where these cause problems. Either make them do something or comment them out.

two() is a function without a purpose. Either give a purpose or delete it.

This line is the root of most of your troubles: if (two() && SensorValue(lline) >200)
two() is a function that does not return anything so it cannot be used like that.
If statements with multiple conditions should be like: if ( (x>1) && (y>1) && (z>1) )

Please verify use of () versus [] in the SensorValue statement.

Good luck. Please post your final code.

Author:  Kodman [ Tue Apr 05, 2016 11:33 am ]
Post subject:  Re: I need help fixing errors

Thanks, but I think we will trash that code. We are gonna get rid of the void statement. Is there something that we can use to to say "if sensor A is on the concrete for 2 seconds, then do this."
Because this doesn't work....

if ((SensorValue(line) > 200) && (wait1Msec(2000)))
{

}

It says "internal failure in expression evaluation for 'wait1Msec(2000)'"

Author:  CARBOT [ Tue Apr 05, 2016 9:12 pm ]
Post subject:  Re: I need help fixing errors

consider this in an area that loops continuously:

if (SensorValue[line] < 201)
{
clearTimer(T1);
}
if ((SensorValue[line] > 200) && (time1[T1] > 2000))
{
//do something great here
}

Author:  Kodman [ Thu Apr 14, 2016 10:57 am ]
Post subject:  Re: I need help fixing errors

Does the timer command act kind of like a wait1Msec? Like if the sensor value is less than 200 for 2 seconds it does the command?

Author:  CARBOT [ Thu Apr 14, 2016 12:45 pm ]
Post subject:  Re: I need help fixing errors

The timers are like counters that count time in the background. When a timer is reset, it is set to zero and begins counting again, it does not stay reset.

Assuming you put that code in a section of your program that continuously loops like a while statement, it will reset the timer whenever the sensor is 200 or less. If the sensor gets to 201 it will not reset the timer so it will count time. After 2000ms of continuously counting time it will make the second if statement true. If you get an instant of the sensor below 200 the timer will reset and the second if statement goes false.

Bad programming habits are hard to break. Please do not ever use wait or delay commands. The CPU could be reading sensors or doing useful things in lieu of waiting.

Good luck.

Author:  HelpMePleaseASAP [ Fri May 27, 2016 9:52 am ]
Post subject:  Re: I need help fixing errors

I am having issues with my code.

I have tried changing the "SensorValue" command with "bump" for the parameters several times. I keep getting the same error. I also have issues where the code doesn't accept the "wait(_) command anymore. i want it to wait 5 seconds then do the next step. Please help me soon as I need to get this in for a grade.

the error that keeps popping up is this

"Exeption Error in User Program:

Exeption Type: 'Invalid task state detected(92)

Program Slot: 0, Task ID : main [0]
Error at PC: main+0x0029
Task PC: Task: main+0x0023,
TaskState: 'Exeption'

Exception Details: Task Index 9





#pragma config(Sensor, dgtl1, bump, sensorTouch)
#pragma config(Sensor, dgtl2, limit, sensorTouch)
#pragma config(Motor, port1, lMotor,
tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port10, rMotor,
tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard
!!*//

task main(){

while (SensorValue(limit)){
startTask(lMotor,-100);
startTask(rMotor,100);

*SensorValue(bump);*
stopTask(lMotor);
stopTask(rMotor);


startTask(lMotor,100);
startTask(rMotor,-100);


stopTask(lMotor);
stopTask(rMotor);


startTask(rMotor,-50);
startTask(lMotor,-50);


stopTask(lMotor);
stopTask(rMotor);


}}

Author:  CARBOT [ Fri May 27, 2016 12:09 pm ]
Post subject:  Re: I need help fixing errors

Your code has no logical flow. You must first be able to explain the task in English at a sensor/motor level. Drawing a flow chart next would help. Please consider some simple programming to learn the WHILE statement, IF statement, reading sensors, and Tasks before going further.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/