diff --git a/components/base/sensorcontrolled/sensorcontrolled_test.go b/components/base/sensorcontrolled/sensorcontrolled_test.go index d79e3d28c32..e7f7ec49cb7 100644 --- a/components/base/sensorcontrolled/sensorcontrolled_test.go +++ b/components/base/sensorcontrolled/sensorcontrolled_test.go @@ -345,6 +345,7 @@ func TestReconfig(t *testing.T) { cfg = sBaseTestConfig([]string{"setvel2"}, 100, wrongTypeLinVel, wrongTypeAngVel) err = b.Reconfigure(ctx, deps, cfg) test.That(t, err.Error(), test.ShouldContainSubstring, "type must be 'linear_velocity' or 'angular_velocity'") + test.That(t, b.Close(ctx), test.ShouldBeNil) } func TestSensorBaseWithVelocitiesSensor(t *testing.T) { @@ -358,7 +359,6 @@ func TestSensorBaseWithVelocitiesSensor(t *testing.T) { test.That(t, err, test.ShouldBeNil) sb, ok := b.(*sensorBase) test.That(t, ok, test.ShouldBeTrue) - test.That(t, err, test.ShouldBeNil) test.That(t, sb.velocities.Name().ShortName(), test.ShouldResemble, "setvel1") test.That(t, sb.SetVelocity(ctx, r3.Vector{X: 0, Y: 100, Z: 0}, r3.Vector{X: 0, Y: 100, Z: 0}, nil), test.ShouldBeNil) @@ -366,7 +366,6 @@ func TestSensorBaseWithVelocitiesSensor(t *testing.T) { loopFreq, err := sb.loop.Frequency(ctx) test.That(t, err, test.ShouldBeNil) test.That(t, loopFreq, test.ShouldEqual, 100) - test.That(t, sb.Stop(ctx, nil), test.ShouldBeNil) test.That(t, sb.Close(ctx), test.ShouldBeNil) } @@ -430,6 +429,7 @@ func TestSensorBaseSpin(t *testing.T) { err := sbNoOri.Spin(ctx, 10, 10, nil) test.That(t, err, test.ShouldBeNil) }) + test.That(t, b.Close(ctx), test.ShouldBeNil) } func TestSensorBaseMoveStraight(t *testing.T) { @@ -519,6 +519,7 @@ func TestSensorBaseMoveStraight(t *testing.T) { } orientationValue = defaultOrientationValue }) + test.That(t, b.Close(ctx), test.ShouldBeNil) } func TestSensorBaseDoCommand(t *testing.T) { @@ -548,4 +549,5 @@ func TestSensorBaseDoCommand(t *testing.T) { resp, err = b.DoCommand(ctx, req) test.That(t, err, test.ShouldBeNil) test.That(t, resp, test.ShouldResemble, emptyMap) + test.That(t, b.Close(ctx), test.ShouldBeNil) } diff --git a/control/constant.go b/control/constant.go index dbfa98b8aa6..fd0c7944a4a 100644 --- a/control/constant.go +++ b/control/constant.go @@ -27,6 +27,8 @@ func newConstant(config BlockConfig, logger logging.Logger) (Block, error) { } func (b *constant) Next(ctx context.Context, x []*Signal, dt time.Duration) ([]*Signal, bool) { + b.mu.Lock() + defer b.mu.Unlock() return b.y, true } diff --git a/control/derivative.go b/control/derivative.go index 43cab2d4008..3343e0c7317 100644 --- a/control/derivative.go +++ b/control/derivative.go @@ -87,6 +87,8 @@ func derive(x []float64, dt time.Duration, stencil *derivativeStencil) (float64, } func (d *derivative) Next(ctx context.Context, x []*Signal, dt time.Duration) ([]*Signal, bool) { + d.mu.Lock() + defer d.mu.Unlock() if d.stencil.Type == "backward" { for idx, s := range x { d.px[idx] = append(d.px[idx][1:], s.GetSignalValueAt(0)) diff --git a/control/encoder_speed.go b/control/encoder_speed.go index a20cbb20b92..23dce82ee4e 100644 --- a/control/encoder_speed.go +++ b/control/encoder_speed.go @@ -28,6 +28,8 @@ func newEncoderSpeed(config BlockConfig, logger logging.Logger) (Block, error) { } func (b *encoderToRPM) Next(ctx context.Context, x []*Signal, dt time.Duration) ([]*Signal, bool) { + b.mu.Lock() + defer b.mu.Unlock() currEncCount := int(x[0].GetSignalValueAt(0)) b.y[0].SetSignalValueAt(0, (float64(currEncCount-b.prevEncCount)/float64(b.ticksPerRevolution))*60.0/(dt.Seconds())) b.prevEncCount = currEncCount diff --git a/control/endpoint.go b/control/endpoint.go index 37d47291e7a..85d0e086ce0 100644 --- a/control/endpoint.go +++ b/control/endpoint.go @@ -27,6 +27,8 @@ func newEndpoint(config BlockConfig, logger logging.Logger, ctr Controllable) (B } func (e *endpoint) Next(ctx context.Context, x []*Signal, dt time.Duration) ([]*Signal, bool) { + e.mu.Lock() + defer e.mu.Unlock() e.logger.CDebugf(ctx, "z length %v", len(x)) e.logger.CDebugf(ctx, "controllable is %v", e.ctr) switch len(x) { diff --git a/control/filters.go b/control/filters.go index 1ba2b55358d..528cc943537 100644 --- a/control/filters.go +++ b/control/filters.go @@ -136,6 +136,8 @@ func (f *filterStruct) initFilter() error { } func (f *filterStruct) Next(ctx context.Context, x []*Signal, dt time.Duration) ([]*Signal, bool) { + f.mu.Lock() + defer f.mu.Unlock() if len(x) == 1 { xFlt, ok := f.filter.Next(x[0].GetSignalValueAt(0)) f.y[0].SetSignalValueAt(0, xFlt) diff --git a/control/gain.go b/control/gain.go index cd94e8af0af..2fb13f20e39 100644 --- a/control/gain.go +++ b/control/gain.go @@ -27,6 +27,8 @@ func newGain(config BlockConfig, logger logging.Logger) (Block, error) { } func (b *gain) Next(ctx context.Context, x []*Signal, dt time.Duration) ([]*Signal, bool) { + b.mu.Lock() + defer b.mu.Unlock() if len(x) != 1 { return b.y, false } diff --git a/control/sum.go b/control/sum.go index 729e4176677..3ee6afe0052 100644 --- a/control/sum.go +++ b/control/sum.go @@ -34,6 +34,8 @@ func newSum(config BlockConfig, logger logging.Logger) (Block, error) { } func (b *sum) Next(ctx context.Context, x []*Signal, dt time.Duration) ([]*Signal, bool) { + b.mu.Lock() + defer b.mu.Unlock() // sum blocks only support signals with the same number of inputs if len(x)%2 != 0 { return b.y, false