Exemplo n.º 1
0
 def test_normalize(self):
     self.assertAlmostEqual((1, 0, 0), normalize((1, 0, 0)))
     self.assertAlmostEqual((1, 0, 0), normalize((2, 0, 0)))
     self.assertAlmostEqual((1 / math.sqrt(2), 1 / math.sqrt(2), 0),
                            normalize((1, 1, 0)))
     self.assertAlmostEqual((1 / math.sqrt(2), 0, 1 / math.sqrt(2)),
                            normalize((1, 0, 1)))
Exemplo n.º 2
0
    def check(self, node, delta_v):
        self.assertAlmostEqual(delta_v[0], node.prograde, places=3)
        self.assertAlmostEqual(delta_v[1], node.normal, places=3)
        self.assertAlmostEqual(delta_v[2], node.radial, places=3)
        self.assertAlmostEqual(norm(delta_v), node.delta_v, places=3)
        self.assertAlmostEqual(norm(delta_v),
                               node.remaining_delta_v,
                               delta=0.2)

        bv = node.burn_vector(node.reference_frame)
        self.assertAlmostEqual(norm(delta_v), norm(bv), places=3)
        self.assertAlmostEqual((0, 1, 0), normalize(bv), places=3)

        orbital_bv = node.burn_vector(node.orbital_reference_frame)
        self.assertAlmostEqual(norm(delta_v), norm(orbital_bv), places=3)
        self.assertAlmostEqual((-delta_v[2], delta_v[0], delta_v[1]),
                               orbital_bv,
                               places=3)

        direction = node.direction(node.reference_frame)
        self.assertAlmostEqual((0, 1, 0), direction, places=3)
        orbital_direction = node.direction(node.orbital_reference_frame)
        self.assertAlmostEqual(normalize(
            (-delta_v[2], delta_v[0], delta_v[1])),
                               orbital_direction,
                               places=3)
Exemplo n.º 3
0
 def test_normalize(self):
     self.assertAlmostEqual((1, 0, 0), normalize((1, 0, 0)))
     self.assertAlmostEqual((1, 0, 0), normalize((2, 0, 0)))
     self.assertAlmostEqual((1/math.sqrt(2), 1/math.sqrt(2), 0),
                            normalize((1, 1, 0)))
     self.assertAlmostEqual((1/math.sqrt(2), 0, 1/math.sqrt(2)),
                            normalize((1, 0, 1)))
Exemplo n.º 4
0
 def test_set_magnitude(self):
     node = self.control.add_node(self.space_center.ut, 1, -2, 3)
     magnitude = 128
     node.delta_v = magnitude
     delta_v = vector(normalize((1, -2, 3))) * magnitude
     self.check(node, delta_v)
     node.remove()
Exemplo n.º 5
0
    def test_move_backward(self):
        self.control = self.space_center.active_vessel.control

        # Check the rover is stationary
        self.assertAlmostEqual(0, self.flight.horizontal_speed, delta=0.01)

        # Reverse throttle for 1 second
        self.control.wheel_steer = 0
        self.control.wheel_throttle = -0.5
        self.control.brakes = False
        self.wait(1)

        # Check the rover is moving south
        self.assertGreater(self.flight.horizontal_speed, 0)
        direction = normalize(self.flight.velocity)
        # In the body's reference frame, y-axis points
        # from the CoM to the north pole
        # As we are close to the equator,
        # this is very close to the north direction
        self.assertAlmostEqual((0, -1, 0), direction, delta=0.2)

        # Apply brakes
        self.control.wheel_throttle = 0.0
        self.control.brakes = True

        # Wait until the rover has stopped
        while self.flight.speed > 0.005:
            self.wait()
Exemplo n.º 6
0
 def test_set_magnitude(self):
     node = self.control.add_node(self.space_center.ut, 1, -2, 3)
     magnitude = 128
     node.delta_v = magnitude
     delta_v = vector(normalize((1, -2, 3))) * magnitude
     self.check(node, delta_v)
     node.remove()
