我正在尝试使用Myo Armband控制AR Parrot Drone 2.0。然而,即使我的Myo频段经过良好校准,我通过OSX Yosemite连接到无人机的无线网络,当我运行以下代码时:
var arDrone = require('ar-drone');
var index = require('myojs');
var keypress = require('keypress');
var client = arDrone.createClient();
var hub = new index.Hub();
var myMyo = new index.Myo();
myMyo.context = hub.connection;
keypress(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', function (ch, key) {
// press ctrl + c to exit the program
if (key && key.ctrl && key.name == 'c' ) {
process.exit();
}
// press 'l' to land
else if (key.name == 'l') {
console.log("landing");
client.land();
take_command = false;
myMyo.lock();
}
// press 'd' to exit emergency state
else if (key.name == 'd') {
client.disableEmergency();
console.log("disable emergency");
}
});
var take_command = false;
var newAngles;
var zeroPos = null;
var curAngles;
// speeds can be anything between 0 and 1
var yawSpeed = 0.5;
var pitchSpeed = 0.5;
var rollSpeed = 0.5;
/*
Pose types:
0 - Rest
1 - Fist
2 - Wave In
3 - Wave Out
4 - Fingers Spread
5 - Double Tap
*/
var getAnglesRelativeToStart = function (input)
{
// obtains the current angular position of arm relative to the starting zero position
newAngles = {
roll: Math.round(Math.abs(input.roll - zeroPos.roll) * 10),
pitch: Math.round(Math.abs(input.pitch - zeroPos.pitch) * 10),
yaw: Math.round(Math.abs(input.yaw - zeroPos.yaw ) * 10)
};
return newAngles;
};
var getAngles = function (frame)
{
// gives us the roll, pitch, and yaw
var values = {
roll: Math.atan2(2.0 * (frame.rotation.w * frame.rotation.x + frame.rotation.y * frame.rotation.z), 1.0 - 2.0 * (frame.rotation.x * frame.rotation.x + frame.rotation.y * frame.rotation.y)),
pitch: Math.asin(Math.max(-1.0, Math.min(1.0, 2.0 * (frame.rotation.w * frame.rotation.y - frame.rotation.z * frame.rotation.x)))),
yaw: Math.atan2(2.0 * (frame.rotation.w * frame.rotation.z + frame.rotation.x * frame.rotation.y), 1.0 - 2.0 * (frame.rotation.y * frame.rotation.y + frame.rotation.z * frame.rotation.z))
};
return values;
};
hub.on('connect', function() {
console.log("connected");
});
console.log("begin");
hub.on('pose', function(pose) {
// takeoff
if (pose.type == 1)
{
client.disableEmergency(); // in case drone crashed on previous run
take_command = true;
console.log("taking flight");
client.takeoff();
myMyo.unlock(1);
}
// landing
else if (pose.type == 5)
{
take_command = false;
console.log("landing");
client.land();
myMyo.lock();
}
// reset the zero position to current position of arm
else if (pose.type == 4)
{
zeroPos = curAngles;
console.log("position reset");
}});
hub.on('frame', function(frame) {
if (take_command === true)
{
curAngles = getAngles(frame);
if (!zeroPos)
{
zeroPos = curAngles;
console.log("reset zero position");
}
getAnglesRelativeToStart(curAngles);
var pitchPercent = newAngles.pitch / 10;
var yawPercent = newAngles.yaw / 10;
//var rollPercent = newAngles.yaw / ; // roll movements are less sensitive than others
if (newAngles.pitch > 3 && pitchPercent > yawPercent)
{
if (curAngles.pitch > 0)
{
console.log("down");
client.down(pitchSpeed);
}
else
{
console.log("up");
client.up(pitchSpeed);
}
}
else if (newAngles.yaw > 2 && yawPercent > pitchPercent)
{
if (curAngles.yaw - zeroPos.yaw > 0)
{
console.log("back");
client.back(yawSpeed);
}
else
{
console.log("front");
client.front(yawSpeed);
}
}
else if (newAngles.roll > 1)
{
if (curAngles.roll - zeroPos.roll > 0)
{
console.log("right");
client.right(rollSpeed);
}
else
{
console.log("left");
client.left(rollSpeed);
}
}
else
{
console.log("stop");
client.stop();
}
}
});
我收到以下错误:
wifi-248:armyo mona$ node myoarmar.js
/Users/mona/node_modules/myojs/src/index.js:1
(function (exports, require, module, __filename, __dirname) { import {BaseConn
^^^^^^
SyntaxError: Unexpected reserved word
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/mona/iotlab/armyo/myoarmar.js:2:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
wifi-248:armyo mona$
我已经从这个github rep o获取了代码,但我根本没有改变它。不知道如何解决这个问题?