Create a simple mblock5 block for mbot


#1

Hello,

I have an mbot and I would like to create blocks in mblock5.
I created an account on the online extension builder.

I would like to begin with a simple block to reset the gyroscope of the Me 3-axis Accelerometer and Gyro Sensor in both live and upload modes.

I managed to create an extension for mcore with a ‘Command’ block called “reset gyroscope” that works on upload mode but do nothing in live mode (no error and no effect).

In the extension builder, in Blocks settings, under Upload transcode, I entered :

  • in include section : <MeMCode.h>
  • in declare section : MeGyro gyro;
  • in code section : gyro.begin(); (this is the code in C to reset the gyroscope)

I understand that I must input code in javascript for live mode but I don’t know where to put the code, and what code I should enter. Actually, I don’t really understand what javascript will know about MeGyro or not. I’m used to programming in C but not in javascript.

Would anybody help me please ?
Thank you in advance.

PS : Here is the extension I made : mbot_addons_hh.mext.zip (315.1 KB) (Just remove the .zip extension, I had to rename the file to attach it to my post)


#2

Up ! Please help me to start with this simple block !
I forgot to tell you that it’s aim to drive a Makeblock Me 3-Axis card.


#3

Hi hdrum81,

Thanks for reaching out to us, I’ve forward your question to our team, and we will get back to you in a few days. For now, why not submit your extension for review with available functions, and update it then when we have the solution for you?

Best,

Allen


#4

Hi Allen,

Thank you very much for your reply.
My extension is only at the test-state and this is my very first one. Should I really submit it for review even if there’s only 1 test block ? How should I do ?

Thank you again.
Hervé


#5

Oh, if that’s the case, I would still suggest you just keep the extension unpublished at this time. I thought you have most functions already done with only the live mode not finished.

Please be patient and we will let you know once we find the answer. You might start to develop other functions with the upload mode, if you would like to.

Best,

Allen


#6

OK Allen, thanks again for your reply.

I’ll wait for your answer because I’m not sure I started properly.
Actually, I’ve built an extension only, thinking it would integrate the existing mbot device from Makeblock. Should I have to create my independent mbot device ?
I’ve seen that in my case there is no mention of a live mode handler… only “Other blocks configuration:” with “When block is running (onRun), execute:”

To me, this block is a kind of “Hello World!” step !

Best,
Hervé


#7

Hi hdrum81,

I’m very happy you chose the Extension Builder and started to learn how to develop your own extension.

Yes you could develop the extension based on the existing mBot device. But I’m wondering where you got the extension file, would you mind telling me?

Since right now we only have Arduino device demo provided in the extension builder, like below:

(though you might load this extension into your extension account and do some changes to make your own extension, please modify the extension id when submitting, otherwise the system would not allow you to submit due to the replicated id)

For another question. Yes the “When block is running (onRun), execute:” is equal to the “live mode handler”, thanks for pointing out this confusion since we didn’t realize this difference of words will make it hard for our user to understand. So you mean you did not regard this section for the configuration of the ‘live mode’ for the block?

Best,

Allen


#8

Hi Allen,

Thank you again for your precious help.

I indeed found the mcore.mext file in C:\Users[username]\mblock\exts\temp by searching every mext files. I imported it in my Ext Builder account and it’s very instructive to be able to watch the construction of the original extension. Even if the blocks appear in chinese! However, I didn’t try to create a block in it yet.

By “Should I have to create my independent mbot device?”, I meant do I NEED to create a My Device or can I simply create a My Extension in order to add customized blocks for my son ? But you answered me to use a My Extension with Default Arduino template.

I don’t understand how the javascript code window works.
What the parameters (args, app, device, block) refer to exactly?
How to refer to MeGyro?
Actually, it would really help me if you would give me the code lines to get the same result of gyro.begin() in cpp in Upload transcode.

As I wrote you before, I don’t master javascript but it doesn’t really scare me. However, it’s difficult for me to begin in this particular context.

Subsidiary question:
Why the edit interface of “Universal template” is so different from “Default Arduino template”? (It’s quite destabilizing.)

Best,
Hervé


#9

Hi hdrum81,

That’s a good trick. We rarely have users looking into their software path folder to search for the extension files.

To answer your question on “Should I have to create my independent mbot device”. We should first clarify the difference between device and extension.

Device more refers to a mainboard while device extension refers to sensors or accessories that rely on the mainboard. For example, the Arduino and the LED light. If you’re adding Arduino device, you should develop device in the extension builder; if you’re adding support for the connection and functionality of a LED light on the Arduino, you should write extension and choose the default Arduino template.

For your question on where to find specific API reference on the live mode handler, in fact, we have a full list of API there: https://www.mblock.cc/doc/en/developer-documentation/extension-builder-api.html

I like your enthusiasm on exploring different languages and hope you will be successful in creating an extension with both upload mode and live mode.

Lastly, why we differentiate two templates. Since we have a huge community of Arduino. We want to simplify the creating process and help user finish most of the configurations from the back, so we provided the Arduino Template with clearer interface and less steps. However, the optimization can only be done when this extension is for specific device type. we still allow users to choose the more versatile universal template to create extensions for other hardware and devices, also including the sprite extensions.

Hope this would answer your question.

It might be a few days until we can get back to you with the solution on your initial extension issue, thanks for your patience.

Best,

Allen


#10

Hi Allen,

I hope you had a merry Christmas, if you celebrate it in your country.

I had read the documentation already but It doesn’t really help me to begin and I’m still lost. I probably have a lack of knowledge and some relationships are missing in my mind. I will wait for your help on my example in order to begin well.

For Christmas, my son received the Variety Gizmos Pack. It’s written nowhere that the example programs (in .sb2) work only with mBlock 3. I had to install it and realized that it is less intuitive but much closest to the Arduino IDE. It will probably help me to apprehend how the mBlock soft works and the relationship between mBlock and the different sections in the Ext Builder.

I don’t know anymore if I should use mBlock 3 or mBlock 5. I know that Makeblock encourages to use mBlock 5 but it seems not to be well supported for everything I want to do.

Hope I will find a way to build my blocks!

Best,
Hervé


#11

Hi hdrum81,

I got you. Thanks for your understanding and support. We do cherish your voice and will seriously consider reconstruct our instructions on documentation.

For enabling the live mode function for your Arduino device (most of the time it’s about allow communication among device and computer via digitalWrite and digitalRead ), in fact, we recently received lots of consultation on this topic, and our engineer is writing an example for users to answer the question (since we have limited resource to answer everybody’s specific question on this issue). So we’re sorry we had some delay in getting back to you, and once we have the example ready, I’ll let you know.

Best regards.

Allen


#12

Hi Allen,

Thank you for your reply.
Yes, a complete example for a simple block would be very useful for the community! And more useful to everyone if it relates to the basic equipment of the robot (I mean the device that everybody bought, not on an additional module like in my original question.)

We will wait patiently for your engineer!
Thanks again.

Best,
Hervé


#13

Hi Allen,

Happy new year to you and your team!

Are there any news about a complete (yet simple) example?
Thanks for your feedback.

Best,
Hervé


#14

Hi hdrum81,

Thanks for following up with this issue.

In fact another user also asked for this demo recently: Help reading from device in Live mode, and we’re indeed working on this. Here is what I replied to him about this unexpected issue that we’re running into:

Thanks for asking about the progress. In fact, when we’re writing the demo. We realized due to some restriction of our extension builder, we had to resolve some issues first.

To differentiate official developers (our inner developers) and the third-party developers, we adopted some mechanisms to do so and restricted third-party user’s access to some APIs. When we wrote demos recently for you, some issues were revealed. We had to first solve them, otherwise the demo won’t work if you try to follow it.

In fact, at this time the issues have been resolved, but as a company providing stable services, every update has to formally go through testing and then be released in the version bugfix version. However, we don’t have sufficient resources to do it now, the next publish plan for this bug is postponed to February (mBlock Web) and March (mBlock PC). I think we’re possibly able to provide working demo for you around February if you wish to test it only on Web first.

We’re so sorry for this delay, and we have been working on it all the time. Please do understand that we’re focusing on the new incoming release for mBlock PC around January recently, but we will not ignore this important concern and will keep working this then.


#15

Thank you for your reply Allen.


#16

Hi Allen,

I hope you’re fine. I just come back to know if it exists some more help about creating an extension for mbot in online and upload mode? I still would love to create more functions for the gyro card but I can’t understand how, even if I downloaded your online_mode_demo.mext which is not for mbot…

As I said to you before, I want to create a very simple sub to reset the gyro from Me-3Axis board and I managed to make it work in upload mode.
Please would you help me to create the same simple RESET GYRO working on online mode too?

Thank you in advance.
Hervé


#17

Hi hdrum81,
Sorry we can’t do that for you.
Hope you can understand.
Thanks.


#18

You can develop your own block for upload mode, it is not that difficult. I can send you some code if you share your email.
For the live mode, it is much more complex although if you spend some (let be honest a lot) of time looking for doc and ressource you can manage it.
Extension do not work with live mode
Live mode works using a communication protocol. Basically, you write an arduino (or whatever is your target) program, called “firmware” that responds to serial/blutooth orders according to a communication protocol. For instance, you define a set of devices (01 for motor, 02 servos, etc) and some actions for each of these devices (01 forward, 01 backward) and some parameters for each device-command pair (speed, duration, etc.). Then sending 01 02 10 could be interpreted by the arduino as motor backward 10 seconds. This is just a very simplifed exemple of course.
In a similar way the arduino card can receive serial data that are interpreted as request to send sensor values.
That was for the arduino card point of view.

Then the mblock software has a “live mode”. Each time you run a program, some javascript code is exectued. The trick is then to ask javascrip to send the correct order thrue the serial/blutooth connection and wait the arduino card to answer.

=> that’s why you cannot have any extension with live mode: unless you program the full firmware yourself that manages all the commands (motor, servo, digital pin, pwm, analog, etc) and sensors (ultrasonic, serial reading, etc), the arduino card does not have a protocol and low level code to manage these new extensions.

When my robot will be finished, I will probably publish the code + tutorial if I have time