Skip to content

Commit 9d8cffa

Browse files
authored
Improve reset (#23)
1 parent f8facd4 commit 9d8cffa

File tree

1 file changed

+83
-24
lines changed

1 file changed

+83
-24
lines changed

pour/vinocart.go

Lines changed: 83 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,72 @@ func (vc *VinoCart) FullDemo(ctx context.Context) error {
302302
func (vc *VinoCart) Reset(ctx context.Context) error {
303303
g := errgroup.Group{}
304304

305+
cupHoldingStatus, err := vc.c.Gripper.IsHoldingSomething(ctx, nil)
306+
if err != nil {
307+
return err
308+
}
309+
bottleHoldingStatus, err := vc.c.BottleGripper.IsHoldingSomething(ctx, nil)
310+
if err != nil {
311+
return err
312+
}
305313
g.Go(func() error {
306-
return vc.c.Gripper.Open(ctx, nil)
314+
var err error
315+
if cupHoldingStatus.IsHoldingSomething {
316+
err = vc.doAll(ctx, "reset", "left-holding-pre", 50)
317+
if err != nil {
318+
return err
319+
}
320+
321+
err = vc.moveToCurrentXYAtCupHeight(ctx)
322+
if err != nil {
323+
return err
324+
}
325+
326+
err = vc.c.Gripper.Open(ctx, nil)
327+
if err != nil {
328+
return err
329+
}
330+
331+
time.Sleep(time.Millisecond * 500)
332+
err = vc.doAll(ctx, "reset", "left-holding-post", 50)
333+
if err != nil {
334+
return err
335+
}
336+
}
337+
return nil
307338
})
308339

309340
g.Go(func() error {
310-
return vc.c.BottleGripper.Open(ctx, nil)
341+
var err error
342+
if bottleHoldingStatus.IsHoldingSomething {
343+
err = vc.doAll(ctx, "reset", "right-holding-pre", 50)
344+
if err != nil {
345+
return err
346+
}
347+
348+
err = vc.c.BottleGripper.Open(ctx, nil)
349+
if err != nil {
350+
return err
351+
}
352+
353+
time.Sleep(time.Millisecond * 500)
354+
355+
err = vc.doAll(ctx, "reset", "right-holding-post", 50)
356+
if err != nil {
357+
return err
358+
}
359+
360+
}
361+
return nil
311362
})
312363

313-
err := vc.doAll(ctx, "touch", "prep", 100)
314364
err2 := g.Wait()
365+
if err2 != nil {
366+
return err2
367+
}
368+
err3 := vc.doAll(ctx, "touch", "prep", 100)
315369

316-
return multierr.Combine(err, err2)
370+
return err3
317371
}
318372

319373
func (vc *VinoCart) GrabCup(ctx context.Context) error {
@@ -782,6 +836,30 @@ func (vc *VinoCart) goTo(ctx context.Context, poss ...toggleswitch.Switch) error
782836
return multierr.Combine(errors...)
783837
}
784838

839+
func (vc *VinoCart) moveToCurrentXYAtCupHeight(ctx context.Context) error {
840+
cur, err := vc.c.Motion.GetPose(ctx, vc.conf.GripperName, "world", vc.pourExtraFrames, nil)
841+
if err != nil {
842+
return err
843+
}
844+
845+
cur = referenceframe.NewPoseInFrame(
846+
cur.Parent(),
847+
spatialmath.NewPose(r3.Vector{
848+
X: cur.Pose().Point().X,
849+
Y: cur.Pose().Point().Y,
850+
Z: vc.conf.CupHeight - vc.conf.cupGripHeightOffset(),
851+
}, cur.Pose().Orientation()))
852+
853+
_, err = vc.c.Motion.Move(
854+
ctx,
855+
motion.MoveReq{
856+
ComponentName: vc.conf.GripperName,
857+
Destination: cur,
858+
},
859+
)
860+
return err
861+
}
862+
785863
func (vc *VinoCart) PourGlassFindCroppedRect(ctx context.Context) (*image.Rectangle, error) {
786864
detections, err := vc.c.PourGlassFindService.DetectionsFromCamera(ctx, "", nil)
787865
if err != nil {
@@ -965,26 +1043,7 @@ func (vc *VinoCart) PutBack(ctx context.Context) error {
9651043
return err
9661044
}
9671045

968-
cur, err := vc.c.Motion.GetPose(ctx, vc.conf.GripperName, "world", vc.pourExtraFrames, nil)
969-
if err != nil {
970-
return err
971-
}
972-
973-
cur = referenceframe.NewPoseInFrame(
974-
cur.Parent(),
975-
spatialmath.NewPose(r3.Vector{
976-
X: cur.Pose().Point().X,
977-
Y: cur.Pose().Point().Y,
978-
Z: vc.conf.CupHeight - vc.conf.cupGripHeightOffset(),
979-
}, cur.Pose().Orientation()))
980-
981-
_, err = vc.c.Motion.Move(
982-
ctx,
983-
motion.MoveReq{
984-
ComponentName: vc.conf.GripperName,
985-
Destination: cur,
986-
},
987-
)
1046+
err = vc.moveToCurrentXYAtCupHeight(ctx)
9881047
if err != nil {
9891048
return err
9901049
}

0 commit comments

Comments
 (0)