Linear Regression Line Following

OpenMV related project discussion.
tedmeyers
Posts: 12
Joined: Sat Jul 02, 2016 4:32 pm

Linear Regression Line Following

Postby tedmeyers » Sat Jul 08, 2017 6:17 pm

Hi Kwabena!

I'm looking for the Linear Regression Line Following code that you recently demo'd on youtube. I'm interested in trying to build my own line following bot; it looks like a really cool project. I don't yet have one of the new M7 cameras, just the M4 v2 camera, so hopefully it will work on that?

Thanks,

Ted
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Linear Regression Line Following

Postby kwagyeman » Sun Jul 09, 2017 12:22 am

The linear regression algorithm works on the OpenMV Cam M4.

The algorithm outputs the line fine, and I tested it in real life and it worked great on the dyi robocars track. However, I'm still working on figuring out how to derive the control loop using it. For example, the line following script I wrote using blob tracking only works as long as the robot stays within +-45 degrees of the line it's tracking. It can't recover if it gets off the line. With linear regression you can find the line anywhere and with any rotation so its a harder to boil all that info down into a single... turn left or right output. But, the benefit is that you can recover if you go off the line.

Anyway, the next race is next week so I should have some good code to post by then.
Nyamekye,
newsilver
Posts: 4
Joined: Wed Jun 14, 2017 3:06 pm

Re: Linear Regression Line Following

Postby newsilver » Tue Jul 11, 2017 9:27 pm

Hi,

If possible in your next code, include the possible to use some colors of line.
Because with diferent colors, is possible to set diferent speeds, danger areas, etc..
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Linear Regression Line Following

Postby kwagyeman » Tue Jul 11, 2017 9:47 pm

The linear regression code has the same threshold interface like find blobs. You pass it some thresholds to use. So, it can easily deal with colored lines.
Nyamekye,
tedmeyers
Posts: 12
Joined: Sat Jul 02, 2016 4:32 pm

Re: Linear Regression Line Following

Postby tedmeyers » Sun Jul 16, 2017 12:34 am

How'd you do in the race? Wish I lived closer and could attend (I'm really into robotics). At least we have the Sparkfun AVC in Colorado!
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Linear Regression Line Following

Postby kwagyeman » Sun Jul 16, 2017 2:08 am

3rd place. Had some throttle switch transmitter problems. Check the YouTube channel for the video. I'm working on a blog post write-up ask we speak.

I'll be at the AVC BTW.
Nyamekye,
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Linear Regression Line Following

Postby kwagyeman » Sun Jul 16, 2017 2:30 pm

Nyamekye,
tedmeyers
Posts: 12
Joined: Sat Jul 02, 2016 4:32 pm

Re: Linear Regression Line Following

Postby tedmeyers » Sun Jul 16, 2017 10:53 pm

