def test_move_backward(self): self.control = self.conn.space_center.active_vessel.control # Check the rover is stationary self.assertClose(0, self.flight.horizontal_speed) # Reverse throttle for 1 second self.control.wheel_steer = 0 self.control.wheel_throttle = -0.5 self.control.brakes = False time.sleep(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 CoM to north pole # As we are close to the equator, this is very close to the north direction self.assertClose((0,-1,0), direction, 0.2) # Apply brakes self.control.wheel_throttle = 0 self.control.brakes = True time.sleep(5) # Check the rover is stopped self.assertClose(self.flight.horizontal_speed, 0)
def test_move_backward(self): self.control = self.conn.space_center.active_vessel.control # Check the rover is stationary self.assertClose(0, self.flight.horizontal_speed) # Reverse throttle for 1 second self.control.wheel_steer = 0 self.control.wheel_throttle = -0.5 self.control.brakes = False time.sleep(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 CoM to north pole # As we are close to the equator, this is very close to the north direction self.assertClose((0, -1, 0), direction, 0.2) # Apply brakes self.control.wheel_throttle = 0 self.control.brakes = True time.sleep(5) # Check the rover is stopped self.assertClose(self.flight.horizontal_speed, 0)
def test_set_magnitude(self): node = self.control.add_node(self.conn.space_center.ut, 1, -2, 3) magnitude = 128 node.delta_v = magnitude v = vector(normalize([1,-2,3])) * magnitude self.check(node, v) node.remove()
def test_set_magnitude(self): node = self.control.add_node(self.conn.space_center.ut, 1, -2, 3) magnitude = 128 node.delta_v = magnitude v = normalize([1,-2,3]) * magnitude self.check(node, v) node.remove()
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)
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)
def check(self, node, deltav): self.assertClose(deltav[0], node.prograde) self.assertClose(deltav[1], node.normal) self.assertClose(deltav[2], node.radial) self.assertClose(norm(deltav), node.delta_v) self.assertClose(norm(deltav), node.remaining_delta_v, 0.2) bv = node.burn_vector(node.reference_frame) self.assertClose(norm(deltav), norm(bv)) self.assertClose((0,1,0), normalize(bv)) orbital_bv = node.burn_vector(node.orbital_reference_frame) self.assertClose(norm(deltav), norm(orbital_bv)) self.assertClose((-deltav[2],deltav[0],deltav[1]), orbital_bv) d = node.direction(node.reference_frame) self.assertClose((0,1,0), d) orbital_d = node.direction(node.orbital_reference_frame) self.assertClose(normalize((-deltav[2],deltav[0],deltav[1])), orbital_d)
def test_angular_velocity(self): for body in self.conn.space_center.bodies.values(): # Check body's angular velocity relative to itself is zero av = body.angular_velocity(body.reference_frame) self.assertClose((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.assertClose((0,-1,0), normalize(av)) self.assertClose(body.rotational_speed, norm(av))
def test_angular_velocity(self): for body in self.conn.space_center.bodies.values(): # Check body's angular velocity relative to itself is zero av = body.angular_velocity(body.reference_frame) self.assertClose((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.assertClose((0, -1, 0), normalize(av)) self.assertClose(body.rotational_speed, norm(av))
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 = speed - abs(vertical_speed) self.assertClose(speed, flight.speed, error=0.5) self.assertClose(vertical_speed, flight.vertical_speed, error=0.5) self.assertClose(horizontal_speed, flight.horizontal_speed, error=0.5)
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.assertClose(speed, flight.speed, error=0.5) self.assertClose(vertical_speed, flight.vertical_speed, error=0.5) self.assertClose(horizontal_speed, flight.horizontal_speed, error=0.5)
def test_basic_direction(self): direction = normalize([10,20,30]) roll = 42 self.vessel.control.sas = False self.ap.set_direction(direction, roll=roll) while self.ap.error > 0.1: time.sleep(0.25) self.vessel.control.sas = True self.ap.disengage() flight = self.vessel.flight() self.assertClose(vector(direction), vector(flight.direction), error=0.1) self.assertClose(roll, flight.roll, error=0.5)
def test_set_direction(self): cases = [ ((1,0,0), 0), ((0,1,0), 0), ((0,0,1), 0), ((-1,0,0), 0), ((0,-1,0), 0), ((0,0,-1), 0), ((1,2,3), 42) ] for direction,roll in cases: direction = normalize(direction) self.set_direction(direction,roll) self.check_direction(direction,roll)
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.check_direction(direction,roll)
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.check_direction(direction)
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.assertClose(1, norm(direction)) # Check vessel direction vector agrees with pitch angle pitch = 90 - rad2deg(math.acos(dot(up_direction, direction))) self.assertClose(flight.pitch, pitch, error=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.assertCloseDegrees(flight.heading, rad2deg(math.acos(dot(north_component, north_direction))), error=1)
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 = 2246.1 self.assertClose(speed, norm(flight.velocity), error=0.5) position = self.vessel.position(ref) direction = vector(cross(normalize(position), (0,1,0))) velocity = direction * speed self.assertClose(velocity, flight.velocity, error=2) self.assertClose(speed, flight.speed, error=0.5) self.assertClose(speed, flight.horizontal_speed, error=0.5) self.assertClose(0, flight.vertical_speed, error=0.5) self.check_speeds(flight) self.check_orbital_vectors(flight)
def test_transform_direction_same_reference_frame(self): d = normalize((1,2,3)) self.assertClose(d, self.sc.transform_direction(d, self.ref_vessel, self.ref_vessel))