Hi,
It seems I am having some problems while trying the NodeJS API on Ultimate 2.0 kit. I am using Raspberry Pi and connected over USB. Before connecting I have updated the MegaPI firmware using mBlock desktop app. From Makeblock iPhone app it says that the firmware version “0e.01.014” us ip to date. Now, after following instructions of NodeJS MegaPi programming, I face two problems
- The encoder motor does not stop, no matter which function (encoderMotorMove, encoderMotorMoveTo, encoderMotorRun) I use. Is there a bug in the firmware or do I need to add anything more in the code?
Here is a simple code
var MegaPi = require('megapi').MegaPi;
var bot = new MegaPi("/dev/ttyUSB0",onStart);
function onStart(){
setTimeout(run,1000);
}
function run() {
bot.encoderMotorMoveTo(1,-10,1,bye);
bot.encoderMotorMoveTo(2,10,1,bye);
}
function bye(){
console.log("Bye");
}
Here, I have tried the “position” parameter of encoderMotorMoveTo function to be 1000, 100, 10 or even 1, but nothing seems to stop it from running forever.
- I want to understand why we use setTimeout in onStart() function
It seems the code wont run if I use timeout value of anything less than 900 (even though the example codes use 500).
I want to create NodeJS web interface with html buttons, so that different motors will run based on button press events. So do I need to add timeout for every control or is it just for the beginning?