Skip to content

Commit 9d9d355

Browse files
committed
hard-coded heracles hold objects
1 parent 66aa0ff commit 9d9d355

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

spot_tools/src/spot_executor/spot_executor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,24 @@ def execute_pick(self, command, feedback):
294294

295295
feedback.pick_image_feedback(sem_img, outline_img)
296296

297+
if success:
298+
# Update object holding state
299+
# TODO: don't hard-code the object to hold
300+
feedback.set_robot_holding_state(True, "O43")
301+
297302
feedback.print("INFO", "Finished `pick` command")
298303
feedback.print("INFO", f"Pick skill success: {success}")
299304
return success
300305

301306
def execute_place(self, command, feedback):
302307
feedback.print("INFO", "Executing `place` command")
303308
success = object_place(self.spot_interface, semantic_class=command.object_class)
309+
310+
if success:
311+
# Update object holding state
312+
# TODO: don't hard-code the object to hold
313+
feedback.set_robot_holding_state(False, "O43")
314+
304315
feedback.print("INFO", "Finished `place` command")
305316
return success
306317

spot_tools_ros/src/spot_tools_ros/spot_executor_ros.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import tf2_ros
1111
import yaml
1212
from cv_bridge import CvBridge
13+
from heracles_ros_interfaces.srv import UpdateHoldingState
1314
from nav_msgs.msg import Path
1415
from rclpy.callback_groups import MutuallyExclusiveCallbackGroup
1516
from rclpy.executors import MultiThreadedExecutor
@@ -229,6 +230,11 @@ def register_publishers(self, node):
229230
10,
230231
)
231232

233+
self.holding_client = node.create_client(
234+
UpdateHoldingState,
235+
"update_holding_state"
236+
)
237+
232238
# TODO(aaron): Once we switch logging to python logger,
233239
# should move into init
234240
self.logger.info(f"Logging to: {self.output_dir}")
@@ -239,6 +245,20 @@ def register_publishers(self, node):
239245
with open(log_fn, "w") as fo:
240246
fo.write("time,event\n")
241247

248+
def set_robot_holding_state(self, is_holding: bool, object_id: str, timeout=5):
249+
req = UpdateHoldingState.Request()
250+
req.is_holding = is_holding
251+
req.id = object_id
252+
253+
future = self.holding_client.call_async(req)
254+
start = time.time()
255+
while not future.done():
256+
if time.time() - start > timeout:
257+
self.logger.error("UpdateHoldingState call timed out")
258+
return False
259+
260+
return future.result().success
261+
242262
def pick_confirmation_callback(self, msg):
243263
if msg.data:
244264
self.logger.info("Detection is valid. Continuing pick action!")

0 commit comments

Comments
 (0)