1

I have just begun programming in JS for the Leap Motion. I am working on a project where I can control motors based on hand gestures that are being read from the Leap Motion. The frames are being parsed and then commands are being sent to the motors through an Arduino Uno using the johnny-five library. Here is the way I am grabbing the frames from the Leap Motion:

`var five = require('johnny-five'),
Leap = require('leapjs'),
board = new five.Board(),
motor, frame, hand;

board.on('ready', function() 
{   
    var controller = Leap.loop({enableGestures: true}, function(frame) 
    {   
        checkData(frame);
    });
});`

I take the frames from the Leap Motion and send the frame to a function that goes through the frame, reads the gestures, and then calls a new function that controls motors:

    var motorA = new five.Motor([3, 0, 2]);

    motorA.start(255);  

    while(!finished)
    {
        board.wait(5000, function()
        {
            motorA.stop();
            runMotorB(number);
            finsihed = true;
        });
    }

My problem is that I need a while loop to make the program wait for the first motor to end before running the next motor. The board.wait() doesn't seem to stop the program from continuing on to the next motor without waiting for the first motor to stop. I also need to be able to grab frames from the Leap Motion while running the motor in the while loop and waiting for it to end. This is because I want to be able to see if new gestures are occurring while the motor is running. However, whenever I try to grab a new frame using a controller.frame() call, I simply get the previous frame from the Leap Motion that started the while loop, not the frame that the Leap Motion is seeing at that second. Is there a way to see what the Leap Motion is seeing while stuck within the while loop? Or is there a better way for me to be stopping the program from moving onto the next motor without actually waiting?

4

1 回答 1

1

嗯。controller.frame()如果控制器正在流式传输,则应始终获取最新帧。这应该是同义词controller.lastConnectionFrame

我会为每个电机保存状态变量,然后运行帧回调中的所有内容。

如果它本身不保持状态,它甚至可能有一个围绕电机的包装器类,它可能有诸如startUnlessStarted tryStart,之类的方法。

于 2014-11-26T21:50:11.163 回答