Default obstacle avoidance smarter and funnier after fix in the firmware code


#1

Hello!
A couple of days ago, after we assembled and powered on mBot, I noticed it worked very well. In particular, in avoiding obstacles mode, it could spot obstacles at a good distance (about 50 cm) and it seemed to be able to make little direction adjustments to find a new clear path. Only when it got stuck it made larger turns. That seemed a smart behaviour and I was fun!
However, I must admit it seemed to run slow in “follow the line” mode, and I wondered how I could make it faster.

Then, I tried a couple of times to upload a new “sketch”, but since I wasn’t happy with that and my daughter wished to play with that, I uploaded the default firmware using the “Reset Default Program” function. Since then, however, something changed.

In particular, in “follow the line” mode, mBot lost all its smartness: it can’t spot an obstacle until about the last 5 cm, and when it does, it always makes kind of 180 degrees turns. No more little frequent direction adjustments, no more distant obstacle spotting… much less fun.
Also, in “follow the line mode” something changed, it is much faster now.

So, I feel like our mBot was shipped with a different “default program” than the default one I’m uploading using the software. I couldn’t test the remote control mode since I haven’t got a battery for that yet, but all the tones and other aspects look like inalterated.

Is this possible? are there different default program versions with such differences? How can I switch between them?

Thank you very much in advance


#2

Hi lanzarro,

Do you remember what is the version of the previous firmware and the version of the current firmware.
The firmware for mBot does update sometimes, when there is a new version firmware, it will replace the old one in mBlock software as well as the one which should be burned in the factory. Normally, the newer the firmware, the better and more stable function it has in total.

If you want to use the previous version firmware, you may try reset default program for the mBot with previous version mBlock softwares have a check.


#3

I guess I found out the problem!

In mbot_factory_firmware.ino inside mblock libraries, lines 63 and 64 declare the same value for “low” and “high” variables used during obstacle avoidance calculations in mode_B function.
As you can see below (where i added the arrow), if low and high values are the same, all the small turns adjustments gets completely skipped. I can’t understand why this was made but it looks like a kind of bug. Changing the high value to a higher number (30-50…) restores the behaviour I liked and makes the obstacle avoidance much more fun and sense.
See below and please let me know.

these are lines 63-64

uint8_t high = 15;
uint8_t low = 15;

and this is the mode_B function

void modeB()
{
uint8_t d = ultr.distanceCm(70);
static long time = millis();
randomSeed(analogRead(6));
uint8_t randNumber = random(2);
if((d > high) || (d == 0))
{
Forward();
}
else if((d > low) && (d < high)) // <-------------------
{
switch (randNumber)
{
case 0:
TurnLeft();
delay(300);
break;
case 1:
TurnRight();
delay(300);
break;
}
}
else
{
switch (randNumber)
{
case 0:
TurnLeft();
delay(800);
break;
case 1:
TurnRight();
delay(800);
break;
}
}
delay(100);
}


#4

Hi lanzarro,

I have consulted our program engineer, this is not a bug on the default firmware.
This modification is base on the requests from part of the users.Different users may have their own preferences.

Since you know very well about the source code of the mBot default firmware, it shouldn’t be difficult for you to modify the program to function as you want.


#5

I understand, but IMHO it’s a pity. Obstacle avoidance is much more interesting and funny when it takes advantage of the complete coding. Also, despite I looked for a solution, I had to dive into the default firmware code to found out how to fix that, so I guess a lot of users just ignore that.
However, I hope this thread will come in handy for someone.

Thank you very much!


#6

Hi lanzarro,

You are a nice man.
Please don’t worry about that since the old version mBlock softwares are still available for downloading.
Any user who like the previous experience on Obstacle avoidance can reset default program for mBot with old version mBlock software too. Though it may be a little annoying by installing different version software, it is still one of workarounds.