mBot gets stuck partway through code


#1

We have a number of mBots at a school. We have on-going issues with the mBots stopping partway through executing code. This occurs with the PC/Cable or via the Android tablets.

As an example, a looped code using the Ultrasonic sensor to get the mBot to turn. You can watch the code cycle through on the Android tablet a few times, then it will get stuck randomly somewhere in the code.

The only common element I can find in the codes that have issues is the use of the time function (“wait X seconds”).

We have updated to latest Firmware, doesn’t seem to make a difference.

Cheers

Jon


#2

Hi Nohair3,

Could you paste your example code here. Do you upgrade firmware for mBots with mBlock 3.4.9 and control it with Makeblock APP 3.0?


#3

this is the code we are using:

#include Arduino.h
#include Wire.h
#include SoftwareSerial.h
#include MeMCore.h

MeDCMotor motor_9(9);
MeDCMotor motor_10(10);
void move(int direction, int speed)
{
int leftSpeed = 0;
int rightSpeed = 0;
if(direction == 1){
leftSpeed = speed;
rightSpeed = speed;
}else if(direction == 2){
leftSpeed = -speed;
rightSpeed = -speed;
}else if(direction == 3){
leftSpeed = -speed;
rightSpeed = speed;
}else if(direction == 4){
leftSpeed = speed;
rightSpeed = -speed;
}
motor_9.run((9)==M1?-(leftSpeed):(leftSpeed));
motor_10.run((10)==M1?-(rightSpeed):(rightSpeed));
}
double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
void stoop();
void right();
void left();
void furword();
void backward();
double tiome;
Servo servo_4_1;
MePort port_4(4);
Servo servo_4_2;

void stoop()
{
motor_9.run((9)==M1?-(0):(0));
motor_10.run((10)==M1?-(0):(0));
}

void right()
{
motor_9.run((9)==M1?-(150):(150));
motor_10.run((10)==M1?-(0):(0));
}

void left()
{
motor_9.run((9)==M1?-(0):(0));
motor_10.run((10)==M1?-(150):(150));
}

void furword()
{
motor_9.run((9)==M1?-(150):(150));
motor_10.run((10)==M1?-(150):(150));
}

void backward()
{
motor_9.run((9)==M1?-(-150):(-150));
motor_10.run((10)==M1?-(-150):(-150));
}

void setup(){
servo_4_1.attach(port_4.pin1());
servo_4_2.attach(port_4.pin2());
tiome = 0.5;
_delay(15);
}

void loop(){
furword();
_delay(tiome);
stoop();
_delay(tiome);
servo_4_1.write(0);
servo_4_2.write(180);
furword();
_delay(tiome);
stoop();
_delay(tiome);
servo_4_1.write(45);
servo_4_2.write(135);
furword();
_delay(tiome);
stoop();
_delay(tiome);
servo_4_1.write(90);
servo_4_2.write(90);
furword();
_delay(tiome);
stoop();
_delay(tiome);
servo_4_1.write(135);
servo_4_2.write(45);
furword();
_delay(tiome);
stoop();
_delay(tiome);
servo_4_1.write(180);
servo_4_2.write(0);
right();
_delay(tiome);
left();
_delay(tiome);
right();
_delay(tiome);
stoop();
_delay(tiome);
servo_4_1.write(180);
servo_4_2.write(0);
right();
_delay(tiome);
left();
_delay(tiome);
right();
_delay(tiome);
stoop();
servo_4_1.write(180);
servo_4_2.write(0);
right();
_delay(tiome);
left();
_delay(tiome);
right();
_delay(tiome);
stoop();
_delay(tiome);
servo_4_1.write(180);
servo_4_2.write(0);
right();
_delay(tiome);
left();
_delay(tiome);
right();
_delay(tiome);
stoop();
_delay(tiome);
_delay(30);
_loop();
}

void _delay(float seconds){
long endTime = millis() + seconds * 1000;
while(millis() < endTime)_loop();
}

void _loop(){
}


#4

Hi Nohair3,

Do you program for mBot with Arduino software or mBlock software?
If you use mBlock software, What is your mBlock graphical program which generated above arduino code?

If you program it with Arduino software directly, the code you pasted can’t pass through the compiling, you may need to double check your arduino program.


#5

Hi,

The program was created with mBlock software, V3.4.9.

Thanks

Jon


#6

Hi Jon,

Please try the latest version mBlock 3.4.10.
Besides, I may suspect if there is any problem on your program. Once still the issue with mBlock 3.4.1, please take a picture to show your original Graphical program.


#7