Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RSDK-3786] full-mod-new-close #186

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b39c81c
RSDK-3547-use-cgo-api-methods2
nicksanford Jul 7, 2023
717af18
wip
nicksanford Jul 7, 2023
6de6b80
wip
nicksanford Jul 7, 2023
b7bc8b9
wip
nicksanford Jul 7, 2023
e1189cb
wip
nicksanford Jul 7, 2023
79dfb99
fix tests
nicksanford Jul 7, 2023
da0e6bc
wip
nicksanford Jul 7, 2023
73a15b4
clean up tests
nicksanford Jul 10, 2023
ca859bb
fix test helper names
nicksanford Jul 10, 2023
4b1c2fb
wip
nicksanford Jul 10, 2023
9305149
wip
nicksanford Jul 10, 2023
3202c73
add tests
nicksanford Jul 10, 2023
e95fa5f
more tests
nicksanford Jul 10, 2023
0f2f56e
more tests
nicksanford Jul 10, 2023
5b09e46
wip
nicksanford Jul 10, 2023
803d2dd
wip
nicksanford Jul 10, 2023
2ccc1bc
wip
nicksanford Jul 11, 2023
a4012ab
add tests
nicksanford Jul 11, 2023
bc1c149
lint
nicksanford Jul 11, 2023
ad23318
fix lint
nicksanford Jul 11, 2023
02df80f
remove debugging stubs
nicksanford Jul 11, 2023
62223bc
wip
nicksanford Jul 11, 2023
8ba1d3c
wip
nicksanford Jul 11, 2023
98dc6ee
Update internal/testhelper/testhelper.go
nicksanford Jul 11, 2023
c57dce6
Update sensors/lidar/dim-2d/dim-2d.go
nicksanford Jul 11, 2023
a35cd37
Update testhelper/testhelper.go
nicksanford Jul 11, 2023
63619ec
Update testhelper/testhelper.go
nicksanford Jul 11, 2023
4f2677c
Update testhelper/testhelper.go
nicksanford Jul 11, 2023
e37e9d9
Update testhelper/testhelper.go
nicksanford Jul 11, 2023
23f7ea1
Update viam-cartographer.go
nicksanford Jul 11, 2023
edfb2d7
fix build & respond to feedback
nicksanford Jul 11, 2023
3b7930b
lint
nicksanford Jul 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ else
$(error "Unsupported system. Only apt and brew currently supported.")
endif

build: ensure-submodule-initialized grpc/buf build-module
build: bin/cartographer-module

viam-cartographer/build/carto_grpc_server: ensure-submodule-initialized grpc/buf
cd viam-cartographer && cmake -Bbuild -G Ninja ${EXTRA_CMAKE_FLAGS} && cmake --build build

bin/cartographer-module: viam-cartographer/build/carto_grpc_server
mkdir -p bin && go build $(GO_BUILD_LDFLAGS) -o bin/cartographer-module module/main.go

# Ideally build-asan would be added to build-debug, but can't yet
# as these options they fail on arm64 linux. This is b/c that
# platform currently uses gcc as opposed to clang & gcc doesn't
Expand All @@ -111,9 +116,6 @@ build-asan: build-debug
build-debug: EXTRA_CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=Debug -DFORCE_DEBUG_BUILD=True
build-debug: build

build-module:
mkdir -p bin && go build $(GO_BUILD_LDFLAGS) -o bin/cartographer-module module/main.go

test-cpp:
viam-cartographer/build/unit_tests -p -l all

