We can Turn Right. We can Turn Left. How do we decide which way to go if there are lines both to the left and to the right. Check out the video.
- 09 Mar 2016
- LEGO MINDSTORMS, LEGO MINDSTORMS EV3
- EV3-G, State machine, Light and Color Sensor, Programming, EV3, FLL
We won't be needing a new state in our State Machine since we can use some of the already developed. But there is a great catch. We must modify the way we calculate in which state we are to make sure both sensors have detected both lines. Only then we can calculate the correct state and behaviour for our robot.
Courses with this episode
The episode is used in the following courses where you can find additional tasks for it to use in class
Use this tasks in you STEM classes:
Tasks description, submission and evaluation are available to subscribed users.
Subscribe now to access the full capacity and get feedback.
In this video we continue with the line following, but this time on a crossed section, we must decide to move right. So the robot comes from this side and when it reaches this section, it must move right.
What we must do in this case is the following. When we have a line both to the left and to the right, we must turn right. State 3 is turning left, state 2 detected with sensor 1 is turning right. And this seems pretty clear. When we detect something on the left we enter state 3, but then if we are detecting something on the right we enter state 2. Sо this program would probably work and we'll turn to the right if we detect with both sensor something. So if we detect a crossed section. Just to make sure we need to add some delay, after the sensor on port 3, the left sensor detect a line we need to make sure that we wait for a very small amount of seconds, before we decide whether the right sensor is detecting something. For this I'll add a very small delay, that's like 0,05 seconds, just to make sure that the right sensor had enough time to move and to detect a black line. Download and run. We start the program from here, just close to the section.
And we turn right. Let's start the robot from here.
Now the delay was not very much and what happened is that we actually turned left. Let's try to repeat the behavior.
Again. we turn left. What happens is that the robot approaches the line in the following way. It's not aligned to the section and the left sensor detects a line to the left, so it decide to turn to the left. What we must do is somehow stop this and detect the black line on the right. Let's try to increase this constant that we are using for waiting. After increasing the value to waiting for 0.1 seconds. This is the result of our program. We follow, we detect a gap, we turn right, we detect another gap and then we continue forward.
So on this section we turn right, which is the desired behavior. In the next video we'll try to run this whole program on the larger field, but before that, we have one more case to look at.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons