-
Notifications
You must be signed in to change notification settings - Fork 110
/
arm.go
143 lines (125 loc) · 4.75 KB
/
arm.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package inject
import (
"context"
pb "go.viam.com/api/component/arm/v1"
"go.viam.com/rdk/components/arm"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/spatialmath"
)
// Arm is an injected arm.
type Arm struct {
arm.Arm
name resource.Name
DoFunc func(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error)
EndPositionFunc func(ctx context.Context, extra map[string]interface{}) (spatialmath.Pose, error)
MoveToPositionFunc func(ctx context.Context, to spatialmath.Pose, extra map[string]interface{}) error
MoveToJointPositionsFunc func(ctx context.Context, pos *pb.JointPositions, extra map[string]interface{}) error
JointPositionsFunc func(ctx context.Context, extra map[string]interface{}) (*pb.JointPositions, error)
StopFunc func(ctx context.Context, extra map[string]interface{}) error
IsMovingFunc func(context.Context) (bool, error)
CloseFunc func(ctx context.Context) error
ModelFrameFunc func() referenceframe.Model
CurrentInputsFunc func(ctx context.Context) ([]referenceframe.Input, error)
GoToInputsFunc func(ctx context.Context, inputSteps ...[]referenceframe.Input) error
GeometriesFunc func(ctx context.Context) ([]spatialmath.Geometry, error)
}
// NewArm returns a new injected arm.
func NewArm(name string) *Arm {
return &Arm{name: arm.Named(name)}
}
// Name returns the name of the resource.
func (a *Arm) Name() resource.Name {
return a.name
}
// EndPosition calls the injected EndPosition or the real version.
func (a *Arm) EndPosition(ctx context.Context, extra map[string]interface{}) (spatialmath.Pose, error) {
if a.EndPositionFunc == nil {
return a.Arm.EndPosition(ctx, extra)
}
return a.EndPositionFunc(ctx, extra)
}
// MoveToPosition calls the injected MoveToPosition or the real version.
func (a *Arm) MoveToPosition(ctx context.Context, to spatialmath.Pose, extra map[string]interface{}) error {
if a.MoveToPositionFunc == nil {
return a.Arm.MoveToPosition(ctx, to, extra)
}
return a.MoveToPositionFunc(ctx, to, extra)
}
// MoveToJointPositions calls the injected MoveToJointPositions or the real version.
func (a *Arm) MoveToJointPositions(ctx context.Context, jp *pb.JointPositions, extra map[string]interface{}) error {
if a.MoveToJointPositionsFunc == nil {
return a.Arm.MoveToJointPositions(ctx, jp, extra)
}
return a.MoveToJointPositionsFunc(ctx, jp, extra)
}
// JointPositions calls the injected JointPositions or the real version.
func (a *Arm) JointPositions(ctx context.Context, extra map[string]interface{}) (*pb.JointPositions, error) {
if a.JointPositionsFunc == nil {
return a.Arm.JointPositions(ctx, extra)
}
return a.JointPositionsFunc(ctx, extra)
}
// Stop calls the injected Stop or the real version.
func (a *Arm) Stop(ctx context.Context, extra map[string]interface{}) error {
if a.StopFunc == nil {
return a.Arm.Stop(ctx, extra)
}
return a.StopFunc(ctx, extra)
}
// IsMoving calls the injected IsMoving or the real version.
func (a *Arm) IsMoving(ctx context.Context) (bool, error) {
if a.IsMovingFunc == nil {
return a.Arm.IsMoving(ctx)
}
return a.IsMovingFunc(ctx)
}
// Close calls the injected Close or the real version.
func (a *Arm) Close(ctx context.Context) error {
if a.CloseFunc == nil {
if a.Arm == nil {
return nil
}
return a.Arm.Close(ctx)
}
return a.CloseFunc(ctx)
}
// DoCommand calls the injected DoCommand or the real version.
func (a *Arm) DoCommand(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error) {
if a.DoFunc == nil {
return a.Arm.DoCommand(ctx, cmd)
}
return a.DoFunc(ctx, cmd)
}
// ModelFrame calls the injected ModelFrame or the real version.
func (a *Arm) ModelFrame() referenceframe.Model {
if a.ModelFrameFunc == nil {
if a.Arm != nil {
return a.Arm.ModelFrame()
}
model := referenceframe.NewSimpleModel("")
return model
}
return a.ModelFrameFunc()
}
// CurrentInputs calls the injected CurrentInputs or the real version.
func (a *Arm) CurrentInputs(ctx context.Context) ([]referenceframe.Input, error) {
if a.CurrentInputsFunc == nil {
return a.Arm.CurrentInputs(ctx)
}
return a.CurrentInputsFunc(ctx)
}
// GoToInputs calls the injected GoToInputs or the real version.
func (a *Arm) GoToInputs(ctx context.Context, inputSteps ...[]referenceframe.Input) error {
if a.GoToInputsFunc == nil {
return a.Arm.GoToInputs(ctx, inputSteps...)
}
return a.GoToInputsFunc(ctx, inputSteps...)
}
// Geometries returns the gripper's geometries.
func (a *Arm) Geometries(ctx context.Context, extra map[string]interface{}) ([]spatialmath.Geometry, error) {
if a.GeometriesFunc == nil {
return a.Arm.Geometries(ctx, extra)
}
return a.GeometriesFunc(ctx)
}