View unanswered posts | View active topics It is currently Wed Aug 27, 2014 5:40 am






Reply to topic  [ 3 posts ] 
**Error**: Internal failure in expression evaluation... 
Author Message
Rookie

Joined: Wed Oct 17, 2012 11:15 am
Posts: 4
Post **Error**: Internal failure in expression evaluation...
Can anyone tell me what this error msg is:
**Error**: Internal failure in expression for 'untilTouch(bump)'

Natural language code:
pragma config(Sensor, dgtl2, bump, sensorTouch)
#pragma config(Motor, port2, motor1, tmotorVex269, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main ()
{
if (untilTouch(bump))
{
stopMotor(motor1);
}
}


Thu Oct 18, 2012 10:57 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: **Error**: Internal failure in expression evaluation...
Well first of all, why are you using "if(untilTouch(bump))"? The return type of untilTouch is void. That expression doesn't really make any sense. What are you trying to accomplish?

_________________
sudo rm -rf /


Thu Oct 18, 2012 12:01 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 565
Post Re: **Error**: Internal failure in expression evaluation...
OldManScoots wrote:
Can anyone tell me what this error msg is:
**Error**: Internal failure in expression for 'untilTouch(bump)'

Natural language code:
pragma config(Sensor, dgtl2, bump, sensorTouch)
#pragma config(Motor, port2, motor1, tmotorVex269, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main ()
{
if (untilTouch(bump))
{
stopMotor(motor1);
}
}


Magicode is absolutely correct, the issue is that you are using untilTouch(bump) as a condition for the if statement. When we break the two pieces of code down, we see that:

The 'If' statement check to see 'if' the condition(s) inside of its parentheses is true (or, a logic '1' value). If the condition evaluates to true (does 1 == 1? Yes, so that would be a true statement and return a value of 1. Does 2 == 1? No, so the condition is false and returns a 0) the code inside of the if statement's curly braces will execute. In this case, it is the stopMotor(motor1); command. If the condition is false, the program flow picks up at the end of the if statement (the closing brace).

The untilTouch(bump) statement is a bit different. It halts the program flow 'until' the 'bump' sensor is 'touch'ed. When the bump sensor is touched, the program flow will continue past the untilTouch(bump) statement. The untilTouch command monitors a sensor (in this case, the sensor named 'bump') and does not return a value when the sensor gives the value of 1.

So the problem is that the code is actually executing something like this: 'Does nothing?'. Since the untilTouch command does not return a value, the if statement has nothing to compare it to and therefore does not work.

To check a sensor value in an if statement, you will have to use the SensorValue[] command. This tells ROBOTC to check the value of the specified sensor (in this case, 'bump') for a value.

Code:
if (SensorValue[bump] == 1)
 {
   stopMotor(motor1);
 }


This will check the value returned by the touch sensor named 'bump' and, if it is a 1, will stop motor1. Note that while touch sensors are switches and will only return a 0 or a 1 depending on their state, other sensors can return a wider range of values (depending on the sensor). You can still use the if statement to check their values, though, but may need to change the '1' to a more appropriate value.

I suggest taking a look at our Natural Language resources that covers all of the Natural Language commands. Also, check out our Natural Language (for Cortex) section on our wiki, which is a superb reference tool: http://www.robotc.net/wiki/VEX2_Natural_Language

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Thu Oct 18, 2012 3:00 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.