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

DATA-841 Add rdk representation of worldstate along with conversion methods #1622

Merged
merged 43 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c11cebf
update sample code
raybjork Aug 10, 2022
c88d44a
Merge branch 'main' into main
raybjork Aug 10, 2022
000aa58
Merge branch 'main' of http://github.com/viamrobotics/rdk
raybjork Aug 10, 2022
718142d
Merge branch 'main' into main
raybjork Aug 15, 2022
e003dbe
Merge branch 'main' into main
raybjork Aug 15, 2022
bf9d187
Merge branch 'main' into main
raybjork Aug 15, 2022
83950f3
Merge branch 'main' of github.com:raybjork/rdk
raybjork Aug 16, 2022
df2d7e7
Merge branch 'main' of http://github.com/viamrobotics/rdk
raybjork Aug 16, 2022
86eb756
lint
raybjork Aug 16, 2022
a7c9bdf
Merge branch 'main' into main
raybjork Aug 16, 2022
177f700
Merge branch 'main' of http://github.com/viamrobotics/rdk
raybjork Sep 8, 2022
8489df2
Merge branch 'main' of github.com:raybjork/rdk
raybjork Sep 8, 2022
3175034
Merge branch 'main' of http://github.com/viamrobotics/rdk
raybjork Sep 14, 2022
c8ded88
Merge branch 'main' of http://github.com/viamrobotics/rdk
raybjork Sep 19, 2022
a18af73
Merge branch 'main' of github.com:raybjork/rdk
raybjork Sep 20, 2022
cee8fa9
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Sep 21, 2022
42e15d4
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Sep 26, 2022
1ed78c8
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Sep 27, 2022
14130d6
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Oct 3, 2022
525cfb2
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Oct 10, 2022
d620c97
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Oct 10, 2022
592ba97
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Oct 10, 2022
24724d1
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Oct 11, 2022
06d5ac5
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Oct 26, 2022
a44a901
catch case where node could not be added to tree
raybjork Oct 26, 2022
e6460f4
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Oct 31, 2022
df59349
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Nov 1, 2022
daa4e52
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Nov 8, 2022
a0dfc1c
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Nov 9, 2022
17ff28a
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Nov 10, 2022
b143385
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Nov 16, 2022
f6f9b66
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Nov 17, 2022
b3488ec
Merge branch 'main' of ssh://github.com/viamrobotics/rdk
raybjork Nov 23, 2022
4d1bc55
add protobuf conversions for worldstate
raybjork Nov 23, 2022
872d030
pass all tests
raybjork Nov 27, 2022
c6e45a9
delete files that should have never been added
raybjork Nov 27, 2022
3b48348
get rid of references to commonpb.Transform
raybjork Nov 29, 2022
e5e962f
address peters comments
raybjork Nov 29, 2022
ac4d560
address gauthams comments
raybjork Nov 30, 2022
5f4a58f
lint
raybjork Nov 30, 2022
ff8cc68
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into worldState
raybjork Nov 30, 2022
e7c7591
lint again
raybjork Nov 30, 2022
a04cba5
lint
raybjork Dec 1, 2022
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
11 changes: 5 additions & 6 deletions components/arm/arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"sync"

