gomotion

package module
v0.0.0-...-8dafc14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2014 License: MIT Imports: 2 Imported by: 0

README

gomotion

Gomotion is a framework that uses the WebSocket protocol to communicate with a LeapMotion device.

baby-gopher

Features

  • Dead simple to use.
  • Frame collection happens concurrently
  • JSON comes back parsed and placed into structs for handling.

Docs

http://godoc.org/github.com/whoisjake/gomotion

To use

In your $GOPATH:

$ cd $GOPATH
$ go get github.com/whoisjake/gomotion

And then: import "github.com/whoisjake/gomotion"

Example

package main

import (
	"github.com/whoisjake/gomotion"
	"log"
	"runtime"
)

func main() {
	// Get a device.
	runtime.GOMAXPROCS(runtime.NumCPU())
	device, err := gomotion.GetDevice("ws://127.0.0.1:6437/v3.json")
	if err != nil {
		log.Fatal(err)
	}
	device.Listen()
	defer device.Close()
	for frame := range device.Pipe {
		log.Printf("%+v\n", frame)
	}
}

Documentation

Overview

The package gomotion defines a concurrent Go library that can connect to a Leap motion device over a WebSocket conection. By default, the LeapMotion exposes a JSON WebSocket that pumps out messages near 30 to 50 fps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Finger

type Finger struct {
	Id int `json:id`
	*Pointable
}

A Frame can have a list of Fingers, which are structured like Pointables

type Frame

type Frame struct {
	Id             int            `json:"id"`
	Timestamp      int            `json:"timestamp"`
	InteractionBox InteractionBox `json:interactionBox`
	Hands          []Hand         `json:"hands"`
	Pointables     []Pointable    `json:"pointables"`
	Fingers        []Finger       `json:"fingers"`
	Tools          []Tool         `json:"tools"`
	Gestures       []Gesture      `json:"gestures"`
	R              [][]float32    `json:"r"`
	S              float32        `json:"s"`
	T              []float32      `json:"t"`
}

This struct represents each Frame presented on the LeapMotionDevice WebSocket. The base structure will fill in with information available or for the arrays, empty arrays, so that you can quickly iterate over each array in the struct.

type FrameErr

type FrameErr struct {
	Frame *Frame
	Error error
}

A simple type to carry decode errors along rather than just dieing.

type Gesture

type Gesture struct {
	Id            int       `json:id`
	State         string    `json:state`
	GestureType   string    `json:type`
	Duration      int       `json:duration`
	HandIds       []int     `json:handIds`
	PointableIds  []int     `json:pointableIds`
	Speed         float32   `json:speed`
	Radius        float32   `json:radius`
	Progress      float32   `json:progress`
	Center        []float32 `json:center`
	Normal        []float32 `json:normal`
	StartPosition []float32 `json:startPosition`
	Position      []float32 `json:position`
	Direction     []float32 `json:direction`
}

A Frame can have a list of Gestures that are starting, updating, or ending. A Gesture will carry the same ID across the frames in which it is visible. *NOTE* Pay attention to the State of the Gesture, as it can give you an idea of where the gesture is going.

type Hand

type Hand struct {
	Id                     int         `json:id`
	Direction              []float32   `json:direction`
	PalmNormal             []float32   `json:palmNormal`
	PalmPosition           []float32   `json:palmPosition`
	PalmVelocity           []float32   `json:palmVelocity`
	SphereCenter           []float32   `json:sphereCenter`
	SphereRadius           float32     `json:"sphereRadius"`
	StabilizedPalmPosition []float32   `json:StabilizedPalmPosition`
	R                      [][]float32 `json:"r"`
	S                      float32     `json:"s"`
	T                      []float32   `json:"t"`
	TimeVisible            float32     `json:timeVisible`
}

The hand is a basic trackable object through the LeapMotionDevice. There can be zero, one, or two that come through each Frame. A Hand will carry the same ID across the frames in which it is visible.

type InteractionBox

type InteractionBox struct {
	Center []float32 `json:center`
	Size   []float32 `json:size`
}

An InteractionBox gives you the physical bounding box in which the device is detecting the Hands, Gestures, etc. It's provided to create a perspective to map your screen view box to.

type LeapMotionDevice

type LeapMotionDevice struct {
	Pipe       chan FrameErr
	Connection *websocket.Conn
}

The LeapMotionDevice definition. Connecting to a device will return an instance of this struct.

func GetDevice

func GetDevice(url string) (*LeapMotionDevice, error)

This function acts as a constructor and connector for the gomotion package.

func (*LeapMotionDevice) Close

func (device *LeapMotionDevice) Close()

This function closes the internal WebSocket connection on a LeapMotionDevice

func (*LeapMotionDevice) Listen

func (device *LeapMotionDevice) Listen() error

This function starts the listening on the WebSocket. By default it enables Gestures on the LeapMotionDevice.

type Pointable

type Pointable struct {
	Id                    int       `json:id`
	HandId                int       `json:handId`
	Direction             []float32 `json:direction`
	Length                float32   `json:length`
	StabilizedTipPosition []float32 `json:stabilizedTipPosition`
	TimeVisible           float32   `json:timeVisible`
	TipPosition           []float32 `json:tipPosition`
	TipVelocity           []float32 `json:tipVelocity`
	Tool                  bool      `json:tool`
	TouchDistance         float32   `json:touchDistance`
	TouchZone             string    `json:touchZone`
}

A Finger or Tool can be a Pointable, as well as pointables themselves. A Frame will have a list of pointables associated with each hand.

type Tool

type Tool struct {
	Id int `json:id`
	*Pointable
}

A Frame can have a list of Tools, which are structured like Pointables

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL