Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 10 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
| ||||||
Hand tools and fabrication machines | ||||||
| ||||||
|
I did not know a lot about autism and autistic children until I worked with them. I volunteered with autistic kids in an athletic program, and I learned a lot about autism.
Individual autistic children are very unique and have different abilities physically, mentally, and emotionally. It is difficult to apply general therapeutic methods to them.
It is even more difficult to train them to control fine motor skills such as drawing, writing, crafting, etc.
When I read a few articles about autistic children's mimicking tendencies, I got an idea to develop a system for autistic children to write better.
The SystemI designed a system with an IR sensor (leap motion), and a Raspberry Pi with 2 motors, which will be a robotic system. These two units are going to be connected through the Internet.
Here are two examples:
1) When kids are learning how to write letter "A," they are looking at the ideal letter "A" and going to write on the top of IR sensor as a practice. Then the robot arm will copy what they are writing. Kids can see what the robot is copying and comparing themselves with the ideal letter "A." This can motivate kids to write better and practice more.
2) When a robot arm is writing an ideal letter "A," kids can see what the robot arm is writing and mimic what it is writing. This can motivate kids to write better and practice more.
This system also has a great potential for therapeutic and rehabilitation practices as well.
I started this project last November 2015 and paused this project for a while because I could not solve the connection problems between the sensor and the robotic arm. I tried to use Pubnub but it was not working. With this opportunity, I would like to solve this problem and want to pursue this project again.
Thank you for reading and supporting this project.
When I got an email from Hackster, I got motivated again and excited to know people care.
This means a lot.
Leap.py
Python# Version 3.0.3
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.3
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info
if version_info >= (2, 6, 0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('LeapPython', [dirname(__file__)])
except ImportError:
import LeapPython
return LeapPython
if fp is not None:
try:
_mod = imp.load_module('LeapPython', fp, pathname, description)
finally:
fp.close()
return _mod
LeapPython = swig_import_helper()
del swig_import_helper
else:
import LeapPython
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
if (name == "thisown"):
return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name, None)
if method:
return method(self, value)
if (not static):
object.__setattr__(self, name, value)
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self, class_type, name, value):
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
def _swig_getattr_nondynamic(self, class_type, name, static=1):
if (name == "thisown"):
return self.this.own()
method = class_type.__swig_getmethods__.get(name, None)
if method:
return method(self)
if (not static):
return object.__getattr__(self, name)
else:
raise AttributeError(name)
def _swig_getattr(self, class_type, name):
return _swig_getattr_nondynamic(self, class_type, name, 0)
def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
except:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except AttributeError:
class _object:
pass
_newclass = 0
try:
import weakref
weakref_proxy = weakref.proxy
except:
weakref_proxy = lambda x: x
class SwigPyIterator(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, SwigPyIterator, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, SwigPyIterator, name)
def __init__(self, *args, **kwargs):
raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
__swig_destroy__ = LeapPython.delete_SwigPyIterator
__del__ = lambda self: None
def value(self):
return LeapPython.SwigPyIterator_value(self)
def incr(self, n=1):
return LeapPython.SwigPyIterator_incr(self, n)
def decr(self, n=1):
return LeapPython.SwigPyIterator_decr(self, n)
def distance(self, x):
return LeapPython.SwigPyIterator_distance(self, x)
def equal(self, x):
return LeapPython.SwigPyIterator_equal(self, x)
def copy(self):
return LeapPython.SwigPyIterator_copy(self)
def next(self):
return LeapPython.SwigPyIterator_next(self)
def __next__(self):
return LeapPython.SwigPyIterator___next__(self)
def previous(self):
return LeapPython.SwigPyIterator_previous(self)
def advance(self, n):
return LeapPython.SwigPyIterator_advance(self, n)
def __eq__(self, x):
return LeapPython.SwigPyIterator___eq__(self, x)
def __ne__(self, x):
return LeapPython.SwigPyIterator___ne__(self, x)
def __iadd__(self, n):
return LeapPython.SwigPyIterator___iadd__(self, n)
def __isub__(self, n):
return LeapPython.SwigPyIterator___isub__(self, n)
def __add__(self, n):
return LeapPython.SwigPyIterator___add__(self, n)
def __sub__(self, *args):
return LeapPython.SwigPyIterator___sub__(self, *args)
def __iter__(self):
return self
SwigPyIterator_swigregister = LeapPython.SwigPyIterator_swigregister
SwigPyIterator_swigregister(SwigPyIterator)
class byte_array(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, byte_array, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, byte_array, name)
__repr__ = _swig_repr
def __init__(self, nelements):
this = LeapPython.new_byte_array(nelements)
try:
self.this.append(this)
except:
self.this = this
__swig_destroy__ = LeapPython.delete_byte_array
__del__ = lambda self: None
def __getitem__(self, index):
return LeapPython.byte_array___getitem__(self, index)
def __setitem__(self, index, value):
return LeapPython.byte_array___setitem__(self, index, value)
def cast(self):
return LeapPython.byte_array_cast(self)
__swig_getmethods__["frompointer"] = lambda x: LeapPython.byte_array_frompointer
if _newclass:
frompointer = staticmethod(LeapPython.byte_array_frompointer)
byte_array_swigregister = LeapPython.byte_array_swigregister
byte_array_swigregister(byte_array)
def byte_array_frompointer(t):
return LeapPython.byte_array_frompointer(t)
byte_array_frompointer = LeapPython.byte_array_frompointer
class float_array(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, float_array, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, float_array, name)
__repr__ = _swig_repr
def __init__(self, nelements):
this = LeapPython.new_float_array(nelements)
try:
self.this.append(this)
except:
self.this = this
__swig_destroy__ = LeapPython.delete_float_array
__del__ = lambda self: None
def __getitem__(self, index):
return LeapPython.float_array___getitem__(self, index)
def __setitem__(self, index, value):
return LeapPython.float_array___setitem__(self, index, value)
def cast(self):
return LeapPython.float_array_cast(self)
__swig_getmethods__["frompointer"] = lambda x: LeapPython.float_array_frompointer
if _newclass:
frompointer = staticmethod(LeapPython.float_array_frompointer)
float_array_swigregister = LeapPython.float_array_swigregister
float_array_swigregister(float_array)
def float_array_frompointer(t):
return LeapPython.float_array_frompointer(t)
float_array_frompointer = LeapPython.float_array_frompointer
class Vector(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, Vector, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Vector, name)
__repr__ = _swig_repr
def __init__(self, *args):
this = LeapPython.new_Vector(*args)
try:
self.this.append(this)
except:
self.this = this
def distance_to(self, other):
return LeapPython.Vector_distance_to(self, other)
def angle_to(self, other):
return LeapPython.Vector_angle_to(self, other)
def dot(self, other):
return LeapPython.Vector_dot(self, other)
def cross(self, other):
return LeapPython.Vector_cross(self, other)
def __neg__(self):
return LeapPython.Vector___neg__(self)
def __add__(self, other):
return LeapPython.Vector___add__(self, other)
def __sub__(self, other):
return LeapPython.Vector___sub__(self, other)
def __mul__(self, scalar):
return LeapPython.Vector___mul__(self, scalar)
def __div__(self, scalar):
return LeapPython.Vector___div__(self, scalar)
def __iadd__(self, other):
return LeapPython.Vector___iadd__(self, other)
def __isub__(self, other):
return LeapPython.Vector___isub__(self, other)
def __imul__(self, scalar):
return LeapPython.Vector___imul__(self, scalar)
def __idiv__(self, scalar):
return LeapPython.Vector___idiv__(self, scalar)
def __str__(self):
return LeapPython.Vector___str__(self)
def __eq__(self, other):
return LeapPython.Vector___eq__(self, other)
def __ne__(self, other):
return LeapPython.Vector___ne__(self, other)
def is_valid(self):
return LeapPython.Vector_is_valid(self)
def __getitem__(self, index):
return LeapPython.Vector___getitem__(self, index)
__swig_setmethods__["x"] = LeapPython.Vector_x_set
__swig_getmethods__["x"] = LeapPython.Vector_x_get
if _newclass:
x = _swig_property(LeapPython.Vector_x_get, LeapPython.Vector_x_set)
__swig_setmethods__["y"] = LeapPython.Vector_y_set
__swig_getmethods__["y"] = LeapPython.Vector_y_get
if _newclass:
y = _swig_property(LeapPython.Vector_y_get, LeapPython.Vector_y_set)
__swig_setmethods__["z"] = LeapPython.Vector_z_set
__swig_getmethods__["z"] = LeapPython.Vector_z_get
if _newclass:
z = _swig_property(LeapPython.Vector_z_get, LeapPython.Vector_z_set)
__swig_getmethods__["magnitude"] = LeapPython.Vector_magnitude_get
if _newclass:
magnitude = _swig_property(LeapPython.Vector_magnitude_get)
__swig_getmethods__["magnitude_squared"] = LeapPython.Vector_magnitude_squared_get
if _newclass:
magnitude_squared = _swig_property(LeapPython.Vector_magnitude_squared_get)
__swig_getmethods__["pitch"] = LeapPython.Vector_pitch_get
if _newclass:
pitch = _swig_property(LeapPython.Vector_pitch_get)
__swig_getmethods__["roll"] = LeapPython.Vector_roll_get
if _newclass:
roll = _swig_property(LeapPython.Vector_roll_get)
__swig_getmethods__["yaw"] = LeapPython.Vector_yaw_get
if _newclass:
yaw = _swig_property(LeapPython.Vector_yaw_get)
__swig_getmethods__["normalized"] = LeapPython.Vector_normalized_get
if _newclass:
normalized = _swig_property(LeapPython.Vector_normalized_get)
def to_float_array(self): return [self.x, self.y, self.z]
def to_tuple(self): return (self.x, self.y, self.z)
__swig_destroy__ = LeapPython.delete_Vector
__del__ = lambda self: None
Vector_swigregister = LeapPython.Vector_swigregister
Vector_swigregister(Vector)
cvar = LeapPython.cvar
PI = cvar.PI
DEG_TO_RAD = cvar.DEG_TO_RAD
RAD_TO_DEG = cvar.RAD_TO_DEG
EPSILON = cvar.EPSILON
Vector.zero = LeapPython.cvar.Vector_zero
Vector.x_axis = LeapPython.cvar.Vector_x_axis
Vector.y_axis = LeapPython.cvar.Vector_y_axis
Vector.z_axis = LeapPython.cvar.Vector_z_axis
Vector.forward = LeapPython.cvar.Vector_forward
Vector.backward = LeapPython.cvar.Vector_backward
Vector.left = LeapPython.cvar.Vector_left
Vector.right = LeapPython.cvar.Vector_right
Vector.up = LeapPython.cvar.Vector_up
Vector.down = LeapPython.cvar.Vector_down
class Matrix(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, Matrix, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Matrix, name)
__repr__ = _swig_repr
def __init__(self, *args):
this = LeapPython.new_Matrix(*args)
try:
self.this.append(this)
except:
self.this = this
def set_rotation(self, axis, angleRadians):
return LeapPython.Matrix_set_rotation(self, axis, angleRadians)
def transform_point(self, arg2):
return LeapPython.Matrix_transform_point(self, arg2)
def transform_direction(self, arg2):
return LeapPython.Matrix_transform_direction(self, arg2)
def rigid_inverse(self):
return LeapPython.Matrix_rigid_inverse(self)
def __mul__(self, other):
return LeapPython.Matrix___mul__(self, other)
def __imul__(self, other):
return LeapPython.Matrix___imul__(self, other)
def __eq__(self, other):
return LeapPython.Matrix___eq__(self, other)
def __ne__(self, other):
return LeapPython.Matrix___ne__(self, other)
def __str__(self):
return LeapPython.Matrix___str__(self)
__swig_setmethods__["x_basis"] = LeapPython.Matrix_x_basis_set
__swig_getmethods__["x_basis"] = LeapPython.Matrix_x_basis_get
if _newclass:
x_basis = _swig_property(LeapPython.Matrix_x_basis_get, LeapPython.Matrix_x_basis_set)
__swig_setmethods__["y_basis"] = LeapPython.Matrix_y_basis_set
__swig_getmethods__["y_basis"] = LeapPython.Matrix_y_basis_get
if _newclass:
y_basis = _swig_property(LeapPython.Matrix_y_basis_get, LeapPython.Matrix_y_basis_set)
__swig_setmethods__["z_basis"] = LeapPython.Matrix_z_basis_set
__swig_getmethods__["z_basis"] = LeapPython.Matrix_z_basis_get
if _newclass:
z_basis = _swig_property(LeapPython.Matrix_z_basis_get, LeapPython.Matrix_z_basis_set)
__swig_setmethods__["origin"] = LeapPython.Matrix_origin_set
__swig_getmethods__["origin"] = LeapPython.Matrix_origin_get
if _newclass:
origin = _swig_property(LeapPython.Matrix_origin_get, LeapPython.Matrix_origin_set)
def to_array_3x3(self, output = None):
if output is None:
output = [0]*9
output[0], output[1], output[2] = self.x_basis.x, self.x_basis.y, self.x_basis.z
output[3], output[4], output[5] = self.y_basis.x, self.y_basis.y, self.y_basis.z
output[6], output[7], output[8] = self.z_basis.x, self.z_basis.y, self.z_basis.z
return output
def to_array_4x4(self, output = None):
if output is None:
output = [0]*16
output[0], output[1], output[2], output[3] = self.x_basis.x, self.x_basis.y, self.x_basis.z, 0.0
output[4], output[5], output[6], output[7] = self.y_basis.x, self.y_basis.y, self.y_basis.z, 0.0
output[8], output[9], output[10], output[11] = self.z_basis.x, self.z_basis.y, self.z_basis.z, 0.0
output[12], output[13], output[14], output[15] = self.origin.x, self.origin.y, self.origin.z, 1.0
return output
__swig_destroy__ = LeapPython.delete_Matrix
__del__ = lambda self: None
Matrix_swigregister = LeapPython.Matrix_swigregister
Matrix_swigregister(Matrix)
Matrix.identity = LeapPython.cvar.Matrix_identity
class Interface(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, Interface, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, Interface, name)
def __init__(self, *args, **kwargs):
raise AttributeError("No constructor defined")
__repr__ = _swig_repr
Interface_swigregister = LeapPython.Interface_swigregister
Interface_swigregister(Interface)
class Pointable(Interface):
__swig_setmethods__ = {}
for _s in [Interface]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, Pointable, name, value)
__swig_getmethods__ = {}
for _s in [Interface]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, Pointable, name)
__repr__ = _swig_repr
ZONE_NONE = LeapPython.Pointable_ZONE_NONE
ZONE_HOVERING = LeapPython.Pointable_ZONE_HOVERING
ZONE_TOUCHING = LeapPython.Pointable_ZONE_TOUCHING
def __init__(self):
this = LeapPython.new_Pointable()
try:
self.this.append(this)
except:
self.this = this
def __eq__(self, arg2):
return LeapPython.Pointable___eq__(self, arg2)
def __ne__(self, arg2):
return LeapPython.Pointable___ne__(self, arg2)
def __str__(self):
return LeapPython.Pointable___str__(self)
__swig_getmethods__["id"] = LeapPython.Pointable_id_get
if _newclass:
id = _swig_property(LeapPython.Pointable_id_get)
__swig_getmethods__["hand"] = LeapPython.Pointable_hand_get
if _newclass:
hand = _swig_property(LeapPython.Pointable_hand_get)
__swig_getmethods__["tip_position"] = LeapPython.Pointable_tip_position_get
if _newclass:
tip_position = _swig_property(LeapPython.Pointable_tip_position_get)
__swig_getmethods__["tip_velocity"] = LeapPython.Pointable_tip_velocity_get
if _newclass:
tip_velocity = _swig_property(LeapPython.Pointable_tip_velocity_get)
__swig_getmethods__["direction"] = LeapPython.Pointable_direction_get
if _newclass:
direction = _swig_property(LeapPython.Pointable_direction_get)
__swig_getmethods__["width"] = LeapPython.Pointable_width_get
if _newclass:
width = _swig_property(LeapPython.Pointable_width_get)
__swig_getmethods__["length"] = LeapPython.Pointable_length_get
if _newclass:
length = _swig_property(LeapPython.Pointable_length_get)
__swig_getmethods__["is_tool"] = LeapPython.Pointable_is_tool_get
if _newclass:
is_tool = _swig_property(LeapPython.Pointable_is_tool_get)
__swig_getmethods__["is_finger"] = LeapPython.Pointable_is_finger_get
if _newclass:
is_finger = _swig_property(LeapPython.Pointable_is_finger_get)
__swig_getmethods__["is_extended"] = LeapPython.Pointable_is_extended_get
if _newclass:
is_extended = _swig_property(LeapPython.Pointable_is_extended_get)
__swig_getmethods__["is_valid"] = LeapPython.Pointable_is_valid_get
if _newclass:
is_valid = _swig_property(LeapPython.Pointable_is_valid_get)
__swig_getmethods__["touch_zone"] = LeapPython.Pointable_touch_zone_get
if _newclass:
touch_zone = _swig_property(LeapPython.Pointable_touch_zone_get)
__swig_getmethods__["touch_distance"] = LeapPython.Pointable_touch_distance_get
if _newclass:
touch_distance = _swig_property(LeapPython.Pointable_touch_distance_get)
__swig_getmethods__["stabilized_tip_position"] = LeapPython.Pointable_stabilized_tip_position_get
if _newclass:
stabilized_tip_position = _swig_property(LeapPython.Pointable_stabilized_tip_position_get)
__swig_getmethods__["time_visible"] = LeapPython.Pointable_time_visible_get
if _newclass:
time_visible = _swig_property(LeapPython.Pointable_time_visible_get)
__swig_getmethods__["frame"] = LeapPython.Pointable_frame_get
if _newclass:
frame = _swig_property(LeapPython.Pointable_frame_get)
__swig_destroy__ = LeapPython.delete_Pointable
__del__ = lambda self: None
Pointable_swigregister = LeapPython.Pointable_swigregister
Pointable_swigregister(Pointable)
Pointable.invalid = LeapPython.cvar.Pointable_invalid
class Arm(Interface):
__swig_setmethods__ = {}
for _s in [Interface]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, Arm, name, value)
__swig_getmethods__ = {}
for _s in [Interface]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, Arm, name)
__repr__ = _swig_repr
def __init__(self):
this = LeapPython.new_Arm()
try:
self.this.append(this)
except:
self.this = this
def __eq__(self, arg2):
return LeapPython.Arm___eq__(self, arg2)
def __ne__(self, arg2):
return LeapPython.Arm___ne__(self, arg2)
def __str__(self):
return LeapPython.Arm___str__(self)
__swig_getmethods__["width"] = LeapPython.Arm_width_get
if _newclass:
width = _swig_property(LeapPython.Arm_width_get)
__swig_getmethods__["center"] = LeapPython.Arm_center_get
if _newclass:
center = _swig_property(LeapPython.Arm_center_get)
__swig_getmethods__["direction"] = LeapPython.Arm_direction_get
if _newclass:
direction = _swig_property(LeapPython.Arm_direction_get)
__swig_getmethods__["basis"] = LeapPython.Arm_basis_get
if _newclass:
basis = _swig_property(LeapPython.Arm_basis_get)
__swig_getmethods__["elbow_position"] = LeapPython.Arm_elbow_position_get
if _newclass:
elbow_position = _swig_property(LeapPython.Arm_elbow_position_get)
__swig_getmethods__["wrist_position"] = LeapPython.Arm_wrist_position_get
if _newclass:
wrist_position = _swig_property(LeapPython.Arm_wrist_position_get)
__swig_getmethods__["is_valid"] = LeapPython.Arm_is_valid_get
if _newclass:
is_valid = _swig_property(LeapPython.Arm_is_valid_get)
__swig_destroy__ = LeapPython.delete_Arm
__del__ = lambda self: None
Arm_swigregister = LeapPython.Arm_swigregister
Arm_swigregister(Arm)
Arm.invalid = LeapPython.cvar.Arm_invalid
class Bone(Interface):
__swig_setmethods__ = {}
for _s in [Interface]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, Bone, name, value)
__swig_getmethods__ = {}
for _s in [Interface]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, Bone, name)
__repr__ = _swig_repr
TYPE_METACARPAL = LeapPython.Bone_TYPE_METACARPAL
TYPE_PROXIMAL = LeapPython.Bone_TYPE_PROXIMAL
TYPE_INTERMEDIATE = LeapPython.Bone_TYPE_INTERMEDIATE
TYPE_DISTAL = LeapPython.Bone_TYPE_DISTAL
def __init__(self):
this = LeapPython.new_Bone()
try:
self.this.append(this)
except:
self.this = this
def __eq__(self, arg2):
return LeapPython.Bone___eq__(self, arg2)
def __ne__(self, arg2):
return LeapPython.Bone___ne__(self, arg2)
def __str__(self):
return LeapPython.Bone___str__(self)
__swig_getmethods__["prev_joint"] = LeapPython.Bone_prev_joint_get
if _newclass:
prev_joint = _swig_property(LeapPython.Bone_prev_joint_get)
__swig_getmethods__["next_joint"] = LeapPython.Bone_next_joint_get
if _newclass:
next_joint = _swig_property(LeapPython.Bone_next_joint_get)
__swig_getmethods__["center"] = LeapPython.Bone_center_get
if _newclass:
center = _swig_property(LeapPython.Bone_center_get)
__swig_getmethods__["direction"] = LeapPython.Bone_direction_get
if _newclass:
direction = _swig_property(LeapPython.Bone_direction_get)
__swig_getmethods__["length"] = LeapPython.Bone_length_get
if _newclass:
length = _swig_property(LeapPython.Bone_length_get)
__swig_getmethods__["width"] = LeapPython.Bone_width_get
if _newclass:
width = _swig_property(LeapPython.Bone_width_get)
__swig_getmethods__["type"] = LeapPython.Bone_type_get
if _newclass:
type = _swig_property(LeapPython.Bone_type_get)
__swig_getmethods__["basis"] = LeapPython.Bone_basis_get
if _newclass:
basis = _swig_property(LeapPython.Bone_basis_get)
__swig_getmethods__["is_valid"] = LeapPython.Bone_is_valid_get
if _newclass:
is_valid = _swig_property(LeapPython.Bone_is_valid_get)
__swig_destroy__ = LeapPython.delete_Bone
__del__ = lambda self: None
Bone_swigregister = LeapPython.Bone_swigregister
Bone_swigregister(Bone)
Bone.invalid = LeapPython.cvar.Bone_invalid
class Finger(Pointable):
__swig_setmethods__ = {}
for _s in [Pointable]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, Finger, name, value)
__swig_getmethods__ = {}
for _s in [Pointable]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, Finger, name)
__repr__ = _swig_repr
JOINT_MCP = LeapPython.Finger_JOINT_MCP
JOINT_PIP = LeapPython.Finger_JOINT_PIP
JOINT_DIP = LeapPython.Finger_JOINT_DIP
JOINT_TIP = LeapPython.Finger_JOINT_TIP
TYPE_THUMB = LeapPython.Finger_TYPE_THUMB
TYPE_INDEX = LeapPython.Finger_TYPE_INDEX
TYPE_MIDDLE = LeapPython.Finger_TYPE_MIDDLE
TYPE_RING = LeapPython.Finger_TYPE_RING
TYPE_PINKY = LeapPython.Finger_TYPE_PINKY
def __init__(self, *args):
this = LeapPython.new_Finger(*args)
try:
self.this.append(this)
except:
self.this = this
def joint_position(self, jointIx):
return LeapPython.Finger_joint_position(self, jointIx)
def bone(self, boneIx):
return LeapPython.Finger_bone(self, boneIx)
def __str__(self):
return LeapPython.Finger___str__(self)
__swig_getmethods__["type"] = LeapPython.Finger_type_get
if _newclass:
type = _swig_property(LeapPython.Finger_type_get)
__swig_destroy__ = LeapPython.delete_Finger
__del__ = lambda self: None
Finger_swigregister = LeapPython.Finger_swigregister
Finger_swigregister(Finger)
Finger.invalid = LeapPython.cvar.Finger_invalid
class Tool(Pointable):
__swig_setmethods__ = {}
for _s in [Pointable]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, Tool, name, value)
__swig_getmethods__ = {}
for _s in [Pointable]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, Tool, name)
__repr__ = _swig_repr
def __init__(self, *args):
this = LeapPython.new_Tool(*args)
try:
self.this.append(this)
except:
self.this = this
def __str__(self):
return LeapPython.Tool___str__(self)
__swig_destroy__ = LeapPython.delete_Tool
__del__ = lambda self: None
Tool_swigregister = LeapPython.Tool_swigregister
Tool_swigregister(Tool)
Tool.invalid = LeapPython.cvar.Tool_invalid
class Hand(Interface):
__swig_setmethods__ = {}
for _s in [Interface]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, Hand, name, value)
__swig_getmethods__ = {}
for _s in [Interface]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, Hand, name)
__repr__ = _swig_repr
def __init__(self):
this = LeapPython.new_Hand()
try:
self.this.append(this)
except:
self.this = this
def pointable(self, id):
return LeapPython.Hand_pointable(self, id)
def finger(self, id):
return LeapPython.Hand_finger(self, id)
def tool(self, id):
return LeapPython.Hand_tool(self, id)
def translation(self, sinceFrame):
return LeapPython.Hand_translation(self, sinceFrame)
def translation_probability(self, sinceFrame):
return LeapPython.Hand_translation_probability(self, sinceFrame)
def rotation_axis(self, sinceFrame):
return LeapPython.Hand_rotation_axis(self, sinceFrame)
def rotation_angle(self, *args):
return LeapPython.Hand_rotation_angle(self, *args)
def rotation_matrix(self, sinceFrame):
return LeapPython.Hand_rotation_matrix(self, sinceFrame)
def rotation_probability(self, sinceFrame):
return LeapPython.Hand_rotation_probability(self, sinceFrame)
def scale_factor(self, sinceFrame):
return LeapPython.Hand_scale_factor(self, sinceFrame)
def scale_probability(self, sinceFrame):
return LeapPython.Hand_scale_probability(self, sinceFrame)
def __eq__(self, arg2):
return LeapPython.Hand___eq__(self, arg2)
def __ne__(self, arg2):
return LeapPython.Hand___ne__(self, arg2)
def __str__(self):
return LeapPython.Hand___str__(self)
__swig_getmethods__["id"] = LeapPython.Hand_id_get
if _newclass:
id = _swig_property(LeapPython.Hand_id_get)
__swig_getmethods__["pointables"] = LeapPython.Hand_pointables_get
if _newclass:
pointables = _swig_property(LeapPython.Hand_pointables_get)
__swig_getmethods__["fingers"] = LeapPython.Hand_fingers_get
if _newclass:
fingers = _swig_property(LeapPython.Hand_fingers_get)
__swig_getmethods__["tools"] = LeapPython.Hand_tools_get
if _newclass:
tools = _swig_property(LeapPython.Hand_tools_get)
__swig_getmethods__["palm_position"] = LeapPython.Hand_palm_position_get
if _newclass:
palm_position = _swig_property(LeapPython.Hand_palm_position_get)
__swig_getmethods__["palm_velocity"] = LeapPython.Hand_palm_velocity_get
if _newclass:
palm_velocity = _swig_property(LeapPython.Hand_palm_velocity_get)
__swig_getmethods__["palm_normal"] = LeapPython.Hand_palm_normal_get
if _newclass:
palm_normal = _swig_property(LeapPython.Hand_palm_normal_get)
__swig_getmethods__["direction"] = LeapPython.Hand_direction_get
if _newclass:
direction = _swig_property(LeapPython.Hand_direction_get)
__swig_getmethods__["basis"] = LeapPython.Hand_basis_get
if _newclass:
basis = _swig_property(LeapPython.Hand_basis_get)
__swig_getmethods__["is_valid"] = LeapPython.Hand_is_valid_get
if _newclass:
is_valid = _swig_property(LeapPython.Hand_is_valid_get)
__swig_getmethods__["sphere_center"] = LeapPython.Hand_sphere_center_get
if _newclass:
sphere_center = _swig_property(LeapPython.Hand_sphere_center_get)
__swig_getmethods__["sphere_radius"] = LeapPython.Hand_sphere_radius_get
if _newclass:
sphere_radius = _swig_property(LeapPython.Hand_sphere_radius_get)
__swig_getmethods__["grab_strength"] = LeapPython.Hand_grab_strength_get
if _newclass:
grab_strength = _swig_property(LeapPython.Hand_grab_strength_get)
__swig_getmethods__["pinch_strength"] = LeapPython.Hand_pinch_strength_get
if _newclass:
pinch_strength = _swig_property(LeapPython.Hand_pinch_strength_get)
__swig_getmethods__["palm_width"] = LeapPython.Hand_palm_width_get
if _newclass:
palm_width = _swig_property(LeapPython.Hand_palm_width_get)
__swig_getmethods__["stabilized_palm_position"] = LeapPython.Hand_stabilized_palm_position_get
if _newclass:
stabilized_palm_position = _swig_property(LeapPython.Hand_stabilized_palm_position_get)
__swig_getmethods__["wrist_position"] = LeapPython.Hand_wrist_position_get
if _newclass:
wrist_position = _swig_property(LeapPython.Hand_wrist_position_get)
__swig_getmethods__["time_visible"] = LeapPython.Hand_time_visible_get
if _newclass:
time_visible = _swig_property(LeapPython.Hand_time_visible_get)
__swig_getmethods__["confidence"] = LeapPython.Hand_confidence_get
if _newclass:
confidence = _swig_property(LeapPython.Hand_confidence_get)
__swig_getmethods__["is_left"] = LeapPython.Hand_is_left_get
if _newclass:
is_left = _swig_property(LeapPython.Hand_is_left_get)
__swig_getmethods__["is_right"] = LeapPython.Hand_is_right_get
if _newclass:
is_right = _swig_property(LeapPython.Hand_is_right_get)
__swig_getmethods__["frame"] = LeapPython.Hand_frame_get
if _newclass:
frame = _swig_property(LeapPython.Hand_frame_get)
__swig_getmethods__["arm"] = LeapPython.Hand_arm_get
if _newclass:
arm = _swig_property(LeapPython.Hand_arm_get)
__swig_destroy__ = LeapPython.delete_Hand
__del__ = lambda self: None
Hand_swigregister = LeapPython.Hand_swigregister
Hand_swigregister(Hand)
Hand.invalid = LeapPython.cvar.Hand_invalid
class Gesture(Interface):
__swig_setmethods__ = {}
for _s in [Interface]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, Gesture, name, value)
__swig_getmethods__ = {}
for _s in [Interface]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, Gesture, name)
__repr__ = _swig_repr
TYPE_INVALID = LeapPython.Gesture_TYPE_INVALID
TYPE_SWIPE = LeapPython.Gesture_TYPE_SWIPE
TYPE_CIRCLE = LeapPython.Gesture_TYPE_CIRCLE
TYPE_SCREEN_TAP = LeapPython.Gesture_TYPE_SCREEN_TAP
TYPE_KEY_TAP = LeapPython.Gesture_TYPE_KEY_TAP
STATE_INVALID = LeapPython.Gesture_STATE_INVALID
STATE_START = LeapPython.Gesture_STATE_START
STATE_UPDATE = LeapPython.Gesture_STATE_UPDATE
STATE_STOP = LeapPython.Gesture_STATE_STOP
def __init__(self, *args):
this = LeapPython.new_Gesture(*args)
try:
self.this.append(this)
except:
self.this = this
def __eq__(self, rhs):
return LeapPython.Gesture___eq__(self, rhs)
def __ne__(self, rhs):
return LeapPython.Gesture___ne__(self, rhs)
def __str__(self):
return LeapPython.Gesture___str__(self)
__swig_getmethods__["type"] = LeapPython.Gesture_type_get
if _newclass:
type = _swig_property(LeapPython.Gesture_type_get)
__swig_getmethods__["state"] = LeapPython.Gesture_state_get
if _newclass:
state = _swig_property(LeapPython.Gesture_state_get)
__swig_getmethods__["id"] = LeapPython.Gesture_id_get
if _newclass:
id = _swig_property(LeapPython.Gesture_id_get)
__swig_getmethods__["duration"] = LeapPython.Gesture_duration_get
if _newclass:
duration = _swig_property(LeapPython.Gesture_duration_get)
__swig_getmethods__["duration_seconds"] = LeapPython.Gesture_duration_seconds_get
if _newclass:
duration_seconds = _swig_property(LeapPython.Gesture_duration_seconds_get)
__swig_getmethods__["frame"] = LeapPython.Gesture_frame_get
if _newclass:
frame = _swig_property(LeapPython.Gesture_frame_get)
__swig_getmethods__["hands"] = LeapPython.Gesture_hands_get
if _newclass:
hands = _swig_property(LeapPython.Gesture_hands_get)
__swig_getmethods__["pointables"] = LeapPython.Gesture_pointables_get
if _newclass:
pointables = _swig_property(LeapPython.Gesture_pointables_get)
__swig_getmethods__["is_valid"] = LeapPython.Gesture_is_valid_get
if _newclass:
is_valid = _swig_property(LeapPython.Gesture_is_valid_get)
__swig_destroy__ = LeapPython.delete_Gesture
__del__ = lambda self: None
Gesture_swigregister = LeapPython.Gesture_swigregister
Gesture_swigregister(Gesture)
Gesture.invalid = LeapPython.cvar.Gesture_invalid
class SwipeGesture(Gesture):
__swig_setmethods__ = {}
for _s in [Gesture]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, SwipeGesture, name, value)
__swig_getmethods__ = {}
for _s in [Gesture]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, SwipeGesture, name)
__repr__ = _swig_repr
__swig_getmethods__["class_type"] = lambda x: LeapPython.SwipeGesture_class_type
if _newclass:
class_type = staticmethod(LeapPython.SwipeGesture_class_type)
def __init__(self, *args):
this = LeapPython.new_SwipeGesture(*args)
try:
self.this.append(this)
except:
self.this = this
__swig_getmethods__["start_position"] = LeapPython.SwipeGesture_start_position_get
if _newclass:
start_position = _swig_property(LeapPython.SwipeGesture_start_position_get)
__swig_getmethods__["position"] = LeapPython.SwipeGesture_position_get
if _newclass:
position = _swig_property(LeapPython.SwipeGesture_position_get)
__swig_getmethods__["direction"] = LeapPython.SwipeGesture_direction_get
if _newclass:
direction = _swig_property(LeapPython.SwipeGesture_direction_get)
__swig_getmethods__["speed"] = LeapPython.SwipeGesture_speed_get
if _newclass:
speed = _swig_property(LeapPython.SwipeGesture_speed_get)
__swig_getmethods__["pointable"] = LeapPython.SwipeGesture_pointable_get
if _newclass:
pointable = _swig_property(LeapPython.SwipeGesture_pointable_get)
__swig_destroy__ = LeapPython.delete_SwipeGesture
__del__ = lambda self: None
SwipeGesture_swigregister = LeapPython.SwipeGesture_swigregister
SwipeGesture_swigregister(SwipeGesture)
def SwipeGesture_class_type():
return LeapPython.SwipeGesture_class_type()
SwipeGesture_class_type = LeapPython.SwipeGesture_class_type
class CircleGesture(Gesture):
__swig_setmethods__ = {}
for _s in [Gesture]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, CircleGesture, name, value)
__swig_getmethods__ = {}
for _s in [Gesture]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, CircleGesture, name)
__repr__ = _swig_repr
__swig_getmethods__["class_type"] = lambda x: LeapPython.CircleGesture_class_type
if _newclass:
class_type = staticmethod(LeapPython.CircleGesture_class_type)
def __init__(self, *args):
this = LeapPython.new_CircleGesture(*args)
try:
self.this.append(this)
except:
self.this = this
__swig_getmethods__["center"] = LeapPython.CircleGesture_center_get
if _newclass:
center = _swig_property(LeapPython.CircleGesture_center_get)
__swig_getmethods__["normal"] = LeapPython.CircleGesture_normal_get
if _newclass:
normal = _swig_property(LeapPython.CircleGesture_normal_get)
__swig_getmethods__["progress"] = LeapPython.CircleGesture_progress_get
if _newclass:
progress = _swig_property(LeapPython.CircleGesture_progress_get)
__swig_getmethods__["radius"] = LeapPython.CircleGesture_radius_get
if _newclass:
radius = _swig_property(LeapPython.CircleGesture_radius_get)
__swig_getmethods__["pointable"] = LeapPython.CircleGesture_pointable_get
if _newclass:
pointable = _swig_property(LeapPython.CircleGesture_pointable_get)
__swig_destroy__ = LeapPython.delete_CircleGesture
__del__ = lambda self: None
CircleGesture_swigregister = LeapPython.CircleGesture_swigregister
CircleGesture_swigregister(CircleGesture)
def CircleGesture_class_type():
return LeapPython.CircleGesture_class_type()
CircleGesture_class_type = LeapPython.CircleGesture_class_type
class ScreenTapGesture(Gesture):
__swig_setmethods__ = {}
for _s in [Gesture]:
...
This file has been truncated, please download it to see its full contents.
sample file
Java# Copyright (C) 2012-2013 Leap Motion, Inc. All rights reserved. #
# Leap Motion proprietary and confidential. Not for distribution. #
# Use subject to the terms of the Leap Motion SDK Agreement available at #
# https://developer.leapmotion.com/sdk_agreement, or another agreement #
# between Leap Motion and you, your company or other organization. #
################################################################################
/******************************************************************************\
* Copyright (C) 2012-2013 Leap Motion, Inc. All rights reserved. *
* Leap Motion proprietary and confidential. Not for distribution. *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
\******************************************************************************/
import java.io.IOException;
import java.lang.Math;
import com.leapmotion.leap.*;
import com.leapmotion.leap.Gesture.State;
class SampleListener extends Listener {
public void onInit(Controller controller) {
System.out.println("Initialized");
}
public void onConnect(Controller controller) {
System.out.println("Connected");
controller.enableGesture(Gesture.Type.TYPE_SWIPE);
controller.enableGesture(Gesture.Type.TYPE_CIRCLE);
controller.enableGesture(Gesture.Type.TYPE_SCREEN_TAP);
controller.enableGesture(Gesture.Type.TYPE_KEY_TAP);
}
public void onDisconnect(Controller controller) {
//Note: not dispatched when running in a debugger.
System.out.println("Disconnected");
}
public void onExit(Controller controller) {
System.out.println("Exited");
}
public void onFrame(Controller controller) {
// Get the most recent frame and report some basic information
Frame frame = controller.frame();
System.out.println("Frame id: " + frame.id()
+ ", timestamp: " + frame.timestamp()
+ ", hands: " + frame.hands().count()
+ ", fingers: " + frame.fingers().count()
+ ", tools: " + frame.tools().count()
+ ", gestures " + frame.gestures().count());
//Get hands
for(Hand hand : frame.hands()) {
String handType = hand.isLeft() ? "Left hand" : "Right hand";
System.out.println(" " + handType + ", id: " + hand.id()
+ ", palm position: " + hand.palmPosition());
// Get the hand's normal vector and direction
Vector normal = hand.palmNormal();
Vector direction = hand.direction();
// Calculate the hand's pitch, roll, and yaw angles
System.out.println(" pitch: " + Math.toDegrees(direction.pitch()) + " degrees, "
+ "roll: " + Math.toDegrees(normal.roll()) + " degrees, "
+ "yaw: " + Math.toDegrees(direction.yaw()) + " degrees");
// Get arm bone
Arm arm = hand.arm();
System.out.println(" Arm direction: " + arm.direction()
+ ", wrist position: " + arm.wristPosition()
+ ", elbow position: " + arm.elbowPosition());
// Get fingers
for (Finger finger : hand.fingers()) {
System.out.println(" " + finger.type() + ", id: " + finger.id()
+ ", length: " + finger.length()
+ "mm, width: " + finger.width() + "mm");
//Get Bones
for(Bone.Type boneType : Bone.Type.values()) {
Bone bone = finger.bone(boneType);
System.out.println(" " + bone.type()
+ " bone, start: " + bone.prevJoint()
+ ", end: " + bone.nextJoint()
+ ", direction: " + bone.direction());
}
}
}
// Get tools
for(Tool tool : frame.tools()) {
System.out.println(" Tool id: " + tool.id()
+ ", position: " + tool.tipPosition()
+ ", direction: " + tool.direction());
}
GestureList gestures = frame.gestures();
for (int i = 0; i < gestures.count(); i++) {
Gesture gesture = gestures.get(i);
switch (gesture.type()) {
case TYPE_CIRCLE:
CircleGesture circle = new CircleGesture(gesture);
// Calculate clock direction using the angle between circle normal and pointable
String clockwiseness;
if (circle.pointable().direction().angleTo(circle.normal()) <= Math.PI/2) {
// Clockwise if angle is less than 90 degrees
clockwiseness = "clockwise";
} else {
clockwiseness = "counterclockwise";
}
// Calculate angle swept since last frame
double sweptAngle = 0;
if (circle.state() != State.STATE_START) {
CircleGesture previousUpdate = new CircleGesture(controller.frame(1).gesture(circle.id()));
sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * Math.PI;
}
System.out.println(" Circle id: " + circle.id()
+ ", " + circle.state()
+ ", progress: " + circle.progress()
+ ", radius: " + circle.radius()
+ ", angle: " + Math.toDegrees(sweptAngle)
+ ", " + clockwiseness);
break;
case TYPE_SWIPE:
SwipeGesture swipe = new SwipeGesture(gesture);
System.out.println(" Swipe id: " + swipe.id()
+ ", " + swipe.state()
+ ", position: " + swipe.position()
+ ", direction: " + swipe.direction()
+ ", speed: " + swipe.speed());
break;
case TYPE_SCREEN_TAP:
ScreenTapGesture screenTap = new ScreenTapGesture(gesture);
System.out.println(" Screen Tap id: " + screenTap.id()
+ ", " + screenTap.state()
+ ", position: " + screenTap.position()
+ ", direction: " + screenTap.direction());
break;
case TYPE_KEY_TAP:
KeyTapGesture keyTap = new KeyTapGesture(gesture);
System.out.println(" Key Tap id: " + keyTap.id()
+ ", " + keyTap.state()
+ ", position: " + keyTap.position()
+ ", direction: " + keyTap.direction());
break;
default:
System.out.println("Unknown gesture type.");
break;
}
}
if (!frame.hands().isEmpty() || !gestures.isEmpty()) {
System.out.println();
}
}
}
class Sample {
public static void main(String[] args) {
// Create a sample listener and controller
SampleListener listener = new SampleListener();
Controller controller = new Controller();
// Have the sample listener receive events from the controller
controller.addListener(listener);
// Keep this process running until Enter is pressed
System.out.println("Press Enter to quit...");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
// Remove the sample listener when done
controller.removeListener(listener);
}
}
/******************************************************************************\
* Author: Justin Platz : @JustinMPlatz *
* This code is completely open-source. Do with it as you please. *
\******************************************************************************/
import java.io.IOException;
import java.lang.Math;
import com.leapmotion.leap.*;
import com.pubnub.api.*;
import org.json.*;
public class LeapToServo implements Runnable{
public static final String CHANNEL = "leap2pi";
private Pubnub pubnub;
private Controller controller;
private boolean running;
int oldLeftYaw = 0;
int oldLeftPitch = 0;
int oldRightYaw = 0;
int oldRightPitch = 0;
public LeapToServo(String pubKey, String subKey){
pubnub = new Pubnub(pubKey, subKey);
pubnub.setUUID("LeapController");
try {
pubnub.subscribe("leap2pi", new Callback() {
@Override
public void connectCallback(String channel, Object message) {
}
@Override
public void disconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : DISCONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
public void reconnectCallback(String channel, Object message) {
System.out.println("SUBSCRIBE : RECONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
@Override
public void successCallback(String channel, Object message) {
}
@Override
public void errorCallback(String channel, PubnubError error) {
System.out.println("SUBSCRIBE : ERROR on channel " + channel
+ " : " + error.toString());
}
}
);
} catch (PubnubException e) {
System.out.println(e.toString());
}
}
public void startTracking(){
// Create a controller
this.controller = new Controller();
this.running = true;
Thread t = new Thread(this);
t.start();
// Keep this process running until Enter is pressed
System.out.println("Press Enter to quit...");
try {
System.in.read();
this.running=false;
t.join();
cleanup();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e){
e.printStackTrace();
}
}
/**
* Take radian reading and return degree value adjusted for our desired range/midpoint of servo range
* @param radians Radian value to be converted
* @return Adjusted degree value
*/
public static int radiansToAdjustedDegrees(int radians){
int degrees = (int) (radians * (180 / Math.PI));
degrees = (int) Math.floor(degrees + 90);
return degrees;
}
/**
* Get a PWM value from degree closely modeled by a quadratic equation
* @param degree pitch degree value
* @return PWM value
*/
public static double pitchDegreeToPWM(double degree){
double a = 0.00061728395;
double b = 2.38888888889;
double c = 150;
return a*(degree*degree) + b*degree + c;
}
/**
* Get a PWM value from degree closely modeled by a quadratic equation
* @param degree pitch degree value
* @return PWM value
*/
public static double yawDegreeToPWM(double degree){
double a = 0.0;
double b = 3.19444444;
double c = 150;
return a*(degree*degree) + b*degree + c;
}
/**
* Force a value to be between 0 and 180 degrees for servo
* @param value degree value returned by Leap Controller
* @return normalized value between 0-180
*/
public static int normalizeDegree(int value){
value = (value > 90) ? 90 : value;
value = (value < -90) ? -90 : value;
return value+90;
}
public static int fingersToByte(Hand hand) {
int theByte = 0;
int value = 0;
if (hand.isRight()) {
for (int j = 1; j < 5; ++j) {
switch (j) {
case 4:
value = 0;
break;
default:
value = j;
break;
}
if (hand.fingers().get(j).isExtended()) {
theByte = theByte | (1 << value);
}
}
theByte <<= 4;
} else if (hand.isLeft()) {
for (int i = 1; i < 5; ++i) { // i = 4; v = 1
switch (i) {
case 1:
value = 0;
break;
case 2:
value = 3;
break;
case 3:
value = 2;
break;
case 4:
value = 1;
break;
default:
break;
}
if (hand.fingers().get(i).isExtended()) {
theByte = theByte | (1 << value);
}
}
}
return theByte;
}
public JSONObject handleHand(Hand hand){
boolean isLeft = hand.isLeft();
String handName = (isLeft) ? "left" : "right";
Vector direction = hand.direction();
int yaw = (int) Math.toDegrees(direction.yaw());
int pitch = (int) Math.toDegrees(direction.pitch());
// Normalize Yaw and Pitch
yaw = normalizeDegree(yaw);
pitch *= (isLeft) ? -1 : 1;
pitch = normalizeDegree(pitch);
// Get PWM Values
yaw = (int) yawDegreeToPWM(yaw);
pitch = (int) pitchDegreeToPWM(pitch);
JSONObject payload = new JSONObject();
int theByte = fingersToByte(hand);
int oldYaw = (isLeft) ? oldLeftYaw : oldRightYaw;
int oldPitch = (isLeft) ? oldLeftPitch : oldRightPitch;
if( (Math.abs(oldPitch - pitch) > 5) || (Math.abs(oldYaw - yaw) > 5) ) {
try {
payload.put(handName + "_yaw", yaw);
payload.put(handName + "_pitch", pitch);
payload.put(handName + "_byte", theByte);
} catch (JSONException e) {
e.printStackTrace();
}
if (isLeft) {
this.oldLeftYaw = yaw;
this.oldLeftPitch = pitch;
} else {
this.oldRightYaw = yaw;
this.oldRightPitch = pitch;
}
}
else{
try {
payload.put(handName + "_yaw", oldYaw);
payload.put(handName + "_pitch", oldPitch);
payload.put(handName + "_byte", theByte);
} catch (JSONException e) {
e.printStackTrace();
}
}
return payload;
}
public void captureFrame(Controller controller) {
// Get the most recent frame and report some basic information
Frame frame = controller.frame();
JSONObject payload = new JSONObject();
for (Hand hand : frame.hands()) {
try {
if (hand.isLeft()) {
payload.put("left_hand", handleHand(hand));
} else {
payload.put("right_hand", handleHand(hand));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
if(!payload.toString().equals("{}")) {
pubnub.publish(CHANNEL, payload, new Callback() { });
}
}
public void cleanup(){
try {
JSONObject payload = new JSONObject();
JSONObject left = new JSONObject();
JSONObject right = new JSONObject();
left.put("left_yaw", 400);
left.put("left_pitch",400);
left.put("left_byte", (1 << 4) - 1);
right.put("right_yaw", 400);
right.put("right_pitch",400);
right.put("right_byte", ((1 << 4) - 1) << 4);
payload.put("left_hand", left);
payload.put("right_hand", right);
this.pubnub.publish(CHANNEL, payload, new Callback() {});
} catch (JSONException e){
e.printStackTrace();
}
}
/**
* Implementation of the Runnable interface.
*/
public void run(){
for(;;) {
if (!running) break;
captureFrame(this.controller);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
String pubKey = "Your_Pub_Key";
String subKey = "Your_Sub_Key";
LeapToServo s = new LeapToServo(pubKey, subKey);
s.startTracking();
}
}
Comments