Shop OBEX P1 Docs P2 Docs Learn Events
How to use 2 sensor systems in Parallel? — Parallax Forums

How to use 2 sensor systems in Parallel?

McdougellMcdougell Posts: 1
edited 2013-11-18 10:51 in Accessories
Hello! I am a student who is very new to programming of any kind . I am currently working on a boe bot (board of education) project with a team of 2 others where we must enter a competition this December in which we must follow a line around a track and avoid a few obstacles along the way.

We are using a qti line sensor set (4 sensors) to follow the line and the stock IR sensors to avoid the blocks. We have a basic line following program as well as an IR free-roam which starts little routines when it detects IR lights in one of the sensors

How would we go about using both of these together? We want the bot to follow the line until it detects an object and starts the avoid object routine then catch up with the line again. Or if there is a better strategy I'm open to opinions.

Any input would be greatly appreciated.:smile:

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-11-18 10:45
    Welcome to the forums! You will have to study the code for each sensor you plan to use. Learn how they operate and then look at the code logically. When you're running servos, reading sensors and making decisions you have to interleave the tasks. So you'll read your sensors, make you calculations and decisions and then update your servos. You can start by using existing examples and then adding in the new code. If you run into issues you can post that code here and get assistance with the specific issues you're having. A flowchart may make it easier to build the code. I hope this helps.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-11-18 10:51
    You don't really use these separate functions "in parallel". You use them in series ... one at a time. You say "We want the bot to follow the line until it detects an object and starts the avoid object routine, then catch up with the line again". That's more or less what your program needs to do. You start with the line following program which consists of a main loop that looks at the line following sensors and decides what to do based on what they detect. At some point in this loop, usually either the beginning or the end, you add a couple of statements to send out an IR pulse and receive any reflection information. If an obstacle is detected, your program would do a GOTO to another loop elsewhere in your program that handles the object avoidance, but includes a test for the line following sensors. If the line is found again, this 2nd loop jumps back to the 1st loop to continue line following. Your program essentially has two states, each implemented as a loop and the program switches states based on sensor input (look up "state machine" in the Wikipedia).
Sign In or Register to comment.