Skip to content

Commit

Permalink
[RSDK-7214] set default mode (viam-modules#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnN193 authored Apr 12, 2024
1 parent 7ff465a commit ee4ea28
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 0 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ func (config *Config) Validate(path string) ([]string, error) {
deps = append(deps, movementSensorName)
}

mode, ok := config.ConfigParams["mode"]
if !ok || mode == "" {
return nil, utils.NewConfigValidationFieldRequiredError(path, "config_params[mode]")
}

return deps, nil
}

Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestValidate(t *testing.T) {
cfgService := makeCfgService()
delete(cfgService.Attributes["config_params"].(map[string]string), "mode")
_, err := newConfig(cfgService)
test.That(t, err, test.ShouldBeError, newError(utils.NewConfigValidationFieldRequiredError(testCfgPath, "config_params[mode]").Error()))
test.That(t, err, test.ShouldBeNil)
})

t.Run("Config with invalid parameter type", func(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion viam_cartographer.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ func New(
}

subAlgo := SubAlgo(svcConfig.ConfigParams["mode"])
if subAlgo != Dim2d {
switch subAlgo {
case "":
subAlgo = Dim2d
case Dim2d:
default:
return nil, errors.Errorf("%v does not have a 'mode: %v'",
c.Model.Name, svcConfig.ConfigParams["mode"])
}
Expand Down
14 changes: 14 additions & 0 deletions viam_cartographer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ func TestNew(t *testing.T) {

test.That(t, svc.Close(context.Background()), test.ShouldBeNil)
})
t.Run("Successful creation of cartographer slam service without mode configured", func(t *testing.T) {
termFunc := testhelper.InitTestCL(t, logger)
defer termFunc()

attrCfg := &vcConfig.Config{
Camera: map[string]string{"name": string(s.GoodLidar), "data_frequency_hz": testLidarDataFreqHz},
EnableMapping: &_true,
}

svc, err := testhelper.CreateSLAMService(t, attrCfg, logger)
test.That(t, err, test.ShouldBeNil)

test.That(t, svc.Close(context.Background()), test.ShouldBeNil)
})

t.Run("Successful creation of cartographer slam service with good lidar without IMU name specified", func(t *testing.T) {
termFunc := testhelper.InitTestCL(t, logger)
Expand Down

0 comments on commit ee4ea28

Please sign in to comment.