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-8926: Rover canary motor test fail because failure to set pins #4549

Merged
merged 3 commits into from
Nov 14, 2024

Conversation

martha-johnston
Copy link
Contributor

The context was getting canceled before the pins could be set correctly in order to stop the motor. by using a background context, Stop() and setPWM() can return while turnOff is still setting the pins. Could this also be done with SelectContextOrWait?

I also updated the error return from local_robot.go because it buried the error from StopAll in order to see what was actually happening.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Nov 11, 2024
@martha-johnston martha-johnston requested review from a team and randhid and removed request for a team November 11, 2024 20:32
Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

We should still return all the errors from all resources from StopAll. Your for loop will return on the first iteration and skip the rest.

Comment on lines 196 to 212
resourceErrs := make(map[string]error)
for _, name := range r.ResourceNames() {
res, err := r.ResourceByName(name)
if err != nil {
resourceErrs = append(resourceErrs, name.Name)
resourceErrs[name.Name] = err
continue
}

if actuator, ok := res.(resource.Actuator); ok {
if err := actuator.Stop(ctx, extra[name]); err != nil {
resourceErrs = append(resourceErrs, name.Name)
resourceErrs[name.Name] = err
}
}
}

if len(resourceErrs) > 0 {
return errors.Errorf("failed to stop components named %s", strings.Join(resourceErrs, ","))
for k, v := range resourceErrs {
return errors.Errorf("failed to stop component named %s with error %v", k, v)
Copy link
Member

Choose a reason for hiding this comment

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

we should join all the errors first before returning them, right now you're returning at the first iteration of this for loop, and so only returning the first error. Not the same behaviour as before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh meant to log this every time not return. is there a benefit to returning a joined error rather than just logging each error as we iterate through resourceErrs

Copy link
Member

Choose a reason for hiding this comment

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

Since the behaviour before was to return an error, that would be a change in the behaviour of StopAll; now - if Stopall failed to stop your actuating components, you've got bigger problems than what the local robot does after. Session manager and App call stopAll for connectivity loss and moving away from the control page. If there are error checks there where they end up retrying if an error is encountered, then you're changing that behaviour of that caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay I'll wrap it all into one error

@@ -306,7 +306,7 @@ func (m *Motor) Stop(ctx context.Context, extra map[string]interface{}) error {
m.opMgr.CancelRunning(ctx)
m.mu.Lock()
defer m.mu.Unlock()
return m.setPWM(ctx, 0, extra)
return m.setPWM(context.Background(), 0, extra)
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Glad you identified the cause os the setPWM failure.

@@ -193,23 +193,23 @@ func (r *localRobot) StopAll(ctx context.Context, extra map[resource.Name]map[st
}

// Stop all stoppable resources
resourceErrs := []string{}
resourceErrs := make(map[string]error)
Copy link
Member

Choose a reason for hiding this comment

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

@cheukt okay with this change? I think it's good for the StopAll error map in general.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 11, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 12, 2024
@martha-johnston martha-johnston merged commit 8bbc629 into viamrobotics:main Nov 14, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants