def test_set_pulse_with_adjusted_throttle(self, serial): driver = RoboHATDriver(cfg) driver.MAX_FORWARD = 1800 driver.write_pwm = MagicMock() driver.set_pulse(1.0, 1.0) driver.write_pwm.assert_called_with(1000, 1800) driver.set_pulse(0.0, 0.5) # (1800 - 1500)/ 2 + 1500 = 1650 driver.write_pwm.assert_called_with(1500, 1650) # Change the STOPPED_PWM driver.STOPPED_PWM = 1400 driver.set_pulse(0.0, 0.5) # (1800 -1400)/2 + 1400 = 1600 driver.write_pwm.assert_called_with(1500, 1600) # Test Reverse driver.STOPPED_PWM = 1500 driver.MAX_REVERSE = 1000 driver.set_pulse(0.0, -0.5) driver.write_pwm.assert_called_with(1500, 1250) driver.MAX_REVERSE = 1250 driver.set_pulse(0.0, -0.5) driver.write_pwm.assert_called_with(1500, 1375)
def test_set_pulse(self, serial): driver = RoboHATDriver(cfg, True) driver.write_pwm = MagicMock() # angle, throttle driver.set_pulse(0.0, 0.0) driver.write_pwm.assert_called_with(1500, 1500) driver.set_pulse(1.0, 0.0) driver.write_pwm.assert_called_with(1000, 1500) driver.set_pulse(0.0, 1.0) driver.write_pwm.assert_called_with(1500, 2000) driver.set_pulse(1.0, 1.0) driver.write_pwm.assert_called_with(1000, 2000) driver.set_pulse(-1.0, 0.0) driver.write_pwm.assert_called_with(2000, 1500) driver.set_pulse(0.0, -1.0) driver.write_pwm.assert_called_with(1500, 1000) driver.set_pulse(-1.0, -1.0) driver.write_pwm.assert_called_with(2000, 1000) driver.set_pulse(-2.0, -2.0) driver.write_pwm.assert_called_with(2000, 1000)