@@ -2008,6 +2008,67 @@ func TestShutDown(t *testing.T) {
20082008 test .That (t , shutdownCalled , test .ShouldBeTrue )
20092009}
20102010
2011+ func TestCurrentInputs (t * testing.T ) {
2012+ logger := logging .NewTestLogger (t )
2013+ listener , err := net .Listen ("tcp" , "localhost:0" )
2014+ test .That (t , err , test .ShouldBeNil )
2015+ gServer := grpc .NewServer ()
2016+
2017+ testAPI := resource .APINamespaceRDK .WithComponentType (arm .SubtypeName )
2018+ testName := resource .NewName (testAPI , "arm1" )
2019+ testName2 := resource .NewName (testAPI , "arm2" )
2020+
2021+ expectedInputs := referenceframe.FrameSystemInputs {
2022+ testName .ShortName (): []referenceframe.Input {{0 }, {math .Pi }, {- math .Pi }, {0 }, {math .Pi }, {- math .Pi }},
2023+ testName2 .ShortName (): []referenceframe.Input {{math .Pi }, {- math .Pi }, {0 }, {math .Pi }, {- math .Pi }, {0 }},
2024+ }
2025+ injectArm := & inject.Arm {
2026+ JointPositionsFunc : func (ctx context.Context , extra map [string ]any ) ([]referenceframe.Input , error ) {
2027+ return expectedInputs [testName .ShortName ()], nil
2028+ },
2029+ KinematicsFunc : func (ctx context.Context ) (referenceframe.Model , error ) {
2030+ return referenceframe .ParseModelJSONFile (rutils .ResolveFile ("components/arm/example_kinematics/ur5e.json" ), "" )
2031+ },
2032+ }
2033+ injectArm2 := & inject.Arm {
2034+ JointPositionsFunc : func (ctx context.Context , extra map [string ]any ) ([]referenceframe.Input , error ) {
2035+ return expectedInputs [testName2 .ShortName ()], nil
2036+ },
2037+ KinematicsFunc : func (ctx context.Context ) (referenceframe.Model , error ) {
2038+ return referenceframe .ParseModelJSONFile (rutils .ResolveFile ("components/arm/example_kinematics/xarm6_kinematics_test.json" ), "" )
2039+ },
2040+ }
2041+ resourceNames := []resource.Name {testName , testName2 }
2042+ resources := map [resource.Name ]arm.Arm {testName : injectArm , testName2 : injectArm2 }
2043+ injectRobot := & inject.Robot {
2044+ ResourceNamesFunc : func () []resource.Name { return resourceNames },
2045+ ResourceByNameFunc : func (n resource.Name ) (resource.Resource , error ) { return resources [n ], nil },
2046+ MachineStatusFunc : func (ctx context.Context ) (robot.MachineStatus , error ) {
2047+ return robot.MachineStatus {State : robot .StateRunning }, nil
2048+ },
2049+ ResourceRPCAPIsFunc : func () []resource.RPCAPI { return nil },
2050+ }
2051+
2052+ armSvc , err := resource .NewAPIResourceCollection (arm .API , resources )
2053+ test .That (t , err , test .ShouldBeNil )
2054+ gServer .RegisterService (& armpb .ArmService_ServiceDesc , arm .NewRPCServiceServer (armSvc ))
2055+ pb .RegisterRobotServiceServer (gServer , server .New (injectRobot ))
2056+
2057+ go gServer .Serve (listener )
2058+ defer gServer .Stop ()
2059+
2060+ client , err := New (context .Background (), listener .Addr ().String (), logger )
2061+ test .That (t , err , test .ShouldBeNil )
2062+ defer func () {
2063+ test .That (t , client .Close (context .Background ()), test .ShouldBeNil )
2064+ }()
2065+
2066+ inputs , err := client .CurrentInputs (context .Background ())
2067+ test .That (t , err , test .ShouldBeNil )
2068+ test .That (t , len (inputs ), test .ShouldEqual , 2 )
2069+ test .That (t , inputs , test .ShouldResemble , expectedInputs )
2070+ }
2071+
20112072func TestUnregisteredResourceByName (t * testing.T ) {
20122073 logger := logging .NewTestLogger (t )
20132074 listener , err := net .Listen ("tcp" , "localhost:0" )
0 commit comments