Skip to content

Commit b3fb0e2

Browse files
authored
Merge branch 'viamrobotics:main' into main
2 parents 707055d + 9df0a4e commit b3fb0e2

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

components/gantry/singleaxis/singleaxis.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
582599
func (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

module/data_consumer.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
type QueryTabularDataOptions struct {
1414
TimeBack time.Duration
1515
AdditionalStages []map[string]any
16+
17+
app.TabularDataByMQLOptions
1618
}
1719

1820
type queryBackend interface {
@@ -68,10 +70,11 @@ func (r ResourceDataConsumer) QueryTabularDataForResource(
6870
},
6971
},
7072
}
71-
73+
var queryOpts *app.TabularDataByMQLOptions
7274
if opts != nil {
7375
query = append(query, opts.AdditionalStages...)
76+
queryOpts = &opts.TabularDataByMQLOptions
7477
}
7578

76-
return r.dataClient.TabularDataByMQL(ctx, orgID, query, nil)
79+
return r.dataClient.TabularDataByMQL(ctx, orgID, query, queryOpts)
7780
}

0 commit comments

Comments
 (0)