@@ -159,7 +159,7 @@ func (g *singleAxis) Reconfigure(ctx context.Context, deps resource.Dependencies
159159 g .rpm = 100
160160 }
161161
162- m , err := referenceframe .KinematicModelFromFile (newConf .Kinematics , g .Named .Name ().String ())
162+ m , err := referenceframe .KinematicModelFromFile (newConf .Kinematics , g .Named .Name ().ShortName ())
163163 if err != nil {
164164 g .logger .CWarnf (ctx , "failed to load kinematics from file '%v': %v" , newConf .Kinematics , err )
165165 }
@@ -250,34 +250,51 @@ func (g *singleAxis) checkHit(ctx context.Context) {
250250 defer utils .UncheckedErrorFunc (func () error {
251251 g .mu .Lock ()
252252 defer g .mu .Unlock ()
253- return g .motor .Stop (ctx , nil )
253+ // Use background context for cleanup since ctx may be cancelled
254+ return g .motor .Stop (context .Background (), nil )
254255 })
255256 defer g .activeBackgroundWorkers .Done ()
256257 for {
257- select {
258- case <- ctx .Done ():
258+ // Check if we should stop
259+ if ctx .Err () != nil {
259260 return
260- default :
261261 }
262262
263263 for i := 0 ; i < len (g .limitSwitchPins ); i ++ {
264264 hit , err := g .limitHit (ctx , i )
265265 if err != nil {
266- g .logger .CError (ctx , err )
266+ // Don't log context cancellation errors (normal during shutdown)
267+ if ctx .Err () == nil {
268+ g .logger .CError (ctx , err )
269+ } else {
270+ return
271+ }
267272 }
268273
269274 if hit {
270275 child , cancel := context .WithTimeout (ctx , 10 * time .Millisecond )
271276 g .mu .Lock ()
272277 if err := g .motor .Stop (ctx , nil ); err != nil {
273- g .logger .CError (ctx , err )
278+ // Don't log context cancellation errors (normal during shutdown)
279+ if ctx .Err () == nil {
280+ g .logger .CError (ctx , err )
281+ }
274282 }
275283 g .mu .Unlock ()
276284 <- child .Done ()
277285 cancel ()
286+
287+ // Check again before moveAway
288+ if ctx .Err () != nil {
289+ return
290+ }
291+
278292 g .mu .Lock ()
279293 if err := g .moveAway (ctx , i ); err != nil {
280- g .logger .CError (ctx , err )
294+ // Don't log context cancellation errors (normal during shutdown)
295+ if ctx .Err () == nil {
296+ g .logger .CError (ctx , err )
297+ }
281298 }
282299 g .mu .Unlock ()
283300 }
@@ -580,13 +597,13 @@ func (g *singleAxis) Stop(ctx context.Context, extra map[string]interface{}) err
580597
581598// Close calls stop.
582599func (g * singleAxis ) Close (ctx context.Context ) error {
583- g .mu .Lock ()
584- defer g .mu .Unlock ()
585600 if err := g .Stop (ctx , nil ); err != nil {
586601 return err
587602 }
588- g .cancelFunc ()
589- g .activeBackgroundWorkers .Wait ()
603+ if g .cancelFunc != nil {
604+ g .cancelFunc ()
605+ g .activeBackgroundWorkers .Wait ()
606+ }
590607 return nil
591608}
592609
0 commit comments