Skip to content

Commit

Permalink
RSDK-8838: Use SetRPM in gantry homing routine (#4380)
Browse files Browse the repository at this point in the history
  • Loading branch information
martha-johnston authored Sep 23, 2024
1 parent 2b2669d commit c0763fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions components/gantry/singleaxis/singleaxis.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (g *singleAxis) moveAway(ctx context.Context, pin int) error {
if pin != 0 {
dir = -1.0
}
if err := g.motor.GoFor(ctx, dir*g.rpm, 0, nil); err != nil {
if err := g.motor.SetRPM(ctx, dir*g.rpm, nil); err != nil {
return err
}
defer utils.UncheckedErrorFunc(func() error {
Expand Down Expand Up @@ -420,7 +420,7 @@ func (g *singleAxis) testLimit(ctx context.Context, pin int) (float64, error) {
wrongPin = 0
}

err := g.motor.GoFor(ctx, d*g.rpm, 0, nil)
err := g.motor.SetRPM(ctx, d*g.rpm, nil)
if err != nil {
return 0, err
}
Expand Down
22 changes: 11 additions & 11 deletions components/gantry/singleaxis/singleaxis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func createFakeMotor() motor.Motor {
},
ResetZeroPositionFunc: func(ctx context.Context, offset float64, extra map[string]interface{}) error { return nil },
GoToFunc: func(ctx context.Context, rpm, position float64, extra map[string]interface{}) error { return nil },
GoForFunc: func(ctx context.Context, rpm, revolutions float64, extra map[string]interface{}) error { return nil },
SetRPMFunc: func(ctx context.Context, rpm float64, extra map[string]interface{}) error { return nil },
StopFunc: func(ctx context.Context, extra map[string]interface{}) error { return nil },
SetPowerFunc: func(ctx context.Context, powerPct float64, extra map[string]interface{}) error { return nil },
}
Expand Down Expand Up @@ -287,16 +287,16 @@ func TestHome(t *testing.T) {
test.That(t, err, test.ShouldBeNil)
test.That(t, homed, test.ShouldBeTrue)

goForErr := errors.New("GoFor failed")
setRPMErr := errors.New("SetRPM failed")
posErr := errors.New("Position fail")
fakeMotor := &inject.Motor{
PropertiesFunc: func(ctx context.Context, extra map[string]interface{}) (motor.Properties, error) {
return motor.Properties{
PositionReporting: false,
}, nil
},
GoForFunc: func(ctx context.Context, rpm, rotations float64, extra map[string]interface{}) error {
return goForErr
SetRPMFunc: func(ctx context.Context, rpm float64, extra map[string]interface{}) error {
return setRPMErr
},
StopFunc: func(ctx context.Context, extra map[string]interface{}) error {
return nil
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestHomeLimitSwitch(t *testing.T) {

getPosErr := errors.New("failed to get position")
fakegantry.motor = &inject.Motor{
GoForFunc: func(ctx context.Context, rpm, rotations float64, extra map[string]interface{}) error { return nil },
SetRPMFunc: func(ctx context.Context, rpm float64, extra map[string]interface{}) error { return nil },
StopFunc: func(ctx context.Context, extra map[string]interface{}) error { return nil },
PositionFunc: func(ctx context.Context, extra map[string]interface{}) (float64, error) { return 0, getPosErr },
}
Expand All @@ -381,7 +381,7 @@ func TestHomeLimitSwitch(t *testing.T) {
PositionReporting: true,
}, nil
},
GoForFunc: func(ctx context.Context, rpm, rotations float64, extra map[string]interface{}) error {
SetRPMFunc: func(ctx context.Context, rpm float64, extra map[string]interface{}) error {
return errors.New("err")
},
StopFunc: func(ctx context.Context, extra map[string]interface{}) error { return nil },
Expand All @@ -395,7 +395,7 @@ func TestHomeLimitSwitch(t *testing.T) {
PositionReporting: true,
}, nil
},
GoForFunc: func(ctx context.Context, rpm, rotations float64, extra map[string]interface{}) error {
SetRPMFunc: func(ctx context.Context, rpm float64, extra map[string]interface{}) error {
return nil
},
StopFunc: func(ctx context.Context, extra map[string]interface{}) error { return errors.New("err") },
Expand All @@ -409,7 +409,7 @@ func TestHomeLimitSwitch(t *testing.T) {
PositionReporting: true,
}, nil
},
GoForFunc: func(ctx context.Context, rpm, rotations float64, extra map[string]interface{}) error {
SetRPMFunc: func(ctx context.Context, rpm float64, extra map[string]interface{}) error {
return errors.New("err")
},
StopFunc: func(ctx context.Context, extra map[string]interface{}) error { return nil },
Expand Down Expand Up @@ -467,7 +467,7 @@ func TestHomeLimitSwitch2(t *testing.T) {

getPosErr := errors.New("failed to get position")
fakegantry.motor = &inject.Motor{
GoForFunc: func(ctx context.Context, rpm, rotations float64, extra map[string]interface{}) error {
SetRPMFunc: func(ctx context.Context, rpm float64, extra map[string]interface{}) error {
return nil
},
StopFunc: func(ctx context.Context, extra map[string]interface{}) error {
Expand All @@ -486,7 +486,7 @@ func TestHomeLimitSwitch2(t *testing.T) {
PositionReporting: true,
}, nil
},
GoForFunc: func(ctx context.Context, rpm, rotations float64, extra map[string]interface{}) error {
SetRPMFunc: func(ctx context.Context, rpm float64, extra map[string]interface{}) error {
return errors.New("not supported")
},
StopFunc: func(ctx context.Context, extra map[string]interface{}) error { return nil },
Expand All @@ -513,7 +513,7 @@ func TestHomeEncoder(t *testing.T) {

resetZeroErr := errors.New("failed to set zero")
injMotor := &inject.Motor{
GoForFunc: func(ctx context.Context, rpm, rotations float64, extra map[string]interface{}) error { return nil },
SetRPMFunc: func(ctx context.Context, rpm float64, extra map[string]interface{}) error { return nil },
StopFunc: func(ctx context.Context, extra map[string]interface{}) error { return nil },
ResetZeroPositionFunc: func(ctx context.Context, offset float64, extra map[string]interface{}) error { return resetZeroErr },
}
Expand Down

0 comments on commit c0763fc

Please sign in to comment.