SamuKata
Pybricks
Pybricks

patreon


Line following with StarterBot - Boost Edition

You can follow the upcoming Pybricks Learn guide with any platform, so I'll include instructions for several versions of the StarterBot.

While I was designing and testing the StarterBot variant for the BOOST set, I thought it would be nice to share this line following demo. This is known as a "proportional controller". The more the reflection value differs from the average (50%), the more it steers.

Naturally, you can make this with SPIKE too. You'll learn more about how this works when we complete chapter 7 about the color sensor.

 

Comments

That looks great! Thank you for sharing the end result. And good idea about timing the transitions to the same colors: Even if the segments look equally wide, the sensor may see one color "wider" than the other, due to the threshold between the colors. Waiting for the next transition to the same color solves that problem indeed.

Laurens Valk

I'm not sure if this is the best place, but wanted to give a little feedback. I always appreciate your prompt and helpful replies. A+ I ended up with something that actually uses the time between the two white segments rather than between the white and black segments. Could be because I did not define black but using it gave unpredictable results.  Once I converted to white, pause until black then look for white again - and the results were excellent as expected. I added an averaging section expecting the results to be more varying (esp because of the initial results) which is probably not necessary. I have a short video and a link to the code on a Rebrickable workbench post. Improvements always welcome, also feel free to use if it helps others. Thanks again. https://rebrickable.com/users/andybell/workbench/11882/

Alexander Bell

Here's one way to do it: - Make a counter variable, start at 0. - Wait until the sensor sees black. - Increment counter. - Wait until the sensor sees white. - Increment counter. - Your counter is a measure of position. - You could divide difference in position by the difference in time between two count values. Either the most recent one, or an older one you keep in a variable. This is a measure for speed.

Laurens Valk

I have been thinking about... finding the RPM with color/light sensor and the Technic, Disk 3 x 3 with 2 Black Opposing Sections Pattern. I certainly can Id the colors but unclear on how often they the sensor sends results and how to leverage that into time and rotation. Has this been done somewhere? (I know the "smart" motors have rotational control but thinking of using as a 'check' or with PF motors. Thanks for your help.

Alexander Bell


More Creators