Hi,
All I’m trying to do is get the robot to run forward if it is placed on a black line. Then, if it encounters another black line to stop (like a start and finish line). Any suggestions??
Hi,
All I’m trying to do is get the robot to run forward if it is placed on a black line. Then, if it encounters another black line to stop (like a start and finish line). Any suggestions??
I’ve tried doing “If variable (line sensor) is less than 3, then run forward at speed 100, else run forward at zero” then “wait until variable is equal to 3” then run forward at speed 100 then “if variable less than 3, run forward at 0”.
Then I’ve tried embedding the “If variable (line sensor) is less than 3, then run forward at speed 100, else run forward at zero” in a repeat once statement then doing the “If variable = 3 then run forward at speed 100, else run forward at 0”.
I’ve tried several other things too. I’m fairly new at this, so any suggestions would help!
Hmm, so I’ll need the following information;
I’m using the Mac operating system, I have the bot v1.1, make block 3.4.11 version, line following sensor, I want to continually execute the code.
So let’s think about the logic first and write that out as pseudo-code:
The wait until a black line is not detected is required so that the program will have a “fresh” state with regard to having seen a black line. This could be accomplish through the use of a state variable as well, but it is not really necessary if the program only needs to go when a black line is detected and keep going until another one is detected.
Take a stab at implement that logic using a wait-until and see if you can make it go.
Hi,
The values for the line following sensor are:
Value | Description |
---|---|
0 | Both sensors over a line (detecting black) |
1 | Left sensor over a line (detecting black), right sensor off line (not detecting black) |
2 | Right sensor over a line (detecting black), left sensor off line (not detecting black) |
3 | Both sensors are off of the line (not detecting black) |
Remember that that line following module has two sensors that are multiplexed, hence the reason for the values 0-3.
The logic for the code might be structured as:
mBot Program
Wait until (line follower [port]) < 3)
Run forward at speed 100
Wait 1 second
Repeat until line follower [port] < 3
Run forward at speed 0
In this implementation you would not need the forever loop because the mBot will wait until it detects a black line before it starts moving. While a 1 second pause might be too long depending on how far apart the black lines are, that can be adjusted. The important thing is that it allows the mBot time to move off of the original black line. I’ve used an empty repeat-until loop that waits until the line follow detects another black line followed by having the mBot stop when a black line is detected. Note that the above accepts a detection of the black line on either or both of the sensors.
In your second code example,the value of linev can never be greater than 3 so the program is actually working correctly by stopping after 1 second.
Hope this helps.
Chuck
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.