-
Notifications
You must be signed in to change notification settings - Fork 3
Fix gripper hang after tool-changer swap #15
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
Open
Joseph Borodach (JosephBorodach)
wants to merge
17
commits into
main
Choose a base branch
from
fix/gripper-reactivate-after-tool-swap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−69
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
174e52d
Fix gripper hang after tool-changer swap
JosephBorodach c41f998
wip
JosephBorodach f140c56
wip
JosephBorodach bbe9867
wip
JosephBorodach e25b736
wip
JosephBorodach 3579fb6
wip
JosephBorodach 1209537
wip
JosephBorodach dfbf9da
wip
JosephBorodach eb15149
wip
JosephBorodach 8cb05a1
wip
JosephBorodach 81886b4
wip
JosephBorodach 2e62f28
wip
JosephBorodach 7880b0d
wip
JosephBorodach 81f8021
wip
JosephBorodach 7c3741e
wip
JosephBorodach 76a4882
wip
JosephBorodach 5ce6877
wip
JosephBorodach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,4 +25,6 @@ go.work.sum | |
| .env | ||
|
|
||
| # binaries | ||
| bin/ | ||
| bin/ | ||
|
|
||
| .VIAM_RELOAD_ARCHIVE.tar.gz | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package robotiq | ||
|
|
||
| import ( | ||
| "context" | ||
| "net" | ||
| "strings" | ||
| "sync" | ||
| "testing" | ||
|
|
||
| "go.viam.com/rdk/logging" | ||
| "go.viam.com/rdk/operation" | ||
| "go.viam.com/test" | ||
| ) | ||
|
|
||
| func TestSetPosRejectsNonNumeric(t *testing.T) { | ||
| g := &robotiqGripper{} | ||
| _, err := g.SetPos(context.Background(), "?") | ||
| test.That(t, err, test.ShouldNotBeNil) | ||
| test.That(t, err.Error(), test.ShouldContainSubstring, "invalid target position") | ||
| } | ||
|
|
||
| // fakeURCap is a minimal in-process stand-in for the Robotiq URCap on port | ||
| // 63352. It responds "ack" to SET commands and answers GET STA with a state | ||
| // value it updates in response to SET ACT writes: SET ACT 0 -> STA 0, SET ACT | ||
| // 1 -> STA 3 (instant activation). | ||
| type fakeURCap struct { | ||
| ln net.Listener | ||
| mu sync.Mutex | ||
| seen []string | ||
| sta string | ||
| } | ||
|
|
||
| func newFakeURCap(t *testing.T) *fakeURCap { | ||
| t.Helper() | ||
| ln, err := net.Listen("tcp", "127.0.0.1:63352") | ||
| test.That(t, err, test.ShouldBeNil) | ||
| f := &fakeURCap{ln: ln, sta: "0"} | ||
| go f.serve() | ||
| return f | ||
| } | ||
|
|
||
| func (f *fakeURCap) close() { _ = f.ln.Close() } | ||
|
|
||
| func (f *fakeURCap) commands() []string { | ||
| f.mu.Lock() | ||
| defer f.mu.Unlock() | ||
| out := make([]string, len(f.seen)) | ||
| copy(out, f.seen) | ||
| return out | ||
| } | ||
|
|
||
| func (f *fakeURCap) serve() { | ||
| for { | ||
| conn, err := f.ln.Accept() | ||
| if err != nil { | ||
| return | ||
| } | ||
| go f.handle(conn) | ||
| } | ||
| } | ||
|
|
||
| func (f *fakeURCap) handle(conn net.Conn) { | ||
| defer conn.Close() | ||
| buf := make([]byte, 128) | ||
| n, err := conn.Read(buf) | ||
| if err != nil { | ||
| return | ||
| } | ||
| cmd := strings.TrimSpace(string(buf[:n])) | ||
|
|
||
| f.mu.Lock() | ||
| f.seen = append(f.seen, cmd) | ||
| switch { | ||
| case cmd == "SET ACT 0": | ||
| f.sta = "0" | ||
| case cmd == "SET ACT 1": | ||
| f.sta = "3" | ||
| } | ||
| var resp string | ||
| switch { | ||
| case cmd == "GET STA": | ||
| resp = "STA " + f.sta | ||
| default: | ||
| resp = "ack" | ||
| } | ||
| f.mu.Unlock() | ||
| _, _ = conn.Write([]byte(resp)) | ||
| } | ||
|
|
||
| // TestActivateDrivesRACTEdgeAndWaitsForSTA3 verifies the core fix: activate | ||
| // forces a SET ACT 0 -> SET ACT 1 transition (bare SET ACT 1 was a no-op after | ||
| // a swap because rACT was still 1), then waits for STA 3. | ||
| // | ||
| // Slow (~3.6s) because MultiSet has hard-coded post-write waits. | ||
| func TestActivateDrivesRACTEdgeAndWaitsForSTA3(t *testing.T) { | ||
| urcap := newFakeURCap(t) | ||
| defer urcap.close() | ||
|
|
||
| g := &robotiqGripper{ | ||
| host: "127.0.0.1", | ||
| logger: logging.NewTestLogger(t), | ||
| opMgr: operation.NewSingleOperationManager(), | ||
| } | ||
|
|
||
| err := g.activate(context.Background()) | ||
| test.That(t, err, test.ShouldBeNil) | ||
|
|
||
| seen := urcap.commands() | ||
| idx0 := indexOf(seen, "SET ACT 0") | ||
| idx1 := indexOf(seen, "SET ACT 1") | ||
| test.That(t, idx0, test.ShouldBeGreaterThanOrEqualTo, 0) | ||
| test.That(t, idx1, test.ShouldBeGreaterThan, idx0) | ||
| test.That(t, indexOf(seen, "GET STA"), test.ShouldBeGreaterThan, idx1) | ||
| } | ||
|
|
||
| func indexOf(ss []string, target string) int { | ||
| for i, s := range ss { | ||
| if s == target { | ||
| return i | ||
| } | ||
| } | ||
| return -1 | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should probably make this config dependent. I don't think "if the machine cannot connect to the gripper don't worry about it" is a good default. If someone misconfigures a gripper it should fail loudly. If someone intentionally configures a gripper which may not be connected it should be allowed but it should be explicit