leap

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2018 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

README

Leap

The Leap Motion is a user-interface device that tracks the user's hand motions, and translates them into events that can control robots and physical computing hardware.

For more info about the Leap Motion platform click Leap Motion

How to Install

First install the Leap Motion Software

Now you can install the package with:

go get -d -u gobot.io/x/gobot/...

How to Use

package main

import (
	"fmt"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/platforms/leap"
)

func main() {
	leapMotionAdaptor := leap.NewAdaptor("127.0.0.1:6437")
	l := leap.NewDriver(leapMotionAdaptor)

	work := func() {
		l.On(l.Event("message"), func(data interface{}) {
			fmt.Println(data.(leap.Frame))
		})
	}

	robot := gobot.NewRobot("leapBot",
		[]gobot.Connection{leapMotionAdaptor},
		[]gobot.Device{l},
		work,
	)

	robot.Start()
}

How To Connect

OSX

This driver works out of the box with the vanilla installation of the Leap Motion Software that you get in their Setup Guide.

The main steps are:

  • Run Leap Motion.app to open a websocket connection in port 6437.
  • Connect your Computer and Leap Motion Controller.
  • Connect to the device via Gobot.
Ubuntu

The Linux download of the Leap Motion software can be obtained from Leap Motion Dev Center (requires free signup)

The main steps are:

  • Run the leapd daemon, to open a websocket connection in port 6437.
  • Connect your computer and the Leap Motion controller
  • Connect to the device via Gobot

Documentation

Overview

Package leap provides the Gobot adaptor and driver for the Leap Motion.

Installing:

* First install the [Leap Motion Software](https://www.leapmotion.com/setup). * Then install the package:

go get gobot.io/x/gobot/platforms/leap

Example:

package main

import (
	"fmt"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/platforms/leap"
)

func main() {
	leapMotionAdaptor := leap.NewAdaptor("127.0.0.1:6437")
	l := leap.NewDriver(leapMotionAdaptor)

	work := func() {
		l.On(l.Event("message"), func(data interface{}) {
			fmt.Println(data.(leap.Frame))
		})
	}

	robot := gobot.NewRobot("leapBot",
		[]gobot.Connection{leapMotionAdaptor},
		[]gobot.Device{l},
		work,
	)

	robot.Start()
}

For more information refer to the leap README: https://github.com/hybridgroup/gobot/blob/master/platforms/leap/README.md

Index

Constants

View Source
const (
	// MessageEvent event
	MessageEvent = "message"
	// HandEvent event
	HandEvent = "hand"
	// GestureEvent event
	GestureEvent = "gesture"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Adaptor added in v1.0.0

type Adaptor struct {
	// contains filtered or unexported fields
}

Adaptor is the Gobot Adaptor connection to the Leap Motion

func NewAdaptor added in v1.0.0

func NewAdaptor(port string) *Adaptor

NewAdaptor creates a new leap motion adaptor using specified port, which is this case is the host IP or name of the Leap Motion daemon

func (*Adaptor) Connect added in v1.0.0

func (l *Adaptor) Connect() (err error)

Connect returns true if connection to leap motion is established successfully

func (*Adaptor) Finalize added in v1.0.0

func (l *Adaptor) Finalize() (err error)

Finalize ends connection to leap motion

func (*Adaptor) Name added in v1.0.0

func (l *Adaptor) Name() string

Name returns the Adaptor Name

func (*Adaptor) Port added in v1.0.0

func (l *Adaptor) Port() string

Port returns the Adaptor Port which is this case is the host IP or name

func (*Adaptor) SetName added in v1.0.0

func (l *Adaptor) SetName(n string)

SetName sets the Adaptor Name

type Driver added in v1.0.0

type Driver struct {
	gobot.Eventer
	// contains filtered or unexported fields
}

Driver the Gobot software device to the Leap Motion

func NewDriver added in v1.0.0

func NewDriver(a *Adaptor) *Driver

NewDriver creates a new leap motion driver

Adds the following events:

"message" - Gets triggered when receiving a message from leap motion
"hand" - Gets triggered per-message when leap motion detects a hand
"gesture" - Gets triggered per-message when leap motion detects a hand

func (*Driver) Connection added in v1.0.0

func (l *Driver) Connection() gobot.Connection

Connection returns the Driver's Connection

func (*Driver) Halt added in v1.0.0

func (l *Driver) Halt() (errs error)

Halt returns nil if driver is halted successfully

func (*Driver) Name added in v1.0.0

func (l *Driver) Name() string

Name returns the Driver Name

func (*Driver) ParseFrame added in v1.0.0

func (l *Driver) ParseFrame(data []byte) Frame

ParseFrame converts json data to a Frame

func (*Driver) SetName added in v1.0.0

func (l *Driver) SetName(n string)

SetName sets the Driver Name

func (*Driver) Start added in v1.0.0

func (l *Driver) Start() (err error)

Start inits leap motion driver by enabling gestures and listening from incoming messages.

Publishes the following events:

"message" - Emits Frame on new message received from Leap.
"hand" - Emits Hand when detected in message from Leap.
"gesture" - Emits Gesture when detected in message from Leap.

type Frame

type Frame struct {
	CurrentFrameRate float64        `json:"currentFrameRate"`
	Gestures         []Gesture      `json:"gestures"`
	Hands            []Hand         `json:"hands"`
	ID               int            `json:"id"`
	InteractionBox   InteractionBox `json:"interactionBox"`
	Pointables       []Pointable    `json:"pointables"`
	R                [][]float64    `json:"r"`
	S                float64        `json:"s"`
	T                []float64      `json:"t"`
	Timestamp        int            `json:"timestamp"`
}

Frame is the base representation returned that holds every other objects

type Gesture

type Gesture struct {
	Direction     []float64   `json:"direction"`
	Duration      int         `json:"duration"`
	Hands         []Hand      `json:"hands"`
	ID            int         `json:"id"`
	Pointables    []Pointable `json:"pointables"`
	Position      []float64   `json:"position"`
	Speed         float64     `json:"speed"`
	StartPosition []float64   `json:"StartPosition"`
	State         string      `json:"state"`
	Type          string      `json:"type"`
}

Gesture is a Leap Motion gesture tht has been detected

type Hand

type Hand struct {
	Direction              []float64   `json:"direction"`
	ID                     int         `json:"id"`
	PalmNormal             []float64   `json:"palmNormal"`
	PalmPosition           []float64   `json:"PalmPosition"`
	PalmVelocity           []float64   `json:"PalmVelocity"`
	R                      [][]float64 `json:"r"`
	S                      float64     `json:"s"`
	SphereCenter           []float64   `json:"sphereCenter"`
	SphereRadius           float64     `json:"sphereRadius"`
	StabilizedPalmPosition []float64   `json:"stabilizedPalmPosition"`
	T                      []float64   `json:"t"`
	TimeVisible            float64     `json:"TimeVisible"`
}

Hand is a Leap Motion hand tht has been detected

func (*Hand) X

func (h *Hand) X() float64

X returns hand x value

func (*Hand) Y

func (h *Hand) Y() float64

Y returns hand y value

func (*Hand) Z

func (h *Hand) Z() float64

Z returns hand z value

type InteractionBox

type InteractionBox struct {
	Center []int     `json:"center"`
	Size   []float64 `json:"size"`
}

InteractionBox is the area within which the gestural interaction has been detected

type Pointable

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

Pointable is a Leap Motion pointing motion tht has been detected

Jump to

Keyboard shortcuts

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