def test_cancelling(capabilities, data_acq_client, group_name, verbose): """Checks that each capability can be cancelled successfully after the acquisition begins. Args: capabilities (list): All the data source capabilities listed for the plugin service (using the GetServiceInfo RPC). data_acq_client (DataAcquisitionClient): The client for the data acquisition service running on robot. group_name (string): Group name for saving in the CaptureActionId of every acquisition tested. verbose (boolean): Print additional logging information on failure. Returns: A boolean indicating that every capability responds to the CancelAcquisition RPC and recieved a "cancellation complete" status for the GetStatus RPC. """ all_cancels_succeed = True for capability in capabilities: acquisition_request = data_acquisition_pb2.AcquisitionRequestList() acquisition_request.data_captures.extend( [data_acquisition_pb2.DataCapture(name=capability.name)]) # Make a request for this data capability and then attempt to cancel the request immediately after. action_name = "cancel acquisition check: " + capability.name request_id = data_acq_client.acquire_data(acquisition_request, action_name, group_name) success = cancel_request_and_monitor_status(request_id, data_acq_client, capability.name, action_name, verbose) if not success: all_cancels_succeed = False return all_cancels_succeed
def test_capabilities_acquires_and_saves(capabilities, data_acq_client, data_store_client, group_name, verbose): """Checks that each capability can individually be acquired, saved to the data store, and respond with a status "complete". Also checks the same sequence of events for an acquisition requesting all data source at once. Args: capabilities (list): All the data source capabilities listed for the plugin service (using the GetServiceInfo RPC). data_acq_client (DataAcquisitionClient): The client for the data acquisition service running on robot. data_store_client (DataAcquisitionStoreClient): The client for the data acquisition store service running on robot. group_name (string): Group name for saving in the CaptureActionId of every acquisition tested. verbose (boolean): Print additional logging information on failure. Returns: A boolean indicating that every capability recieved a "complete" status for the GetStatus RPC and an action id for the acquisition can be found in the data store. """ success = True # Test each capability individually. for capability in capabilities: action_name = "acquire and status check: " + capability.name acquisition_request = data_acquisition_pb2.AcquisitionRequestList() acquisition_request.data_captures.extend( [data_acquisition_pb2.DataCapture(name=capability.name)]) capability_success = acquire_get_status_and_save( acquisition_request, capability.name, action_name, group_name, data_acq_client, data_store_client, verbose) success = capability_success and success # Test requesting all the capabilities at once (if there are more than one data capabilities available). if len(capabilities) > 1: action_name = "acquire and status check: all data at once" acquisition_request = data_acquisition_pb2.AcquisitionRequestList() acquisition_request.data_captures.extend([ data_acquisition_pb2.DataCapture(name=capability.name) for capability in capabilities ]) all_capabilities_success = acquire_get_status_and_save( acquisition_request, "all data", action_name, group_name, data_acq_client, data_store_client, verbose) success = all_capabilities_success and success return success
def data_acquisition(config): """A simple example of using the data acquisition client to request data and check status.""" bosdyn.client.util.setup_logging(config.verbose) sdk = bosdyn.client.create_standard_sdk('DataAcquisitionClientExample') robot = sdk.create_robot(config.hostname) robot.authenticate(config.username, config.password) robot.time_sync.wait_for_sync() # Create data acquisition clients data_acq_client = robot.ensure_client( DataAcquisitionClient.default_service_name) now = robot.time_sync.robot_timestamp_from_local_secs(time.time()) capture_name = "DataAcquisitionExample_{}".format( now.ToJsonString().replace(':', '-')) service_info = data_acq_client.get_service_info() print("Available capabilities are:\n" + str(service_info)) # Request 1 contains only internal metadata capture requests and an image request. acquisition_requests = data_acquisition_pb2.AcquisitionRequestList() acquisition_requests.image_captures.extend([ data_acquisition_pb2.ImageSourceCapture( image_service="image", image_source="back_fisheye_image") ]) acquisition_requests.data_captures.extend([ data_acquisition_pb2.DataCapture(name="robot-state"), data_acquisition_pb2.DataCapture(name="detailed-position-data"), data_acquisition_pb2.DataCapture(name="detected-objects") ]) process_request(data_acq_client, config.hostname, robot, acquisition_requests, capture_name, "InternalAcquisitions") # Request 2 contains capture requests for all the capabilities and a user-generated metadata # struct. json_struct = Struct() json_struct.update({"user_comment": "it is raining"}) metadata = data_acquisition_pb2.Metadata(data=json_struct) acquisition_requests = data_acquisition_pb2.AcquisitionRequestList() acquisition_requests.image_captures.extend([ data_acquisition_pb2.ImageSourceCapture( image_service="image", image_source="left_fisheye_image"), data_acquisition_pb2.ImageSourceCapture( image_service="image", image_source="right_fisheye_image") ]) acquisition_requests.data_captures.extend([ data_acquisition_pb2.DataCapture(name="robot-state"), data_acquisition_pb2.DataCapture(name="detailed-position-data"), data_acquisition_pb2.DataCapture(name="basic-position-data"), data_acquisition_pb2.DataCapture(name="detected-objects"), data_acquisition_pb2.DataCapture(name="GPS"), data_acquisition_pb2.DataCapture(name="velodyne-point-cloud") ]) process_request(data_acq_client, config.hostname, robot, acquisition_requests, capture_name, "AllAcquisitions", metadata) # Request 3 contains capture requests for only one capability from main DAQ and one capability # from DAQ plugin. acquisition_requests = data_acquisition_pb2.AcquisitionRequestList() acquisition_requests.data_captures.extend([ data_acquisition_pb2.DataCapture(name="robot-state"), data_acquisition_pb2.DataCapture(name="GPS"), data_acquisition_pb2.DataCapture(name="velodyne-point-cloud"), ]) process_request(data_acq_client, config.hostname, robot, acquisition_requests, capture_name, "PartialAcquisitions") # Request #4 shows how to issue and then cancel different data acquistion requests (one on-robot # data source and one off-robot plugin data source). print("\n-----------------------------------") acquisition_requests = data_acquisition_pb2.AcquisitionRequestList() acquisition_requests.data_captures.extend([ data_acquisition_pb2.DataCapture(name="robot-state"), data_acquisition_pb2.DataCapture(name="slow-gps"), ]) request_id, action_id = issue_acquire_data_request(data_acq_client, acquisition_requests, capture_name, "AcquisitionsToCancel") time.sleep(2) cancel_acquisition_request(data_acq_client, request_id) # Request 5 contains a SpotCAM capture request. acquisition_requests = data_acquisition_pb2.AcquisitionRequestList() acquisition_requests.data_captures.extend([ data_acquisition_pb2.DataCapture(name="spot-cam-pano"), data_acquisition_pb2.DataCapture(name="spot-cam-ptz"), data_acquisition_pb2.DataCapture(name="spot-cam-ir"), data_acquisition_pb2.DataCapture(name="robot-state") ]) process_request(data_acq_client, config.hostname, robot, acquisition_requests, capture_name, "SpotCAMAcquisitions")