-
Notifications
You must be signed in to change notification settings - Fork 17
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-4106: Restructure lidar name and data rate to use map #213
Changes from 33 commits
3fe89df
00badc5
c6601b4
4c276e3
ba1a345
41f06ad
e4af834
a68ac81
14f5c56
18c9d7b
6d688bc
bee9d7f
7c7abfe
8608484
d7d8c5f
fc03df7
dc7adb3
09c0bda
339ae73
8679e01
ac1eccf
260e94a
c456d37
2304abc
128c20b
281d4a0
7e3386a
a4e6284
01751f8
0241490
c1edb8a
def1699
1c2fc0d
f1f8b9f
bbf95a7
2fa3e28
9b389be
de90d37
36cc0a3
52bb8b7
647e244
699cd47
21da3bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,7 @@ const ( | |
|
||
// CartoConfig contains config values from app | ||
type CartoConfig struct { | ||
Sensors []string | ||
Camera map[string]string | ||
MapRateSecond int | ||
DataDir string | ||
ComponentReference string | ||
|
@@ -179,7 +179,7 @@ func NewCarto(cfg CartoConfig, acfg CartoAlgoConfig, vcl CartoLibInterface) (Car | |
return Carto{}, err | ||
} | ||
|
||
status = C.free_bstring_array(vcc.sensors, C.size_t(len(cfg.Sensors))) | ||
status = C.free_bstring_array(vcc.sensors, C.size_t(1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets change the C API to take a lidar & optionally an imu, rather than having a sensor list |
||
if status != C.BSTR_OK { | ||
return Carto{}, errors.New("unable to free memory for sensor list") | ||
} | ||
|
@@ -354,15 +354,15 @@ func getConfig(cfg CartoConfig) (C.viam_carto_config, error) { | |
vcc := C.viam_carto_config{} | ||
|
||
// create pointer to bstring which can represent a list of sensors | ||
sz := len(cfg.Sensors) | ||
sz := 1 | ||
pSensor := C.alloc_bstring_array(C.size_t(sz)) | ||
if pSensor == nil { | ||
return C.viam_carto_config{}, errors.New("unable to allocate memory for sensor list") | ||
} | ||
sensorSlice := unsafe.Slice(pSensor, sz) | ||
for i, sensor := range cfg.Sensors { | ||
sensorSlice[i] = goStringToBstring(sensor) | ||
} | ||
|
||
sensorSlice[0] = goStringToBstring(cfg.Camera["name"]) | ||
|
||
lidarCfg, err := toLidarConfig(cfg.LidarConfig) | ||
if err != nil { | ||
return C.viam_carto_config{}, err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ func GetTestConfig(sensor string) (CartoConfig, string, error) { | |
} | ||
|
||
return CartoConfig{ | ||
Sensors: []string{sensor, "imu"}, | ||
Camera: map[string]string{"name": "test_lidar", "data_freq_hz": "20"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cartographer doesn't need to know the data_frequency_hz does it? |
||
MapRateSecond: 5, | ||
DataDir: dir, | ||
ComponentReference: "component", | ||
|
@@ -23,7 +23,7 @@ func GetTestConfig(sensor string) (CartoConfig, string, error) { | |
// GetBadTestConfig gets a sample config for testing purposes that will cause a failure. | ||
func GetBadTestConfig() CartoConfig { | ||
return CartoConfig{ | ||
Sensors: []string{"rplidar", "imu"}, | ||
Camera: map[string]string{"name": "rplidar", "data_freq_hz": "20"}, | ||
LidarConfig: TwoD, | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,8 @@ | |||||
package config | ||||||
|
||||||
import ( | ||||||
"strconv" | ||||||
|
||||||
"github.com/edaniels/golog" | ||||||
"github.com/pkg/errors" | ||||||
"go.viam.com/utils" | ||||||
|
@@ -14,19 +16,29 @@ func newError(configError string) error { | |||||
|
||||||
// Config describes how to configure the SLAM service. | ||||||
type Config struct { | ||||||
Sensors []string `json:"sensors"` | ||||||
Camera map[string]string `json:"camera"` | ||||||
ConfigParams map[string]string `json:"config_params"` | ||||||
DataDirectory string `json:"data_dir"` | ||||||
DataRateMsec int `json:"data_rate_msec"` | ||||||
MapRateSec *int `json:"map_rate_sec"` | ||||||
} | ||||||
|
||||||
var errSensorsMustNotBeEmpty = errors.New("\"sensors\" must not be empty") | ||||||
var errCameraMustHaveName = errors.New("\"camera[name]\" is required") | ||||||
|
||||||
// Validate creates the list of implicit dependencies. | ||||||
func (config *Config) Validate(path string) ([]string, error) { | ||||||
if config.Sensors == nil || len(config.Sensors) < 1 { | ||||||
return nil, utils.NewConfigValidationError(path, errSensorsMustNotBeEmpty) | ||||||
_, ok := config.Camera["name"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if !ok { | ||||||
return nil, utils.NewConfigValidationError(path, errCameraMustHaveName) | ||||||
} | ||||||
dataFreqHz, ok := config.Camera["data_freq_hz"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The scope doc says this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if ok { | ||||||
dataFreqHz, err := strconv.Atoi(dataFreqHz) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if err != nil { | ||||||
return nil, errors.New("data_freq_hz must only contain digits") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should specify we are talking about |
||||||
} | ||||||
if dataFreqHz < 0 { | ||||||
return nil, errors.New("cannot specify data_freq_hz less than zero") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should specify we are talking about |
||||||
} | ||||||
} | ||||||
|
||||||
if config.ConfigParams["mode"] == "" { | ||||||
|
@@ -37,30 +49,19 @@ func (config *Config) Validate(path string) ([]string, error) { | |||||
return nil, utils.NewConfigValidationFieldRequiredError(path, "data_dir") | ||||||
} | ||||||
|
||||||
if config.DataRateMsec < 0 { | ||||||
return nil, errors.New("cannot specify data_rate_msec less than zero") | ||||||
} | ||||||
|
||||||
if config.MapRateSec != nil && *config.MapRateSec < 0 { | ||||||
return nil, errors.New("cannot specify map_rate_sec less than zero") | ||||||
} | ||||||
|
||||||
deps := config.Sensors | ||||||
deps := []string{config.Camera["name"]} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
return deps, nil | ||||||
} | ||||||
|
||||||
// GetOptionalParameters sets any unset optional config parameters to the values passed to this function, | ||||||
// and returns them. | ||||||
func GetOptionalParameters(config *Config, | ||||||
defaultDataRateMsec, defaultMapRateSec int, logger golog.Logger, | ||||||
) (int, int) { | ||||||
dataRateMsec := config.DataRateMsec | ||||||
if config.DataRateMsec == 0 { | ||||||
dataRateMsec = defaultDataRateMsec | ||||||
logger.Debugf("no data_rate_msec given, setting to default value of %d", defaultDataRateMsec) | ||||||
} | ||||||
|
||||||
func GetOptionalParameters(config *Config, defaultMapRateSec int, logger golog.Logger, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where are we deriving the default lidar data rate? |
||||||
) int { | ||||||
mapRateSec := 0 | ||||||
if config.MapRateSec == nil { | ||||||
logger.Debugf("no map_rate_sec given, setting to default value of %d", defaultMapRateSec) | ||||||
|
@@ -69,5 +70,5 @@ func GetOptionalParameters(config *Config, | |||||
mapRateSec = *config.MapRateSec | ||||||
} | ||||||
|
||||||
return dataRateMsec, mapRateSec | ||||||
return mapRateSec | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.