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-863: Add implicit depends_on for services #1584

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 1 addition & 5 deletions etc/configs/fake.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@
},
"movement_sensor": "movement_sensor1",
"base": "base1"
},
"depends_on": [
"base1",
"movement_sensor1"
]
}
}
]
}
24 changes: 23 additions & 1 deletion services/baseremotecontrol/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/golang/geo/r3"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
vutils "go.viam.com/utils"

"go.viam.com/rdk/components/base"
"go.viam.com/rdk/components/input"
Expand Down Expand Up @@ -66,6 +67,22 @@ type Config struct {
MaxLinearVelocity float64 `json:"max_linear_mm_per_sec,omitempty"`
}

// Validate creates the list of implicit dependencies.
func (config *Config) Validate(path string) ([]string, error) {
var deps []string
if config.InputControllerName == "" {
return nil, vutils.NewConfigValidationFieldRequiredError(path, "input_controller")
}
deps = append(deps, config.InputControllerName)

if config.BaseName == "" {
return nil, vutils.NewConfigValidationFieldRequiredError(path, "base")
}
deps = append(deps, config.BaseName)

return deps, nil
}

// builtIn is the structure of the remote service.
type builtIn struct {
base base.Base
Expand All @@ -80,7 +97,12 @@ type builtIn struct {
}

// NewDefault returns a new remote control service for the given robot.
func NewBuiltIn(ctx context.Context, deps registry.Dependencies, config config.Service, logger golog.Logger) (baseremotecontrol.Service, error) {
func NewBuiltIn(
ctx context.Context,
deps registry.Dependencies,
config config.Service,
logger golog.Logger,
) (baseremotecontrol.Service, error) {
svcConfig, ok := config.ConvertedAttributes.(*Config)
if !ok {
return nil, utils.NewUnexpectedTypeError(svcConfig, config.ConvertedAttributes)
Expand Down
4 changes: 4 additions & 0 deletions services/baseremotecontrol/builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func TestBaseRemoteControl(t *testing.T) {
ControlModeName: "",
}

depNames, err := cfg.Validate("")
test.That(t, err, test.ShouldBeNil)
test.That(t, utils.NewStringSet(depNames...), test.ShouldResemble, utils.NewStringSet("baseTest", "inputTest"))

fakeController := &inject.InputController{}
fakeBase := &fakebase.Base{}

Expand Down
17 changes: 17 additions & 0 deletions services/navigation/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ type Config struct {
MMPerSecDefault float64 `json:"mm_per_sec"`
}

// Validate creates the list of implicit dependencies.
func (config *Config) Validate(path string) ([]string, error) {
var deps []string

if config.BaseName == "" {
return nil, utils.NewConfigValidationFieldRequiredError(path, "base")
}
deps = append(deps, config.BaseName)

if config.MovementSensorName == "" {
return nil, utils.NewConfigValidationFieldRequiredError(path, "movement_sensor")
}
deps = append(deps, config.MovementSensorName)

return deps, nil
}

// NewBuiltIn returns a new navigation service for the given robot.
func NewBuiltIn(ctx context.Context, deps registry.Dependencies, config config.Service, logger golog.Logger) (navigation.Service, error) {
svcConfig, ok := config.ConvertedAttributes.(*Config)
Expand Down
5 changes: 2 additions & 3 deletions web/frontend/cypress/data/test_robot_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@
},
"movement_sensor": "test_movement",
"base": "test_base"
},
"depends_on":["test_movement","test_base"]
}
}
]
}
}