diff --git a/config/config.go b/config/config.go index 7ecbd57d9..e7b582077 100644 --- a/config/config.go +++ b/config/config.go @@ -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 } diff --git a/config/config_test.go b/config/config_test.go index 0b149f9ca..d3f704e78 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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) { diff --git a/viam_cartographer.go b/viam_cartographer.go index d6a03f028..c4ca3dca2 100644 --- a/viam_cartographer.go +++ b/viam_cartographer.go @@ -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"]) } diff --git a/viam_cartographer_test.go b/viam_cartographer_test.go index 269802626..05790a1bd 100644 --- a/viam_cartographer_test.go +++ b/viam_cartographer_test.go @@ -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)