Expand Down
62 changes: 32 additions & 30 deletions cartofacade/capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ type GetPosition struct {
type LidarConfig int64

const (
twoD LidarConfig = iota
threeD
// TwoD LidarConfig denotes a 2d lidar
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to make these public to use them in viam-cartographer

TwoD LidarConfig = iota
// ThreeD LidarConfig denotes a 3d lidar
ThreeD
)

// CartoConfig contains config values from app
Expand All @@ -92,19 +94,19 @@ type CartoConfig struct {

// CartoAlgoConfig contains config values from app
type CartoAlgoConfig struct {
optimizeOnStart bool
optimizeEveryNNodes int
numRangeData int
missingDataRayLength float32
maxRange float32
minRange float32
maxSubmapsToKeep int
freshSubmapsCount int
minCoveredArea float64
minAddedSubmapsCount int
occupiedSpaceWeight float64
translationWeight float64
rotationWeight float64
OptimizeOnStart bool
Copy link
Collaborator Author

@nicksanford nicksanford Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to make these public to set them in viam-cartographer

OptimizeEveryNNodes int
NumRangeData int
MissingDataRayLength float32
MaxRange float32
MinRange float32
MaxSubmapsToKeep int
FreshSubmapsCount int
MinCoveredArea float64
MinAddedSubmapsCount int
OccupiedSpaceWeight float64
TranslationWeight float64
RotationWeight float64
}

// NewLib calls viam_carto_lib_init and returns a pointer to a viam carto lib object.
Expand Down Expand Up @@ -311,9 +313,9 @@ func goStringToBstring(goStr string) C.bstring {

func toLidarConfig(lidarConfig LidarConfig) (C.viam_carto_LIDAR_CONFIG, error) {
switch lidarConfig {
case twoD:
case TwoD:
return C.VIAM_CARTO_TWO_D, nil
case threeD:
case ThreeD:
return C.VIAM_CARTO_THREE_D, nil
default:
return 0, errors.New("invalid lidar config value")
Expand Down Expand Up @@ -349,19 +351,19 @@ func getConfig(cfg CartoConfig) (C.viam_carto_config, error) {

func toAlgoConfig(acfg CartoAlgoConfig) C.viam_carto_algo_config {
vcac := C.viam_carto_algo_config{}
vcac.optimize_on_start = C.bool(acfg.optimizeOnStart)
vcac.optimize_every_n_nodes = C.int(acfg.optimizeEveryNNodes)
vcac.num_range_data = C.int(acfg.numRangeData)
vcac.missing_data_ray_length = C.float(acfg.missingDataRayLength)
vcac.max_range = C.float(acfg.maxRange)
vcac.min_range = C.float(acfg.minRange)
vcac.max_submaps_to_keep = C.int(acfg.maxSubmapsToKeep)
vcac.fresh_submaps_count = C.int(acfg.freshSubmapsCount)
vcac.min_covered_area = C.double(acfg.minCoveredArea)
vcac.min_added_submaps_count = C.int(acfg.minAddedSubmapsCount)
vcac.occupied_space_weight = C.double(acfg.occupiedSpaceWeight)
vcac.translation_weight = C.double(acfg.translationWeight)
vcac.rotation_weight = C.double(acfg.rotationWeight)
vcac.optimize_on_start = C.bool(acfg.OptimizeOnStart)
vcac.optimize_every_n_nodes = C.int(acfg.OptimizeEveryNNodes)
vcac.num_range_data = C.int(acfg.NumRangeData)
vcac.missing_data_ray_length = C.float(acfg.MissingDataRayLength)
vcac.max_range = C.float(acfg.MaxRange)
vcac.min_range = C.float(acfg.MinRange)
vcac.max_submaps_to_keep = C.int(acfg.MaxSubmapsToKeep)
vcac.fresh_submaps_count = C.int(acfg.FreshSubmapsCount)
vcac.min_covered_area = C.double(acfg.MinCoveredArea)
vcac.min_added_submaps_count = C.int(acfg.MinAddedSubmapsCount)
vcac.occupied_space_weight = C.double(acfg.OccupiedSpaceWeight)
vcac.translation_weight = C.double(acfg.TranslationWeight)
vcac.rotation_weight = C.double(acfg.RotationWeight)
return vcac
}

Expand Down
2 changes: 1 addition & 1 deletion cartofacade/capi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestGetConfig(t *testing.T) {

freeBstringArray(vcc.sensors, vcc.sensors_len)

test.That(t, vcc.lidar_config, test.ShouldEqual, twoD)
test.That(t, vcc.lidar_config, test.ShouldEqual, TwoD)
})
}

Expand Down
30 changes: 15 additions & 15 deletions cartofacade/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@ func GetTestConfig(sensor string) (CartoConfig, string, error) {
MapRateSecond: 5,
DataDir: dir,
ComponentReference: "component",
LidarConfig: twoD,
LidarConfig: TwoD,
}, dir, nil
}

// GetBadTestConfig gets a sample config for testing purposes that will cause a failure.
func GetBadTestConfig() CartoConfig {
return CartoConfig{
Sensors: []string{"rplidar", "imu"},
LidarConfig: twoD,
LidarConfig: TwoD,
}
}

// GetTestAlgoConfig gets a sample algo config for testing purposes.
func GetTestAlgoConfig() CartoAlgoConfig {
return CartoAlgoConfig{
optimizeOnStart: false,
optimizeEveryNNodes: 3,
numRangeData: 100,
missingDataRayLength: 25.0,
maxRange: 25.0,
minRange: 0.2,
maxSubmapsToKeep: 3,
freshSubmapsCount: 3,
minCoveredArea: 1.0,
minAddedSubmapsCount: 1,
occupiedSpaceWeight: 20.0,
translationWeight: 10.0,
rotationWeight: 1.0,
OptimizeOnStart: false,
OptimizeEveryNNodes: 3,
NumRangeData: 100,
MissingDataRayLength: 25.0,
MaxRange: 25.0,
MinRange: 0.2,
MaxSubmapsToKeep: 3,
FreshSubmapsCount: 3,
MinCoveredArea: 1.0,
MinAddedSubmapsCount: 1,
OccupiedSpaceWeight: 20.0,
TranslationWeight: 10.0,
RotationWeight: 1.0,
}
}
37 changes: 19 additions & 18 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
viamcartographer "github.com/viamrobotics/viam-cartographer"
vcConfig "github.com/viamrobotics/viam-cartographer/config"
"github.com/viamrobotics/viam-cartographer/dataprocess"
"github.com/viamrobotics/viam-cartographer/internal/testhelper"
internaltesthelper "github.com/viamrobotics/viam-cartographer/internal/testhelper"
"github.com/viamrobotics/viam-cartographer/testhelper"
)

const (
Expand Down Expand Up @@ -99,7 +100,7 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
t.Skip()
}

dataDir, err := testhelper.CreateTempFolderArchitecture(logger)
dataDir, err := internaltesthelper.CreateTempFolderArchitecture(logger)
test.That(t, err, test.ShouldBeNil)

prevNumFiles := 0
Expand All @@ -126,14 +127,14 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
// Release point cloud for service validation
testhelper.IntegrationLidarReleasePointCloudChan <- 1
// Create slam service using a real cartographer binary
svc, err := testhelper.CreateSLAMService(t, attrCfg, logger, true, viamcartographer.DefaultExecutableName)
svc, err := internaltesthelper.CreateSLAMService(t, attrCfg, logger, true, viamcartographer.DefaultExecutableName)
test.That(t, err, test.ShouldBeNil)

// Release point cloud, since cartographer looks for the second most recent point cloud
testhelper.IntegrationLidarReleasePointCloudChan <- 1

// Make sure we initialize in mapping mode
logReader := svc.(testhelper.Service).GetSLAMProcessBufferedLogReader()
logReader := svc.(internaltesthelper.Service).GetSLAMProcessBufferedLogReader()
for {
line, err := logReader.ReadString('\n')
test.That(t, err, test.ShouldBeNil)
Expand All @@ -153,7 +154,7 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
line, err := logReader.ReadString('\n')
test.That(t, err, test.ShouldBeNil)
if strings.Contains(line, "Passed sensor data to SLAM") {
prevNumFiles = testhelper.CheckDeleteProcessedData(
prevNumFiles = internaltesthelper.CheckDeleteProcessedData(
t,
subAlgo,
dataDir,
Expand Down Expand Up @@ -206,11 +207,11 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
}

// Create slam service using a real cartographer binary
svc, err = testhelper.CreateSLAMService(t, attrCfg, golog.NewTestLogger(t), true, viamcartographer.DefaultExecutableName)
svc, err = internaltesthelper.CreateSLAMService(t, attrCfg, golog.NewTestLogger(t), true, viamcartographer.DefaultExecutableName)
test.That(t, err, test.ShouldBeNil)

// Make sure we initialize in mapping mode
logReader = svc.(testhelper.Service).GetSLAMProcessBufferedLogReader()
logReader = svc.(internaltesthelper.Service).GetSLAMProcessBufferedLogReader()
for {
line, err := logReader.ReadString('\n')
test.That(t, err, test.ShouldBeNil)
Expand All @@ -226,7 +227,7 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
line, err := logReader.ReadString('\n')
test.That(t, err, test.ShouldBeNil)
if strings.Contains(line, "Passed sensor data to SLAM") {
prevNumFiles = testhelper.CheckDeleteProcessedData(
prevNumFiles = internaltesthelper.CheckDeleteProcessedData(
t,
subAlgo,
dataDir,
Expand All @@ -252,7 +253,7 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
time.Sleep(time.Millisecond * cartoSleepMsec)

// Remove existing pointclouds, but leave maps and config (so we keep the lua files).
test.That(t, testhelper.ResetFolder(dataDir+"/data"), test.ShouldBeNil)
test.That(t, internaltesthelper.ResetFolder(dataDir+"/data"), test.ShouldBeNil)
prevNumFiles = 0

// Count the initial number of maps in the map directory (should equal 1)
Expand Down Expand Up @@ -280,11 +281,11 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
// Release point cloud for service validation
testhelper.IntegrationLidarReleasePointCloudChan <- 1
// Create slam service using a real cartographer binary
svc, err = testhelper.CreateSLAMService(t, attrCfg, golog.NewTestLogger(t), true, viamcartographer.DefaultExecutableName)
svc, err = internaltesthelper.CreateSLAMService(t, attrCfg, golog.NewTestLogger(t), true, viamcartographer.DefaultExecutableName)
test.That(t, err, test.ShouldBeNil)

// Make sure we initialize in localization mode
logReader = svc.(testhelper.Service).GetSLAMProcessBufferedLogReader()
logReader = svc.(internaltesthelper.Service).GetSLAMProcessBufferedLogReader()
for {
line, err := logReader.ReadString('\n')
test.That(t, err, test.ShouldBeNil)
Expand All @@ -304,7 +305,7 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
line, err := logReader.ReadString('\n')
test.That(t, err, test.ShouldBeNil)
if strings.Contains(line, "Passed sensor data to SLAM") {
prevNumFiles = testhelper.CheckDeleteProcessedData(
prevNumFiles = internaltesthelper.CheckDeleteProcessedData(
t,
subAlgo,
dataDir,
Expand All @@ -320,7 +321,7 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
testCartographerMap(t, svc, true)

// Remove maps so that testing is done on the map generated by the internal map
test.That(t, testhelper.ResetFolder(dataDir+"/map"), test.ShouldBeNil)
test.That(t, internaltesthelper.ResetFolder(dataDir+"/map"), test.ShouldBeNil)

testCartographerInternalState(t, svc, dataDir)

Expand All @@ -334,7 +335,7 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
time.Sleep(time.Millisecond * cartoSleepMsec)

// Remove existing pointclouds, but leave maps and config (so we keep the lua files).
test.That(t, testhelper.ResetFolder(dataDir+"/data"), test.ShouldBeNil)
test.That(t, internaltesthelper.ResetFolder(dataDir+"/data"), test.ShouldBeNil)
prevNumFiles = 0

// Test online mode using the map generated in the offline test
Expand All @@ -356,11 +357,11 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
// Release point cloud for service validation
testhelper.IntegrationLidarReleasePointCloudChan <- 1
// Create slam service using a real cartographer binary
svc, err = testhelper.CreateSLAMService(t, attrCfg, golog.NewTestLogger(t), true, viamcartographer.DefaultExecutableName)
svc, err = internaltesthelper.CreateSLAMService(t, attrCfg, golog.NewTestLogger(t), true, viamcartographer.DefaultExecutableName)
test.That(t, err, test.ShouldBeNil)

// Make sure we initialize in updating mode
logReader = svc.(testhelper.Service).GetSLAMProcessBufferedLogReader()
logReader = svc.(internaltesthelper.Service).GetSLAMProcessBufferedLogReader()
for {
line, err := logReader.ReadString('\n')
test.That(t, err, test.ShouldBeNil)
Expand All @@ -380,7 +381,7 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
line, err := logReader.ReadString('\n')
test.That(t, err, test.ShouldBeNil)
if strings.Contains(line, "Passed sensor data to SLAM") {
prevNumFiles = testhelper.CheckDeleteProcessedData(
prevNumFiles = internaltesthelper.CheckDeleteProcessedData(
t,
subAlgo,
dataDir,
Expand All @@ -404,7 +405,7 @@ func integrationtestHelperCartographer(t *testing.T, subAlgo viamcartographer.Su
testCartographerDir(t, dataDir, 2)

// Clear out directory
testhelper.ClearDirectory(t, dataDir)
internaltesthelper.ClearDirectory(t, dataDir)
}

// Checks the current slam directory to see if the number of files matches the expected amount.
Expand Down
Loading