Line Following Help

OpenMV related project discussion.
rescueops
Posts: 8
Joined: Thu Dec 29, 2016 4:54 pm

Line Following Help

Postby rescueops » Thu Dec 29, 2016 5:06 pm

So I followed the line following script and got it to follow a straight black line. But how do I go about coding it to tell it to stop of it doesn't see a black line anymore or to following the line if it curves or goes in like a track shape.
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Line Following Help

Postby kwagyeman » Thu Dec 29, 2016 5:19 pm

Hi, the line following script should output a turn angle that you can use to turn robot to say on the line. That said, making a robot in the real world requires tuning control parameters. So, for example, the line following script outputs a turn angle that tells the motors how much to turn. But, the script doesn't define how much power that turn angle translates into. You have to provide some type of multiplier to the turn angle output to convert that into a motor power number. Usually, you do something like a PID loop. Here's a good discussion on PID theory: http://learn.parallax.com/tutorials/lan ... id-control.

As stopping if the robot doesn't see the line. I guess you could just check if the middle region doesn't see anything and stop then.
Nyamekye,
rescueops
Posts: 8
Joined: Thu Dec 29, 2016 4:54 pm

Re: Line Following Help

Postby rescueops » Sat Dec 31, 2016 5:22 pm

kwagyeman wrote:Hi, the line following script should output a turn angle that you can use to turn robot to say on the line. That said, making a robot in the real world requires tuning control parameters. So, for example, the line following script outputs a turn angle that tells the motors how much to turn. But, the script doesn't define how much power that turn angle translates into. You have to provide some type of multiplier to the turn angle output to convert that into a motor power number. Usually, you do something like a PID loop. Here's a good discussion on PID theory: http://learn.parallax.com/tutorials/lan ... id-control.

As stopping if the robot doesn't see the line. I guess you could just check if the middle region doesn't see anything and stop then.
So I went around what you were saying this is what I have worked out so far I posted on github https://github.com/E-V-G-N/OpenMV-Line- ... %20V%201.0

So it goes through process correctly and will follow the line like it should but when it see's a stop line "biggest blob" it will not stop it just twitches out. I want it to fully stop if it see's the largest blob or turn around and go back to start
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Line Following Help

Postby kwagyeman » Sun Jan 01, 2017 1:14 pm

Okay, so, can you explain to be what's the large blob look like?

The easiest thing to do is to just check the number of pixels in the largest blob and if that goes over a threshold you stop.

...

From your script it looks like you enter an infinite loop doing check_stop.

Code: Select all

check_stop()
    while check_stop() == True:
        check_stop()
Writing the code like that will stop driving the motors anymore. So... I guess the goal then was to just stop and spin if you see the stop marker? Okay...

Do this instead then:

Code: Select all

while check_stop():
        pass
The pass statement is an empty line of code you have to use for python.

As for this:

Code: Select all

def check_stop():
    GRAYSCALE_THRESHOLD = [(0, 64)]
    stopROI = [(0, 000, 160,20)]
    blobs = img.find_blobs(GRAYSCALE_THRESHOLD, stopROI)
    merged_blobs = img.find_markers(blobs)
    if merged_blobs:
        # Find the index of the blob with the most pixels.
        most_pixels = 0
        largest_blob = 0
        for i in range(len(merged_blobs)):
            if merged_blobs[i][4] > most_pixels:
                most_pixels = merged_blobs[i][4] # [4] is pixels.
                largest_blob = i
            if merged_blobs[largest_blob][2] > 80:
                # Draw a rect around the blob.
                img.draw_rectangle(merged_blobs[largest_blob][0:4]) # rect
                img.draw_cross(merged_blobs[largest_blob][5], # cx
                               merged_blobs[largest_blob][6]) # cy
                sl.speed(0)
                sr.speed(0)
                print("false")
                return True
So, the ROI is not being passed correctly. You have to say "roi="

Code: Select all

def check_stop():
    GRAYSCALE_THRESHOLD = [(0, 64)]
    stopROI = (0, 000, 160,20)
    blobs = img.find_blobs(GRAYSCALE_THRESHOLD, roi=stopROI)
    merged_blobs = img.find_markers(blobs)
    if merged_blobs:
        # Find the index of the blob with the most pixels.
        most_pixels = 0
        largest_blob = 0
        large_blob_found = False
        for i in range(len(merged_blobs)):
            if merged_blobs[i][4] > most_pixels:
                most_pixels = merged_blobs[i][4] # [4] is pixels.
                largest_blob = i
                large_blob_found = True
        if large_blob_found and (merged_blobs[largest_blob][4] > 80): # pixels threshold for triggering
            # Draw a rect around the blob.
            img.draw_rectangle(merged_blobs[largest_blob][0:4]) # rect
            img.draw_cross(merged_blobs[largest_blob][5], # cx
                                    merged_blobs[largest_blob][6]) # cy
            sl.speed(0)
            sr.speed(0)
            print("false")
            return True
I think all this should fix your issues.
Nyamekye,
rescueops
Posts: 8
Joined: Thu Dec 29, 2016 4:54 pm

Re: Line Following Help

Postby rescueops » Sun Jan 01, 2017 2:16 pm

Hello,

Thank you very much for viewing over the code. Yes so you want to know what the largest blob is? The largest blob is a thick black line the runs horizontally at the end of a vertical line. I did this using black electrical tape is the line, So the robot follows the line keeps driving until it reaches the end where it see's the horizontal line kind of like a stop sign line. As per the movement yes we were trying to get the robot to completely stop at the line and turn around to search for smaller line again.
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Line Following Help

Postby kwagyeman » Sun Jan 01, 2017 4:00 pm

Oh, okay, well, the thing to do would be then to just check if you see the large blob like 10 times in a row and if you are stopped. Assuming that is true then just execute some code to spin the robot and then restore normal line following operation.
Nyamekye,

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest