gobot: gobot.io/x/gobot/platforms/leap Index | Files

package leap

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

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

Package Files

doc.go leap_motion_adaptor.go leap_motion_driver.go parser.go

Constants

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

type Adaptor Uses

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

Adaptor is the Gobot Adaptor connection to the Leap Motion

func NewAdaptor Uses

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 Uses

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

Connect returns true if connection to leap motion is established successfully

func (*Adaptor) Finalize Uses

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

Finalize ends connection to leap motion

func (*Adaptor) Name Uses

func (l *Adaptor) Name() string

Name returns the Adaptor Name

func (*Adaptor) Port Uses

func (l *Adaptor) Port() string

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

func (*Adaptor) SetName Uses

func (l *Adaptor) SetName(n string)

SetName sets the Adaptor Name

type Driver Uses

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

Driver the Gobot software device to the Leap Motion

func NewDriver Uses

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 gesture

func (*Driver) Connection Uses

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

Connection returns the Driver's Connection

func (*Driver) Halt Uses

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

Halt returns nil if driver is halted successfully

func (*Driver) Name Uses

func (l *Driver) Name() string

Name returns the Driver Name

func (*Driver) ParseFrame Uses

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

ParseFrame converts json data to a Frame

func (*Driver) SetName Uses

func (l *Driver) SetName(n string)

SetName sets the Driver Name

func (*Driver) Start Uses

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 Uses

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        uint64         `json:"timestamp"`
}

Frame is the base representation returned that holds every other objects

type Gesture Uses

type Gesture struct {
    Center        []float64 `json:"center"`
    Direction     []float64 `json:"direction"`
    Duration      int       `json:"duration"`
    HandIDs       []int     `json:"handIds"`
    ID            int       `json:"id"`
    Normal        []float64 `json:"normal"`
    PointableIDs  []int     `json:"pointableIds"`
    Position      []float64 `json:"position"`
    Progress      float64   `json:"progress"`
    Radius        float64   `json:"radius"`
    Speed         float64   `json:"speed"`
    StartPosition []float64 `json:"StartPosition"`
    State         string    `json:"state"`
    Type          string    `json:"type"`
}

Gesture is a Leap Motion gesture that has been detected

type Hand Uses

type Hand struct {
    ArmBasis               [][]float64 `json:"armBasis"`
    ArmWidth               float64     `json:"armWidth"`
    Confidence             float64     `json:"confidence"`
    Direction              []float64   `json:"direction"`
    Elbow                  []float64   `json:"elbow"`
    GrabStrength           float64     `json:"grabStrength"`
    ID                     int         `json:"id"`
    PalmNormal             []float64   `json:"palmNormal"`
    PalmPosition           []float64   `json:"PalmPosition"`
    PalmVelocity           []float64   `json:"PalmVelocity"`
    PinchStrength          float64     `json:"PinchStrength"`
    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"`
    Type                   string      `json:"type"`
    Wrist                  []float64   `json:"wrist"`
}

Hand is a Leap Motion hand that has been detected

func (*Hand) X Uses

func (h *Hand) X() float64

X returns hand x value

func (*Hand) Y Uses

func (h *Hand) Y() float64

Y returns hand y value

func (*Hand) Z Uses

func (h *Hand) Z() float64

Z returns hand z value

type InteractionBox Uses

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

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

type Pointable Uses

type Pointable struct {
    Bases                 [][][]float64 `json:"bases"`
    BTipPosition          []float64     `json:"btipPosition"`
    CarpPosition          []float64     `json:"carpPosition"`
    DipPosition           []float64     `json:"dipPosition"`
    Direction             []float64     `json:"direction"`
    Extended              bool          `json:"extended"`
    HandID                int           `json:"handId"`
    ID                    int           `json:"id"`
    Length                float64       `json:"length"`
    MCPPosition           []float64     `json:"mcpPosition"`
    PIPPosition           []float64     `json:"pipPosition"`
    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"`
    Type                  int           `json:"type"`
    Width                 float64       `json:"width"`
}

Pointable is a Leap Motion pointing motion that has been detected

Package leap imports 4 packages (graph). Updated 2019-05-23. Refresh now. Tools for package owners.