How do I make my mBot follow a line and avoid an obstacle?


#1

Hi,

Does anybody know as to how I can make my mBot to follow a line and avoid obstacles at the same time. I can do each individually but not together. Any help would be appreciated :slightly_smiling:

Kind Regards


#2

Look at this thread.


This is another example that will also work, but showing LED’s flashing and playing a tune


#3

Realistically, you’ll need to have a loop that checks the line follower sensor followed by a check of the ultrasonic sensor (or vice versa). The mBot doesn’t multi-task per se, but it will execute the instructions in the loop() methods so long as they aren’t blocking. Your code would need to look something like:

mBot Program
    repeat until (some end condition)
        run forward at speed (your speed)
        if line follower = 1      ----+
            turn right slightly       |
        if line follower = 2          +--- This is the line follower code 
            turn left slightly        |
        if line follower = 3          |
            find line            -----+  <--- You'll need to define your strategy for this

        if ultrasonic sensor < (your minimum range)
            avoid obstacle                 <--- You'll need to define your strategy for this.

Hope this helps.


mBot getting around an obstacle
#4

and yet there is an youtube video that shows the example without sharing the code https://www.youtube.com/watch?v=Le57JXARfSQ


#5

Check this tutorial 2-in-1 mBot: Line Follower and Object Avoidance http://openlab.makeblock.com/topic/56e38e5660a70d5c503f7fce Source code is provided.


#6

The link to the article containing the source is in the comments. See here. :slight_smile:


#7

thank you I forgot about the openlab part of the website :slight_smile:


#8

Hi,

I was wondering if you could make the mBot follow the infinity sign that they include when you buy the mBot. Can you make it follow the infinity line on these two apps on the iPad? Makeblock, mBlockly.


#9

I tested the suggested combined line follower and obstacle avoidance sketch (C++) on my mBOT and it worked, however I would like to see it in SCRATCH.
The SCRATCH tutorial for this leaves a chalenge to combine these two reactions, however the osbstacle avoidance part is a simple STOP which is NOT really ancomplete reaction

Arick
Fleur@inter.net.il


#10