@@ -2,18 +2,13 @@ package arm_test
2
2
3
3
import (
4
4
"context"
5
- "errors"
6
5
"testing"
7
6
8
- "github.com/go-viper/mapstructure/v2"
9
7
"github.com/golang/geo/r3"
10
- pb "go.viam.com/api/component/arm/v1"
11
8
"go.viam.com/test"
12
- "go.viam.com/utils/protoutils"
13
9
14
10
"go.viam.com/rdk/components/arm"
15
11
"go.viam.com/rdk/components/arm/fake"
16
- ur "go.viam.com/rdk/components/arm/universalrobots"
17
12
"go.viam.com/rdk/components/generic"
18
13
"go.viam.com/rdk/logging"
19
14
"go.viam.com/rdk/referenceframe"
@@ -30,167 +25,6 @@ const (
30
25
missingArmName = "arm4"
31
26
)
32
27
33
- var pose = spatialmath .NewPoseFromPoint (r3.Vector {X : 1 , Y : 2 , Z : 3 })
34
-
35
- func TestStatusValid (t * testing.T ) {
36
- status := & pb.Status {
37
- EndPosition : spatialmath .PoseToProtobuf (pose ),
38
- JointPositions : & pb.JointPositions {Values : []float64 {1.1 , 2.2 , 3.3 }},
39
- IsMoving : true ,
40
- }
41
- newStruct , err := protoutils .StructToStructPb (status )
42
- test .That (t , err , test .ShouldBeNil )
43
- test .That (
44
- t ,
45
- newStruct .AsMap (),
46
- test .ShouldResemble ,
47
- map [string ]interface {}{
48
- "end_position" : map [string ]interface {}{"o_z" : 1.0 , "x" : 1.0 , "y" : 2.0 , "z" : 3.0 },
49
- "joint_positions" : map [string ]interface {}{"values" : []interface {}{1.1 , 2.2 , 3.3 }},
50
- "is_moving" : true ,
51
- },
52
- )
53
-
54
- convMap := & pb.Status {}
55
- decoder , err := mapstructure .NewDecoder (& mapstructure.DecoderConfig {TagName : "json" , Result : & convMap })
56
- test .That (t , err , test .ShouldBeNil )
57
- err = decoder .Decode (newStruct .AsMap ())
58
- test .That (t , err , test .ShouldBeNil )
59
- test .That (t , convMap , test .ShouldResemble , status )
60
- }
61
-
62
- func TestCreateStatus (t * testing.T ) {
63
- successfulPose := spatialmath .NewPose (
64
- r3.Vector {- 802.801508917897990613710135 , - 248.284077946287368376943050 , 9.115758604150467903082244 },
65
- & spatialmath.R4AA {1.5810814917942602 , 0.992515011486776 , - 0.0953988491934626 , 0.07624310818669232 },
66
- )
67
- successfulStatus := & pb.Status {
68
- EndPosition : spatialmath .PoseToProtobuf (successfulPose ),
69
- JointPositions : & pb.JointPositions {Values : []float64 {1.1 , 2.2 , 3.3 , 1.1 , 2.2 , 3.3 }},
70
- IsMoving : true ,
71
- }
72
-
73
- injectArm := & inject.Arm {}
74
-
75
- //nolint:unparam
76
- successfulJointPositionsFunc := func (context.Context , map [string ]interface {}) ([]referenceframe.Input , error ) {
77
- return referenceframe .FloatsToInputs (referenceframe .JointPositionsToRadians (successfulStatus .JointPositions )), nil
78
- }
79
-
80
- successfulIsMovingFunc := func (context.Context ) (bool , error ) {
81
- return true , nil
82
- }
83
-
84
- successfulModelFrameFunc := func () referenceframe.Model {
85
- model , _ := ur .MakeModelFrame ("ur5e" )
86
- return model
87
- }
88
-
89
- t .Run ("working" , func (t * testing.T ) {
90
- injectArm .JointPositionsFunc = successfulJointPositionsFunc
91
- injectArm .IsMovingFunc = successfulIsMovingFunc
92
- injectArm .ModelFrameFunc = successfulModelFrameFunc
93
-
94
- expectedPose := successfulPose
95
- expectedStatus := successfulStatus
96
-
97
- actualStatus , err := arm .CreateStatus (context .Background (), injectArm )
98
- test .That (t , err , test .ShouldBeNil )
99
- test .That (t , actualStatus .IsMoving , test .ShouldEqual , expectedStatus .IsMoving )
100
- test .That (t , actualStatus .JointPositions , test .ShouldResemble , expectedStatus .JointPositions )
101
-
102
- actualPose := spatialmath .NewPoseFromProtobuf (actualStatus .EndPosition )
103
- test .That (t , spatialmath .PoseAlmostEqualEps (actualPose , expectedPose , 0.01 ), test .ShouldBeTrue )
104
-
105
- resourceAPI , ok , err := resource.LookupAPIRegistration [arm.Arm ](arm .API )
106
- test .That (t , err , test .ShouldBeNil )
107
- test .That (t , ok , test .ShouldBeTrue )
108
- statusInterface , err := resourceAPI .Status (context .Background (), injectArm )
109
- test .That (t , err , test .ShouldBeNil )
110
-
111
- statusMap , err := protoutils .InterfaceToMap (statusInterface )
112
- test .That (t , err , test .ShouldBeNil )
113
-
114
- endPosMap , err := protoutils .InterfaceToMap (statusMap ["end_position" ])
115
- test .That (t , err , test .ShouldBeNil )
116
- actualPose = spatialmath .NewPose (
117
- r3.Vector {endPosMap ["x" ].(float64 ), endPosMap ["y" ].(float64 ), endPosMap ["z" ].(float64 )},
118
- & spatialmath.OrientationVectorDegrees {
119
- endPosMap ["theta" ].(float64 ), endPosMap ["o_x" ].(float64 ),
120
- endPosMap ["o_y" ].(float64 ), endPosMap ["o_z" ].(float64 ),
121
- },
122
- )
123
- test .That (t , spatialmath .PoseAlmostEqualEps (actualPose , expectedPose , 0.01 ), test .ShouldBeTrue )
124
-
125
- moving := statusMap ["is_moving" ].(bool )
126
- test .That (t , moving , test .ShouldEqual , expectedStatus .IsMoving )
127
-
128
- jPosFace := statusMap ["joint_positions" ].(map [string ]interface {})["values" ].([]interface {})
129
- actualJointPositions := []float64 {
130
- jPosFace [0 ].(float64 ), jPosFace [1 ].(float64 ), jPosFace [2 ].(float64 ),
131
- jPosFace [3 ].(float64 ), jPosFace [4 ].(float64 ), jPosFace [5 ].(float64 ),
132
- }
133
- test .That (t , actualJointPositions , test .ShouldResemble , expectedStatus .JointPositions .Values )
134
- })
135
-
136
- t .Run ("not moving" , func (t * testing.T ) {
137
- injectArm .JointPositionsFunc = successfulJointPositionsFunc
138
- injectArm .ModelFrameFunc = successfulModelFrameFunc
139
-
140
- injectArm .IsMovingFunc = func (context.Context ) (bool , error ) {
141
- return false , nil
142
- }
143
-
144
- expectedPose := successfulPose
145
- expectedStatus := & pb.Status {
146
- EndPosition : successfulStatus .EndPosition , //nolint:govet
147
- JointPositions : successfulStatus .JointPositions ,
148
- IsMoving : false ,
149
- }
150
-
151
- actualStatus , err := arm .CreateStatus (context .Background (), injectArm )
152
- test .That (t , err , test .ShouldBeNil )
153
- test .That (t , actualStatus .IsMoving , test .ShouldEqual , expectedStatus .IsMoving )
154
- test .That (t , actualStatus .JointPositions , test .ShouldResemble , expectedStatus .JointPositions )
155
- actualPose := spatialmath .NewPoseFromProtobuf (actualStatus .EndPosition )
156
- test .That (t , spatialmath .PoseAlmostEqualEps (actualPose , expectedPose , 0.01 ), test .ShouldBeTrue )
157
- })
158
-
159
- t .Run ("fail on JointPositions" , func (t * testing.T ) {
160
- injectArm .IsMovingFunc = successfulIsMovingFunc
161
- injectArm .ModelFrameFunc = successfulModelFrameFunc
162
-
163
- errFail := errors .New ("can't get joint positions" )
164
- injectArm .JointPositionsFunc = func (ctx context.Context , extra map [string ]interface {}) ([]referenceframe.Input , error ) {
165
- return nil , errFail
166
- }
167
-
168
- actualStatus , err := arm .CreateStatus (context .Background (), injectArm )
169
- test .That (t , err , test .ShouldBeError , errFail )
170
- test .That (t , actualStatus , test .ShouldBeNil )
171
- })
172
-
173
- t .Run ("nil model frame" , func (t * testing.T ) {
174
- injectArm .IsMovingFunc = successfulIsMovingFunc
175
- injectArm .JointPositionsFunc = successfulJointPositionsFunc
176
- injectArm .ModelFrameFunc = func () referenceframe.Model {
177
- return nil
178
- }
179
-
180
- expectedStatus := & pb.Status {
181
- EndPosition : nil ,
182
- JointPositions : successfulStatus .JointPositions ,
183
- IsMoving : successfulStatus .IsMoving ,
184
- }
185
-
186
- actualStatus , err := arm .CreateStatus (context .Background (), injectArm )
187
- test .That (t , err , test .ShouldBeNil )
188
- test .That (t , actualStatus .EndPosition , test .ShouldEqual , expectedStatus .EndPosition )
189
- test .That (t , actualStatus .JointPositions , test .ShouldResemble , expectedStatus .JointPositions )
190
- test .That (t , actualStatus .IsMoving , test .ShouldEqual , expectedStatus .IsMoving )
191
- })
192
- }
193
-
194
28
func TestXArm6Locations (t * testing.T ) {
195
29
// check the exact values/locations of arm geometries at a couple different poses
196
30
logger := logging .NewTestLogger (t )
0 commit comments