View unanswered posts | View active topics It is currently Sun Oct 21, 2018 8:49 am






Reply to topic  [ 2 posts ] 
Problems with natural language and EV3 
Author Message
Rookie

Joined: Fri Apr 26, 2013 11:05 am
Posts: 39
Post Problems with natural language and EV3
I am new to using natural language with the EV3 robot. I have used text-based code for several years with the NXT.

I have found the online version of the text-based curriculum for RobotC and how to use natural language. The problem we are having is with detecting certain colors. I have four different color pieces of tape on a white table. The students have to have their robot detect which color their robot runs over and then perform a command to move towards the next piece of tape on the table. I am pasting the code we have written:

#pragma config(StandardModel, "EV3_REMBOT")
#pragma config(RenamedStdModelMotor, motorB, left)
#pragma config(RenamedStdModelMotor, motorC, right)
#pragma config(RenamedStdModelSensor, S3, light)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
clearTimer(T1);
while(time1[T1] < 10000) // while the time is less than 10 seconds
{
if(getColorName(light) == colorWhite) // if the color is white, move forward at 25% power
{
motor[left] = 25;
motor[right] = 25;
}

if(getColorName(light) == colorRed) // if the color is red, turn left for 90 wheel degrees at 25% power
{
turnLeft( 90, degrees, 25 );

}
if ( getColorName(light) == colorYellow) // if the color is yellow, turn right for 270 wheel degrees at 25% power

{
turnRight ( 270, degrees, 25) ;
}

if ( getColorName(light) == colorBlue) // if the color is blue, turn left for 180 wheel degrees at 25% power

{
turnLeft ( 180, degrees, 25) ;
}

}

The problem we are having is that the robot will detect the white table and move forward. The program then moves to the second block of code and will detect that color ONLY IF there are no other blocks of code written below it. If we have the third block, where it is detecting some other color, in this case, yellow, the robot will make a right hand turn, instead of left when it sees red. We have changed multiple variables, one at a time, in order to narrow down the problem with no luck. Any ideas? Thanks!


Thu Apr 05, 2018 11:05 am
Profile
Rookie

Joined: Thu Sep 25, 2014 8:34 pm
Posts: 23
Post Re: Problems with natural language and EV3
I would suggest that after each turn, add a wait().

Example:

if(...detected color...) {
turnLeft( 90, degrees, 25 );
wait(4);
}
if(...detected next color...) {
turnRight( 270, degrees, 25 );
wait(4);
}

Give that a try and see what happens.

Sometimes I will use the writeDebugStreamLine() function to monitor the program through a streaming debug window.
I would, for example, use:

writeDebugStreamLine("I am driving Forward") ;
if(...detected color...) {
turnLeft( 90, degrees, 25 );
writeDebugStreamLine("Now I am turning Left") ;
wait(4);
}
if(...detected next color...) {
turnRight( 270, degrees, 25 );
writeDebugStreamLine("Now I am turning Right") ;
wait(4);
}

And finally, have you tried adding breakpoints to stop the program in mid function?


Fri Apr 06, 2018 11:48 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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:  
cron



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