Skip to content

Commit

Permalink
expand DoCommand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martha-johnston committed Sep 11, 2024
1 parent f652d0d commit 9fa5ff2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions components/base/sensorcontrolled/sensorcontrolled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,10 @@ func TestSensorBaseDoCommand(t *testing.T) {
resp, err := b.DoCommand(ctx, req)
test.That(t, err, test.ShouldBeNil)
test.That(t, resp, test.ShouldResemble, expectedeMap)

emptyMap := make(map[string]interface{})
req["get_tuned_pid"] = false
resp, err = b.DoCommand(ctx, req)
test.That(t, err, test.ShouldBeNil)
test.That(t, resp, test.ShouldResemble, emptyMap)
}
6 changes: 6 additions & 0 deletions components/motor/gpio/controlled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,10 @@ func TestControlledMotorCreation(t *testing.T) {
resp, err := m.DoCommand(context.Background(), req)
test.That(t, err, test.ShouldBeNil)
test.That(t, resp, test.ShouldResemble, expectedeMap)

emptyMap := make(map[string]interface{})
req["get_tuned_pid"] = false
resp, err = cm.DoCommand(context.Background(), req)
test.That(t, err, test.ShouldBeNil)
test.That(t, resp, test.ShouldResemble, emptyMap)
}
7 changes: 2 additions & 5 deletions control/setup_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,9 @@ func UpdateTrapzBlock(ctx context.Context, name string, maxVel float64, dependsO
// TunedPIDErr returns an error with the stored tuned PID values.
func TunedPIDErr(name string, tunedVals []PIDConfig) error {
var tunedStr string
for i, pid := range tunedVals {
if i > 0 {
tunedStr += `, `
}
for _, pid := range tunedVals {
if !pid.NeedsAutoTuning() {
tunedStr += fmt.Sprintf(`{"p": %v, "i": %v, "d": %v, "type": "%v"}`, pid.P, pid.I, pid.D, pid.Type)
tunedStr += fmt.Sprintf(`{"p": %v, "i": %v, "d": %v, "type": "%v"} `, pid.P, pid.I, pid.D, pid.Type)
}
}
return fmt.Errorf(`%v has been tuned, please copy the following control values into your config: %v`, name, tunedStr)
Expand Down

0 comments on commit 9fa5ff2

Please sign in to comment.