gobot.io/x/gobot/v2@v2.1.0/platforms/leap/parser.go (about)

     1  package leap
     2  
     3  import (
     4  	"encoding/json"
     5  )
     6  
     7  // Gesture is a Leap Motion gesture that has been detected
     8  type Gesture struct {
     9  	Center        []float64   `json:"center"`
    10  	Direction     []float64   `json:"direction"`
    11  	Duration      int         `json:"duration"`
    12  	HandIDs       []int       `json:"handIds"`
    13  	ID            int         `json:"id"`
    14  	Normal        []float64   `json:"normal"`
    15  	PointableIDs  []int       `json:"pointableIds"`
    16  	Position      []float64   `json:"position"`
    17  	Progress      float64     `json:"progress"`
    18  	Radius        float64     `json:"radius"`
    19  	Speed         float64     `json:"speed"`
    20  	StartPosition []float64   `json:"StartPosition"`
    21  	State         string      `json:"state"`
    22  	Type          string      `json:"type"`
    23  }
    24  
    25  // Hand is a Leap Motion hand that has been detected
    26  type Hand struct {
    27  	ArmBasis               [][]float64 `json:"armBasis"`
    28  	ArmWidth               float64     `json:"armWidth"`
    29  	Confidence             float64     `json:"confidence"`
    30  	Direction              []float64   `json:"direction"`
    31  	Elbow                  []float64   `json:"elbow"`
    32  	GrabStrength           float64     `json:"grabStrength"`
    33  	ID                     int         `json:"id"`
    34  	PalmNormal             []float64   `json:"palmNormal"`
    35  	PalmPosition           []float64   `json:"PalmPosition"`
    36  	PalmVelocity           []float64   `json:"PalmVelocity"`
    37  	PinchStrength          float64     `json:"PinchStrength"`
    38  	R                      [][]float64 `json:"r"`
    39  	S                      float64     `json:"s"`
    40  	SphereCenter           []float64   `json:"sphereCenter"`
    41  	SphereRadius           float64     `json:"sphereRadius"`
    42  	StabilizedPalmPosition []float64   `json:"stabilizedPalmPosition"`
    43  	T                      []float64   `json:"t"`
    44  	TimeVisible            float64     `json:"TimeVisible"`
    45  	Type                   string      `json:"type"`
    46  	Wrist                  []float64   `json:"wrist"`
    47  }
    48  
    49  // Pointable is a Leap Motion pointing motion that has been detected
    50  type Pointable struct {
    51  	Bases                 [][][]float64  `json:"bases"`
    52  	BTipPosition          []float64    `json:"btipPosition"`
    53  	CarpPosition          []float64    `json:"carpPosition"`
    54  	DipPosition           []float64    `json:"dipPosition"`
    55  	Direction             []float64    `json:"direction"`
    56  	Extended              bool         `json:"extended"`
    57  	HandID                int          `json:"handId"`
    58  	ID                    int          `json:"id"`
    59  	Length                float64      `json:"length"`
    60  	MCPPosition           []float64    `json:"mcpPosition"`
    61  	PIPPosition           []float64    `json:"pipPosition"`
    62  	StabilizedTipPosition []float64    `json:"stabilizedTipPosition"`
    63  	TimeVisible           float64      `json:"timeVisible"`
    64  	TipPosition           []float64    `json:"tipPosition"`
    65  	TipVelocity           []float64    `json:"tipVelocity"`
    66  	Tool                  bool         `json:"tool"`
    67  	TouchDistance         float64      `json:"touchDistance"`
    68  	TouchZone             string       `json:"touchZone"`
    69  	Type                  int          `json:"type"`
    70  	Width                 float64      `json:"width"`
    71  }
    72  
    73  // InteractionBox is the area within which the gestural interaction has been detected
    74  type InteractionBox struct {
    75  	Center []float64 `json:"center"`
    76  	Size   []float64 `json:"size"`
    77  }
    78  
    79  // Frame is the base representation returned that holds every other objects
    80  type Frame struct {
    81  	CurrentFrameRate float64        `json:"currentFrameRate"`
    82  	Gestures         []Gesture      `json:"gestures"`
    83  	Hands            []Hand         `json:"hands"`
    84  	ID               int            `json:"id"`
    85  	InteractionBox   InteractionBox `json:"interactionBox"`
    86  	Pointables       []Pointable    `json:"pointables"`
    87  	R                [][]float64    `json:"r"`
    88  	S                float64        `json:"s"`
    89  	T                []float64      `json:"t"`
    90  	Timestamp        uint64         `json:"timestamp"`
    91  }
    92  
    93  // X returns hand x value
    94  func (h *Hand) X() float64 {
    95  	return h.PalmPosition[0]
    96  }
    97  
    98  // Y returns hand y value
    99  func (h *Hand) Y() float64 {
   100  	return h.PalmPosition[1]
   101  }
   102  
   103  // Z returns hand z value
   104  func (h *Hand) Z() float64 {
   105  	return h.PalmPosition[2]
   106  }
   107  
   108  // ParseFrame converts json data to a Frame
   109  func (l *Driver) ParseFrame(data []byte) Frame {
   110  	var frame Frame
   111  	json.Unmarshal(data, &frame)
   112  	return frame
   113  }