View unanswered posts | View active topics It is currently Wed Oct 17, 2018 8:22 pm






Reply to topic  [ 8 posts ] 
I need help fixing errors 
Author Message
Rookie

Joined: Thu Mar 31, 2016 12:08 pm
Posts: 3
Post 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;
}
}
}


Thu Mar 31, 2016 8:49 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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.


Fri Apr 01, 2016 12:24 pm
Profile
Rookie

Joined: Thu Mar 31, 2016 12:08 pm
Posts: 3
Post 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)'"


Tue Apr 05, 2016 11:33 am
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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
}


Tue Apr 05, 2016 9:12 pm
Profile
Rookie

Joined: Thu Mar 31, 2016 12:08 pm
Posts: 3
Post 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?


Thu Apr 14, 2016 10:57 am
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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.


Thu Apr 14, 2016 12:45 pm
Profile
Rookie

Joined: Fri May 27, 2016 9:38 am
Posts: 1
Post 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);


}}


Fri May 27, 2016 9:52 am
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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.


Fri May 27, 2016 12:09 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.