Skip to content

Commit 9eb2b3c

Browse files
authored
Add arm surface contact to spot wrapper (#168)
This adds arm surface contact to spot wrapper. Testing will be done in spot ros2 and bdai.
1 parent 12afad0 commit 9eb2b3c

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

spot_wrapper/wrapper.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
import bosdyn.client.auth
77
from bosdyn.api import (
8+
arm_surface_contact_pb2,
9+
arm_surface_contact_service_pb2,
810
basic_command_pb2,
11+
header_pb2,
912
lease_pb2,
1013
manipulation_api_pb2,
1114
point_cloud_pb2,
@@ -32,6 +35,7 @@
3235
frame_helpers,
3336
math_helpers,
3437
)
38+
from bosdyn.client.arm_surface_contact import ArmSurfaceContactClient
3539
from bosdyn.client.async_tasks import AsyncPeriodicQuery, AsyncTasks
3640
from bosdyn.client.docking import DockingClient
3741
from bosdyn.client.estop import (
@@ -489,10 +493,15 @@ def __init__(
489493
self._manipulation_api_client = self._robot.ensure_client(
490494
ManipulationApiClient.default_service_name
491495
)
496+
self._arm_surface_contact_client = self._robot.ensure_client(
497+
ArmSurfaceContactClient.default_service_name
498+
)
492499
else:
493500
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+
)
496505
initialised = True
497506
except Exception as e:
498507
sleep_secs = 15
@@ -528,6 +537,7 @@ def __init__(
528537
self.execute_dance,
529538
self._robot_command,
530539
self._manipulation_request,
540+
self.arm_surface_contact_command,
531541
],
532542
)
533543

@@ -1446,6 +1456,29 @@ def manipulation_command(self, request):
14461456
timesync_endpoint=self._robot.time_sync.endpoint,
14471457
)
14481458

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+
14491482
def get_robot_command_feedback(self, cmd_id: int) -> robot_command_pb2.RobotCommandFeedbackResponse:
14501483
return self._robot_command_client.robot_command_feedback(cmd_id)
14511484

0 commit comments

Comments
 (0)