Mbot ranger bug


#1

I am trying to adjust the right motor speed and by an increment counter (search), as below:

in the setup function:
void setup(){
TCCR1A = _BV(WGM10);
TCCR1B = _BV(CS11) | _BV(WGM12);
TCCR2A = _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS21);
attachInterrupt(Encoder_1.getIntNum(), isr_process_encoder1, RISING);
attachInterrupt(Encoder_2.getIntNum(), isr_process_encoder2, RISING);
search = 30;
while(!(search > 50)){
seg7_6.display(float(search));
// changer the motor power //
Encoder_1.setTarPWM(-1search/100.0255);
Encoder_2.setTarPWM(80/100.0*255);
search += 0.005;
delay (1);

}

}

I increased the right motor power within the while loop by the variable “search”. Therefore the ranger would circling with a growing radius.
Yet in reality, the ranger action is:
1.none of the motor is moving, and wait until the “search” counts to the max, 50,
2.then both of the motors start move as the left one 80% and the right one 50% power.

What happened to the ranger.
ps : an mBot may perform the same action correctly, yet the ranger acts strange.

below is the whole code:

#include <Arduino.h>;
#include <Wire.h>;
#include <SoftwareSerial.h>;
#include <MeAuriga.h>;

double distance;
double obj_dist;
double search;
Me7SegmentDisplay seg7_6(6);
MeEncoderOnBoard Encoder_1(SLOT1);
MeEncoderOnBoard Encoder_2(SLOT2);
void isr_process_encoder1(void)
{
if(digitalRead(Encoder_1.getPortB()) == 0){
Encoder_1.pulsePosMinus();
}else{
Encoder_1.pulsePosPlus();
}
}
void isr_process_encoder2(void)
{
if(digitalRead(Encoder_2.getPortB()) == 0){
Encoder_2.pulsePosMinus();
}else{
Encoder_2.pulsePosPlus();
}
}
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;
}
Encoder_1.setTarPWM(leftSpeed);
Encoder_2.setTarPWM(rightSpeed);
}

void _loop(){
Encoder_1.loop();
Encoder_2.loop();
}
void _delay(float seconds){
long endTime = millis() + seconds * 1000;
while(millis() < endTime)_loop();
}
void setup(){
TCCR1A = _BV(WGM10);
TCCR1B = _BV(CS11) | _BV(WGM12);
TCCR2A = _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS21);
attachInterrupt(Encoder_1.getIntNum(), isr_process_encoder1, RISING);
attachInterrupt(Encoder_2.getIntNum(), isr_process_encoder2, RISING);
search = 40;
while(!(search > 50)){
seg7_6.display(float(search));
Encoder_1.setTarPWM(-1search/100.0255);
Encoder_2.setTarPWM(80/100.0*255);
search += 0.005;
delay (1);

}

}
void loop(){
_loop();

}


#2

ok, I think that it’s the programming issue. Calling the two functions Encoder_1.setTarPWM(-1search/100.0255);
Encoder_2.setTarPWM(80/100.0
255);
in the setup procedure would cause the controller acting strange.
by an unknown reason.

Thanks


#3

Glad to hear that you fixed~


#4

The problem is that such codes might be generated by mblock5 resulting rangers running abnormal. Do we always have to use Arduino C to fix?


#5

Would you show me the graphic codes in mBlock5 that have problem? We’ll have a check and try to improve that.


#6

This is an example.Capture
mBlock version 5.0.0-beta3.1

while the system works, if i do this:ranger_bug1


#7

Now mBlock 5 released beta 5, please update and test again. In my side, both codes work.


#8

Hi,

Beta 5.2 does not make a difference for me. The generated C code and the robot action are the same as 3.1.


#9

How did it run abnormal with the two codes you posted? It works ok when I test the two codes.


#10

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.