mBot always turns right in wall avoidance mode?


#1

Just playing with a new mBot, and noticed that in the wall avoidance mode (“Unmaned” mode on Android controller), the robot always turns right when it nears an obstacle, but never left or backwards. When I look at the source code for the default program (https://github.com/Makeblock-official/mBot/blob/master/mBot-default-program/mBot-default-program.ino), this doesn’t seem to be the desired behavior. It’s still like this after I used “Reset default program” in mBlock. Any idea if this Is a software or a hardware problem?


#2

If the code block below is what you are referring to, it may be the ‘random’ generator’. It is initialized by reading an ‘unused’ analog pin (6 in this case). The range is only 1 or 0 so they can use a ‘case’ statement.

You might try changing the analog read pin, or mess with the code:

uint8_t randNumber = random(100); //random range 1-100

and replace the Switch/Case with an If-Then

if (randNumber <= 50){
TurnLeft();
delay(200);
}
else{
TurnRight();
delay(200);
}

randomSeed(analogRead(6));
** uint8_t randNumber = random(2);**
** if (d > 15 || d == 0)Forward();**
** else if (d > 10) {**
** switch (randNumber)**
** {**
** case 0:**
** TurnLeft();**
** delay(200);**
** break;**
** case 1:**
** TurnRight();**
** delay(200);**
** break;**
** }**
** }**


#3

Thanks, but unfortunately after trying to upload some changes using the Arduino IDE I now seem to have lost both the avoidance mode and line follower functions entirely. The avoidance mode now just plows straight ahead without any sensor reading. Sensors work when I test them in Scratch. I checked the wiring and tried to get back to the original state by using “Upgrade firmware” and “Reset default program” in mBlock 3.2.2, but no change. Frustrating.


#4

Ok, I guess I confused the issue since I’m using the Android and iOS Bluetooth controllers (haven’t gotten around to getting a battery for the IR controller!), and I just realized that these apps do not seem to be using the firmware functions at all. The iOS avoidance mode is the one turning to the right, while the android avoidance mode isn’t working for me at all. On the other hand, the iOS app doesn’t seem to operate the lights, but the Android app does. So maybe the apps are just buggy…


#5

Arduino IDE has a feature where is saves (automatically) the program when you compile or upload. So you may have overwritten the program with your changes. Best to re-download and replace in your files.

Speaking of that default program, it is rather ambitious. It is doing many different functions and modes. It may be best to start with a program which only does the avoidance with the IR.
That has been written and there are a few different examples here.


#6

Now that I’ve found a battery to use in the infrared controller, I’ve found that the programs (wall avoidance and line follower) work as expected. So the firmware works ok after all. I guess I didn’t realize that for the Bluetooth controllers, the program logic is entirely in the app, not the firmware. So the Android app is not entirely working right - controls work fine but wall avoidance isn’t working at all. For the iPad, wall avoidance works but the mBot only turns right, never left.


#7