支持两个夹爪

This commit is contained in:
NuoDaJia02
2026-01-07 10:02:38 +08:00
parent 9eacb3529b
commit f6c0a6e6d6

View File

@@ -57,7 +57,8 @@ class CtrlGuiNode(Node):
JointState, '/joint_states', self._on_joint_state, 10
)
self.gripper_action_client_ = ActionClient(self, GripperCmd, '/gripper_cmd0')
self.gripper0_action_client_ = ActionClient(self, GripperCmd, '/gripper_cmd0')
self.gripper1_action_client_ = ActionClient(self, GripperCmd, '/gripper_cmd1')
self.file_logger.info('CtrlGuiNode initialized')
self.file_logger.info(f'Node started at: {self.start_time}')
@@ -116,19 +117,30 @@ class CtrlGuiNode(Node):
gm.torque = int(torq)
gm.mode = int(mode)
print("Pack Gripper..")
print(f"Pack Gripper..{id}")
print(f"goal_msg: {gm}")
self.file_logger.info(f'Sending goal to execute Gripper action')
self.file_logger.info(f"goal_msg: {gm}")
if self.gripper_action_client_.wait_for_server(10.0) == False:
print("Gripper Server not available")
if id == 0:
if self.gripper0_action_client_.wait_for_server(10.0) == False:
print("Gripper0 Server not available")
else:
send_goal_future = self.gripper0_action_client_.send_goal_async(gm, self.gripper_action_feedback_callback)
send_goal_future.add_done_callback(self.gripper_action_response_callback)
self.file_logger.info(f'Action Gripper0 goal sent.')
print("Gripper0 Finish..")
elif id == 1:
if self.gripper1_action_client_.wait_for_server(10.0) == False:
print("Gripper1 Server not available")
else:
send_goal_future = self.gripper1_action_client_.send_goal_async(gm, self.gripper_action_feedback_callback)
send_goal_future.add_done_callback(self.gripper_action_response_callback)
self.file_logger.info(f'Action Gripper1 goal sent.')
print("Gripper1 Finish..")
else:
send_goal_future = self.gripper_action_client_.send_goal_async(gm, self.gripper_action_feedback_callback)
send_goal_future.add_done_callback(self.gripper_action_response_callback)
self.file_logger.info(f'Action Gripper goal sent.')
print("Gripper Finish..")
print(f"Gripper id error: {id}")
def gripper_action_response_callback(self, future):
goal_handle = future.result()
@@ -423,16 +435,17 @@ def build_ui(node: CtrlGuiNode) -> None:
except Exception as e:
node.file_logger.error(f'Failed to trigger rebuild: {str(e)}')
def cripper_control() -> None:
def gripper_control(id) -> None:
try:
print("Gripper Send Action Start..")
node.gripper_action_send_goal(6, int(gripper_width.value), 50, 50, 2)
print("Gripper Send Action Goal Finish")
print(f"Gripper {id} Send Action Start..")
node.gripper_action_send_goal(id, int(gripper_width.value), 50, 50, 2)
print(f"Gripper {id} Send Action Goal Finish")
except Exception as e:
node.file_logger.error(f'Failed to gripper action send goal: {str(e)}')
# ui.element().style('height: 40px')
ui.button('夹爪控制', on_click=lambda: show_confirm_dialog(f'确定控制夹爪? gripper width: {gripper_width.value}', cripper_control)).classes('self-end')
ui.button('控制夹爪0', on_click=lambda: show_confirm_dialog(f'确定控制夹爪0? gripper width: {gripper_width.value}', lambda: gripper_control(0))).classes('self-end')
ui.button('控制夹爪1', on_click=lambda: show_confirm_dialog(f'确定控制夹爪1? gripper width: {gripper_width.value}', lambda: gripper_control(1))).classes('self-end')
ui.button('视觉识别', on_click=lambda: show_confirm_dialog('执行视觉识别流程?', rebuild_out)).classes('self-end')
#move wheel