Can y'all point me to good sample code for the mbot2 - line follower code


#1

hi, i have good code for the mbot v1 line follow, but for the mbot2, with the quad sensor, id like to see sample code for the following, if you can point me there.
THANKS AS ALWAYS!

mbot2 - line follower code
mbot2 - obstacle avoidance code

thanks
marc

also, im still unsure about how to pair each mbot2 with an mbot bluetooth controller, it works fine for the 1 mbot2/controller i tested… but were getting 5 more controllers next week… how do we ‘assign’ a controller bluetooth connection to a specific mbot2?

i remember with the old mbot v1, it was i/r controllers and each kinda paired with its mbot…


#2

Hi @magicmarc, not sure if there is an online resource for this already, but I’ll make a code later this week and send it!

I think @CommandeR might be able to help with the Bluetooth controller.


#3

thank you, yes, i used to know the easy line follow for the iold mbot v1, but the new line sensor has me confused, and the sample code mbot has in their library is even more confusing… the code part for the sensor at least…
thank you.
my students are very disengaged, thus i try to make the programs as stripped down and basic for them to learn the workslow steps in the code.
m


#4

Hi @magicmarc

Add the mBot Neo device on https://ide.mblock.cc or mBlock PC and use this code:

It works for me. :slight_smile: I use a thick black line on a white paper.


#5

Here’s another resource you might find useful:


#6

thank you, ill try this today, later.
mm


#7

hi, yes i tried withthe track from mbot, the figure 8 and the newer version the color track, and it didnt work, im going to try a thicker black lije using tape.
the old mbot v1 was so easy to figure out, this new mbo2 and the quad and the bluetooth, are hard for me for some reason, i wish there were a hands on class for teachers here locally, or a projects book for the mbot2 available.
m


#8

@magicmarc
The code works fine for me. Try a few things to make sure it’s not a sensor issue:

  • Make sure the paper is on a light color surface, not a dark one
  • Put the sensor over a black paper and a white paper. The small blue lights on the top of the sensor should light up on a white surface and not light up on a black one.
  • Push and hold the button on the bottom of the sensor to change the emitted color (sometimes a yellow emitted color works best and sometimes the red one)
  • Don’t do the line following in a really bright environment

#9

ill check it out, i was using the figure-8 track from the mbot v1


#10

:+1: Let me know how it turns out.


#11

this is the line follow example code from the mblock,
https://support.makeblock.com/hc/en-us/articles/6566809702167-Case-32-mBot-Neo-Follows-Lines

the part about the kp * sensor * deviation, etc… is too confusing… isnt there a simpler way to (like the old version) to just say if quad sensor l1 is this and sensor r1 is this, then do this.


#12

@magicmarc I’m curious why my code isn’t working for you; it works perfectly for me.

Anyway, the code on the link you sent is fairly easy to understand once you study it a bit. :sweat_smile:

  • The quad RGB sensor deviation returns a value from -100 to 100. A positive value means the robot is veering to the left of the line; negative means it is veering to the right (I had to write that out a few times, hopefully I didn’t get them reversed). 0 means the robot is perfectly on the line.
  • The base_power variable is the speed at which the robot moves when it is perfectly on the line. In the example, the robot will move at 30% power.
  • The kp variable is a proportional constant. Basically, if the kp value is higher, the robot will respond more sensitively to veering from the line; if it is lower, it will be less sensitive.

You should give their code a try. :slight_smile:


#13

thata makes sense now that you explain the deviation , in the old version it would just return the code 0, 1, 2, or 3, on, left, right, off, so it he dev is below 0, we tell the motors to turn more left to get back to zero, etc…
ill give a try, we have light day today for students.
m
thank you


#14

:+1:
Let me know how it goes and if you need anything else!