@@ -63,6 +63,7 @@ def blackboard_inputs(
63
63
move_above_dist_m : Union [BlackboardKey , float ] = 0.05 ,
64
64
food_frame_id : Union [BlackboardKey , str ] = "food" ,
65
65
approach_frame_id : Union [BlackboardKey , str ] = "approach" ,
66
+ action : Union [BlackboardKey , Optional [AcquisitionSchema ]] = None ,
66
67
) -> None :
67
68
"""
68
69
Blackboard Inputs
@@ -73,6 +74,7 @@ def blackboard_inputs(
73
74
move_above_dist_m: how far from the food to start
74
75
food_frame_id: food frame defined in AcquisitionSchema.msg
75
76
approach_frame_id: approach frame defined in AcquisitionSchema.msg
77
+ action: which action has been chosen in the initial pi-symmetry break
76
78
"""
77
79
# pylint: disable=unused-argument, duplicate-code
78
80
# Arguments are handled generically in base class.
@@ -141,64 +143,67 @@ def update(self) -> py_trees.common.Status:
141
143
self .logger .error (f"Malformed action select response: { response } " )
142
144
return py_trees .common .Status .FAILURE
143
145
144
- # Sample Action
145
- index = np .random .choice (np .arange (prob .size ), p = prob )
146
- action = response .actions [index ]
147
-
148
- ### Construct Constraints
149
-
150
- # Re-scale pre-transform to move_above_dist_m
151
- position = ros2_numpy .numpify (action .pre_transform .position )
152
- if np .isclose (np .linalg .norm (position ), 0.0 ):
153
- self .logger .error (
154
- f"Malformed action pre_transform: { action .pre_transform .position } "
146
+ action_set = self .blackboard_get ("action" )
147
+ if action_set is None :
148
+ # Sample Action
149
+ index = np .random .choice (np .arange (prob .size ), p = prob )
150
+ action = response .actions [index ]
151
+ self .logger .info (f"Chosen action index: { index } " )
152
+
153
+ ### Construct Constraints
154
+
155
+ # Re-scale pre-transform to move_above_dist_m
156
+ position = ros2_numpy .numpify (action .pre_transform .position )
157
+ if np .isclose (np .linalg .norm (position ), 0.0 ):
158
+ self .logger .error (
159
+ f"Malformed action pre_transform: { action .pre_transform .position } "
160
+ )
161
+ return py_trees .common .Status .FAILURE
162
+ position = (
163
+ position
164
+ * self .blackboard_get ("move_above_dist_m" )
165
+ / np .linalg .norm (position )
166
+ )
167
+ action .pre_transform .position = ros2_numpy .msgify (Point , position )
168
+ self .blackboard_set ("move_above_pose" , action .pre_transform )
169
+
170
+ # Calculate Approach Target (in food frame)
171
+ move_into_pose = Pose ()
172
+ move_into_pose .orientation = deepcopy (action .pre_transform .orientation )
173
+ offset = ros2_numpy .numpify (action .pre_offset )
174
+ move_into_pose .position = ros2_numpy .msgify (Point , offset )
175
+ self .blackboard_set ("move_into_pose" , move_into_pose )
176
+
177
+ ### Calculate Approach Frame
178
+ approach_vec = offset - position
179
+ approach_frame = TransformStamped ()
180
+ approach_mat = np .eye (4 )
181
+ if not np .all (np .isclose (approach_vec [:2 ], np .zeros (2 ))):
182
+ approach_mat [:3 , :3 ] = R .from_rotvec (
183
+ np .arctan2 (approach_vec [1 ], approach_vec [0 ]) * np .array ([0 , 0 , 1 ])
184
+ ).as_matrix ()
185
+ approach_frame .transform = ros2_numpy .msgify (Transform , approach_mat )
186
+ approach_frame .header .stamp = self .node .get_clock ().now ().to_msg ()
187
+ approach_frame .header .frame_id = "food"
188
+ approach_frame .child_frame_id = "approach"
189
+ set_static_tf (approach_frame , self .blackboard , self .node )
190
+
191
+ ### Calculate F/T Thresholds
192
+ self .blackboard_set (
193
+ "approach_thresh" ,
194
+ create_ft_thresh_request (action .pre_force , action .pre_torque ),
195
+ )
196
+ self .blackboard_set (
197
+ "grasp_thresh" ,
198
+ create_ft_thresh_request (action .grasp_force , action .grasp_torque ),
199
+ )
200
+ self .blackboard_set (
201
+ "ext_thresh" ,
202
+ create_ft_thresh_request (action .ext_force , action .ext_torque ),
155
203
)
156
- return py_trees .common .Status .FAILURE
157
- position = (
158
- position
159
- * self .blackboard_get ("move_above_dist_m" )
160
- / np .linalg .norm (position )
161
- )
162
- action .pre_transform .position = ros2_numpy .msgify (Point , position )
163
- self .blackboard_set ("move_above_pose" , action .pre_transform )
164
-
165
- # Calculate Approach Target (in food frame)
166
- move_into_pose = Pose ()
167
- move_into_pose .orientation = deepcopy (action .pre_transform .orientation )
168
- offset = ros2_numpy .numpify (action .pre_offset )
169
- move_into_pose .position = ros2_numpy .msgify (Point , offset )
170
- self .blackboard_set ("move_into_pose" , move_into_pose )
171
-
172
- ### Calculate Approach Frame
173
- approach_vec = offset - position
174
- approach_frame = TransformStamped ()
175
- approach_mat = np .eye (4 )
176
- if not np .all (np .isclose (approach_vec [:2 ], np .zeros (2 ))):
177
- approach_mat [:3 , :3 ] = R .from_rotvec (
178
- np .arctan2 (approach_vec [1 ], approach_vec [0 ]) * np .array ([0 , 0 , 1 ])
179
- ).as_matrix ()
180
- approach_frame .transform = ros2_numpy .msgify (Transform , approach_mat )
181
- approach_frame .header .stamp = self .node .get_clock ().now ().to_msg ()
182
- approach_frame .header .frame_id = "food"
183
- approach_frame .child_frame_id = "approach"
184
- set_static_tf (approach_frame , self .blackboard , self .node )
185
-
186
- ### Calculate F/T Thresholds
187
- self .blackboard_set (
188
- "approach_thresh" ,
189
- create_ft_thresh_request (action .pre_force , action .pre_torque ),
190
- )
191
- self .blackboard_set (
192
- "grasp_thresh" ,
193
- create_ft_thresh_request (action .grasp_force , action .grasp_torque ),
194
- )
195
- self .blackboard_set (
196
- "ext_thresh" ,
197
- create_ft_thresh_request (action .ext_force , action .ext_torque ),
198
- )
199
204
200
- ### Final write to Blackboard
201
- self .blackboard_set ("action" , action )
205
+ ### Final write to Blackboard
206
+ self .blackboard_set ("action" , action )
202
207
return py_trees .common .Status .SUCCESS
203
208
204
209
0 commit comments