When use "Timer"feature, the mBlock 3.4.5 something wrong


#1

Hi,

I use “timer” feature.
But the new mBlock(v3.4.5) seems something wrong.
When I use “timer”, it seems to affect the result of the next building block.

The below is my test platform.
OS: Win7 x64
mBlock: v3.4.5 and v3.4.3_re2
Hardware: Arduino uno
The Pin9 does not need to connect anything or device.

At mBlock, v3.4.5 or v3.4.4,
When I click start, the “Count” has been accumulated.
But the “Count” should be 0. Because Pin9 don’t connect anything,

At mBlock, v3.4.3 re2,
The “Count” always is 0.

The TimerTest_ng.sb2 (73.0 KB)


Timer compiler error, mBlock 3.4.9
Upload to Arduino Failed, when I use both "timer" and "read ultrasonic sensor"
#2

Hi,

And I find the time unit of the arduino.js and mbot.js seems to be different.
The time unit of the arduino.js looks like millisecond, but the mbot.js is second.

arduino.js

ext.resetTimer = function(){
	startTimer = new Date().getTime();          <-- Here
	responseValue();
};

ext.getTimer = function(nextID){
	if(startTimer==0){
		startTimer = new Date().getTime();   <-- Here
	}
	responseValue(nextID,new Date().getTime()-startTimer);    <-- And, here
}

mbot.js

ext.resetTimer = function(){
	startTimer = (new Date().getTime())/1000.0;
	responseValue();
};

ext.getTimer = function(nextID){
	if(startTimer==0){
		startTimer = (new Date().getTime())/1000.0;
	}
	responseValue(nextID,(new Date().getTime())/1000.0-startTimer);
}

#3

Hi wpopoily,

We have verified the issue between the timer and read digital pin block.
Have added it to the repair list. Thanks for your feedback.


#4

HI,

I try the latest mblock v3.4.6. The two problem seems unresolved.
Could I know when the mblock team can fix them? Thank you.


#5

Hi wpopoily,

Yes, the mBlock 3.4.6 hasn’t fixed this issue since this version had been finished test before we received this feedback.
Please keep an eye on our newer version mBlock software.


#6

Just installed 3.4.9 and the issue seems to be unresolved…mBot code is still specified in seconds, no ms.
More importantly, compiling in 3.4.9 is broken due to currentTime and lastTime variables getting defined twice.


#7

Weird, I see the same code gen error in 3.4.9 on the Mac. However, on 3.4.8 I get the following code generated from your program:

#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;
double currentTime = 0;
double lastTime = 0;
double getLastTime(){
    return currentTime = millis()/1000.0 - lastTime;
}

void setup(){
    pinMode(A7,INPUT);
    while(!((0^(analogRead(A7)>10?0:1))))
    {
       _loop();
    }
    lastTime = millis()/1000.0;
}

void loop(){
    if((getLastTime()) < (6000)){
        move(1,255);
    }else{
        move(1,0);
    }
    _loop();
}

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

void _loop(){
}

I’m not seeing a redefinition for currentTime or lastTime so the bug was apparently fixed in 3.4.8 and then re-broken in 3.4.9. Also, note that tin the getLastTime() method that the time is being converted to seconds by dividing the return value of the millis() method by 1000. I suspect this is done as a convenience for younger audiences.


#8

Right, forgot to mention this is on OSX. And yes, my students running 3.4.8 don’t have the compiler error. It would be great if there was a quick patch for that, otherwise I have to make sure they don’t install the update. @tec_support

By the way @chuckmcknight we are using your gentle introduction and it’s working out great, thanks!


#9

I’m very happy to hear that the book works for you and your students. I’m also working on the second volume that focuses on the mBot and Arduino programming now with a target publishing date of next Spring (earlier if I get done sooner).

I’m not sure whether the mBlock team (who are working on 4.0 right now) will have a lot of bandwidth to do things on 3.x, but let’s hope for the best (and hold off on the upgrade to 3.4.9). :slight_smile:


#10

Hi Gmo,

For the previous issue between the timer and read digital pin block, this is solved on mBlock 4.0, please kindly wait for its official version.

As for the new issue you put forward, our engineers have verified it and record this in the repair list, thanks for your feedback!