Exemplo n.º 1
0
 def setUp(self):
     self.sensors = Mock()
     self.sensors.wind_direction = 0
     self.timer = Mock()
     self.helm = Mock()
     self.course_steerer = CourseSteerer(self.sensors, self.helm,
                                         self.timer,
                                         CONFIG['course steerer'])
Exemplo n.º 2
0
class TestCourseSteerer(unittest.TestCase):

    def setUp(self):
        self.sensors = Mock()
        self.sensors.wind_direction = 0
        self.timer = Mock()
        self.helm = Mock()
        self.course_steerer = CourseSteerer(self.sensors,self.helm,self.timer,CONFIG['course steerer'])

    def test_should_return_immediately_if_time_has_expired(self):
        self.sensors.track = 200
        required_course = 180
        for_zero_seconds = 0

        self.course_steerer.steer_course(required_course,for_zero_seconds)

        self.assertEqual(self.helm.steer.call_count,0)

    def test_should_steer_and_wait_for_one_second_if_time_has_not_expired(self):
        required_course = 180
        for_one_second = 1

        self.course_steerer.steer_course(required_course,for_one_second)

        self.helm.steer.assert_called_with(180)
        self.timer.wait_for.assert_called_with(1)

    def test_should_steer_repeatedly_and_with_greater_deflection_to_max_until_time_has_expired(self):
        required_course = 180
        for_seconds = 4

        self.course_steerer.steer_course(required_course,for_seconds)

        self.helm.steer.assert_has_calls([call(180),call(180),call(180),call(180)])
        self.timer.wait_for.assert_has_calls([call(1),call(1),call(1)])

    def test_should_not_steer_right_into_the_no_go_zone(self):
        self.sensors.wind_direction = 225
        required_course = 190
        for_seconds = 2
        no_go_angle = 45

        self.course_steerer.steer_course(required_course,for_seconds,no_go_angle)

        self.helm.steer.assert_has_calls([call(180),call(180)])
        self.timer.wait_for.assert_has_calls([call(1),call(1)])

    def test_should_not_steer_left_into_the_no_go_zone(self):
        self.sensors.wind_direction = 135
        required_course = 170
        for_seconds = 2
        no_go_angle = 45

        self.course_steerer.steer_course(required_course,for_seconds,no_go_angle)

        self.helm.steer.assert_has_calls([call(180),call(180)])
        self.timer.wait_for.assert_has_calls([call(1),call(1)])
Exemplo n.º 3
0
    def __init__(self, gps=False, servo_port=SERVO_PORT):
        # devices
        self._gps = gps
        self.windsensor = WindSensor(I2C(WINDSENSOR_I2C_ADDRESS))
        self.compass = Compass(I2C(COMPASS_I2C_ADDRESS),
                               I2C(ACCELEROMETER_I2C_ADDRESS))
        self.red_led = GpioWriter(17, os)
        self.green_led = GpioWriter(18, os)

        # Navigation
        self.globe = Globe()
        self.timer = Timer()
        self.application_logger = self._rotating_logger(APPLICATION_NAME)
        self.position_logger = self._rotating_logger("position")
        self.exchange = Exchange(self.application_logger)
        self.timeshift = TimeShift(self.exchange, self.timer.time)
        self.event_source = EventSource(self.exchange, self.timer,
                                        self.application_logger,
                                        CONFIG['event source'])

        self.sensors = Sensors(self.gps, self.windsensor, self.compass,
                               self.timer.time, self.exchange,
                               self.position_logger, CONFIG['sensors'])
        self.gps_console_writer = GpsConsoleWriter(self.gps)
        self.rudder_servo = Servo(serial.Serial(servo_port),
                                  RUDDER_SERVO_CHANNEL, RUDDER_MIN_PULSE,
                                  RUDDER_MIN_ANGLE, RUDDER_MAX_PULSE,
                                  RUDDER_MAX_ANGLE)
        self.steerer = Steerer(self.rudder_servo, self.application_logger,
                               CONFIG['steerer'])
        self.helm = Helm(self.exchange, self.sensors, self.steerer,
                         self.application_logger, CONFIG['helm'])
        self.course_steerer = CourseSteerer(self.sensors, self.helm,
                                            self.timer,
                                            CONFIG['course steerer'])
        self.navigator = Navigator(self.sensors, self.globe, self.exchange,
                                   self.application_logger,
                                   CONFIG['navigator'])
        self.self_test = SelfTest(self.red_led, self.green_led, self.timer,
                                  self.rudder_servo, RUDDER_MIN_ANGLE,
                                  RUDDER_MAX_ANGLE)

        # Tracking
        self.tracking_logger = self._rotating_logger("track")
        self.tracking_sensors = Sensors(self.gps, self.windsensor,
                                        self.compass, self.timer.time,
                                        self.exchange, self.tracking_logger,
                                        CONFIG['sensors'])
        self.tracker = Tracker(self.tracking_logger, self.tracking_sensors,
                               self.timer)
