-
Notifications
You must be signed in to change notification settings - Fork 110
/
gripper.go
91 lines (79 loc) · 2.63 KB
/
gripper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package inject
import (
"context"
"go.viam.com/rdk/components/gripper"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/spatialmath"
)
// Gripper is an injected gripper.
type Gripper struct {
gripper.Gripper
name resource.Name
DoFunc func(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error)
OpenFunc func(ctx context.Context, extra map[string]interface{}) error
GrabFunc func(ctx context.Context, extra map[string]interface{}) (bool, error)
StopFunc func(ctx context.Context, extra map[string]interface{}) error
IsMovingFunc func(context.Context) (bool, error)
CloseFunc func(ctx context.Context) error
GeometriesFunc func(ctx context.Context) ([]spatialmath.Geometry, error)
}
// NewGripper returns a new injected gripper.
func NewGripper(name string) *Gripper {
return &Gripper{name: gripper.Named(name)}
}
// Name returns the name of the resource.
func (g *Gripper) Name() resource.Name {
return g.name
}
// Open calls the injected Open or the real version.
func (g *Gripper) Open(ctx context.Context, extra map[string]interface{}) error {
if g.OpenFunc == nil {
return g.Gripper.Open(ctx, extra)
}
return g.OpenFunc(ctx, extra)
}
// Grab calls the injected Grab or the real version.
func (g *Gripper) Grab(ctx context.Context, extra map[string]interface{}) (bool, error) {
if g.GrabFunc == nil {
return g.Gripper.Grab(ctx, extra)
}
return g.GrabFunc(ctx, extra)
}
// Stop calls the injected Stop or the real version.
func (g *Gripper) Stop(ctx context.Context, extra map[string]interface{}) error {
if g.StopFunc == nil {
return g.Gripper.Stop(ctx, extra)
}
return g.StopFunc(ctx, extra)
}
// IsMoving calls the injected IsMoving or the real version.
func (g *Gripper) IsMoving(ctx context.Context) (bool, error) {
if g.IsMovingFunc == nil {
return g.Gripper.IsMoving(ctx)
}
return g.IsMovingFunc(ctx)
}
// Close calls the injected Close or the real version.
func (g *Gripper) Close(ctx context.Context) error {
if g.CloseFunc == nil {
if g.Gripper == nil {
return nil
}
return g.Gripper.Close(ctx)
}
return g.CloseFunc(ctx)
}
// DoCommand calls the injected DoCommand or the real version.
func (g *Gripper) DoCommand(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error) {
if g.DoFunc == nil {
return g.Gripper.DoCommand(ctx, cmd)
}
return g.DoFunc(ctx, cmd)
}
// Geometries returns the gripper's geometries.
func (g *Gripper) Geometries(ctx context.Context, extra map[string]interface{}) ([]spatialmath.Geometry, error) {
if g.GeometriesFunc == nil {
return g.Gripper.Geometries(ctx, extra)
}
return g.GeometriesFunc(ctx)
}