Exemplo n.º 7
0
    def test_move_backward(self):
        self.control = self.space_center.active_vessel.control

        # Check the rover is stationary
        self.assertAlmostEqual(0, self.flight.horizontal_speed, delta=0.01)

        # Reverse throttle for 1 second
        self.control.wheel_steer = 0
        self.control.wheel_throttle = -0.5
        self.control.brakes = False
        self.wait(1)

        # Check the rover is moving south
        self.assertGreater(self.flight.horizontal_speed, 0)
        direction = normalize(self.flight.velocity)
        # In the body's reference frame, y-axis points
        # from the CoM to the north pole
        # As we are close to the equator,
        # this is very close to the north direction
        self.assertAlmostEqual((0, -1, 0), direction, delta=0.2)

        # Apply brakes
        self.control.wheel_throttle = 0.0
        self.control.brakes = True

        # Wait until the rover has stopped
        while self.flight.speed > 0.005:
            self.wait()
Exemplo n.º 8
0
    def test_set_direction(self):
        cases = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (-1, 0, 0), (0, -1, 0),
                 (0, 0, -1), (1, 2, 3)]

        for direction in cases:
            direction = normalize(direction)
            self.set_direction(direction)
            self.wait_for_autopilot()
            self.check_direction(direction)
Exemplo n.º 9
0
    def test_angular_velocity(self):
        for body in self.space_center.bodies.values():
            # Check body's angular velocity relative to itself is zero
            av = body.angular_velocity(body.reference_frame)
            self.assertAlmostEqual((0, 0, 0), av)

            # Check body's angular velocity relative to it's own non-rotating reference frame
            av = body.angular_velocity(body.non_rotating_reference_frame)
            self.assertAlmostEqual((0, -1, 0), normalize(av))
            self.assertAlmostEqual(body.rotational_speed, norm(av))
Exemplo n.º 10
0
    def check(self, node, delta_v):
        self.assertAlmostEqual(delta_v[0], node.prograde, places=3)
        self.assertAlmostEqual(delta_v[1], node.normal, places=3)
        self.assertAlmostEqual(delta_v[2], node.radial, places=3)
        self.assertAlmostEqual(norm(delta_v), node.delta_v, places=3)
        self.assertAlmostEqual(norm(delta_v), node.remaining_delta_v, delta=0.2)

        bv = node.burn_vector(node.reference_frame)
        self.assertAlmostEqual(norm(delta_v), norm(bv), places=3)
        self.assertAlmostEqual((0, 1, 0), normalize(bv), places=3)

        orbital_bv = node.burn_vector(node.orbital_reference_frame)
        self.assertAlmostEqual(norm(delta_v), norm(orbital_bv), places=3)
        self.assertAlmostEqual((-delta_v[2], delta_v[0], delta_v[1]), orbital_bv, places=3)

        direction = node.direction(node.reference_frame)
        self.assertAlmostEqual((0, 1, 0), direction, places=3)
        orbital_direction = node.direction(node.orbital_reference_frame)
        self.assertAlmostEqual(normalize((-delta_v[2], delta_v[0], delta_v[1])), orbital_direction, places=3)
Exemplo n.º 11
0
    def test_set_direction_and_roll(self):
        cases = [((1, 1, 0), 23), ((0, 1, 1), -75), ((1, 0, 1), 14),
                 ((-1, 0, 1), -83), ((0, -1, 1), -11), ((1, 0, -1), 2),
                 ((1, 2, 3), 42)]

        for direction, roll in cases:
            direction = normalize(direction)
            self.set_direction(direction, roll)
            self.wait_for_autopilot()
            self.check_direction(direction, roll)
Exemplo n.º 12
0
    def test_angular_velocity(self):
        for body in self.space_center.bodies.values():
            # Check body's angular velocity relative to itself is zero
            av = body.angular_velocity(body.reference_frame)
            self.assertAlmostEqual((0, 0, 0), av)

            # Check body's angular velocity relative to it's own non-rotating reference frame
            av = body.angular_velocity(body.non_rotating_reference_frame)
            self.assertAlmostEqual((0, -1, 0), normalize(av))
            self.assertAlmostEqual(body.rotational_speed, norm(av))
Exemplo n.º 13
0
    def check_speed(self, flight, ref):
        up = normalize(vector(self.vessel.position(ref))
                       - vector(self.vessel.orbit.body.position(ref)))
        v = self.vessel.velocity(ref)

        speed = norm(v)
        vertical_speed = dot(v, up)
        horizontal_speed = math.sqrt(speed*speed - vertical_speed*vertical_speed)

        self.assertAlmostEqual(speed, flight.speed, delta=0.5)
        self.assertAlmostEqual(vertical_speed, flight.vertical_speed, delta=0.5)
        self.assertAlmostEqual(horizontal_speed, flight.horizontal_speed, delta=0.5)
