-
Notifications
You must be signed in to change notification settings - Fork 109
/
servo.go
51 lines (42 loc) · 1.27 KB
/
servo.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
// Package fake implements a fake servo.
package fake
import (
"context"
"github.com/edaniels/golog"
"go.viam.com/rdk/components/generic"
"go.viam.com/rdk/components/servo"
"go.viam.com/rdk/config"
"go.viam.com/rdk/registry"
"go.viam.com/rdk/resource"
)
func init() {
registry.RegisterComponent(servo.Subtype, resource.NewDefaultModel("fake"), registry.Component{
Constructor: func(ctx context.Context, _ registry.Dependencies, config config.Component, logger golog.Logger) (interface{}, error) {
var s servo.LocalServo = &Servo{Name: config.Name}
return s, nil
},
})
}
// A Servo allows setting and reading a single angle.
type Servo struct {
Name string
angle uint32
generic.Echo
}
// Move sets the given angle.
func (s *Servo) Move(ctx context.Context, angleDeg uint32, extra map[string]interface{}) error {
s.angle = angleDeg
return nil
}
// Position returns the set angle.
func (s *Servo) Position(ctx context.Context, extra map[string]interface{}) (uint32, error) {
return s.angle, nil
}
// Stop doesn't do anything for a fake servo.
func (s *Servo) Stop(ctx context.Context, extra map[string]interface{}) error {
return nil
}
// IsMoving is always false for a fake servo.
func (s *Servo) IsMoving(ctx context.Context) (bool, error) {
return false, nil
}