|
Page 1 of 1
|
[ 4 posts ] |
|
Author |
Message |
Korndog
Rookie
Joined: Fri Apr 26, 2013 11:05 am Posts: 39
|
 Looping problem
I am having our students use three different sensors to navigate an obstacle course. They can do it anyway they wish, as long as they use all three sensors at least once. One pair of students are using the touch sensor first, followed by the light sensor (to track a curved line). Everything works fine until the end of the line, as the robot circles around looking for the line. So, I know it is stuck in the loop. I tried to have them insert the "break;" command in the "if-else" loop, but it doesn't seem to work. I also had them try adding a motor stop command set, but all this did was slow the line tracking down to a snails pace. I am pasting their code, with hopes that someone can help us out. Thank you!
task main() { while(SensorValue(touch) < 1) { motor(motorB) = -40; motor(motorC) = -40; }
while(SensorValue(sonar) > 60) { motor(motorB) = 40; motor(motorC) = 40; }
motor(motorB) = -40; motor(motorC) = -40; wait1Msec(700);
motor(motorB) = 40; motor(motorC) = -40; wait1Msec(700);
while(true) { if(SensorValue(light) > 61) { motor(motorB) = 0; motor(motorC) = 40; }
else { motor(motorB) = 40; motor(motorC) = 0; }
}
while(SensorValue(sonar) > 25) { motor(motorB) = 40; motor(motorC) = 40; }
}
|
Tue Apr 22, 2014 8:14 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Looping problem
Since you didn't describe the details of the behavior you are expecting from that code, I can only comment on my understanding on what the code is trying to do: Please describe what you expect the robot to do so we can help you to figure out how to correct it.
|
Wed Apr 23, 2014 2:18 am |
|
 |
Korndog
Rookie
Joined: Fri Apr 26, 2013 11:05 am Posts: 39
|
 Re: Looping problem
Sorry for not providing enough information.
After the robot reaches the end of the line, using the light sensor, we want the robot to go on to the next piece of code. There are more obstacles on this challenge, after the line and these students are planning on using their sonar sensor next.
|
Wed Apr 23, 2014 8:48 am |
|
 |
Korndog
Rookie
Joined: Fri Apr 26, 2013 11:05 am Posts: 39
|
 Re: Looping problem
I think I have figured out why we couldn't get out of the loop with the light sensor. We didn't have another sensor (sonar or touch) for the if-else statement to check against. Once I put a second sensor at the beginning of the if-else loop, which means it would only run if this condition was true, the program would stop and move on to the next command set. Here is how this statement now looks:
while(SensorValue(sonar) > 20) This was the new line of code that we added. { if(SensorValue(light) > 61) { motor(motorB) = 0; motor(motorC) = 40; }
else { motor(motorB) = 40; motor(motorC) = 0; }
}
|
Wed Apr 23, 2014 4:38 pm |
|
|
|
Page 1 of 1
|
[ 4 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
|
|