-
Notifications
You must be signed in to change notification settings - Fork 110
/
gripper.go
95 lines (80 loc) · 2.46 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
92
93
94
95
// Package fake implements a fake gripper.
package fake
import (
"context"
"sync"
"go.viam.com/rdk/components/gripper"
"go.viam.com/rdk/logging"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/spatialmath"
)
var model = resource.DefaultModelFamily.WithModel("fake")
// Config is the config for a trossen gripper.
type Config struct {
resource.TriviallyValidateConfig
}
func init() {
resource.RegisterComponent(gripper.API, model, resource.Registration[gripper.Gripper, *Config]{Constructor: NewGripper})
}
// Gripper is a fake gripper that can simply read and set properties.
type Gripper struct {
resource.Named
resource.TriviallyCloseable
geometries []spatialmath.Geometry
mu sync.Mutex
logger logging.Logger
}
// NewGripper instantiates a new gripper of the fake model type.
func NewGripper(
ctx context.Context, deps resource.Dependencies, conf resource.Config, logger logging.Logger,
) (gripper.Gripper, error) {
g := &Gripper{
Named: conf.ResourceName().AsNamed(),
geometries: []spatialmath.Geometry{},
logger: logger,
}
if err := g.Reconfigure(ctx, deps, conf); err != nil {
return nil, err
}
return g, nil
}
// Reconfigure reconfigures the gripper atomically and in place.
func (g *Gripper) Reconfigure(_ context.Context, _ resource.Dependencies, conf resource.Config) error {
g.mu.Lock()
defer g.mu.Unlock()
if conf.Frame != nil && conf.Frame.Geometry != nil {
geometry, err := conf.Frame.Geometry.ParseConfig()
if err != nil {
return err
}
g.geometries = []spatialmath.Geometry{geometry}
}
return nil
}
// ModelFrame returns the dynamic frame of the model.
func (g *Gripper) ModelFrame() referenceframe.Model {
return nil
}
// Open does nothing.
func (g *Gripper) Open(ctx context.Context, extra map[string]interface{}) error {
return nil
}
// Grab does nothing.
func (g *Gripper) Grab(ctx context.Context, extra map[string]interface{}) (bool, error) {
return false, nil
}
// Stop doesn't do anything for a fake gripper.
func (g *Gripper) Stop(ctx context.Context, extra map[string]interface{}) error {
return nil
}
// IsMoving is always false for a fake gripper.
func (g *Gripper) IsMoving(ctx context.Context) (bool, error) {
return false, nil
}
// Geometries returns the geometries associated with the fake base.
func (g *Gripper) Geometries(ctx context.Context, extra map[string]interface{}) ([]spatialmath.Geometry, error) {
g.mu.Lock()
defer g.mu.Unlock()
return g.geometries, nil
}