Skip to content

[RSDK-8438] add updating mode support#6

Merged
JohnN193 merged 5 commits intomainfrom
updating-mode
Aug 12, 2024
Merged

[RSDK-8438] add updating mode support#6
JohnN193 merged 5 commits intomainfrom
updating-mode

Conversation

@JohnN193
Copy link
Copy Markdown
Collaborator

@JohnN193 JohnN193 commented Aug 8, 2024

this pr adds the ability to use updating mode with the cloudslam module. It works by making a Config Request to app, then parsing the packages within the config until a slam_map package is found. This assumes that only one map package is configured on the robot, which is a perfectly valid assumption. The feature only works if a machine part ID is configured in on the service, which allows users a workaround to disable updating mode as an option for cloudslam, if they choose to.

Using the Config API might not be the best choice, as it is the API that viam-servers use to read their own configs, but functionally it does what we want and is a part of the public API that location owners have permission to use.

ticket: https://viam.atlassian.net/browse/RSDK-8438

@JohnN193 JohnN193 requested a review from penguinland August 8, 2024 18:31
Copy link
Copy Markdown

@penguinland penguinland left a comment

Choose a reason for hiding this comment

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

I still don't really grok any of this module, but the code LPlausibleTM. All my feedback is either minor or optional.

Comment thread cloudslam/app.go Outdated
}

// GetPackagesOnRobot makes a Config request to app and returns the first SLAM map that it finds on the robot.
func (app *AppClient) GetPackagesOnRobot(ctx context.Context, partID string) (string, string, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Discussion question: does this name misleadingly suggest it gets all packages, not just SLAM paths? Perhaps it's obvious what it does in the context of the cloudslam package, and the name is good as-is. I'm unsure.

I'd at least update the comment on line 67 to explain that it returns the name and version of the map it finds; otherwise it's not clear what the return values are.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

renamed to GetSLAMMapPackageOnRobot to be more clear this will only retrieve information on the SLAM map package

Comment thread cloudslam/cloudslam.go Outdated

const (
startJobKey = "start"
updatingModeKey = "updating mode"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure what these keys are, but localPackageKey used hyphens instead of spaces. Is it okay to have spaces in here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

so I was using this key as a way to only return information that updating mdoe is happening, but i should probably make the formatting consistent.

since these keys are used in a map[string]interface{} I figured it was okay to have spaces, as it improved readability. When testing I did not notice any issues, but I do not know if requests & responses are handled differently for some reason.

Comment thread cloudslam/cloudslam.go
}
if cfg.RobotID == "" {
return []string{}, resource.NewConfigValidationFieldRequiredError(path, "robot_id")
return []string{}, resource.NewConfigValidationFieldRequiredError(path, "machine_id")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not a fan of this. If we're checking cfg.RobotID, the required JSON field should be robot_id. If the JSON field is machine_id, I'd prefer to check cfg.MachineID.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

i was being lazy and only changed the json to use machine_id, rather than changing all of the code.

I can be not lazy

Comment thread cloudslam/cloudslam.go Outdated
}

// initialize completes the initiaization of the cloudslam wrapper struct.
func (svc *cloudslamWrapper) initialize() error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 I really like that this is broken out into a helper function. Nice work!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

still don't think its too necessary, but I realized I didn't like all the extra stuff happening after I made the struct.

Comment thread cloudslam/cloudslam.go

if isUpdating {
resp[updatingModeKey] = fmt.Sprintf("slam map found on machine, starting cloudslam in updating mode. Map "+
"Name = %v // Updating Version = %v", svc.updatingMapName, svc.updatingMapVersion)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If someone wants to consume this data programmatically, they need to parse the string again. What do you think about having 3 separate keys, updatingMode, updatingMapName, and updatingMapVersion or similar?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

the problem I ran into is the keys did not appear to be guaranteed to have a specific order, and having to read that information from the docommand got alittle bit annoying

Comment thread cloudslam/cloudslam.go
if isUpdating {
resp[updatingModeKey] = fmt.Sprintf("slam map found on machine, starting cloudslam in updating mode. Map "+
"Name = %v // Updating Version = %v", svc.updatingMapName, svc.updatingMapVersion)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you're not updating, this key isn't set at all. Would it make sense to have an else down here that sets it to, like, "no pre-made map found, creating a new one" or something?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think its okay to not have the updating mode key, as its intended to be a feature that a user adds on top of the default cloudslam behavior. Having something always return for updating mode would notify users of the feature, but it would also be kinda spammy?

if ya feel strongly I can add something

Comment thread cloudslam/cloudslam.go
}
resp[startJobKey] = "Starting cloudslam session, the robot should appear in ~1 minute. Job ID: " + jobID

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'd swap these two lines. I never like blank lines immediately after a { or immediately before a }, but having them after the } to indicate we're about to do something very different is a good choice.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

my b, just some leftover whitespace!

Comment thread cloudslam/cloudslam.go
@@ -321,7 +350,8 @@ func (svc *cloudslamWrapper) StopJob(ctx context.Context) (string, error) {
}

// StartJob starts a cloudslam job with the requested map name. Currently assumes a set of config parameters.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Explain what the new return value is.

...explain what the pre-existing return value is, too. 😄

@JohnN193 JohnN193 merged commit d2eabea into main Aug 12, 2024
@JohnN193 JohnN193 deleted the updating-mode branch August 12, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants