我正在开发一个只需要通过网页控制机器人的简单项目。基本上,使用nodejs Web应用程序向机器人发送命令。
我基于英特尔网站的代码:https://software.intel.com/en-us/articles/programming-robotics-using-the-intel-xdk-nodejs-and-mraa-library
我面临的问题是在运行命令后电机没有移动。
以下是示例代码:
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);