-
Notifications
You must be signed in to change notification settings - Fork 110
/
movementsensor.go
116 lines (94 loc) · 4.09 KB
/
movementsensor.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
// Package fake is a fake MovementSensor for testing
package fake
import (
"context"
"github.com/golang/geo/r3"
geo "github.com/kellydunn/golang-geo"
"go.viam.com/rdk/components/movementsensor"
"go.viam.com/rdk/logging"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/spatialmath"
)
var model = resource.DefaultModelFamily.WithModel("fake")
// Config is used for converting fake movementsensor attributes.
type Config struct {
resource.TriviallyValidateConfig
}
func init() {
resource.RegisterComponent(
movementsensor.API,
model,
resource.Registration[movementsensor.MovementSensor, *Config]{Constructor: NewMovementSensor})
}
// NewMovementSensor makes a new fake movement sensor.
func NewMovementSensor(ctx context.Context, deps resource.Dependencies, conf resource.Config, logger logging.Logger,
) (movementsensor.MovementSensor, error) {
return &MovementSensor{
Named: conf.ResourceName().AsNamed(),
logger: logger,
}, nil
}
// MovementSensor implements is a fake movement sensor interface.
type MovementSensor struct {
resource.Named
resource.AlwaysRebuild
logger logging.Logger
}
// Position gets the position of a fake movementsensor.
func (f *MovementSensor) Position(ctx context.Context, extra map[string]interface{}) (*geo.Point, float64, error) {
p := geo.NewPoint(40.7, -73.98)
return p, 50.5, nil
}
// LinearVelocity gets the linear velocity of a fake movementsensor.
func (f *MovementSensor) LinearVelocity(ctx context.Context, extra map[string]interface{}) (r3.Vector, error) {
return r3.Vector{Y: 5.4}, nil
}
// LinearAcceleration gets the linear acceleration of a fake movementsensor.
func (f *MovementSensor) LinearAcceleration(ctx context.Context, extra map[string]interface{}) (r3.Vector, error) {
return r3.Vector{X: 2.2, Y: 4.5, Z: 2}, nil
}
// AngularVelocity gets the angular velocity of a fake movementsensor.
func (f *MovementSensor) AngularVelocity(ctx context.Context, extra map[string]interface{}) (spatialmath.AngularVelocity, error) {
return spatialmath.AngularVelocity{Z: 1}, nil
}
// CompassHeading gets the compass headings of a fake movementsensor.
func (f *MovementSensor) CompassHeading(ctx context.Context, extra map[string]interface{}) (float64, error) {
return 25, nil
}
// Orientation gets the orientation of a fake movementsensor.
func (f *MovementSensor) Orientation(ctx context.Context, extra map[string]interface{}) (spatialmath.Orientation, error) {
return spatialmath.NewZeroOrientation(), nil
}
// DoCommand uses a map string to run custom functionality of a fake movementsensor.
func (f *MovementSensor) DoCommand(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error) {
return map[string]interface{}{}, nil
}
// Accuracy gets the accuracy of a fake movementsensor.
func (f *MovementSensor) Accuracy(ctx context.Context, extra map[string]interface{}) (map[string]float32, error) {
return map[string]float32{}, nil
}
// Readings gets the readings of a fake movementsensor.
func (f *MovementSensor) Readings(ctx context.Context, extra map[string]interface{}) (map[string]interface{}, error) {
return movementsensor.DefaultAPIReadings(ctx, f, extra)
}
// Properties returns the properties of a fake movementsensor.
func (f *MovementSensor) Properties(ctx context.Context, extra map[string]interface{}) (*movementsensor.Properties, error) {
return &movementsensor.Properties{
LinearVelocitySupported: true,
AngularVelocitySupported: true,
OrientationSupported: true,
PositionSupported: true,
CompassHeadingSupported: true,
LinearAccelerationSupported: true,
}, nil
}
// Start returns the fix of a fake gps movementsensor.
func (f *MovementSensor) Start(ctx context.Context) error { return nil }
// Close returns the fix of a fake gps movementsensor.
func (f *MovementSensor) Close(ctx context.Context) error {
return nil
}
// ReadFix returns the fix of a fake gps movementsensor.
func (f *MovementSensor) ReadFix(ctx context.Context) (int, error) { return 1, nil }
// ReadSatsInView returns the number of satellites in view.
func (f *MovementSensor) ReadSatsInView(ctx context.Context) (int, error) { return 2, nil }