-
Notifications
You must be signed in to change notification settings - Fork 5
/
controller_test.go
47 lines (41 loc) · 1.45 KB
/
controller_test.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
package kaburaya
import (
"testing"
)
func TestDynamicTargetControllerCompute(t *testing.T) {
var pid *pidController
var c *dynamicTargetController
var feedback float64
// ChangeRate == 0.0
pid = newPIDController(0.0, 0.1, 0.1, 0.1)
c = newDynamicTargetController(pid)
feedback = defaultPrevious
c.Compute(feedback)
if expect := feedback - 2.0; c.controller.target != expect {
t.Errorf("dynamicTargetController.Compute should change target to %f, but %f", expect, c.controller.target)
}
// ChangeRate > 0.3
pid = newPIDController(0.0, 0.1, 0.1, 0.1)
c = newDynamicTargetController(pid)
feedback = 1.0
c.Compute(feedback)
if expect := feedback + 2.0; c.controller.target != expect {
t.Errorf("dynamicTargetController.Compute should change target to %f, but %f", expect, c.controller.target)
}
// ChangeRate < -0.3 && feedback > 0.0
pid = newPIDController(0.0, 0.1, 0.1, 0.1)
c = newDynamicTargetController(pid)
feedback = 1.0
c.Compute(feedback)
if expect := feedback + 2.0; c.controller.target != expect {
t.Errorf("dynamicTargetController.Compute should change target to %f, but %f", expect, c.controller.target)
}
// ChangeRate < -0.3 && feedback == 0.0
pid = newPIDController(0.0, 0.1, 0.1, 0.1)
c = newDynamicTargetController(pid)
feedback = 0.0
c.Compute(feedback)
if expect := -100.0; c.controller.target != expect {
t.Errorf("dynamicTargetController.Compute should change target to %f, but %f", expect, c.controller.target)
}
}