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")
def test_full_data_acquisition_integration(robot, image_sources, service_name, verbose): """Check that the image service is properly integrated with the data-acquisition service. Ensures that all image sources are listed as data acquisition image capabilities, and that each image capability for the service can be acquired and saved successfully. Args: robot (Robot): The robot to make client connections to. image_sources (List[string]): The image source names from the image service. service_name (string): The unique service name of the image service. verbose (boolean): Print additional logging information on failure. Returns: Boolean indicating that all of the service's image sources are listed in the on-robot data acquisition service and can be acquired successfully. """ data_acquisition_client = robot.ensure_client(DataAcquisitionClient.default_service_name) data_store_client = robot.ensure_client(DataAcquisitionStoreClient.default_service_name) # Check that all the image sources from the image service are listed in the image capabilities of # the on-robot data acquisition service. capabilities = data_acquisition_client.get_service_info() found_service_name = False for capability in capabilities.image_sources: if capability.service_name == service_name: found_service_name = True # Check that each source is present. sources_not_found = [] for src in image_sources: if src not in capability.image_source_names: sources_not_found.append(src) if len(sources_not_found) > 0: _LOGGER.error( "Image sources listed by the image service are not present in the data " "acquisition service's set of image capabilities: %s", sources_not_found) if verbose: _LOGGER.info("GetServiceInfo response: %s", capabilities) return False if not found_service_name: _LOGGER.error( "The image service %s is not listed as an image source in the data acquisition " "service's set of image capabilities.", service_name) if verbose: _LOGGER.info("GetServiceInfo response: %s", capabilities) return False # Check that each image source can be acquired and saved successfully. success = True group_name = "Image Service [%s] Test %s" % ( service_name, datetime.datetime.today().strftime("%b %d %Y %H:%M:%S")) for src in image_sources: action_name = "acquire and status check: " + src acquisition_request = data_acquisition_pb2.AcquisitionRequestList() acquisition_request.image_captures.extend( [data_acquisition_pb2.ImageSourceCapture(image_service=service_name, image_source=src)]) capability_success = acquire_get_status_and_save(acquisition_request, src, action_name, group_name, data_acquisition_client, data_store_client, verbose) success = capability_success and success return success