コード例 #1
0
 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
コード例 #2
0
 def test_current_standby(self, motor : Motor) :
     motor.current_standby = self.__module.motor_current_minimum
     self.assertEqual(motor.current_standby, self.__module.motor_current_minimum)
     motor.current_standby = self.__module.motor_current_maximum
     self.assertEqual(motor.current_standby, self.__module.motor_current_maximum)
     motor.current_standby = environment.MOTOR_CURRENT_STANDBY
     self.assertEqual(motor.current_standby, environment.MOTOR_CURRENT_STANDBY)
     with self.assertRaises(ValueError) :
         motor.current_standby = self.__module.motor_current_minimum - 1
     self.assertEqual(motor.current_standby, environment.MOTOR_CURRENT_STANDBY)
     with self.assertRaises(ValueError) :
         motor.current_standby = self.__module.motor_current_maximum + 1
     self.assertEqual(motor.current_standby, environment.MOTOR_CURRENT_STANDBY)
コード例 #3
0
 def test_current_moving(self, motor : Motor) :
     motor.current_moving = self.__module.motor_current_minimum
     self.assertEqual(motor.current_moving, self.__module.motor_current_minimum)
     motor.current_moving = self.__module.motor_current_maximum
     self.assertEqual(motor.current_moving, self.__module.motor_current_maximum)
     motor.current_moving = environment.MOTOR_CURRENT_MOVING
     self.assertEqual(motor.current_moving, environment.MOTOR_CURRENT_MOVING)
     with self.assertRaises(ValueError) :
         motor.current_moving = self.__module.motor_current_minimum - 1
     self.assertEqual(motor.current_moving, environment.MOTOR_CURRENT_MOVING)
     with self.assertRaises(ValueError) :
         motor.current_moving = self.__module.motor_current_maximum + 1
     self.assertEqual(motor.current_moving, environment.MOTOR_CURRENT_MOVING)
コード例 #4
0
 def test_direction_reversed(self, motor : Motor) :
     self.assertFalse(motor.direction_reversed)
     switch_limit_left = motor.switch_limit_left
     switch_limit_right = motor.switch_limit_right
     motor.position = +1234
     motor.direction_reversed = True
     self.assertTrue(motor.direction_reversed)
     self.assertIs(motor.switch_limit_left, switch_limit_right)
     self.assertIs(motor.switch_limit_right, switch_limit_left)
     self.assertEqual(motor.position, -1234)
     motor.direction_reversed = False
     self.assertFalse(motor.direction_reversed)
     self.assertIs(motor.switch_limit_left, switch_limit_left)
     self.assertIs(motor.switch_limit_right, switch_limit_right)
     self.assertEqual(motor.position, +1234)
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 def test_move_by_left_no_wait(self, motor : Motor) :
     position_before = 0
     position_target = -environment.MOTOR_STEPS * motor.microstep_resolution
     overshoot = False
     motor.move_by(position_target, False)
     while True :
         position = motor.position
         if overshoot is False :
             self.assertLessEqual(position, position_before)
         position_before = position
         velocity = motor.velocity
         if not motor.moving :
             break
         if overshoot is False and velocity > 0.0 :
             overshoot = True
         if overshoot :
             self.assertGreater(velocity, 0.0)
         else :
             self.assertLess(velocity, 0.0)
     self.assertEqual(motor.position, position_target)
     self.__test_stopped(motor)
コード例 #8
0
 def test_move_left(self, motor : Motor) :
     position_before = 0
     velocity_before = 0.0
     motor.move_left(False)
     while True :
         self.assertTrue(motor.moving)
         position = motor.position
         acceleration = motor.acceleration
         velocity = motor.velocity
         self.assertLessEqual(position, position_before)
         self.assertLessEqual(velocity, velocity_before)
         self.assertLess(velocity, 0.0)
         position_before = position
         velocity_before = velocity
         if -velocity == motor.velocity_moving :
             break
         self.assertEqual(acceleration, -motor.acceleration_moving)
     self.assertTrue(motor.moving)
     self.assertEqual(motor.velocity, -motor.velocity_moving)
     motor.stop(False)
     # Expects no overshoot.
     while True :
         acceleration = motor.acceleration
         velocity = motor.velocity
         position = motor.position
         moving = motor.moving
         if moving :
             self.assertLess(velocity, 0.0)
             self.assertEqual(acceleration, motor.acceleration_moving)
         self.assertGreaterEqual(velocity, velocity_before)
         self.assertLessEqual(position, position_before)
         velocity_before = velocity
         position_before = position
         if not moving :
             break
     self.__test_stopped(motor)
コード例 #9
0
 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)
コード例 #10
0
 def test_stop_left(self, motor : Motor) :
     motor.move_left(False)
     while motor.velocity > -motor.velocity_moving :
         pass
     motor.stop()
     self.__test_stopped(motor)
コード例 #11
0
 def test_move_to_left(self, motor : Motor) :
     position_target = -environment.MOTOR_STEPS * motor.microstep_resolution
     motor.move_to(position_target)
     self.assertEqual(motor.position, position_target)
     self.__test_stopped(motor)
コード例 #12
0
 def test_position(self, motor : Motor) :
     self.assertEqual(motor.position, 0)
     position = 100 * motor.number
     motor.position = position
     self.assertEqual(motor.position, position)