コード例 #1
0
ファイル: test_robohat.py プロジェクト: cfox570/dk
    def test_controller_update_with_adjusted_max_reverse(self, serial):
        controller = RoboHATController(cfg, True)
        controller.STOPPED_PWM = 1500
        controller.MAX_REVERSE = 1200

        controller.serial.readline.side_effect = [
            b"1500, 1000\n", b"1500, 1250\n", b"1500, 1000\n", b"1500, 1250\n",
            b"1500, 1500\n"
        ]

        # 1500, 1000
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == -1.0

        # 1500, 1250
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == -0.5

        # 1500, 1000
        controller.STOPPED_PWM = 1400
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == -1.0

        # 1500, 1250
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == -0.5

        # 1500, 1500
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == 0
コード例 #2
0
ファイル: test_robohat.py プロジェクト: cfox570/dk
    def test_controller_update_with_adjusted_mid_steering(self, serial):
        controller = RoboHATController(cfg)
        controller.STEERING_MID = 1450

        controller.serial.readline.side_effect = [
            b"1450, 1500\n", b"1500, 1500\n"
        ]

        # 1450, 1500
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == 0

        # 1500, 1500
        controller.read_serial()
        # 1450 is the mid value. So the correct angle should be (1450-1500)/ (2000-1450)
        assert controller.angle == -0.09
        assert controller.throttle == 0
コード例 #3
0
ファイル: test_robohat.py プロジェクト: cfox570/dk
    def test_controller_update_with_adjusted_max_throttle(self, serial):
        '''
        The adjusted MAX_FORWARD here should not affect the output throttle
        value.
        For example, when RC controller sending a 2000 value it means the user
        want to go full speed. The throttle value should therefore be 1.0. It is
        the RoboHATDriver responsibility to translate this 1.0 to an adjusted
        pwm value.
        '''
        controller = RoboHATController(cfg, True)
        controller.MAX_FORWARD = 1800
        controller.STOPPED_PWM = 1500

        controller.serial.readline.side_effect = [
            b"1500, 2000\n", b"1500, 1500\n", b"1500, 1750\n"
        ]

        # 1500, 2000
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == 1.0

        # 1500, 1500
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == 0

        # 1500, 1750
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == 0.5
コード例 #4
0
ファイル: test_robohat.py プロジェクト: cfox570/dk
    def test_controller_update(self, serial):
        controller = RoboHATController(cfg)

        # print("timeout = {}".format(seriala.timeout))
        controller.serial.readline.side_effect = [
            b"1500, 1500\n", b"2000, 1500\n", b"1600, 1600\n", b"2000, 2000\n",
            b"1000, 1000\n", b"1200, 1200\n"
        ]

        # 1500, 1500
        controller.read_serial()
        assert controller.angle == 0
        assert controller.throttle == 0

        # 2000, 1500
        controller.read_serial()
        assert controller.angle == -1.0
        assert controller.throttle == 0

        # 1600, 1600
        controller.read_serial()
        assert controller.angle == -0.2
        assert controller.throttle == 0.2

        # 2000, 2000
        controller.read_serial()
        assert controller.angle == -1.0
        assert controller.throttle == 1.0

        # 1000, 1000
        controller.read_serial()
        assert controller.angle == 1.0
        assert controller.throttle == -1.0

        # 1200, 1200
        controller.read_serial()
        assert controller.angle == 0.6
        assert controller.throttle == -0.6