Skip to content

Commit

Permalink
move inputEnabled to framesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
raybjork committed Sep 23, 2024
1 parent 8bb2243 commit 71c912a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
3 changes: 2 additions & 1 deletion components/arm/arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/robot"
"go.viam.com/rdk/robot/framesystem"
"go.viam.com/rdk/spatialmath"
)

Expand Down Expand Up @@ -98,7 +99,7 @@ type Arm interface {
referenceframe.ModelFramer
resource.Shaped
resource.Actuator
referenceframe.InputEnabled
framesystem.InputEnabled

// EndPosition returns the current position of the arm.
EndPosition(ctx context.Context, extra map[string]interface{}) (spatialmath.Pose, error)
Expand Down
3 changes: 2 additions & 1 deletion components/base/kinematicbase/kinematics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
"go.viam.com/rdk/logging"
"go.viam.com/rdk/motionplan"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/robot/framesystem"
"go.viam.com/rdk/services/motion"
)

// KinematicBase is an interface for Bases that also satisfy the ModelFramer and InputEnabled interfaces.
type KinematicBase interface {
base.Base
motion.Localizer
referenceframe.InputEnabled
framesystem.InputEnabled

Kinematics() referenceframe.Frame
LocalizationFrame() referenceframe.Frame
Expand Down
3 changes: 2 additions & 1 deletion components/gantry/gantry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/robot"
"go.viam.com/rdk/robot/framesystem"
)

func init() {
Expand Down Expand Up @@ -85,7 +86,7 @@ type Gantry interface {
resource.Resource
resource.Actuator
referenceframe.ModelFramer
referenceframe.InputEnabled
framesystem.InputEnabled

// Position returns the position in meters.
Position(ctx context.Context, extra map[string]interface{}) ([]float64, error)
Expand Down
10 changes: 0 additions & 10 deletions referenceframe/primitives.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package referenceframe

import (
"context"
"fmt"
"math"

Expand Down Expand Up @@ -56,15 +55,6 @@ func JointPositionsFromRadians(radians []float64) *pb.JointPositions {
return &pb.JointPositions{Values: n}
}

// InputEnabled is a standard interface for all things that interact with the frame system
// This allows us to figure out where they currently are, and then move them.
// Input units are always in meters or radians.
// TODO: this really belongs in the motion service theres nothing stateful about the referenceframe package.
type InputEnabled interface {
CurrentInputs(ctx context.Context) ([]Input, error)
GoToInputs(context.Context, ...[]Input) error
}

// interpolateInputs will return a set of inputs that are the specified percent between the two given sets of
// inputs. For example, setting by to 0.5 will return the inputs halfway between the from/to values, and 0.25 would
// return one quarter of the way from "from" to "to".
Expand Down
18 changes: 13 additions & 5 deletions robot/framesystem/framesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ var API = resource.APINamespaceRDKInternal.WithServiceType(SubtypeName)
// InternalServiceName is used to refer to/depend on this service internally.
var InternalServiceName = resource.NewName(API, "builtin")

// InputEnabled is a standard interface for all things that interact with the frame system
// This allows us to figure out where they currently are, and then move them.
// Input units are always in meters or radians.
type InputEnabled interface {
CurrentInputs(ctx context.Context) ([]referenceframe.Input, error)
GoToInputs(context.Context, ...[]referenceframe.Input) error
}

// A Service that returns the frame system for a robot.
//
// TransformPose example:
Expand Down Expand Up @@ -73,7 +81,7 @@ type Service interface {

// CurrentInputs returns a map of the current inputs for each component of a machine's frame system
// and a map of statuses indicating which of the machine's components may be actuated through input values.
CurrentInputs(ctx context.Context) (map[string][]referenceframe.Input, map[string]referenceframe.InputEnabled, error)
CurrentInputs(ctx context.Context) (map[string][]referenceframe.Input, map[string]InputEnabled, error)

// FrameSystem returns the frame system of the machine and incorporates any specified additional transformations.
FrameSystem(ctx context.Context, additionalTransforms []*referenceframe.LinkInFrame) (referenceframe.FrameSystem, error)
Expand Down Expand Up @@ -222,7 +230,7 @@ func (svc *frameSystemService) TransformPose(
if !ok {
return nil, DependencyNotFoundError(name)
}
inputEnabled, ok := component.(referenceframe.InputEnabled)
inputEnabled, ok := component.(InputEnabled)
if !ok {
return nil, NotInputEnabledError(component)
}
Expand All @@ -247,15 +255,15 @@ func (svc *frameSystemService) TransformPose(
// InputEnabled resources that those inputs came from.
func (svc *frameSystemService) CurrentInputs(
ctx context.Context,
) (map[string][]referenceframe.Input, map[string]referenceframe.InputEnabled, error) {
) (map[string][]referenceframe.Input, map[string]InputEnabled, error) {
fs, err := svc.FrameSystem(ctx, []*referenceframe.LinkInFrame{})
if err != nil {
return nil, nil, err
}
input := referenceframe.StartPositions(fs)

// build maps of relevant components and inputs from initial inputs
resources := map[string]referenceframe.InputEnabled{}
resources := map[string]InputEnabled{}
for name, original := range input {
// skip frames with no input
if len(original) == 0 {
Expand All @@ -267,7 +275,7 @@ func (svc *frameSystemService) CurrentInputs(
if !ok {
return nil, nil, DependencyNotFoundError(name)
}
inputEnabled, ok := component.(referenceframe.InputEnabled)
inputEnabled, ok := component.(InputEnabled)
if !ok {
return nil, nil, NotInputEnabledError(component)
}
Expand Down
2 changes: 1 addition & 1 deletion services/motion/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var (
// move it. Input units are always in meters or radians.
type inputEnabledActuator interface {
resource.Actuator
referenceframe.InputEnabled
framesystem.InputEnabled
}

// Config describes how to configure the service; currently only used for specifying dependency on framesystem service.
Expand Down
2 changes: 1 addition & 1 deletion services/motion/explore/explore.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type moveResponse struct {
// move it. Input units are always in meters or radians.
type inputEnabledActuator interface {
resource.Actuator
referenceframe.InputEnabled
framesystem.InputEnabled
}

// obstacleDetectorObject provides a map for matching vision services to any and all cameras names they use.
Expand Down
4 changes: 2 additions & 2 deletions testutils/inject/framesystem_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type FrameSystemService struct {
srcpc pointcloud.PointCloud,
srcName, dstName string,
) (pointcloud.PointCloud, error)
CurrentInputsFunc func(ctx context.Context) (map[string][]referenceframe.Input, map[string]referenceframe.InputEnabled, error)
CurrentInputsFunc func(ctx context.Context) (map[string][]referenceframe.Input, map[string]framesystem.InputEnabled, error)
FrameSystemFunc func(
ctx context.Context,
additionalTransforms []*referenceframe.LinkInFrame,
Expand Down Expand Up @@ -80,7 +80,7 @@ func (fs *FrameSystemService) TransformPointCloud(
// CurrentInputs calls the injected method or the real variant.
func (fs *FrameSystemService) CurrentInputs(
ctx context.Context,
) (map[string][]referenceframe.Input, map[string]referenceframe.InputEnabled, error) {
) (map[string][]referenceframe.Input, map[string]framesystem.InputEnabled, error) {
if fs.CurrentInputsFunc == nil {
return fs.Service.CurrentInputs(ctx)
}
Expand Down

0 comments on commit 71c912a

Please sign in to comment.