Skip to content

Commit 416614e

Browse files
authored
[RSDK-9657] Datarace: gpiostepper (viamrobotics#4677)
1 parent af605e7 commit 416614e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

components/motor/gpiostepper/gpiostepper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ type gpioStepper struct {
201201

202202
// SetPower sets the percentage of power the motor should employ between 0-1.
203203
func (m *gpioStepper) SetPower(ctx context.Context, powerPct float64, extra map[string]interface{}) error {
204+
m.lock.Lock()
205+
defer m.lock.Unlock()
204206
if math.Abs(powerPct) <= .0001 {
205207
return m.Stop(ctx, nil)
206208
}
@@ -213,9 +215,7 @@ func (m *gpioStepper) SetPower(ctx context.Context, powerPct float64, extra map[
213215
}
214216

215217
// lock added here to prevent race with doStep
216-
m.lock.Lock()
217218
m.stepperDelay = time.Duration(float64(m.minDelay) / math.Abs(powerPct))
218-
m.lock.Unlock()
219219

220220
if powerPct < 0 {
221221
m.targetStepPosition = math.MinInt64

0 commit comments

Comments
 (0)