Exemplo n.º 14
0
    def check_speed(self, flight, ref):
        up = normalize(vector(self.vessel.position(ref)) -
                       vector(self.vessel.orbit.body.position(ref)))
        v = self.vessel.velocity(ref)

        speed = norm(v)
        vertical_speed = dot(v, up)
        horizontal_speed = math.sqrt(
            speed*speed - vertical_speed*vertical_speed)

        self.assertAlmostEqual(speed, flight.speed, delta=0.5)
        self.assertAlmostEqual(vertical_speed,
                               flight.vertical_speed, delta=0.5)
        self.assertAlmostEqual(horizontal_speed,
                               flight.horizontal_speed, delta=0.5)
Exemplo n.º 15
0
    def test_set_direction_and_roll(self):
        cases = [
            ((1, 1, 0), 23),
            ((0, 1, 1), -75),
            ((1, 0, 1), 14),
            ((-1, 0, 1), -83),
            ((0, -1, 1), -11),
            ((1, 0, -1), 2),
            ((1, 2, 3), 42)
        ]

        for direction, roll in cases:
            direction = normalize(direction)
            self.set_direction(direction, roll)
            self.wait_for_autopilot()
            self.check_direction(direction, roll)
Exemplo n.º 16
0
    def test_set_direction(self):
        cases = [
            (1, 0, 0),
            (0, 1, 0),
            (0, 0, 1),
            (-1, 0, 0),
            (0, -1, 0),
            (0, 0, -1),
            (1, 2, 3)
        ]

        for direction in cases:
            direction = normalize(direction)
            self.set_direction(direction)
            self.wait_for_autopilot()
            self.check_direction(direction)
Exemplo n.º 17
0
    def check_directions(self, flight):
        """ Check flight.direction against flight.heading and flight.pitch """
        direction = vector(flight.direction)
        up_direction = (1, 0, 0)
        north_direction = (0, 1, 0)
        self.assertAlmostEqual(1, norm(direction))

        # Check vessel direction vector agrees with pitch angle
        pitch = 90 - rad2deg(math.acos(dot(up_direction, direction)))
        self.assertAlmostEqual(pitch, flight.pitch, delta=2)

        # Check vessel direction vector agrees with heading angle
        up_component = dot(direction, up_direction) * vector(up_direction)
        north_component = normalize(vector(direction) - up_component)
        self.assertDegreesAlmostEqual(
            rad2deg(math.acos(dot(north_component, north_direction))),
            flight.heading, delta=1)
Exemplo n.º 18
0
    def test_flight_orbit_body_non_rotating_reference_frame(self):
        ref = self.vessel.orbit.body.non_rotating_reference_frame
        flight = self.vessel.flight(ref)
        self.check_properties_not_affected_by_reference_frame(flight)

        speed = 2245.75
        self.assertAlmostEqual(speed, norm(flight.velocity), delta=0.5)
        position = self.vessel.position(ref)
        direction = vector(cross(normalize(position), (0, 1, 0)))
        velocity = direction * speed
        self.assertAlmostEqual(tuple(velocity), flight.velocity, delta=2)
        self.assertAlmostEqual(speed, flight.speed, delta=0.5)
        self.assertAlmostEqual(speed, flight.horizontal_speed, delta=0.5)
        self.assertAlmostEqual(0, flight.vertical_speed, delta=0.5)

        self.check_speeds(flight)
        self.check_orbital_vectors(flight)
Exemplo n.º 19
0
 def test_transform_direction_same_reference_frame(self):
     direction = normalize((1, 2, 3))
     self.assertAlmostEqual(
         direction,
         self.sc.transform_direction(direction, self.ref_vessel,
                                     self.ref_vessel))
Exemplo n.º 20
0
 def test_transform_direction_same_reference_frame(self):
     direction = normalize((1, 2, 3))
     self.assertAlmostEqual(
         direction,
         self.sc.transform_direction(
             direction, self.ref_vessel, self.ref_vessel))