Skip to content

Commit

Permalink
RSDK-9136: issues when stopping motor with controls (#4550)
Browse files Browse the repository at this point in the history
  • Loading branch information
martha-johnston authored Nov 12, 2024
1 parent a3262bf commit ae58534
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions components/motor/gpio/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func NewMotor(b board.Board, mc Config, name resource.Name, logger logging.Logge
m.EnablePinLow = enablePinLow
}

if m.maxRPM == 0 {
m.maxRPM = 100
}

return m, nil
}

Expand Down
10 changes: 5 additions & 5 deletions components/motor/gpio/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestMotorDirPWM(t *testing.T) {
mc.ResourceName(), logger)

test.That(t, err, test.ShouldBeNil)
test.That(t, m.GoFor(ctx, 50, 10, nil), test.ShouldBeError, errors.New("not supported, define max_rpm attribute != 0"))
test.That(t, m.GoFor(ctx, 50, 10, nil), test.ShouldBeNil)

m, err = NewMotor(b, Config{Pins: PinConfig{Direction: "1", EnablePinLow: "2"}, PWMFreq: 4000},
mc.ResourceName(), logger)
Expand All @@ -191,7 +191,7 @@ func TestMotorDirPWM(t *testing.T) {

t.Run("motor (DIR/PWM) Off testing", func(t *testing.T) {
test.That(t, m.Stop(ctx, nil), test.ShouldBeNil)
test.That(t, mustGetGPIOPinByName(b, "1").Get(context.Background()), test.ShouldEqual, false)
test.That(t, mustGetGPIOPinByName(b, "1").Get(context.Background()), test.ShouldEqual, true)
test.That(t, mustGetGPIOPinByName(b, "2").Get(context.Background()), test.ShouldEqual, true)
test.That(t, mustGetGPIOPinByName(b, "1").PWM(context.Background()), test.ShouldEqual, 0)
test.That(t, mustGetGPIOPinByName(b, "2").PWM(context.Background()), test.ShouldEqual, 0)
Expand All @@ -204,11 +204,11 @@ func TestMotorDirPWM(t *testing.T) {

t.Run("motor (DIR/PWM) GoFor testing", func(t *testing.T) {
test.That(t, m.GoFor(ctx, 50, 0, nil), test.ShouldBeError, motor.NewZeroRevsError())
test.That(t, mustGetGPIOPinByName(b, "1").Get(context.Background()), test.ShouldEqual, false)
test.That(t, mustGetGPIOPinByName(b, "1").Get(context.Background()), test.ShouldEqual, true)
test.That(t, mustGetGPIOPinByName(b, "3").PWM(context.Background()), test.ShouldEqual, 0)

test.That(t, m.GoFor(ctx, -50, 0, nil), test.ShouldBeError, motor.NewZeroRevsError())
test.That(t, mustGetGPIOPinByName(b, "1").Get(context.Background()), test.ShouldEqual, false)
test.That(t, mustGetGPIOPinByName(b, "1").Get(context.Background()), test.ShouldEqual, true)
test.That(t, mustGetGPIOPinByName(b, "3").PWM(context.Background()), test.ShouldEqual, 0)

test.That(t, m.Stop(context.Background(), nil), test.ShouldBeNil)
Expand Down Expand Up @@ -341,7 +341,7 @@ func TestMotorABNoEncoder(t *testing.T) {
test.That(t, err, test.ShouldBeNil)

t.Run("motor no encoder GoFor testing", func(t *testing.T) {
test.That(t, m.GoFor(ctx, 50, 10, nil), test.ShouldBeError, errors.New("not supported, define max_rpm attribute != 0"))
test.That(t, m.GoFor(ctx, 50, 10, nil), test.ShouldBeNil)
})

t.Run("motor no encoder GoTo testing", func(t *testing.T) {
Expand Down

0 comments on commit ae58534

Please sign in to comment.