Skip to content

Commit

Permalink
fix sensor validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnN193 committed May 23, 2024
1 parent 132a438 commit 903404a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cartofacade/capi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestCGoAPIWithoutMovementSensor(t *testing.T) {
cfgBad := GetBadTestConfig()
vc, err = NewCarto(cfgBad, algoCfg, &pvcl)
// initialize viam_carto incorrectly
test.That(t, err, test.ShouldResemble, errors.New("VIAM_CARTO_COMPONENT_REFERENCE_INVALID"))
test.That(t, err, test.ShouldResemble, errors.New("VIAM_CARTO_LIDAR_CONFIG_INVALID"))
test.That(t, vc, test.ShouldNotBeNil)

algoCfg = GetTestAlgoConfig(false)
Expand Down
12 changes: 11 additions & 1 deletion viam-cartographer/src/carto_facade/carto_facade.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ config from_viam_carto_config(viam_carto_config vcc) {
c.lidar_config = vcc.lidar_config;

if (c.camera.empty()) {
throw VIAM_CARTO_COMPONENT_REFERENCE_INVALID;
throw VIAM_CARTO_LIDAR_CONFIG_INVALID;
}
validate_lidar_config(c.lidar_config);

Expand Down Expand Up @@ -640,6 +640,16 @@ void CartoFacade::AddLidarReading(const viam_carto_lidar_reading *sr) {
<< CartoFacadeState::STARTED;
throw VIAM_CARTO_NOT_IN_STARTED_STATE;
}

bstring camera_sensor = to_bstring(config.camera);
bool known_sensor = biseq(camera_sensor, sr->lidar);
bdestroy(camera_sensor);
if (!known_sensor) {
VLOG(1) << "expected sensor: " << to_std_string(sr->lidar) << " to be "
<< config.camera;
throw VIAM_CARTO_UNKNOWN_SENSOR_NAME;
}

std::string lidar_reading = to_std_string(sr->lidar_reading);
if (lidar_reading.length() == 0) {
throw VIAM_CARTO_LIDAR_READING_EMPTY;
Expand Down
2 changes: 1 addition & 1 deletion viam-cartographer/src/carto_facade/carto_facade_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(CartoFacade_init_validate) {
VIAM_CARTO_THREE_D, no_camera, no_movement_sensor, true, "");

BOOST_TEST(viam_carto_init(&vc, lib, vcc_empty_component_ref, ac) ==
VIAM_CARTO_COMPONENT_REFERENCE_INVALID);
VIAM_CARTO_LIDAR_CONFIG_INVALID);

ac = viam_carto_algo_config_setup(true);
// Test config validation with invalid lidar config
Expand Down

0 comments on commit 903404a

Please sign in to comment.