Wednesday, 10 May 2017

Run DC Motors on Devastator Robot (intel edison) through node js

I am working on a simple project which just need to control the robot through a web page. Basically, sending commands to the robot using a nodejs web application.

I based the code from intel's site: https://software.intel.com/en-us/articles/programming-robotics-using-the-intel-xdk-nodejs-and-mraa-library

The issue I am facing is that the motors is not moving after running the command.

Here is the sample code:

var m = require("mraa");

var x, buf;

x = new m.I2c(Number(0));
x.address(Number(4));

setTimeout(function () {
    try {
        buf = new Buffer(5);
        buf[0] = 0x55;  //Header 1
        buf[1] = 0xaa;  //Header 2
    } catch (e) {
        console.log('Error in initializing m buffer or I2c');
    }
}, 1000);

setTimeout(function () {
    try {
        var speed = 0xCC;

        //Left Motor CounterClockwise
        buf[2] = 0xB1;
        buf[3] = 0x1;
        buf[4] = (buf[0] + buf[1] + buf[2] + buf[3]) & 0xFF;
        x.write(buf);

        //Right Motor CounterClockwise
        buf[2] = 0xB2;
        buf[3] = 0x1;
        buf[4] = (buf[0] + buf[1] + buf[2] + buf[3]) & 0xFF;
        x.write(buf);

        //Left Motor Speed
        buf[2] = 0xC1;
        buf[3] = speed;
        buf[4] = (buf[0] + buf[1] + buf[2] + buf[3]) & 0xFF;
        x.write(buf);

        //Right Motor Speed
        buf[2] = 0xC2;
        buf[3] = speed;
        buf[4] = (buf[0] + buf[1] + buf[2] + buf[3]) & 0xFF;
        x.write(buf);
    } catch (e) {
        console.log('error: ' + e.message);
    }
}, 2000);



via carloliwanag

No comments:

Post a Comment