def test_microstep_resolution(self, motor : Motor) : velocity_moving = motor.velocity_moving for microstep_resolution in Motor.MICROSTEP_RESOLUTIONS : motor.microstep_resolution = microstep_resolution self.assertEqual(motor.microstep_resolution, microstep_resolution) self.assertEqual(motor.velocity_moving, velocity_moving) with self.assertRaises(ValueError) : motor.microstep_resolution = 0 with self.assertRaises(ValueError) : motor.microstep_resolution = 512
def test_acceleration_moving(self, motor : Motor) : for microstep_resolution in Motor.MICROSTEP_RESOLUTIONS : motor.microstep_resolution = microstep_resolution velocity_minimum = motor.velocity_minimum velocity_maximum = motor.velocity_maximum velocity_range = velocity_maximum - velocity_minimum for velocity_portion in range(1, 11) : velocity = velocity_minimum + velocity_range * velocity_portion / 10 motor.velocity_moving = velocity acceleration_minimum = motor.acceleration_minimum acceleration_maximum = motor.acceleration_maximum with self.assertRaises(ValueError) : motor.acceleration_moving = math.nextafter(acceleration_minimum, -math.inf) with self.assertRaises(ValueError) : motor.acceleration_moving = math.nextafter(acceleration_maximum, +math.inf) motor.acceleration_moving = acceleration_minimum self.assertEqual(motor.acceleration_moving, acceleration_minimum) motor.acceleration_moving = acceleration_maximum self.assertEqual(motor.acceleration_moving, acceleration_maximum) acceleration_range = acceleration_maximum - acceleration_minimum for portion in range(1, 100) : acceleration = acceleration_minimum + acceleration_range * portion / 100 motor.acceleration_moving = acceleration error_absolute = motor.acceleration_moving - acceleration error_relative = error_absolute / acceleration self.assertLessEqual(error_relative, 0.0) self.assertGreater(error_relative, -0.025)
def test_velocity_moving_extrema(self, motor : Motor) : frequency_minimum = motor.module.motor_frequency_minimum frequency_maximum = motor.module.motor_frequency_maximum for microstep_resolution in Motor.MICROSTEP_RESOLUTIONS : motor.microstep_resolution = microstep_resolution velocity_minimum = frequency_minimum / microstep_resolution velocity_maximum = frequency_maximum / microstep_resolution self.assertEqual(motor.velocity_minimum, velocity_minimum) self.assertEqual(motor.velocity_maximum, velocity_maximum)
def test_velocity_moving(self, motor : Motor) : for microstep_resolution in Motor.MICROSTEP_RESOLUTIONS : motor.microstep_resolution = microstep_resolution velocity_minimum = motor.velocity_minimum velocity_maximum = motor.velocity_maximum with self.assertRaises(ValueError) : motor.velocity_moving = math.nextafter(velocity_minimum, -math.inf) with self.assertRaises(ValueError) : motor.velocity_moving = math.nextafter(velocity_maximum, +math.inf) motor.velocity_moving = velocity_minimum self.assertEqual(motor.velocity_moving, velocity_minimum) motor.velocity_moving = velocity_maximum self.assertEqual(motor.velocity_moving, velocity_maximum) velocity_range = velocity_maximum - velocity_minimum for portion in range(1, 100) : velocity = velocity_minimum + velocity_range * portion / 100 motor.velocity_moving = velocity error_absolute = motor.velocity_moving - velocity error_relative = error_absolute / velocity self.assertLessEqual(error_relative, 0.0) self.assertGreater(error_relative, -0.001)