Exemplo n.º 4
0
    def __init__(self):
        self.globe = Globe()
        self.console_logger = self._console_logger()
        self.exchange = Exchange(self.console_logger)
        self.gps = SimulatedGPS(CHORLTON.position,0,0.1)
        self.vehicle = SimulatedVehicle(self.gps, self.globe,self.console_logger,single_step=False)
        self.timeshift = TimeShift(self.exchange,self.vehicle.timer.time)
        self.event_source = EventSource(self.exchange,self.vehicle.timer,self.console_logger,CONFIG['event source'])
        self.sensors = Sensors(self.vehicle.gps, self.vehicle.windsensor,self.vehicle.compass,self.vehicle.timer.time,self.exchange,self.console_logger,CONFIG['sensors'])
        self.steerer = Steerer(self.vehicle.rudder,self.console_logger,CONFIG['steerer'])
        self.helm = Helm(self.exchange, self.sensors, self.steerer, self.console_logger, CONFIG['helm'])
        self.course_steerer = CourseSteerer(self.sensors,self.helm,self.vehicle.timer, CONFIG['course steerer'])
        self.navigator_simulator = Navigator(self.sensors,self.globe,self.exchange,self.console_logger,CONFIG['navigator'])

        self.tracking_timer = Timer()
        self.tracker_simulator = Tracker(self.console_logger,self.sensors,self.tracking_timer)
Exemplo n.º 5
0
 def setUp(self):
     self.sensors = Mock()
     self.sensors.wind_direction = 0
     self.timer = Mock()
     self.helm = Mock()
     self.course_steerer = CourseSteerer(self.sensors,self.helm,self.timer,CONFIG['course steerer'])
Exemplo n.º 6
0
class TestCourseSteerer(unittest.TestCase):
    def setUp(self):
        self.sensors = Mock()
        self.sensors.wind_direction = 0
        self.timer = Mock()
        self.helm = Mock()
        self.course_steerer = CourseSteerer(self.sensors, self.helm,
                                            self.timer,
                                            CONFIG['course steerer'])

    def test_should_return_immediately_if_time_has_expired(self):
        self.sensors.track = 200
        required_course = 180
        for_zero_seconds = 0

        self.course_steerer.steer_course(required_course, for_zero_seconds)

        self.assertEqual(self.helm.steer.call_count, 0)

    def test_should_steer_and_wait_for_one_second_if_time_has_not_expired(
            self):
        required_course = 180
        for_one_second = 1

        self.course_steerer.steer_course(required_course, for_one_second)

        self.helm.steer.assert_called_with(180)
        self.timer.wait_for.assert_called_with(1)

    def test_should_steer_repeatedly_and_with_greater_deflection_to_max_until_time_has_expired(
            self):
        required_course = 180
        for_seconds = 4

        self.course_steerer.steer_course(required_course, for_seconds)

        self.helm.steer.assert_has_calls(
            [call(180), call(180), call(180),
             call(180)])
        self.timer.wait_for.assert_has_calls([call(1), call(1), call(1)])

    def test_should_not_steer_right_into_the_no_go_zone(self):
        self.sensors.wind_direction = 225
        required_course = 190
        for_seconds = 2
        no_go_angle = 45

        self.course_steerer.steer_course(required_course, for_seconds,
                                         no_go_angle)

        self.helm.steer.assert_has_calls([call(180), call(180)])
        self.timer.wait_for.assert_has_calls([call(1), call(1)])

    def test_should_not_steer_left_into_the_no_go_zone(self):
        self.sensors.wind_direction = 135
        required_course = 170
        for_seconds = 2
        no_go_angle = 45

        self.course_steerer.steer_course(required_course, for_seconds,
                                         no_go_angle)

        self.helm.steer.assert_has_calls([call(180), call(180)])
        self.timer.wait_for.assert_has_calls([call(1), call(1)])