Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSDK-8824: Test Datarace: go.viam.com/rdk/components/base/sensorcontrolled.TestSensorBaseWithVelocitiesSensor #4395

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/base/sensorcontrolled/sensorcontrolled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -358,15 +359,13 @@ 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)
test.That(t, sb.loop, test.ShouldNotBeNil)
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)
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -519,6 +519,7 @@ func TestSensorBaseMoveStraight(t *testing.T) {
}
orientationValue = defaultOrientationValue
})
test.That(t, b.Close(ctx), test.ShouldBeNil)
}

func TestSensorBaseDoCommand(t *testing.T) {
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions control/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions control/derivative.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions control/encoder_speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions control/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions control/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions control/gain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions control/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading