Skip to content
Open
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: 3 additions & 3 deletions components/arm/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewArm(ctx context.Context, deps resource.Dependencies, conf resource.Confi
Named: conf.ResourceName().AsNamed(),
logger: logger,
}
if err := a.Reconfigure(ctx, deps, conf); err != nil {
if err := a.reconfigure(ctx, deps, conf); err != nil {
return nil, err
}
return a, nil
Expand Down Expand Up @@ -126,8 +126,8 @@ type Arm struct {
armModel string
}

// Reconfigure atomically reconfigures this arm in place based on the new config.
func (a *Arm) Reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error {
// reconfigure atomically reconfigures this arm in place based on the new config.
func (a *Arm) reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error {
newConf, err := resource.NativeConfig[*Config](conf)
if err != nil {
return err
Expand Down
73 changes: 1 addition & 72 deletions components/arm/fake/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,77 +13,6 @@ import (
"go.viam.com/rdk/resource"
)

func TestReconfigure(t *testing.T) {
ctx := context.Background()
conf0 := resource.Config{
Name: "testArm",
ConvertedAttributes: &Config{},
}

conf1 := resource.Config{
Name: "testArm",
ConvertedAttributes: &Config{
ArmModel: xArm6Model,
},
}

conf2 := resource.Config{
Name: "testArm",
ConvertedAttributes: &Config{
ModelFilePath: "zero_model.json",
},
}

conf3 := resource.Config{
Name: "testArm",
ConvertedAttributes: &Config{
ModelFilePath: "DNE",
},
}

conf4 := resource.Config{
Name: "testArm",
ConvertedAttributes: &Config{
ModelFilePath: "a.json",
ArmModel: ur5eModel,
},
}

a, err := NewArm(ctx, nil, conf0, logging.NewTestLogger(t))
test.That(t, err, test.ShouldBeNil)
fakeArm, _ := a.(*Arm)
test.That(t, fakeArm.armModel, test.ShouldResemble, "")

model, err := fakeArm.Kinematics(ctx)
test.That(t, err, test.ShouldBeNil)
test.That(t, fakeArm.joints, test.ShouldResemble, make([]referenceframe.Input, len(model.DoF())))
test.That(t, fakeArm.model, test.ShouldResemble, model)

test.That(t, fakeArm.Reconfigure(ctx, nil, conf1), test.ShouldBeNil)
model, err = fakeArm.Kinematics(ctx)
test.That(t, err, test.ShouldBeNil)
modelJoints := make([]referenceframe.Input, len(model.DoF()))
test.That(t, fakeArm.joints, test.ShouldResemble, modelJoints)
test.That(t, fakeArm.model, test.ShouldResemble, model)
test.That(t, fakeArm.armModel, test.ShouldResemble, xArm6Model)

err = fakeArm.Reconfigure(ctx, nil, conf2)
test.That(t, err, test.ShouldNotBeNil)
test.That(t, err.Error(), test.ShouldContainSubstring, "fake arm built with zero degrees-of-freedom")
test.That(t, fakeArm.joints, test.ShouldResemble, modelJoints)
test.That(t, fakeArm.model, test.ShouldResemble, model)

err = fakeArm.Reconfigure(ctx, nil, conf3)
test.That(t, err, test.ShouldNotBeNil)
test.That(t, err.Error(), test.ShouldContainSubstring, "only files")
test.That(t, fakeArm.joints, test.ShouldResemble, modelJoints)
test.That(t, fakeArm.model, test.ShouldResemble, model)

err = fakeArm.Reconfigure(ctx, nil, conf4)
test.That(t, err, test.ShouldNotBeNil)
test.That(t, err, test.ShouldResemble, errAttrCfgPopulation)
}

func TestJointPositions(t *testing.T) {
ctx := context.Background()
logger := logging.NewTestLogger(t)
Expand Down Expand Up @@ -137,7 +66,7 @@ func TestGet3DModels(t *testing.T) {
ArmModel: ur5eModel,
},
}
err = fakeArm.Reconfigure(ctx, nil, confWith3DModels)
err = fakeArm.reconfigure(ctx, nil, confWith3DModels)
test.That(t, err, test.ShouldBeNil)
models, err = fakeArm.Get3DModels(ctx, nil)
test.That(t, err, test.ShouldBeNil)
Expand Down
6 changes: 3 additions & 3 deletions components/arm/wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ func NewWrapperArm(
logger: logger,
opMgr: operation.NewSingleOperationManager(),
}
if err := a.Reconfigure(ctx, deps, conf); err != nil {
if err := a.reconfigure(ctx, deps, conf); err != nil {
return nil, err
}
return a, nil
}

// Reconfigure atomically reconfigures this arm in place based on the new config.
func (wrapper *Arm) Reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error {
// reconfigure atomically reconfigures this arm in place based on the new config.
func (wrapper *Arm) reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error {
newConf, err := resource.NativeConfig[*Config](conf)
if err != nil {
return err
Expand Down
78 changes: 0 additions & 78 deletions components/arm/wrapper/wrapper_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions components/base/sensorcontrolled/sensorcontrolled.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ func createSensorBase(
opMgr: operation.NewSingleOperationManager(),
}

if err := sb.Reconfigure(ctx, deps, conf); err != nil {
if err := sb.reconfigure(ctx, deps, conf); err != nil {
return nil, err
}

return sb, nil
}

func (sb *sensorBase) Reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error {
func (sb *sensorBase) reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error {
newConf, err := resource.NativeConfig[*Config](conf)
sb.conf = newConf
if err != nil {
Expand Down
96 changes: 0 additions & 96 deletions components/base/sensorcontrolled/sensorcontrolled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,102 +251,6 @@ func msDependencies(t *testing.T, msNames []string,
return deps, cfg
}

func TestReconfig(t *testing.T) {
ctx := context.Background()
logger := logging.NewTestLogger(t)

deps, cfg := msDependencies(t, []string{"orientation"})

b, err := createSensorBase(ctx, deps, cfg, logger)
test.That(t, err, test.ShouldBeNil)
sb, ok := b.(*sensorBase)
test.That(t, ok, test.ShouldBeTrue)
headingOri, headingSupported, err := sb.headingFunc(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, headingSupported, test.ShouldBeTrue)
test.That(t, headingOri, test.ShouldEqual, orientationValue)
test.That(t, sb.controlFreq, test.ShouldEqual, defaultControlFreq)

deps, cfg = msDependencies(t, []string{"orientation1"})
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, err, test.ShouldBeNil)
test.That(t, err, test.ShouldBeNil)
test.That(t, headingSupported, test.ShouldBeTrue)
test.That(t, headingOri, test.ShouldEqual, orientationValue)

deps, cfg = msDependencies(t, []string{"setvel1"})
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, err, test.ShouldBeNil)
test.That(t, sb.velocities.Name().ShortName(), test.ShouldResemble, "setvel1")

deps, _ = msDependencies(t, []string{"setvel2"})
// generate a config with a non default freq
cfg = sBaseTestConfig([]string{"setvel2"}, 100, typeLinVel, typeAngVel)
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, err, test.ShouldBeNil)
test.That(t, sb.velocities.Name().ShortName(), test.ShouldResemble, "setvel2")
headingNone, headingSupported, err := sb.headingFunc(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, headingSupported, test.ShouldBeFalse)
test.That(t, headingNone, test.ShouldEqual, 0)
test.That(t, sb.controlFreq, test.ShouldEqual, 100.0)

deps, cfg = msDependencies(t, []string{"orientation3", "setvel3", "Bad"})
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, err, test.ShouldBeNil)
headingOri, headingSupported, err = sb.headingFunc(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, headingSupported, test.ShouldBeTrue)
test.That(t, headingOri, test.ShouldEqual, orientationValue)
test.That(t, sb.velocities.Name().ShortName(), test.ShouldResemble, "setvel3")

deps, cfg = msDependencies(t, []string{"Bad", "orientation4", "setvel4", "orientation5", "setvel5"})
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, err, test.ShouldBeNil)
headingOri, headingSupported, err = sb.headingFunc(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, headingSupported, test.ShouldBeTrue)
test.That(t, headingOri, test.ShouldEqual, orientationValue)
test.That(t, sb.velocities.Name().ShortName(), test.ShouldResemble, "setvel4")

deps, cfg = msDependencies(t, []string{"Bad", "orientation6", "setvel6", "position1", "compass1"})
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, err, test.ShouldBeNil)
headingOri, headingSupported, err = sb.headingFunc(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, headingSupported, test.ShouldBeTrue)
test.That(t, headingOri, test.ShouldEqual, orientationValue)
test.That(t, sb.velocities.Name().ShortName(), test.ShouldResemble, "setvel6")
test.That(t, sb.position.Name().ShortName(), test.ShouldResemble, "position1")

deps, cfg = msDependencies(t, []string{"Bad", "setvel7", "position2", "compass2"})
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, err, test.ShouldBeNil)
test.That(t, sb.velocities.Name().ShortName(), test.ShouldResemble, "setvel7")
test.That(t, sb.position.Name().ShortName(), test.ShouldResemble, "position2")
headingCompass, headingSupported, err := sb.headingFunc(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, headingSupported, test.ShouldBeTrue)
test.That(t, headingCompass, test.ShouldNotEqual, orientationValue)
test.That(t, headingCompass, test.ShouldEqual, -compassValue)

deps, cfg = msDependencies(t, []string{"Bad"})
err = b.Reconfigure(ctx, deps, cfg)
test.That(t, sb.velocities, test.ShouldBeNil)
test.That(t, err, test.ShouldBeError, errNoGoodSensor)
headingBad, headingSupported, err := sb.headingFunc(context.Background())
test.That(t, err, test.ShouldBeNil)
test.That(t, headingSupported, test.ShouldBeFalse)
test.That(t, headingBad, test.ShouldEqual, 0)

deps, _ = msDependencies(t, []string{"setvel2"})
// generate a config with invalid pid types
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) {
ctx := context.Background()
logger := logging.NewTestLogger(t)
Expand Down
6 changes: 3 additions & 3 deletions components/base/wheeled/wheeled_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ type wheeledBase struct {
name string
}

// Reconfigure reconfigures the base atomically and in place.
func (wb *wheeledBase) Reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error {
// reconfigure reconfigures the base atomically and in place.
func (wb *wheeledBase) reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error {
wb.mu.Lock()
defer wb.mu.Unlock()

Expand Down Expand Up @@ -227,7 +227,7 @@ func createWheeledBase(
name: conf.Name,
}

if err := wb.Reconfigure(ctx, deps, conf); err != nil {
if err := wb.reconfigure(ctx, deps, conf); err != nil {
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions components/base/wheeled/wheeled_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func TestWheeledBaseReconfigure(t *testing.T) {
deps, _, err = newTestConf.Validate("path", resource.APITypeComponentName)
test.That(t, err, test.ShouldBeNil)
motorDeps = fakeMotorDependencies(t, deps)
test.That(t, wb.Reconfigure(ctx, motorDeps, newTestConf), test.ShouldBeNil)
test.That(t, wb.reconfigure(ctx, motorDeps, newTestConf), test.ShouldBeNil)

// Add a new motor to Left only to confirm that Reconfigure is impossible because cfg validation fails
newerTestCfg := newTestCfg()
Expand Down Expand Up @@ -435,7 +435,7 @@ func TestWheeledBaseReconfigure(t *testing.T) {
deps, _, err = newestTestCfg.Validate("path", resource.APITypeComponentName)
test.That(t, err, test.ShouldBeNil)
motorDeps = fakeMotorDependencies(t, deps)
test.That(t, wb.Reconfigure(ctx, motorDeps, newestTestCfg), test.ShouldBeNil)
test.That(t, wb.reconfigure(ctx, motorDeps, newestTestCfg), test.ShouldBeNil)
}

func TestValidate(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions components/board/fake/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ func (b *Board) processConfig(conf resource.Config) error {
return nil
}

// Reconfigure atomically reconfigures this board in place based on the new config.
func (b *Board) Reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error {
return b.processConfig(conf)
}

// A Board provides dummy data from fake parts in order to implement a Board.
type Board struct {
resource.Named
Expand Down
6 changes: 3 additions & 3 deletions components/board/genericlinux/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ func NewBoard(
interrupts: map[string]*digitalInterrupt{},
}

if err := b.Reconfigure(ctx, nil, conf); err != nil {
if err := b.reconfigure(ctx, nil, conf); err != nil {
return nil, err
}
return b, nil
}

// Reconfigure reconfigures the board with interrupt pins, spi and i2c, and analogs.
func (b *Board) Reconfigure(
// reconfigure reconfigures the board with interrupt pins, spi and i2c, and analogs.
func (b *Board) reconfigure(
ctx context.Context,
_ resource.Dependencies,
conf resource.Config,
Expand Down
Loading
Loading