Beispiel #1
0
    def test_switch_from_low_power(self):
        mock_speed = sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS - 0.1

        # Can be anything
        mock_heading_error = 2 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH

        # Enter JIBE_ONLY from UNKNOWN
        hc = HeadingController(mock_speed, ControlModes.UNKNOWN.value)
        self.assertEqual(hc.getControlModeID(), ControlModes.JIBE_ONLY.value)

        # Adjust parameters to switch to LOW POWER
        # Only one or both of these need to be 1
        low_battery = 1
        low_wind = 1

        # A switch should occur
        self.assertTrue(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed,
                                 low_battery_level=low_battery,
                                 low_wind=low_wind))

        # Adjust parameters to switch to TACKABLE
        mock_speed = 2 * sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS
        mock_heading_error = 0.5 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH

        # A switch should occur
        self.assertTrue(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed))

        # Should now be in TACKABLE mode
        self.assertEqual(hc.getControlModeID(), ControlModes.TACKABLE.value)
Beispiel #2
0
    def test_noExit_jibeMode(self):
        mock_speed = sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS - 0.1
        mock_heading_error = 2 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH

        # Enter JIBE_ONLY mode from UNKNOWN
        hc = HeadingController(mock_speed, ControlModes.UNKNOWN.value)

        # No switch
        self.assertFalse(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed))
        self.assertEqual(hc.getControlModeID(), ControlModes.JIBE_ONLY.value)

        # Adjust parameters
        mock_speed /= 2
        mock_heading_error = 1.5 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH

        # No switch
        self.assertFalse(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed))
        self.assertEqual(hc.getControlModeID(), ControlModes.JIBE_ONLY.value)
Beispiel #3
0
    def test_reachedHeading_exitTackable(self):
        mock_speed = sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS + 0.1

        # Enter TACKABLE from UNKNOWN
        hc = HeadingController(mock_speed, ControlModes.UNKNOWN.value)
        mock_heading_error = -0.5 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH

        # A switch occurs
        self.assertTrue(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed))

        # Should not have changed modes
        self.assertEqual(hc.getControlModeID(), ControlModes.TACKABLE.value)
Beispiel #4
0
    def test_slowSpeed_exitTackable(self):
        mock_speed = sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS + 0.1
        mock_heading_error = 2 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH

        # Enter TACKABLE from UNKNOWN
        hc = HeadingController(mock_speed, ControlModes.UNKNOWN.value)

        # Make speed low
        mock_speed -= 0.2

        self.assertTrue(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed))

        # Should not be in TACKABLE or UNKNOWN
        self.assertNotEqual(hc.getControlModeID(), ControlModes.TACKABLE.value)
        self.assertNotEqual(hc.getControlModeID(), ControlModes.UNKNOWN.value)
Beispiel #5
0
    def test_tack_to_jibe(self):
        mock_speed = sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS + 0.1
        mock_heading_error = 2 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH

        # Enter TACKABLE from UNKNOWN
        hc = HeadingController(mock_speed, ControlModes.UNKNOWN.value)
        self.assertEqual(hc.getControlModeID(), ControlModes.TACKABLE.value)

        # Adjust parameters to switch to JIBE_ONLY
        mock_speed = 0.5 * sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS

        # A switch should occur
        self.assertTrue(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed))

        # Should now be in JIBE_ONLY mode
        self.assertEqual(hc.getControlModeID(), ControlModes.JIBE_ONLY.value)
Beispiel #6
0
    def test_fixed_low_power(self):
        mock_speed = sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS - 0.1
        mock_heading_error = 2 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH
        fixedMode = ControlModes.LOW_POWER.value

        # Enter LOWER_POWER from UNKNOWN
        hc = HeadingController(mock_speed,
                               ControlModes.UNKNOWN.value,
                               fixedControlMode=fixedMode)
        self.assertEqual(hc.getControlModeID(), ControlModes.LOW_POWER.value)

        # A switch should NOT occur
        self.assertFalse(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed))

        # Should now be in LOW_POWER mode
        self.assertEqual(hc.getControlModeID(), ControlModes.LOW_POWER.value)
        self.assertTrue(hc.controlModeIsFixed)
Beispiel #7
0
    def test_tack_disabled_low_power(self):
        mock_speed = sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS + 0.1
        mock_heading_error = 2 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH

        # Enter TACKABLE from UNKNOWN
        hc = HeadingController(mock_speed, ControlModes.UNKNOWN.value, True)
        self.assertEqual(hc.getControlModeID(), ControlModes.TACKABLE.value)

        # Adjust parameters to switch to LOW POWER
        low_battery = 0
        low_wind = 1

        # A switch should NOT occur
        self.assertFalse(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed,
                                 low_battery_level=low_battery,
                                 low_wind=low_wind))

        # Should now be in TACKABLE mode and not in LOW_POWER mode
        self.assertEqual(hc.getControlModeID(), ControlModes.TACKABLE.value)
Beispiel #8
0
    def test_fixed_tack_mode(self):
        mock_speed = sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS + 0.1
        mock_heading_error = 2 * sailbot_constants.MIN_HEADING_ERROR_FOR_SWITCH
        fixedMode = ControlModes.TACKABLE.value

        # Enter TACKABLE from UNKNOWN
        hc = HeadingController(mock_speed,
                               ControlModes.UNKNOWN.value,
                               fixedControlMode=fixedMode)
        self.assertEqual(hc.getControlModeID(), ControlModes.TACKABLE.value)

        # Adjust parameters to switch to JIBE_ONLY
        mock_speed = 0.5 * sailbot_constants.SPEED_THRESHOLD_FOR_JIBING_KNOTS

        # A switch should NOT occur
        self.assertFalse(
            hc.switchControlMode(heading_error=mock_heading_error,
                                 boat_speed=mock_speed))

        # Should still be in TACKABLE mode
        self.assertEqual(hc.getControlModeID(), ControlModes.TACKABLE.value)
        self.assertTrue(hc.controlModeIsFixed)