@@ -59,7 +59,17 @@ def get_waypoints_srv(self,req):
59
59
60
60
return resp
61
61
62
- def get_waypoints (self ,frame_type ,predicates ,transforms ,names ):
62
+ def get_waypoints (self , frame_type , predicates , transforms , names , constraints ):
63
+ '''
64
+ Parameters:
65
+ -----------
66
+ frame_type: object class to match when generating new frames
67
+ predicates: other list of predicates to add
68
+ transforms: used to generate the actual poses
69
+ names: should be same size as transforms
70
+ above: prunes list of transforms based on criteria, transforms should
71
+ be above their parent frame in the world coordinates
72
+ '''
63
73
self .and_srv .wait_for_service ()
64
74
65
75
if not len (names ) == len (transforms ):
@@ -89,6 +99,7 @@ def get_waypoints(self,frame_type,predicates,transforms,names):
89
99
poses = []
90
100
for tform in transforms :
91
101
poses .append (pm .fromMsg (tform ))
102
+ break # we only do one
92
103
93
104
if frame_type not in self .obj_symmetries .keys ():
94
105
self .obj_symmetries [frame_type ] = ObjectSymmetry ()
@@ -108,15 +119,6 @@ def get_waypoints(self,frame_type,predicates,transforms,names):
108
119
quaternion_list .append (rot_matrix .GetQuaternion ())
109
120
quaternion_list = np .array (quaternion_list )
110
121
111
- unique_rot_matrix = list ()
112
- # quaternion_list = np.around(quaternion_list,decimals=5)
113
- # b = np.ascontiguousarray(quaternion_list).view(np.dtype((np.void, quaternion_list.dtype.itemsize * quaternion_list.shape[1])))
114
- # _, unique_indices = np.unique(b, return_index=True)
115
-
116
- # for index in unique_indices:
117
- # unique_rot_matrix.append( pm.Rotation.Quaternion( *quaternion_list[index].tolist() ) )
118
-
119
-
120
122
unique_brute_force = list ()
121
123
for i in xrange (len (quaternion_list )):
122
124
unique = True
@@ -126,13 +128,11 @@ def get_waypoints(self,frame_type,predicates,transforms,names):
126
128
else :
127
129
if abs (quaternion_list [i ].dot (quaternion_list [j ])) > 0.99 :
128
130
unique = False
129
- # print i, j, ' is not unique', quaternion_list[i], quaternion_list[j]
130
131
break
131
132
if unique :
132
133
unique_brute_force .append (i )
133
- # print 'unique brute force: ', len(unique_brute_force)
134
- # print unique_brute_force
135
134
135
+ unique_rot_matrix = list ()
136
136
for index in unique_brute_force :
137
137
unique_rot_matrix .append ( pm .Rotation .Quaternion ( * quaternion_list [index ].tolist () ) )
138
138
@@ -142,18 +142,33 @@ def get_waypoints(self,frame_type,predicates,transforms,names):
142
142
143
143
for match in res .matching :
144
144
try :
145
- (trans ,rot ) = self .listener .lookupTransform (self .world ,match ,rospy .Time (0 ))
146
- # for (pose, name) in zip(poses,names):
145
+ (trans ,rot ) = self .listener .lookupTransform (self .world , match , rospy .Time (0 ))
146
+ match_tform = pm . fromTf (( trans , rot ))
147
147
148
148
if frame_type in self .obj_symmetries :
149
149
for rot_matrix in unique_rot_matrix :
150
150
tform = pm .Frame (rot_matrix )
151
- new_poses .append (pm .toMsg (pm .fromTf ((trans ,rot )) * tform * poses [0 ]))
151
+ world_tform = match_tform * tform * poses [0 ]
152
+ violated = False
153
+ for constraint in constraints :
154
+ v1 = match_tform .p [constraint .pose_variable ]
155
+ v2 = world_tform .p [constraint .pose_variable ]
156
+ if constraint .greater and not (v2 >= v1 + constraint .threshold ):
157
+ violated = True
158
+ #print "VIOLATED", constraint
159
+ break
160
+ elif not constraint .greater and not (v2 <= v1 - constraint .threshold ):
161
+ violated = True
162
+ #print "VIOLATED", constraint
163
+ break
164
+ if violated :
165
+ continue
166
+ #else:
167
+ # print match_tform.p, world_tform.p
168
+
169
+ new_poses .append (pm .toMsg (world_tform ))
152
170
new_names .append (match + "/" + names [0 ] + "/x%fy%fz%f" % (rot_matrix .GetRPY ()))
153
171
154
- #print match, str(match + "/" + names[0] + "/x%fy%fz%f"%(rot_matrix.GetRPY())),
155
- # pm.toTf(pm.fromTf((trans,rot)) * tform * poses[0])[0]
156
-
157
172
objects .append (match )
158
173
159
174
except (tf .LookupException , tf .ConnectivityException , tf .ExtrapolationException ):
0 commit comments