def create(cls, config):
     """
     Creates a new instance of an AbstractNaviagor, using the locator to get any dependencies.
     Args:
         config: a dict containing any optional parameters for self.__init__
     """
     return cls(locator.get_driver(), locator.get_helmsman(), **config)
 def create(cls, config) -> 'RudderController':
     """
     Constructs an instance of a RudderController using the locator to get any dependencies.
     Args:
         config: a dict that contains optional parameters for the RudderController and IntervalRepeater constructors
     """
     return cls(locator.get_driver(), **config)
Пример #3
0
    def create(cls, config) -> 'Helmsman':
        """
        Constructs an instance of a Helmsman using the locator to get dependencies.

        config should be a dict with the following entries:
            "sail_controller": a SailController config dict
            "rudder_controller": a RudderController config dict
        """
        return Helmsman(locator.get_driver(), locator.get_sail_controller(), locator.get_rudder_controller(), **config)
Пример #4
0
def exec():
    """
    All routines return:
        blocking (bool): Whether or not the manager should wait until this routine is finished 
        before starting the next

        is_done (function): Returns true if the routine has finished

        cleanup (function): Performs any necessary cleanup once the routine finishes or is
        interrupted
    """
    # If your routine is quick, you can just run it right on the main thread
    print('Executing quick sample routine')

    # You can access instances of the boat driver or helmsman (and more) from the locator
    driver = locator.get_driver()
    driver.get_sail()

    # If the routine is non-blocking and takes some time, it should run on a seperate thread.
    # Keep track of whether or not the routine has finished.
    done = False
    def run():
        nonlocal done
        print('Starting long sample routine')
        sleep(2)
        print('Finished long sample routine')
        done = True

    thread = Thread(target=run, daemon=True)
    thread.start()

    # Some long routines can't be run on a seperate thread (ex: if they are using Tkinter).
    # In that case, be aware that your routine will block and keyboard interrupts may not work.

    # Whether or not the process is blocking should be returned
    blocking = False

    # Function that returns true only when the routine is complete
    def is_done():
        return done

    # Function that performs any necessary cleanup
    def cleanup():
        print('Performing cleanup')

    return blocking, is_done, cleanup
Пример #5
0
def exec():
    sim_interface = locator.get_sim_interface()
    assert isinstance(sim_interface, SimulatorInterface)
    root = tk.Tk()
    start_frame = sim_interface.current_frame()
    fig = plot.setup(start_frame)
    plotcanvas = FigureCanvasTkAgg(fig, root)
    plotcanvas.get_tk_widget().grid(column=1, row=1)

    # initializes driver, which gets it's data from the simulator
    driver = locator.get_driver()

    # initializes the helmsman
    helmsman = locator.get_helmsman()
    # print(helmsman.turn(260))
    navigator = locator.get_navigator()
    navigator.add_waypoint((1, 4))

    # creates getters for the env/control from the driver
    get_control = sim_runner.make_control_getter(driver)
    get_env = sim_runner.make_env_getter(driver)

    def progress():
        nonlocal root, sim_interface
        plot.updplot(sim_interface.simulate(get_control(), get_env()))
        sim_interface.current_frame()
        root.after(250, progress)

    root.after(250, progress)
    root.mainloop()

    blocking = True

    def is_done():
        return False

    def cleanup():
        pass

    return blocking, is_done, cleanup
import unittest
import locator
from pi.navigator.poll_navigator.voter import WindVoter
from pi.boat_driver import AbstractBoatDriver

locator.load_config('tests/configs/test_voter.json')
driver = locator.get_driver()
wind_voter = WindVoter(driver)


class TestWindVoter(unittest.TestCase):
    def setUp(self):
        global driver
        #driver will be of type test_driver
        driver.reset()

    def test_heading_100_wind_200(self):
        global driver, wind_voter
        driver.wind_dir = 200

        self.assertGreater(
            wind_voter.vote(100), 0,
            "Voted 0 when candidate heading was 100 and wind_dir was 200")

    def test_heading_60_wind_300(self):
        global driver, wind_voter
        driver.wind_dir = 300

        self.assertGreater(
            wind_voter.vote(60), 0,
            "Voted 0 when candidate heading was 60 and wind_dir was 300")
 def setUp(self):
     global locator
     locator = reload(locator)
     locator.load_config(config_path)
     self.driver = locator.get_driver()
Пример #8
0
def exec():

    done = False

    def handle_input(task):
        while True:
            command = input().strip().lower()
            if command == 'y':
                break
            elif command == 'n':
                print('Failed at: ', task)
                done = True
                exit()

    print("Performing physical tests for ASV")
    
    driver = locator.get_driver()
    print("Driver loaded sucessfully\n")

    print("Testing sails.")
    for angle in [90, 60, 30, 0]:
        driver.set_sail(angle)
        print("Were the sails set to {} degrees? (y/n)".format(angle))
        handle_input('Setting sail')
    print("Sail tests passed.\n")
    sleep(1)

    print("Testing rudder.")
    for angle in [-45, -15, 15, 45]:
        driver.set_rudder(angle)
        print("Was the rudder set to {} degrees? (y/n)".format(angle))
        handle_input('Setting rudder')
    print("Rudder tests passed.\n")
    sleep(1)

    def angle_diff(a1, a2):
        a = a1 - a2
        if a > 180:
            a -= 360
        if a < -180:
            a += 360
        return abs(a)

    print("Testing windex.")
    num_trials = 4
    trial = 1
    for direction, angle in [('forwards', 360), ('left', 270), ('backwards', 180), ('right', 90)]:
        print("Trial {}/{}. Point the windex {}.".format(trial, num_trials, direction))
        print('Waiting 3 seconds.')
        sleep(3)
        read_angle = driver.get_wind_dir()
        print('Windex reports angle of {} degrees, expected angle of {} degrees.'.format(read_angle, angle))
        if angle_diff(read_angle, angle) > 30:
             print('Failed at : Windex test')
             done = True
             exit()
    print("Windex tests passed.\n")

    print('Success! All tests passed!')
    done = True

    def is_done():
        return done
    
    def cleanup():
        pass

    return True, is_done, cleanup