Skip to content

Commit

Permalink
RSDK-2262 - use config to determine slam mode during validation (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-mishra authored Aug 17, 2023
1 parent 0220f1f commit 63d44a6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
28 changes: 25 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ type OptionalConfigParams struct {
}

var (
errCameraMustHaveName = errors.New("\"camera[name]\" is required")
errSensorsMustNotBeEmpty = errors.New("\"sensors\" must not be empty")
errCameraMustHaveName = errors.New("\"camera[name]\" is required")
errSensorsMustNotBeEmpty = errors.New("\"sensors\" must not be empty")
errLocalizationInOfflineMode = newError("data_rate_msec = 0 and enable_mapping = false. localization in offline mode not supported.")
errLocalizationInOfflineModeIMU = newError("camera[data_freq_hz] and enable_mapping = false. localization in offline mode not supported.")
)

// Validate creates the list of implicit dependencies.
Expand Down Expand Up @@ -161,8 +163,13 @@ func GetOptionalParameters(config *Config, defaultLidarDataRateMsec, defaultIMUD
if config.EnableMapping == nil {
logger.Debug("no enable_mapping given, setting to default value of false")
} else {
optionalConfigParams.EnableMapping = config.CloudStoryEnabled
optionalConfigParams.EnableMapping = *config.EnableMapping
}

if err := validateModes(optionalConfigParams, config.IMUIntegrationEnabled); err != nil {
return OptionalConfigParams{}, err
}

return optionalConfigParams, nil
}

Expand All @@ -179,3 +186,18 @@ func GetOptionalParameters(config *Config, defaultLidarDataRateMsec, defaultIMUD

return optionalConfigParams, nil
}

func validateModes(
optionalConfigParams OptionalConfigParams,
imuEnabled bool,
) error {
offlineMode := optionalConfigParams.LidarDataRateMsec == 0
localizationMode := !optionalConfigParams.EnableMapping
if localizationMode && offlineMode {
if imuEnabled {
return errLocalizationInOfflineModeIMU
}
return errLocalizationInOfflineMode
}
return nil
}
34 changes: 34 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,40 @@ func getOptionalParametersTestHelper(
}
})

t.Run(fmt.Sprintf("config that puts cartographer in offline mode and in localization mode %s", suffix), func(t *testing.T) {
cfgService := makeCfgService(imuIntegrationEnabled, cloudStoryEnabled)
cfgService.Attributes["existing_map"] = "test-file.pbstream"
cfgService.Attributes["enable_mapping"] = false
if imuIntegrationEnabled {
cfgService.Attributes["camera"] = map[string]string{
"name": "testcam",
"data_frequency_hz": "0",
}
} else {
cfgService.Attributes["data_rate_msec"] = 0
}
cfg, err := newConfig(cfgService)
test.That(t, err, test.ShouldBeNil)
optionalConfigParams, err := GetOptionalParameters(
cfg,
1000,
1000,
1002,
logger)
if cloudStoryEnabled {
if imuIntegrationEnabled {
test.That(t, err, test.ShouldBeError, errLocalizationInOfflineModeIMU)
} else {
test.That(t, err, test.ShouldBeError, errLocalizationInOfflineMode)
}
} else {
test.That(t, err, test.ShouldBeNil)
test.That(t, optionalConfigParams.LidarDataRateMsec, test.ShouldEqual, 0)
test.That(t, optionalConfigParams.EnableMapping, test.ShouldBeFalse)
test.That(t, optionalConfigParams.MapRateSec, test.ShouldEqual, 1002)
}
})

if imuIntegrationEnabled {
sensorAttributeTestHelper(t, logger, imuIntegrationEnabled, cloudStoryEnabled)
}
Expand Down

0 comments on commit 63d44a6

Please sign in to comment.