Skip to content

Commit

Permalink
[DATA-536] Make Camera.fps in orbslam file generation use Hz instead … (
Browse files Browse the repository at this point in the history
  • Loading branch information
tessavitabile authored Oct 12, 2022
1 parent 37430a9 commit ad9503b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions services/slam/builtin/orbslam_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ func (slamSvc *builtIn) orbCamMaker(camProperties *transform.PinholeCameraModel)
FPSCamera: int16(slamSvc.dataRateMs),
FileVersion: fileVersion,
}
if slamSvc.dataRateMs <= 0 {
// dataRateMs is always expected to be positive, since 0 gets reset to the default, and all other
// values lower than the default are rejected
return nil, errors.Errorf("orbslam yaml generation expected dataRateMs greater than 0, got %d", slamSvc.dataRateMs)
}
orbslam.FPSCamera = int16(1000 / slamSvc.dataRateMs)
if orbslam.FPSCamera == 0 {
orbslam.FPSCamera = 1
}
distortion, ok := camProperties.Distortion.(*transform.BrownConrady)
if !ok {
return nil, utils.NewUnimplementedInterfaceError(distortion, camProperties.Distortion)
Expand Down
42 changes: 42 additions & 0 deletions services/slam/builtin/orbslam_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ func TestOrbslamYAMLNew(t *testing.T) {
DataRateMs: dataRateMs,
Port: "localhost:4445",
}
attrCfgGoodHighDataRateMs := &builtin.AttrConfig{
Algorithm: "fake_orbslamv3",
Sensors: []string{"good_color_camera"},
ConfigParams: map[string]string{
"mode": "mono",
"orb_n_features": "1000",
"orb_scale_factor": "1.2",
"orb_n_levels": "8",
"orb_n_ini_th_fast": "20",
"orb_n_min_th_fast": "7",
},
DataDirectory: name,
DataRateMs: 10000,
Port: "localhost:4445",
}
attrCfgBadCam := &builtin.AttrConfig{
Algorithm: "fake_orbslamv3",
Sensors: []string{"bad_camera_intrinsics"},
Expand Down Expand Up @@ -124,6 +139,7 @@ func TestOrbslamYAMLNew(t *testing.T) {
test.That(t, orbslam.NLevels, test.ShouldEqual, 8)
test.That(t, orbslam.ScaleFactor, test.ShouldEqual, 1.2)
test.That(t, orbslam.LoadMapLoc, test.ShouldEqual, "")
test.That(t, orbslam.FPSCamera, test.ShouldEqual, 5)

//save a fake map for the next map using the previous timestamp
fakeMap = filepath.Join(name, "map", attrCfgGood.Sensors[0]+"_data_"+yamlFileTimeStampGood)
Expand Down Expand Up @@ -167,6 +183,32 @@ func TestOrbslamYAMLNew(t *testing.T) {
test.That(t, saveTimeStamp.After(oldTimeStamp), test.ShouldBeTrue)
})

t.Run("New orbslamv3 service with high dataRateMs", func(t *testing.T) {
// Create slam service
logger := golog.NewTestLogger(t)
grpcServer := setupTestGRPCServer(attrCfgGoodHighDataRateMs.Port)
svc, err := createSLAMService(t, attrCfgGoodHighDataRateMs, logger, false, true)
test.That(t, err, test.ShouldBeNil)

grpcServer.Stop()
test.That(t, utils.TryClose(context.Background(), svc), test.ShouldBeNil)

yamlFileTimeStampGood, yamlFilePathGood, err := findLastYAML(name)

fakeMapTimestamp = yamlFileTimeStampGood
test.That(t, err, test.ShouldBeNil)

yamlDataAll, err := os.ReadFile(yamlFilePathGood)
test.That(t, err, test.ShouldBeNil)
test.That(t, yamlDataAll[:len(yamlFilePrefixBytes)], test.ShouldResemble, []byte(yamlFilePrefixBytes))

yamlData := bytes.Replace(yamlDataAll, []byte(yamlFilePrefixBytes), []byte(""), 1)
orbslam := builtin.ORBsettings{}
err = yaml.Unmarshal(yamlData, &orbslam)
// Even though the real fps is 0.1 Hz, we set it to 1
test.That(t, orbslam.FPSCamera, test.ShouldEqual, 1)
})

t.Run("New orbslamv3 service with camera that errors from bad intrinsics", func(t *testing.T) {
// Create slam service
logger := golog.NewTestLogger(t)
Expand Down

0 comments on commit ad9503b

Please sign in to comment.