def test_long_way_around(self): error = smallest_allowed_error( mount_enc_position=-1.0, target_enc_position=1.0, no_cross_position=0.0, ) assert_allclose(error, -358.0)
def test_target_opposite_dir_from_limit(self): error = smallest_allowed_error( mount_enc_position=0.0, target_enc_position=60.0, no_cross_position=-30.0, ) assert_allclose(error, 60.0)
def test_target_closer_than_limit(self): error = smallest_allowed_error( mount_enc_position=0.0, target_enc_position=1.0, no_cross_position=30.0, ) assert_allclose(error, 1.0)
def distance_to(self, other_destination: "Position") -> int: """Returns the cost of moving the mount from this position to another position Assumes that the slew rate is the same for all mount axes. Args: other_destination: Another instance of this class Returns: An integer value representing the cost. """ smallest_encoder_errors = [] for axis, encoder_position in enumerate(self.encoder_positions): smallest_encoder_errors.append( smallest_allowed_error( encoder_position.deg, other_destination.encoder_positions[axis].deg, self.mount.no_cross_encoder_positions()[axis].deg)) max_error_mag = np.max(np.abs(smallest_encoder_errors)) # scale by 1000 to minimize precision loss when quantizing to integer return int(1000 * max_error_mag)
def test_vector_with_limit(self): error = smallest_allowed_error( mount_enc_position=np.array([1, 10, 10, 10], dtype=float), target_enc_position=np.array([2, 11, 90, -10], dtype=float), no_cross_position=0) assert_allclose(error, np.array([1, 1, 80, 340], dtype=float))
def test_vector(self): error = smallest_allowed_error( mount_enc_position=np.array([1, 2, 359], dtype=float), target_enc_position=np.array([2, 1, 0], dtype=float), ) assert_allclose(error, np.array([1, -1, 1]))
def test_wrapping(self): error = smallest_allowed_error(mount_enc_position=359.0, target_enc_position=0.0) assert_allclose(error, 1.0)
def test_negative_error(self): error = smallest_allowed_error(mount_enc_position=2.0, target_enc_position=1.0) assert_allclose(error, -1.0)