Great write-up, thanks! (I'm still studying it, though). I noticed from the video that your car drives consistently outside the road-line, was this on purpose? Could you perhaps bias the line following, so that it drives _inside_ the line?

Anyway, I'm building one, I already have an OpenMV cam hooked up to a small vehicle. My initial attempts at line following have not been very successful, but I have high hopes, once I figure out your code.

Thanks again,

Ted
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Linear Regression Line Following

Postby kwagyeman » Mon Jul 17, 2017 1:16 am

Hi, I'm just following the line on the outside of the road. As for following the inside line... the dotted one is a bit harder to lock onto and I was mainly trying to prove the algorithm. Given my lessons learned I think I can get it to follow the yellow dotted line by just applying a color filter in RGB565 mode.

That said, I'd rather get working a mode where I can do find_lines() on the image and use the left, right, and center dotted line all as support information to drive the robot. Not sure how to combine them but I've determined how to at least use the theta() and rho() output to drive the robot which was the hard part.

Following the yellow line in the center was hard because given the code I posted... If it saw the outside line it would then lock to that because it is the better quality line as far as the robot is concerned. I'm thinking a Kalman filter to reject spontaneously changing lines would help along with doing some color filtering. But, if possible I'd rather solve the problem in grayscale since that's more robust and more general. Color filtering fails so easily.

Anyway, my goal is to make an algorithm that works really well on following an line/edge robustly. For the AVC competition I think I should look at edges,
Nyamekye,
User avatar
dcolemans
Posts: 10
Joined: Fri Aug 25, 2017 9:43 am

Re: Linear Regression Line Following

Postby dcolemans » Fri Sep 22, 2017 5:50 pm

Hi Kwabena,

I'm having pretty good results using your Linear Regression function to follow a single line. For head-to-head racing however, I'd like to be able to see Two lines, and be able to drive down the center (vanishing point perhaps), then move to the side for passing. I think that in the Sept 16th meetup in Oakland your car was indeed driving between the white and the yellow lines. I'm wondering how you did that.

I've tried using Get Lines and saving the strongest two, but it doesn't give nearly as good a result as Linear Regression. I guess I could go with blobs as we've been doing with the Pixy cameras and infer two lines, but surely there's a better way to do this. Your thoughts please?
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Linear Regression Line Following

Postby kwagyeman » Sat Sep 23, 2017 12:35 am

I've been thinking about this issue since I need to solve it for the sparkfun race coming up in october. My basic idea is to do the following:

Code: Select all

img = sensor.snapshot()
lines = img.find_lines
<remove low magnitude lines and horizontal lines>
img.xor(img) # zero image
<draw lines on image - the image will be black with just the lines>
img.get_regression(robust=True)
The robust linear regression of a bunch of vertical lines is still a vertical line. However, the line will be centered on one or the other lines. Not in the middle. So, you can only use the slope. However, you can calculate the centroid of all the lines in the image.

That said, it's far easier just to follow the yellow line in the center and then just change the RHO offset from being the center of the image to the edge of the image. This should solve the problem. If you look in the code there's a place where I'm subtracting half the resolution (horizontal) from rho. Just use a different number there.
Nyamekye,
User avatar
dcolemans
Posts: 10
Joined: Fri Aug 25, 2017 9:43 am

Re: Linear Regression Line Following

Postby dcolemans » Sat Sep 23, 2017 10:38 am

Thanks for your quick reply. I wasn't aware of the Sparkfun race. Is this the one at the Denver Maker Faire? Am I correct in thinking you are entering the Speed Demon category, large figure 8 track with hay bale sides, no painted center line, and OBSTACLES?

One of the difficulties might be seeing past/around the obstacles. I'm running into that trying to overtake another car when we're both following a line.

Your idea of drawing lines on the image interests me. I'll give that a try.
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Linear Regression Line Following

Postby kwagyeman » Sat Sep 23, 2017 6:07 pm

We're just going to hug the wall. We'll use the find lines technique to get the edges of the wall and then use linear regression to follow that. As for obstacles... One of the walls you can follow doesn't have many obstacles.
Nyamekye,
User avatar
dcolemans
Posts: 10
Joined: Fri Aug 25, 2017 9:43 am

Re: Linear Regression Line Following

Postby dcolemans » Sat Sep 23, 2017 10:44 pm

What do you think of the idea of getting a linear regression line on the left half of the image, saving its info, then getting another on the right side? I just had some success with that with two white tape lines about 14 inches apart. When it failed to find both, it just used the one it found. I expect that wider spaced lines would work too if they were visible to the cam.
User avatar
kwagyeman
Posts: 1314
Joined: Sun May 24, 2015 2:10 pm

Re: Linear Regression Line Following

Postby kwagyeman » Sat Sep 23, 2017 10:52 pm

Yeah, that will work too. You could also support higher res then for each side of the image (this is because the linear regression is N^2... so, as long as the number of set pixels are low in a frame it can do more). Not quite sure how to merge the turning results from both sides however. I guess an average of the output of the code I wrote for both sides would suffice.
Nyamekye,
User avatar
dcolemans
Posts: 10
Joined: Fri Aug 25, 2017 9:43 am

Re: Linear Regression Line Following

Postby dcolemans » Sat Sep 23, 2017 11:11 pm

I'm using dumb guy math, just finding the midpoint between x1 Left and x1 right and mapping that against 0 to 80 to an angle from -45 to +45. It works. It's an imprecise science anyway. Sometimes it "cuts the corners" a bit but that just gets you there faster.

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest