Skip to content

Commit

Permalink
add test for incorrect pid type
Browse files Browse the repository at this point in the history
  • Loading branch information
martha-johnston committed Sep 11, 2024
1 parent 9fa5ff2 commit 0e00008
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions components/base/sensorcontrolled/sensorcontrolled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
// compassValue and orientationValue should be different for tests.
defaultCompassValue = 45.
defaultOrientationValue = 40.
wrongTypeLinVel = "linear"
wrongTypeAngVel = "angulr_velocity"
)

var (
Expand Down Expand Up @@ -146,16 +148,16 @@ func TestSensorBase(t *testing.T) {
test.That(t, sb.Close(ctx), test.ShouldBeNil)
}

func sBaseTestConfig(msNames []string, freq float64) resource.Config {
func sBaseTestConfig(msNames []string, freq float64, linType, angType string) resource.Config {
controlParams := make([]control.PIDConfig, 2)
controlParams[0] = control.PIDConfig{
Type: typeLinVel,
Type: linType,
P: 0.5,
I: 0.5,
D: 0.0,
}
controlParams[1] = control.PIDConfig{
Type: typeAngVel,
Type: angType,
P: 0.5,
I: 0.5,
D: 0.0,
Expand All @@ -178,7 +180,7 @@ func msDependencies(t *testing.T, msNames []string,
) (resource.Dependencies, resource.Config) {
t.Helper()

cfg := sBaseTestConfig(msNames, defaultControlFreq)
cfg := sBaseTestConfig(msNames, defaultControlFreq, typeLinVel, typeAngVel)

deps := make(resource.Dependencies)

Expand Down Expand Up @@ -280,7 +282,7 @@ func TestReconfig(t *testing.T) {

deps, _ = msDependencies(t, []string{"setvel2"})
// generate a config with a non default freq
cfg = sBaseTestConfig([]string{"setvel2"}, 100)
cfg = sBaseTestConfig([]string{"setvel2"}, 100, typeLinVel, typeAngVel)
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, err, test.ShouldBeNil)
test.That(t, sb.velocities.Name().ShortName(), test.ShouldResemble, "setvel2")
Expand Down Expand Up @@ -337,14 +339,20 @@ func TestReconfig(t *testing.T) {
test.That(t, err, test.ShouldBeNil)
test.That(t, headingSupported, test.ShouldBeFalse)
test.That(t, headingBad, test.ShouldEqual, 0)

deps, _ = msDependencies(t, []string{"setvel2"})
// generate a config with invalid pid types
cfg = sBaseTestConfig([]string{"setvel2"}, 100, wrongTypeLinVel, wrongTypeAngVel)
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, err.Error(), test.ShouldContainSubstring, "type must be 'linear_velocity' or 'angular_velocity'")
}

func TestSensorBaseWithVelocitiesSensor(t *testing.T) {
ctx := context.Background()
logger := logging.NewTestLogger(t)
deps, _ := msDependencies(t, []string{"setvel1"})
// generate a config with a non default freq
cfg := sBaseTestConfig([]string{"setvel1"}, 100)
cfg := sBaseTestConfig([]string{"setvel1"}, 100, typeLinVel, typeAngVel)

b, err := createSensorBase(ctx, deps, cfg, logger)
test.That(t, err, test.ShouldBeNil)
Expand Down

0 comments on commit 0e00008

Please sign in to comment.