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

Problems with natural language and EV3
http://www.robotc.net/forums/viewtopic.php?f=1&t=19582
Page 1 of 1

Author:  Korndog [ Thu Apr 05, 2018 11:05 am ]
Post subject:  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!

Author:  jkandra [ Fri Apr 06, 2018 11:48 am ]
Post subject:  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?

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