|
5 | 5 |
|
6 | 6 | import bosdyn.client.auth |
7 | 7 | from bosdyn.api import ( |
| 8 | + arm_surface_contact_pb2, |
| 9 | + arm_surface_contact_service_pb2, |
8 | 10 | basic_command_pb2, |
| 11 | + header_pb2, |
9 | 12 | lease_pb2, |
10 | 13 | manipulation_api_pb2, |
11 | 14 | point_cloud_pb2, |
|
32 | 35 | frame_helpers, |
33 | 36 | math_helpers, |
34 | 37 | ) |
| 38 | +from bosdyn.client.arm_surface_contact import ArmSurfaceContactClient |
35 | 39 | from bosdyn.client.async_tasks import AsyncPeriodicQuery, AsyncTasks |
36 | 40 | from bosdyn.client.docking import DockingClient |
37 | 41 | from bosdyn.client.estop import ( |
@@ -489,10 +493,15 @@ def __init__( |
489 | 493 | self._manipulation_api_client = self._robot.ensure_client( |
490 | 494 | ManipulationApiClient.default_service_name |
491 | 495 | ) |
| 496 | + self._arm_surface_contact_client = self._robot.ensure_client( |
| 497 | + ArmSurfaceContactClient.default_service_name |
| 498 | + ) |
492 | 499 | else: |
493 | 500 | self._manipulation_api_client = None |
494 | | - self._logger.info("Manipulation API is not available.") |
495 | | - |
| 501 | + self._arm_surface_contact_client = None |
| 502 | + self._logger.info( |
| 503 | + "Manipulation and Arm Surface Contact APIs are not available (this robot doesn't have an arm)." |
| 504 | + ) |
496 | 505 | initialised = True |
497 | 506 | except Exception as e: |
498 | 507 | sleep_secs = 15 |
@@ -528,6 +537,7 @@ def __init__( |
528 | 537 | self.execute_dance, |
529 | 538 | self._robot_command, |
530 | 539 | self._manipulation_request, |
| 540 | + self.arm_surface_contact_command, |
531 | 541 | ], |
532 | 542 | ) |
533 | 543 |
|
@@ -1446,6 +1456,29 @@ def manipulation_command(self, request): |
1446 | 1456 | timesync_endpoint=self._robot.time_sync.endpoint, |
1447 | 1457 | ) |
1448 | 1458 |
|
| 1459 | + def arm_surface_contact_command( |
| 1460 | + self, request: arm_surface_contact_pb2.ArmSurfaceContact.Request |
| 1461 | + ) -> tuple[bool, str]: |
| 1462 | + """Generic function for sending arm surface contact commands. |
| 1463 | +
|
| 1464 | + Args: |
| 1465 | + request: Protobuf request |
| 1466 | +
|
| 1467 | + Returns: True/False on success/failure and a failure message |
| 1468 | + """ |
| 1469 | + try: |
| 1470 | + response = self._arm_surface_contact_client.arm_surface_contact_command( |
| 1471 | + arm_surface_contact_service_pb2.ArmSurfaceContactCommand(request=request) |
| 1472 | + ) |
| 1473 | + if ( |
| 1474 | + response.header.error.code != header_pb2.CommonError.CODE_OK |
| 1475 | + and response.header.error.code != header_pb2.CommonError.CODE_UNSPECIFIED |
| 1476 | + ): |
| 1477 | + return False, f"Returned CommonError code {response.header.error.code}" |
| 1478 | + return True, "Success" |
| 1479 | + except Exception as e: |
| 1480 | + return False, str(e) |
| 1481 | + |
1449 | 1482 | def get_robot_command_feedback(self, cmd_id: int) -> robot_command_pb2.RobotCommandFeedbackResponse: |
1450 | 1483 | return self._robot_command_client.robot_command_feedback(cmd_id) |
1451 | 1484 |
|
|
0 commit comments