leapFrame.js defines a function that helps you read and act on a single frame of leap data.
The leap device passes 'frames' of data as it sees objects in the world. A single frame of data has information on how many objects are seen, what direction they're pointing, where they're located in 3D space etc. Take time and look at leapFrame.js and the functions it provides:
- palm position
- palm direction
- palm normal vector
- finger position
- finger angle
- delta finger position
If you need some help figuring out what some of these vectors look like, take a look at the leap documentation, they have nice pictures showing all the axis etc.
joint.js defines a function that helps create and move joints. In the sample code sent me, you see a joint constructed like this:
var middle = new Joint({
minPos: 70,
maxPos: 220,
pin: 6,
range: [60,150]
});
The range is quite important, this is where you specify the range of motion in degrees of the servo. The servo above is being set to 60 degrees minimum, 150 degrees maximum.
minPos, maxPos - These define the minimum and maximum value for the leap property that is being used to move this servo. For instance, in the code above, you can see the minPos and maxPos values being set to 70 and 220. 70 and 220 are values you'll be getting from the leap device for whatever part/property of the hand you choose. In the example, the palm's height is being used:
middle.move(frame.palmPosition.y);
Remember that middle is a Joint, and here you see that from the frame data, the palmPosition Y value is being passed to the joint move function. What happens to the value passed into middle.move?
var _move = function(pos, constraint) {
var angle;
if (constraint) {
pos = constraint(pos);
}
angle = _scale(pos);
_servo.move(angle);
};
You can see that without a second argument, the call to move basically just calls scale(pos)
and stores the value.
Let's see what scale does:
var _scale = function(pos) {
if (pos<minPos) {
pos = minPos;
}
else if (pos>maxPos) {
pos = maxPos;
}
return Math.floor(five.Fn.map(pos, minPos, maxPos, _servo.range[0], _servo.range[1]));
};
This function clamps the position passed in to the minPos and maxPos values that were defined when constructing the joint. It then interpolates the value across the min/max servo range.
the best explanation yet! i understood the whole thing perfectly!! (like never before)
i read the documentation of leap, well this part** confused me a bit, because i got a hang of everything, everything is kinda working perfect, but the leap only detects a pointable object or a finger.
**You can also find an individual finger or tool using an ID value obtained in a previous frame. Use the Hand.finger(), the Hand.tool()
since i want to control 5 servos individually using my 5 individual fingers, i don't really understand where and how to use the Hand.tool() or Hand.finger(), like which part of leapFrame.js? is it even possible to know to what degree an individual finger (say the index finger) is bent? so i may be able to map the same on separate servo.
till where i've thought about it, in the leapFrame.js file,
the function _isValid starts only when it detects a pointable object if i'm not wrong, changing this to frame.hand should do the job if i'm not wrong. but if you can further explain it to me, it'd be better...
thanks a lot! really appreciate the help!