@@ -115,13 +115,15 @@ def test_pathfind(num_samples = 1000, max_velocities=[0.1, 0.1, 0.1, 0.1, 0.1],
115
115
print ("------------------------------------------------------------------" )
116
116
print ("-------------------------test_pathfind----------------------------" )
117
117
print ("------------------------------------------------------------------" )
118
+
119
+ joints = ["Waist" , "Shoulder" , "Elbow" , "Wrist" , "Hand" ]
118
120
num_failed = 0
119
121
for i in range (num_samples ):
120
122
failed = False
121
123
122
124
start_joints = [np .random .random () * (jointUpperLimits [i ]- jointLowerLimits [i ]) + jointLowerLimits [i ] for i in range (5 )]
123
125
end_joints = [np .random .random () * (jointUpperLimits [i ]- jointLowerLimits [i ]) + jointLowerLimits [i ] for i in range (5 )]
124
- differences = [start_joints [i ] - end_joints [i ] for i in range (5 )]
126
+ differences = [end_joints [i ] - start_joints [i ] for i in range (5 )]
125
127
min_time = max ([abs ((differences [i ])/ max_velocities [i ]) for i in range (5 )])
126
128
# TODO: figure out how to calculate max time???
127
129
max_distance = max (abs (differences [i ]) for i in range (5 )) # Using furthest distance to get a reasonable max time
@@ -132,66 +134,66 @@ def test_pathfind(num_samples = 1000, max_velocities=[0.1, 0.1, 0.1, 0.1, 0.1],
132
134
133
135
polynomials = arm_pathfinding .pathfiningPolynomial (start_joints , end_joints , time )
134
136
for k , polynomial in enumerate (polynomials ):
135
- if sum ([polynomial [j ] * math .pow (time , 6 - j ) for j in range (4 )]) != differences [k ]: # Checking final position
137
+ if abs ( sum ([polynomial [j ] * math .pow (time , 6 - j ) for j in range (4 )]) - differences [k ]) > 0.001 : # Checking final position
136
138
failed = True
137
139
if verbose :
138
140
given = sum ([polynomial [j ] * math .pow (time , 6 - j ) for j in range (4 )])
139
- print ("Polynoial failed final position." )
140
- print (f"Result: { given } Difference: { differences [k ] - given } " )
141
+ print (f" { joints [ k ] } polynomial failed final position." )
142
+ print (f"Result: { given } Expected: { differences [ k ] } Difference: { differences [k ] - given } " )
141
143
break
142
144
143
- if sum ([polynomial [j ] * (6 - j ) * math .pow (time / 2 , 5 - j ) for j in range (4 )]) != max_velocities [k ]: # Checking max velocity
145
+ if abs ( sum ([polynomial [j ] * (6 - j ) * math .pow (time / 2 , 5 - j ) for j in range (4 )]) - max_velocities [k ]) > 0.001 : # Checking max velocity
144
146
failed = True
145
147
if verbose :
146
148
given = sum ([polynomial [j ] * (6 - j ) * math .pow (time / 2 , 5 - j ) for j in range (4 )])
147
149
print ("Polynoial failed midway velocity." )
148
150
print (f"Result: { given } Difference: { max_velocities [k ] - given } " )
149
151
break
150
152
151
- if sum ([polynomial [j ] * (6 - j ) * math .pow (time , 5 - j ) for j in range (4 )]) != 0 : # Checking final velocity
153
+ if abs ( sum ([polynomial [j ] * (6 - j ) * math .pow (time , 5 - j ) for j in range (4 )])) > 0.001 : # Checking final velocity
152
154
failed = True
153
155
if verbose :
154
156
given = sum ([polynomial [j ] * (6 - j ) * math .pow (time , 5 - j ) for j in range (4 )])
155
157
print ("Polynoial failed final velocity." )
156
158
print (f"Result: { given } " )
157
159
break
158
160
159
- if sum ([polynomial [j ] * (6 - j ) * (5 - j ) * math .pow (time / 2 , 4 - j ) for j in range (4 )]) != 0 : # Check halfway acceleration
161
+ if abs ( sum ([polynomial [j ] * (6 - j ) * (5 - j ) * math .pow (time / 2 , 4 - j ) for j in range (4 )])) > 0.001 : # Check halfway acceleration
160
162
failed = True
161
163
if verbose :
162
164
given = sum ([polynomial [j ] * (6 - j ) * (5 - j ) * math .pow (time / 2 , 4 - j ) for j in range (4 )])
163
165
print ("Polynoial failed midway acceleration." )
164
166
print (f"Result: { given } " )
165
167
break
166
168
167
- if not failed and end_joints != arm_pathfinding .nextJointPosition (start_joints , time , polynomials ):
168
- failed = True
169
- if verbose :
170
- given = arm_pathfinding .nextJointPosition (start_joints , time , polynomials )
171
- print ("nextJointPosition failed final position." )
172
- print (f"Result: { given } Difference: { [end_joints [j ] - given [j ] for j in range (5 )]} " )
173
-
174
- if not failed and end_joints != arm_pathfinding .pathfind (start_joints , end_joints , time ):
175
- failed = True
176
- if verbose :
177
- given = arm_pathfinding .pathfind (start_joints , end_joints , time )
178
- print ("Pathfind failed final position." )
179
- print (f"Result: { given } Difference: { [end_joints [j ] - given [j ] for j in range (5 )]} " )
180
-
181
- if not failed and start_joints != arm_pathfinding .nextJointPosition (start_joints , 0 , polynomials ):
169
+ if not failed and abs (sum (start_joints [j ] - arm_pathfinding .nextJointPosition (start_joints , 0 , polynomials )[j ] for j in range (5 ))) > 0.001 :
182
170
failed = True
183
171
if verbose :
184
172
given = arm_pathfinding .nextJointPosition (start_joints , 0 , polynomials )
185
173
print ("nextJointPosition failed initial position." )
186
174
print (f"Result: { given } Difference: { [start_joints [j ] - given [j ] for j in range (5 )]} " )
187
175
188
- if not failed and start_joints != arm_pathfinding .pathfind (start_joints , end_joints , 0 ) :
176
+ if not failed and abs ( sum ( start_joints [ j ] - arm_pathfinding .pathfind (start_joints , end_joints , time )[ j ] for j in range ( 5 ))) > 0.001 :
189
177
failed = True
190
178
if verbose :
191
179
given = arm_pathfinding .pathfind (start_joints , end_joints , 0 )
192
180
print ("Pathfnd failed initial position." )
193
181
print (f"Result: { given } Difference: { [start_joints [j ] - given [j ] for j in range (5 )]} " )
194
182
183
+ if not failed and abs (sum (end_joints [j ] - arm_pathfinding .nextJointPosition (start_joints , time , polynomials )[j ] for j in range (5 ))) > 0.001 :
184
+ failed = True
185
+ if verbose :
186
+ given = arm_pathfinding .nextJointPosition (start_joints , time , polynomials )
187
+ print ("nextJointPosition failed final position." )
188
+ print (f"Result: { given } Difference: { [end_joints [j ] - given [j ] for j in range (5 )]} " )
189
+
190
+ if not failed and abs (sum (end_joints [j ] - arm_pathfinding .pathfind (start_joints , end_joints , 0 )[j ] for j in range (5 ))) > 0.001 :
191
+ failed = True
192
+ if verbose :
193
+ given = arm_pathfinding .pathfind (start_joints , end_joints , time )
194
+ print ("Pathfind failed final position." )
195
+ print (f"Result: { given } Difference: { [end_joints [j ] - given [j ] for j in range (5 )]} " )
196
+
195
197
if failed :
196
198
num_failed += 1
197
199
print ("------------------------------------------------------------------" )
0 commit comments