"github.com/edaniels/golog"
commonpb "go.viam.com/api/common/v1"
pb "go.viam.com/api/component/arm/v1"
viamutils "go.viam.com/utils"
"go.viam.com/utils/rpc"
Expand Down Expand Up @@ -85,7 +84,7 @@ type Arm interface {
// MoveToPosition moves the arm to the given absolute position.
// The worldState argument should be treated as optional by all implementing drivers
// This will block until done or a new operation cancels this one
MoveToPosition(ctx context.Context, pose spatialmath.Pose, worldState *commonpb.WorldState, extra map[string]interface{}) error
MoveToPosition(ctx context.Context, pose spatialmath.Pose, worldState *referenceframe.WorldState, extra map[string]interface{}) error

// MoveToJointPositions moves the arm's joints to the given positions.
// This will block until done or a new operation cancels this one
Expand Down Expand Up @@ -214,7 +213,7 @@ func (r *reconfigurableArm) EndPosition(ctx context.Context, extra map[string]in
func (r *reconfigurableArm) MoveToPosition(
ctx context.Context,
pose spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
r.mu.RLock()
Expand Down Expand Up @@ -345,7 +344,7 @@ func WrapWithReconfigurable(r interface{}) (resource.Reconfigurable, error) {
}

// Move is a helper function to abstract away movement for general arms.
func Move(ctx context.Context, r robot.Robot, a Arm, dst spatialmath.Pose, worldState *commonpb.WorldState) error {
func Move(ctx context.Context, r robot.Robot, a Arm, dst spatialmath.Pose, worldState *referenceframe.WorldState) error {
solution, err := Plan(ctx, r, a, dst, worldState)
if err != nil {
return err
Expand All @@ -360,10 +359,10 @@ func Plan(
r robot.Robot,
a Arm,
dst spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
) ([][]referenceframe.Input, error) {
// build the framesystem
fs, err := framesystem.RobotFrameSystem(ctx, r, worldState.GetTransforms())
fs, err := framesystem.RobotFrameSystem(ctx, r, worldState.Transforms)
if err != nil {
return nil, err
}
Expand Down
9 changes: 6 additions & 3 deletions components/arm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"

"github.com/edaniels/golog"
commonpb "go.viam.com/api/common/v1"
pb "go.viam.com/api/component/arm/v1"
"go.viam.com/utils/protoutils"
"go.viam.com/utils/rpc"
Expand Down Expand Up @@ -55,17 +54,21 @@ func (c *client) EndPosition(ctx context.Context, extra map[string]interface{})
func (c *client) MoveToPosition(
ctx context.Context,
pose spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
ext, err := protoutils.StructToStructPb(extra)
if err != nil {
return err
}
worldStateMsg, err := referenceframe.WorldStateToProtobuf(worldState)
if err != nil {
return err
}
_, err = c.client.MoveToPosition(ctx, &pb.MoveToPositionRequest{
Name: c.name,
To: spatialmath.PoseToProtobuf(pose),
WorldState: worldState,
WorldState: worldStateMsg,
Extra: ext,
})
return err
Expand Down
8 changes: 4 additions & 4 deletions components/arm/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/edaniels/golog"
"github.com/golang/geo/r3"
commonpb "go.viam.com/api/common/v1"
componentpb "go.viam.com/api/component/arm/v1"
"go.viam.com/test"
"go.viam.com/utils"
Expand All @@ -17,6 +16,7 @@ import (
"go.viam.com/rdk/components/arm"
"go.viam.com/rdk/components/generic"
viamgrpc "go.viam.com/rdk/grpc"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/registry"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/spatialmath"
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestClient(t *testing.T) {
injectArm.MoveToPositionFunc = func(
ctx context.Context,
ap spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
capArmPos = ap
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestClient(t *testing.T) {
injectArm2.MoveToPositionFunc = func(
ctx context.Context,
ap spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
capArmPos = ap
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestClient(t *testing.T) {
test.That(t, jointPos.String(), test.ShouldResemble, jointPos1.String())
test.That(t, extraOptions, test.ShouldResemble, map[string]interface{}{"foo": "JointPositions"})

err = arm1Client.MoveToPosition(context.Background(), pos2, &commonpb.WorldState{}, map[string]interface{}{"foo": "MoveToPosition"})
err = arm1Client.MoveToPosition(context.Background(), pos2, &referenceframe.WorldState{}, map[string]interface{}{"foo": "MoveToPosition"})
test.That(t, err, test.ShouldBeNil)
test.That(t, spatialmath.PoseAlmostEqual(capArmPos, pos2), test.ShouldBeTrue)

Expand Down
3 changes: 1 addition & 2 deletions components/arm/eva/eva.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/edaniels/golog"
"github.com/pkg/errors"
"go.uber.org/multierr"
commonpb "go.viam.com/api/common/v1"
pb "go.viam.com/api/component/arm/v1"
"go.viam.com/utils"

Expand Down Expand Up @@ -123,7 +122,7 @@ func (e *eva) EndPosition(ctx context.Context, extra map[string]interface{}) (sp
func (e *eva) MoveToPosition(
ctx context.Context,
pos spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
ctx, done := e.opMgr.New(ctx)
Expand Down
3 changes: 1 addition & 2 deletions components/arm/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/edaniels/golog"
"github.com/pkg/errors"
commonpb "go.viam.com/api/common/v1"
pb "go.viam.com/api/component/arm/v1"

"go.viam.com/rdk/components/arm"
Expand Down Expand Up @@ -133,7 +132,7 @@ func (a *Arm) EndPosition(ctx context.Context, extra map[string]interface{}) (sp
func (a *Arm) MoveToPosition(
ctx context.Context,
pos spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
joints, err := a.JointPositions(ctx, extra)
Expand Down
7 changes: 6 additions & 1 deletion components/arm/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
pb "go.viam.com/api/component/arm/v1"

"go.viam.com/rdk/operation"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/spatialmath"
"go.viam.com/rdk/subtype"
)
Expand Down Expand Up @@ -76,10 +77,14 @@ func (s *subtypeServer) MoveToPosition(ctx context.Context, req *pb.MoveToPositi
if err != nil {
return nil, err
}
worldState, err := referenceframe.WorldStateFromProtobuf(req.GetWorldState())
if err != nil {
return nil, err
}
return &pb.MoveToPositionResponse{}, arm.MoveToPosition(
ctx,
spatialmath.NewPoseFromProtobuf(req.GetTo()),
req.GetWorldState(),
worldState,
req.Extra.AsMap(),
)
}
Expand Down
5 changes: 3 additions & 2 deletions components/arm/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.viam.com/utils/protoutils"

"go.viam.com/rdk/components/arm"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/spatialmath"
"go.viam.com/rdk/subtype"
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestServer(t *testing.T) {
injectArm.MoveToPositionFunc = func(
ctx context.Context,
ap spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
capArmPos = ap
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestServer(t *testing.T) {
injectArm2.MoveToPositionFunc = func(
ctx context.Context,
ap spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
capArmPos = ap
Expand Down
3 changes: 1 addition & 2 deletions components/arm/trossen/trossen.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/edaniels/golog"
"github.com/jacobsa/go-serial/serial"
"github.com/pkg/errors"
commonpb "go.viam.com/api/common/v1"
pb "go.viam.com/api/component/arm/v1"
"go.viam.com/dynamixel/network"
"go.viam.com/dynamixel/servo"
Expand Down Expand Up @@ -203,7 +202,7 @@ func (a *Arm) EndPosition(ctx context.Context, extra map[string]interface{}) (sp
func (a *Arm) MoveToPosition(
ctx context.Context,
pos spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
ctx, done := a.opMgr.New(ctx)
Expand Down
5 changes: 2 additions & 3 deletions components/arm/universalrobots/ur.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/edaniels/golog"
"github.com/pkg/errors"
"go.uber.org/multierr"
commonpb "go.viam.com/api/common/v1"
pb "go.viam.com/api/component/arm/v1"
goutils "go.viam.com/utils"

Expand Down Expand Up @@ -257,7 +256,7 @@ func (ua *URArm) EndPosition(ctx context.Context, extra map[string]interface{})
func (ua *URArm) MoveToPosition(
ctx context.Context,
pos spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
ctx, done := ua.opMgr.New(ctx)
Expand Down Expand Up @@ -473,7 +472,7 @@ func reader(ctx context.Context, conn io.Reader, ua *URArm, onHaveData func()) e

const errURHostedKinematics = "cannot use UR hosted kinematics with obstacles or interaction spaces"

func (ua *URArm) useURHostedKinematics(worldState *commonpb.WorldState, extra map[string]interface{}) (bool, error) {
func (ua *URArm) useURHostedKinematics(worldState *referenceframe.WorldState, extra map[string]interface{}) (bool, error) {
// function to error out if trying to use world state with hosted kinematics
checkWorldState := func(usingHostedKinematics bool) (bool, error) {
if usingHostedKinematics && worldState != nil && (len(worldState.Obstacles) != 0 || len(worldState.InteractionSpaces) != 0) {
Expand Down
20 changes: 10 additions & 10 deletions components/arm/universalrobots/ur5e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/edaniels/golog"
"github.com/go-gl/mathgl/mgl64"
"github.com/golang/geo/r3"
commonpb "go.viam.com/api/common/v1"
"go.viam.com/test"
"gonum.org/v1/gonum/mat"
"gonum.org/v1/gonum/num/quat"
Expand Down Expand Up @@ -134,14 +133,15 @@ func TestKin1(t *testing.T) {
}

func TestUseURHostedKinematics(t *testing.T) {
gifs := []*commonpb.GeometriesInFrame{{Geometries: []*commonpb.Geometry{{
Center: spatialmath.PoseToProtobuf(spatialmath.NewZeroPose()),
GeometryType: &commonpb.Geometry_Sphere{Sphere: &commonpb.Sphere{RadiusMm: 1}},
}}}}
sphere, err := spatialmath.NewSphere(r3.Vector{}, 1, "")
test.That(t, err, test.ShouldBeNil)
obstacles := make(map[string]spatialmath.Geometry)
obstacles["sphere"] = sphere
gifs := []*referenceframe.GeometriesInFrame{referenceframe.NewGeometriesInFrame(referenceframe.World, obstacles)}

// test that under normal circumstances we can use worldstate and our own kinematics
ur := URArm{}
using, err := ur.useURHostedKinematics(&commonpb.WorldState{Obstacles: gifs}, nil)
using, err := ur.useURHostedKinematics(&referenceframe.WorldState{Obstacles: gifs}, nil)
test.That(t, err, test.ShouldBeNil)
test.That(t, using, test.ShouldBeFalse)

Expand All @@ -154,23 +154,23 @@ func TestUseURHostedKinematics(t *testing.T) {

// test specifying at config time with no obstacles or extra params at runtime
ur.urHostedKinematics = true
using, err = ur.useURHostedKinematics(&commonpb.WorldState{}, nil)
using, err = ur.useURHostedKinematics(&referenceframe.WorldState{}, nil)
test.That(t, err, test.ShouldBeNil)
test.That(t, using, test.ShouldBeTrue)

// test that we can override the config preference with extra params
extraParams["arm_hosted_kinematics"] = false
using, err = ur.useURHostedKinematics(&commonpb.WorldState{Obstacles: gifs}, extraParams)
using, err = ur.useURHostedKinematics(&referenceframe.WorldState{Obstacles: gifs}, extraParams)
test.That(t, err, test.ShouldBeNil)
test.That(t, using, test.ShouldBeFalse)

// test obstacles will cause this to error
_, err = ur.useURHostedKinematics(&commonpb.WorldState{Obstacles: gifs}, nil)
_, err = ur.useURHostedKinematics(&referenceframe.WorldState{Obstacles: gifs}, nil)
test.That(t, err, test.ShouldNotBeNil)
test.That(t, err.Error(), test.ShouldResemble, errURHostedKinematics)

// test obstacles will cause this to error
_, err = ur.useURHostedKinematics(&commonpb.WorldState{InteractionSpaces: gifs}, nil)
_, err = ur.useURHostedKinematics(&referenceframe.WorldState{InteractionSpaces: gifs}, nil)
test.That(t, err, test.ShouldNotBeNil)
test.That(t, err.Error(), test.ShouldResemble, errURHostedKinematics)
}
Expand Down
3 changes: 1 addition & 2 deletions components/arm/wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"

"github.com/edaniels/golog"
commonpb "go.viam.com/api/common/v1"
pb "go.viam.com/api/component/arm/v1"
"go.viam.com/utils"

Expand Down Expand Up @@ -103,7 +102,7 @@ func (wrapper *Arm) EndPosition(ctx context.Context, extra map[string]interface{
func (wrapper *Arm) MoveToPosition(
ctx context.Context,
pos spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
ctx, done := wrapper.opMgr.New(ctx)
Expand Down
3 changes: 1 addition & 2 deletions components/arm/xarm/xarm_comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"go.uber.org/multierr"
commonpb "go.viam.com/api/common/v1"
pb "go.viam.com/api/component/arm/v1"
"go.viam.com/utils"

Expand Down Expand Up @@ -399,7 +398,7 @@ func (x *xArm) EndPosition(ctx context.Context, extra map[string]interface{}) (s
func (x *xArm) MoveToPosition(
ctx context.Context,
pos spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
ctx, done := x.opMgr.New(ctx)
Expand Down
3 changes: 1 addition & 2 deletions components/arm/yahboom/dofbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/edaniels/golog"
"github.com/pkg/errors"
commonpb "go.viam.com/api/common/v1"
componentpb "go.viam.com/api/component/arm/v1"
"go.viam.com/utils"

Expand Down Expand Up @@ -176,7 +175,7 @@ func (a *Dofbot) EndPosition(ctx context.Context, extra map[string]interface{})
func (a *Dofbot) MoveToPosition(
ctx context.Context,
pos spatialmath.Pose,
worldState *commonpb.WorldState,
worldState *referenceframe.WorldState,
extra map[string]interface{},
) error {
ctx, done := a.opMgr.New(ctx)
Expand Down
7 changes: 4 additions & 3 deletions components/camera/videosource/join_pointcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/edaniels/golog"
"github.com/golang/geo/r3"
commonpb "go.viam.com/api/common/v1"
"go.viam.com/test"
"go.viam.com/utils"
"go.viam.com/utils/artifact"
Expand Down Expand Up @@ -93,7 +92,8 @@ func makeFakeRobot(t *testing.T) robot.Robot {
},
}
r.FrameSystemConfigFunc = func(
ctx context.Context, additionalTransforms []*commonpb.Transform,
ctx context.Context,
additionalTransforms []*referenceframe.PoseInFrame,
) (framesystemparts.Parts, error) {
return fsParts, nil
}
Expand Down Expand Up @@ -349,7 +349,8 @@ func makeFakeRobotICP(t *testing.T) (robot.Robot, error) {
},
}
r.FrameSystemConfigFunc = func(
ctx context.Context, additionalTransforms []*commonpb.Transform,
ctx context.Context,
additionalTransforms []*referenceframe.PoseInFrame,
) (framesystemparts.Parts, error) {
return fsParts, nil
}
Expand Down
Loading