Skip to content

Commit

Permalink
Remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
randhid committed Apr 13, 2023
1 parent c0196c6 commit aac53e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 33 deletions.
34 changes: 9 additions & 25 deletions components/motor/gpio/motor_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,6 @@ func (m *EncodedMotor) RPMMonitorCalls() int64 {
return atomic.LoadInt64(&m.rpmMonitorCalls)
}

// IsRegulated returns if the motor is currently regulated or not.
func (m *EncodedMotor) IsRegulated() bool {
m.stateMu.RLock()
regulated := m.state.regulated
m.stateMu.RUnlock()
return regulated
}

// SetRegulated sets if the motor should be regulated.
func (m *EncodedMotor) SetRegulated(b bool) {
m.stateMu.Lock()
defer m.stateMu.Unlock()
m.state.regulated = b
}

func (m *EncodedMotor) fixPowerPct(powerPct float64) float64 {
powerPct = math.Min(powerPct, m.maxPowerPct)
powerPct = math.Max(powerPct, -1*m.maxPowerPct)
Expand Down Expand Up @@ -303,7 +288,7 @@ func (m *EncodedMotor) rpmMonitor() {
if err != nil {
panic(err)
}
lastTime := time.Now().UnixNano()
lastTime := float64(time.Now().UnixNano())

rpmSleep, rpmDebug := getRPMSleepDebug()
inRamp := false
Expand Down Expand Up @@ -331,7 +316,7 @@ func (m *EncodedMotor) rpmMonitor() {
}
continue
}
now := time.Now().UnixNano()
now := float64(time.Now().UnixNano())
if now == lastTime {
// this really only happens in testing, b/c we decrease sleep, but nice defense anyway
continue
Expand All @@ -347,7 +332,7 @@ func (m *EncodedMotor) rpmMonitor() {
}

// return is if we are in a ramp phase.
func (m *EncodedMotor) rpmMonitorPass(setPoint, pos, lastPos float64, now, lastTime int64, regulated, rpmDebug bool) bool {
func (m *EncodedMotor) rpmMonitorPass(setPoint, pos, lastPos, now, lastTime float64, regulated, rpmDebug bool) bool {
m.stateMu.Lock()
defer m.stateMu.Unlock()

Expand Down Expand Up @@ -419,12 +404,12 @@ func slowDownMath(timeLeftSeconds, desiredRPM, rampRate float64) float64 {
return desiredRPM
}

func (m *EncodedMotor) computeRPM(pos, lastPos float64, now, lastTime int64) float64 {
func (m *EncodedMotor) computeRPM(pos, lastPos, now, lastTime float64) float64 {
minutes := float64(now-lastTime) / (1e9 * 60)
if minutes == 0 {
return 0.0
}
rotations := float64(pos-lastPos) / m.ticksPerRotation
rotations := (pos - lastPos) / m.ticksPerRotation
return rotations / minutes
}

Expand All @@ -447,7 +432,7 @@ func (m *EncodedMotor) computeNewPowerPct(currentRPM, desiredRPM float64) float6
// to it, and we'll start moving soon.
return m.computeRamp(lastPowerPct, lastPowerPct*2)
}
dOverC := desiredRPM / currentRPM * m.flip
dOverC := desiredRPM / currentRPM
dOverC = math.Min(dOverC, 2)
dOverC = math.Max(dOverC, -2)

Expand Down Expand Up @@ -529,11 +514,10 @@ func (m *EncodedMotor) GoFor(ctx context.Context, rpm, revolutions float64, extr
func (m *EncodedMotor) goForInternal(ctx context.Context, rpm, revolutions float64) error {
m.RPMMonitorStart()

var d float64 = 1

var d = 1.0
// Backwards
if math.Signbit(revolutions) != math.Signbit(rpm) {
d *= -1
d *= -1.0
}

revolutions = math.Abs(revolutions)
Expand Down Expand Up @@ -561,7 +545,7 @@ func (m *EncodedMotor) goForInternal(ctx context.Context, rpm, revolutions float
if err != nil {
return err
}
m.state.setPoint = pos + d*numTicks*m.flip
m.state.setPoint = pos + d*numTicks

_, rpmDebug := getRPMSleepDebug()
if rpmDebug {
Expand Down
8 changes: 0 additions & 8 deletions components/motor/gpio/motor_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ func TestMotorEncoder1(t *testing.T) {
test.That(t, features[motor.PositionReporting], test.ShouldBeTrue)
})

t.Run("encoded motor testing regulation", func(t *testing.T) {
test.That(t, _motor.IsRegulated(), test.ShouldBeFalse)
_motor.SetRegulated(true)
test.That(t, _motor.IsRegulated(), test.ShouldBeTrue)
_motor.SetRegulated(false)
test.That(t, _motor.IsRegulated(), test.ShouldBeFalse)
})

t.Run("encoded motor testing SetPower", func(t *testing.T) {
test.That(t, _motor.SetPower(context.Background(), .01, nil), test.ShouldBeNil)
test.That(t, fakeMotor.Direction(), test.ShouldEqual, 1)
Expand Down

0 comments on commit aac53e5

Please sign in to comment.