def test_connect(): """ connects and configures , reqs: 03, 04 """ tracker = NDITracker(SETTINGS_DUMMY) tracker.close()
def test_connect(): """ connects and configures , reqs: 03, 04 """ tracker = NDITracker(SETTINGS_DUMMY) assert not tracker.use_quaternions tracker.close()
def test_connect_network(): """ connects and configures, throws error when no vega reqs: 03, 04 """ with pytest.raises(IOError): tracker = NDITracker(SETTINGS_VEGA) del tracker
def test_connect_serial(): """ connects and configures, throws error when no serial reqs: 03, 04 """ tracker = None with pytest.raises(IOError): tracker = NDITracker(SETTINGS_POLARIS) del tracker
def configure_tracker(config): """ Configures the tracking system. :param: A dictionary containing configuration data :return: The tracker object :raises: KeyError if no tracker entry in config """ if "tracker type" not in config: raise KeyError('Tracker configuration requires tracker type') tracker_type = config.get("tracker type") tracker = None if tracker_type in ("vega", "polaris", "aurora", "dummy"): tracker = NDITracker(config) if tracker_type in "aruco": tracker = ArUcoTracker(config) tracker.start_tracking() return tracker
def test_get_frame(): """ test get frame returns numpy array reqs:05, 06 """ tracker = NDITracker(SETTINGS_DUMMY) _port_handles, _timestamps, _framenumbers, \ tracking, _tracking_quality = tracker.get_frame() assert not tracking del tracker dummy_two_rom = { "tracker type": "dummy", "romfiles" : [ "../data/something_else.rom", "../data/8700339.rom"] } tracker = NDITracker(dummy_two_rom) _port_handles, _timestamps, _framenumbers, \ tracking, _tracking_quality = tracker.get_frame() assert len(tracking) == 2 assert tracking[0].shape == (4, 4) assert tracking[0].dtype == 'float64'
def configure_tracker(config): """ Configures a scikit-surgery tracker based on the passed config :param config: a tracker configuration dictionary :returns: The tracker :raises: KeyError """ if "tracker type" not in config: raise KeyError('Tracker configuration requires tracker type') tracker_type = config.get("tracker type") tracker = None if tracker_type in ("vega", "polaris", "aurora", "dummy"): tracker = NDITracker(config) if tracker_type in "aruco": tracker = ArUcoTracker(config) if tracker_type not in "dummy": tracker.start_tracking() return tracker
def test_stop_tracking(): """ test stop tracking reqs: """ tracker = NDITracker(SETTINGS_DUMMY) with pytest.raises(ValueError): tracker.stop_tracking() tracker.close()
def run(): """Demonstration program Example showing how to initialise, configure, and communicate with NDI Polaris, Vega, and Aurora trackers. Configuration is by python dictionaries, edit as necessary. Dictionaries for other systems: settings_polaris = {"tracker type": "polaris", "romfiles" : ["../data/8700339.rom"]} settings_aurora = { "tracker type": "aurora", "ports to use" : [1,2]} settings_dummy = {"tracker type": "dummy",} """ settings_vega = { "tracker type": "vega", "ip address": "192.168.2.17", "port": 8765, "romfiles": ["../data/8700339.rom", "../data/something_else.rom"] } tracker = NDITracker(settings_vega) tracker.start_tracking() six.print_(tracker.get_tool_descriptions()) for _ in range(20): six.print_(tracker.get_frame()) time.sleep(0.300333) tracker.stop_tracking() tracker.close()
def test_configure(): """ connects and configures, throws errors when when errors in dictionary reqs: 03, 04 """ no_rom = { "tracker type": "polaris", } with pytest.raises(KeyError): tracker = NDITracker(no_rom) del tracker bad_tracker = { "tracker type": "optotrack", } with pytest.raises(ValueError): tracker = NDITracker(bad_tracker) del tracker no_ip = {"tracker type": "vega", "romfiles": "[rom]"} with pytest.raises(KeyError): tracker = NDITracker(no_ip) del tracker with pytest.raises(IOError) or pytest.raises(OSError): no_port = { "tracker type": "vega", "ip address": "tracker", "romfiles": "[rom]" } tracker = NDITracker(no_port) del tracker with pytest.raises(IOError) or pytest.raises(OSError): aurora = {"tracker type": "aurora"} tracker = NDITracker(aurora) del tracker with pytest.raises(IOError) or pytest.raises(OSError): aurora_sp = {"tracker type": "aurora", "serial_port": "1"} tracker = NDITracker(aurora_sp) del tracker with pytest.raises(IOError) or pytest.raises(OSError): aurora_np = {"tracker type": "aurora", "ports to probe": "50"} tracker = NDITracker(aurora_np) del tracker
def test_connect_quaternions(): """ connects and configures , reqs: 03, 04 """ tracker = NDITracker(SETTINGS_DUMMY_QUATERNIONS) assert tracker.use_quaternions assert tracker.buffer_size == 1 tracker.close() SETTINGS_DUMMY_QUATERNIONS['smoothing buffer'] = 3 tracker = NDITracker(SETTINGS_DUMMY_QUATERNIONS) assert tracker.buffer_size == 3
def test_get_tool_descriptions(): """ test get tool descriptions reqs:05, 06 """ tracker = NDITracker(SETTINGS_DUMMY) _port_handles, descriptions = tracker.get_tool_descriptions() assert not descriptions del tracker dummy_two_rom = { "tracker type": "dummy", "romfiles": ["../data/something_else.rom", "../data/8700339.rom"] } tracker = NDITracker(dummy_two_rom) _port_handles, descriptions = tracker.get_tool_descriptions() assert len(descriptions) == 2
def test_configure(): """ connects and configures, throws errors when when errors in dictionary reqs: 03, 04 """ no_rom = { "tracker type": "polaris", } with pytest.raises(KeyError): tracker = NDITracker(no_rom) del tracker bad_tracker = { "tracker type": "optotrack", } with pytest.raises(ValueError): tracker = NDITracker(bad_tracker) del tracker no_ip = { "tracker type": "vega", "romfiles": "[rom]" } with pytest.raises(KeyError): tracker = NDITracker(no_ip) del tracker with pytest.raises(IOError) or pytest.raises(OSError): no_port = { "tracker type": "vega", "ip address": "tracker", "romfiles": "[rom]" } tracker = NDITracker(no_port) del tracker with pytest.raises(IOError) or pytest.raises(OSError): aurora = {"tracker type": "aurora"} tracker = NDITracker(aurora) del tracker #try with an integer serial port with pytest.raises(IOError) or pytest.raises(OSError): aurora_sp = {"tracker type": "aurora", "serial port": 0} tracker = NDITracker(aurora_sp) del tracker #try with verbose on with pytest.raises(IOError) or pytest.raises(OSError): aurora_np = {"tracker type": "aurora", "ports to probe": 10, "verbose": True} tracker = NDITracker(aurora_np) del tracker #with a named serial port on windows with pytest.raises(IOError) or pytest.raises(OSError): aurora_np = {"tracker type": "aurora", "serial port": "COM2", "verbose": True} tracker = NDITracker(aurora_np) del tracker