Hello,

I got a leapmotion, i've installed the software from their website and tested it, it works. Then i installed the leapmotion2 service, and typed this script as explain in the leapmotion page :

 

#this simple script will print in the python tab the grab strength of your left hand
 
from __future__ import division
 
leap = Runtime.createAndStart("leap","LeapMotion2")
 
leap.addFrameListener(python)
 
def onFrame(frame):
strength = ((frame.hands().leftmost().grabStrength())*100)
print strength
 
leap.startTracking()
 
And i would get this error : 4982 [Thread-6] ERROR class org.myrobotlab.framework.Service  - did not find method - onInit(Controller)
 
Then i checked the python tab and it was showing a number between 0 and 100 and i was wondering if it possible to get the fingers position or not ?
 
Thanks in advance

GroG

9 years 10 months ago

Correct its Java, but you can access the Java methods "through" Python - but they will have the Java format of the method.

Did you get what you needed?

In MRL on a frame you should be able to do this method..

 

frame.hands().rightmost().fingers().isEmpty()

 

I can't identify the fingers in MRL, it's so weird i use this : 

 

finger_list = frame.hands().get(0).fingers()

for finger in finger_list:

   if finger.type() == TYPE_THUMB:

      print "thumb"

 

but it says that it doesn't know TYPE_THUMB, so i tried Finger.TYPE_THUMB as there is an enum in the Finger class with TYPE_THUMB, TYPE_INDEX, etc..I don't understand this.

upper case usually stands for constants - quick google search on TYPE_THUMB, LeapMotion gave me this link
https://developer.leapmotion.com/documentation/python/api/Leap.Finger.h…;

Below is snippet ..  so in Python just have at the top
TYPE_THUMB = 0 etc. ..

then in your function you can have

def onFrame(frame):
  global TYPE_THUMB, etc...
 finger_list = frame.hands().get(0).fingers()

  for finger in finger_list:

    if finger.type() == TYPE_THUMB:

      print "thumb"

New in version 2.0.

type()
Type: integer

The integer code representing the finger name.

  • 0 = TYPE_THUMB
  • 1 = TYPE_INDEX
  • 2 = TYPE_MIDDLE
  • 3 = TYPE_RING
  • 4 = TYPE_PINKY

 

No, anyway i've used the tools here : http://www.inmoov.fr/leap-motion-tuto/

And i manage to control the servos with leapmotion, however in order to get this working i have to upload StandardFirmata to arduino and i have an issue here. Is there a way to get StandardFirmata and the generated MRL code for arduino to coexist ? Because i want to get kinect and leapmotion working to control my InMoov.

 

So i took the javascript code given in the Inmoov website to control hand with leapmotion, and tried to convert it to be usable in MRL, but i have an issue : 

That javascript code expects to have 40 frames/s and not capture every frame like it is the case in MRL, so i wanna implement LeapMotion so that you can use both methods (The listener and the while version where you process as much frames as you want and not every frame whenever there is one) since i dont need to be as precise as onFrame function allows me to be (it causes a problem where my servo doesn't have enough time to move, but moves all direction too fast and gives me a weird result).

 

So my question here is how do i recompile (easily if possible) MRL if i wanted to (i want to modify the LeapMotion.java file) ?

In python land, you've gotta import the java classes to they are known locally.  

At the top of your script, you can add the following line:

 

import com.leapmotion.leap.Finger.Type as Type
 
 
# Then you can see the type is defined
 
print(Type.TYPE_THUMB)
if Type.TYPE_THUMB == myFinger:
  print "It's a thumb!"
 
 
The enum is defined as following:
 
Type.TYPE_THUMB 
Type.TYPE_INDEX 
Type.TYPE_MIDDLE
Type.TYPE_RING 
Type.TYPE_PINKY
 
 
Hope this helps!

Hmm.. That's strange. so when you do

"import com.leapmotion.leap.Finger.Type as Type"   it no worky..
I wonder if the LeapJava.jar is in your classpath...  Check if you have it in your libraries/jar directory...  That's where it's defined..

Sorry, my bad.  The example I gave was some strange hybrid of java syntax and python syntax. 

try 

 

"from com.leapmotion.leap.Finger import Type"

that should work for you.  
then you can reference  Type.TYPE_THUMB in your python code  (I hope)