The ultrasound block in mbloc returns NULL when I use it outside a loop. It seems to me that the block execution terminates before it haw enough time to read the distance from the Ultrasound module.
Any suggestions are welcomed.
Napoleon Maou
The ultrasound block in mbloc returns NULL when I use it outside a loop. It seems to me that the block execution terminates before it haw enough time to read the distance from the Ultrasound module.
Any suggestions are welcomed.
Napoleon Maou
Show us the arduino code generated and the mblock code you use so we can look at exactly what you are doing. I’m not sure what use there is in having much outside of a loop, outside of initialization code, but I’d like to see your example.
Hello,
I am using the 2.4GHz version of mBot and Mblock 3.0 on Windows 10 and Windows 7.
I want to use the mbot with scratch so I can use it in my scratch programming class so I am not interested in loading the script to the board and running it locally.
The following is the scratch code I use.
Initially I run it on my laptop (windows 10) and the code did not work.
Today I tried the code on my desktop (Windows 7) and initially it worked fine. But after a few tries it stopped working.
The behavior of the mBot is the following.
(1) It stopped moving on a straight line. It turns left. I assume this is a problem with the motors, which is disappointing because I only used it for a few hours but this is a problem I do not care to solve right now.
(2) Sometimes I hear the motors running but the mbot does not move. I assumed that this is a problem with the batteries so I changed them and it seems that the problem is solved. CAN I USE RECHARGEABLE BATTERIES?
(3) When I run the scenarios sometimes it works OK. It tells me the correct distance and it moves forward and when it reaches the obstacle it stops. If I run it again the second time it does not work.
(a) Sometimes it gives me the wrong distance and it does not move. I think that it gives me the same distance it measured the moment it stopped moving. As if the ultrasound sensor stopped working.
(b) Sometimes it gives me the correct distance but it does not move.
In both cases I hear the motors start and stop immediately and the scenarios terminate.
I just tested and it tells me that the distance to the obstacle is 65 cm it starts the motors and it stops them immediately. And the scenarios terminate.
I modified the senario and used the following
The say after the forward at speed 0 told me NULL
If I activate again the loop that tells me the distance the say in that loop tells me the correct distance 65cm.
So the problem seems to be that when the if 5 > ultrasound sensor port 4 distance is executed the distance measured is NULL.
I really have no idea what to do. Any suggestions are welcomed.
Napoleon Maou
Napoleon,
Try something like this.
Mike
mBotUltrasonicTest.sb2 (74.7 KB)
Hello,
Thanks for the reply.
I used your code and I also tried the following
In both cases I got the same problem which is reproducible.
(1) I press the green flag and run the scripts and it works fine
(2) I move the mbot back to the starting position to run them again
(3) I press the green flag to run them again and it stops immediately because the distance it measures is less than 10 (9.5 to 9.86 cm)
(4) I press the green flag and it runs fine
SO it seems that for some reason after it stops the mcore keeps the last value the sensor measured and it returns it the next time I try to get the distance.
I do not use the USB cable. I use the 2.4 GHz connection to control the mbot.
Do you have any problems with the mbot driving on a straight line. It does not move on a straight line even when I hold it on the air so it does not touch the floor, so it must be a problem with the motors or the gearboxes. One of the two motors seems to run slower than the other.
And a last question. Do you know where I can find documentation for the mbot extention blocks? Online or in pdf form.
Thanks again,
Napoleon Maou
Napoleon,
I have had no success resolving the problem in #3 above. I have tried a number of things with inconsistent results.
I have made some progress with the motors though. If you increase the speed setting to 75 or 100, it seems to work better. A speed setting of 50 just does not seem to provide enough power to work as expected.
I hope this helps some.
Mike
My finding is that the motors need to have a power of at least 70 to move forward. Going backwards takes a bit more.
On a side note, what type of batteries are you using? I’m using a 3.7V 2500 maH LiPo, but I’m wondering if the extra weight of the batteries might be playing into the motors being able to get the robot moving.
The input voltage has a LOT to do with the value that will cause the motors to start. At some point the internal resistance will matter but that is more for high stall situations. The power level in the programming is really just a setting for the speed control to use for how much not to reduce the output voltage. Unless there is a step-up voltage circuit in there the most you will get to the motor is the input voltage of the battery. Then as you reduce the power it starts to lower the effective voltage (not really exactly but it uses a PWM to chop up the voltage and the motor sort of sees that as a lower voltage)
So if you start with 6v your bot will go faster than at 3.7v with all other things equal.
Hi Napoleon,
I don’t know what’s going on with your motors but I think I might know what’s the problem with the distance sensor.
I tried the two bits of code shown in the image.
With the first, no success.
I tried to change the port number, to disconnect and connect again the 2.4G and no success, Panda kept saying NULL.
Then I thought it might be the 2 seconds that confused Panda.
I tried the second bit of code shown in the image and it worked!
It could be that Panda gets info from the sensor at a high rate and when he’s got to wait 2 seconds he panics, doesn’t know what to do and goes NULL? Just speculating…
Also, if your ultrasonic sensor is connected to Port3, make sure you have Port3 selected in the scroll-down menu on your sensor block.
Hope this helps!
I’m sort of wondering because I set up my mBot with the 6v battery pack and I’m not seeing significantly different performance with regard to the power. It starts moving very slowly at 50, but not much under that. At a power level of 70, it moves at the same speed as with the 3.7v LiPo. I agree that the input voltage causes the motors to start at a lower power level, but I’ll need to do additional testing to determine whether or not the robot actually goes faster at the same power level setting. It appears to travel the same distance so far, so I’ll post my results when I get a chance to tally them up. Wouldn’t there normally be a step-down circuit to keep the voltage at 5v DC or under since most Arduino-based stuff is aimed at either 3.3VDC or 5VDC?
according to this:
http://wiki.makeblock.cc/index.php?title=Me-Motor_Driver
The DC motor driver will run from 6-12v so I’m not sure how you are getting them to run at all with 3.7v.
I’m guessing you are actually using a 2 or 3 cell LiPo which would be giving 7.4v or 11.1v respectively.
I am magical?
The spec sheet on the battery says it pushes 4.2vdc when fully charged. I bought it from Adafruit at this link. Adafruit doesn’t specify whether or not it is a multi-cell battery, and the spec sheet doesn’t mention it either. The major attraction was the price. It would be really helpful if our friends at Makeblock would list a battery specification and / or sourcing for said same.
it is a single cell. I’d suspect you might have odd issues running the makeblock boards with only that much voltage. Obviously you have something working but there are probably some situations where a motor load or something else that will cause a drop in voltage that the processor or supporting part will cease to work.
Nothing damaging but potentially frustrating.
So here’s the weird part. As I’ve been writing the apps for my class, I have not had any issues out of the 3.7v LiPo. Since the board is custom, I’m wondering if there is a voltage amplifier circuit somewhere that is stepping up the power for the motors or if there is another explanation. :-/
Just another fun day in the asylum!
Good News!
Here is the answer from makeblock in another forum post:
So it looks like the mCore can handle lower voltage than the Orion. I suspect that has a lot to do with the lack of red DC voltage out ports.
You mean I’m not magical?
Seriously though, I had suspected that might be the case. .
hello I’m sorry not good my english.
I have a mbot and I want a project for student but ı dont work ultrasonic sensor.I try all of your writing .Not work.I explorer google .And so not working.Mbot not see distance anything.I hope I tell my problem .Please help me.
#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
MeUltrasonicSensor UltraSensor(PORT_6);
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print("Distance: ");
Serial.print(ultraSensor.distanceCm());
Serial.println("cm");
Serial.print(ultraSensor.distanceInch());
Serial.println("inch");
delay(100);
}