def test_gps_serial_connect_failure(): gps_object = GPS(fakeconfig) gps_object.start() # let process attempt to start... sleep(0.5) # verify there was an exception raised by the process assert isinstance(gps_object.get_raised_exception(), Exception)
def test_gps_is_minimally_not_overlapping(): gps = GPS(config) overlap = config["gps"]["minimum_overlap"] * 1.0001 gps.current_coordinate = Coordinate(30.0000, -80.0000) test_coordinates = [] test_coordinates.append(Coordinate(30.0000 + overlap, -80.0000)) test_coordinates.append(Coordinate(30.0000 - overlap, -80.0000)) test_coordinates.append(Coordinate(30.0000, -80.0000 - overlap)) test_coordinates.append(Coordinate(30.0000, -80.0000 + overlap)) for coordinate in test_coordinates: print(coordinate) assert not gps.is_overlapping(coordinate)
def test_gps_is_minimally_overlapping(): gps = GPS(config) # make overlap marginally smaller to account for float math error overlap = config["gps"]["minimum_overlap"] * 0.9999 gps.current_coordinate = Coordinate(30.0000, -80.0000) test_coordinates = [] test_coordinates.append(Coordinate(30.0000 + overlap, -80.0000)) test_coordinates.append(Coordinate(30.0000 - overlap, -80.0000)) test_coordinates.append(Coordinate(30.0000, -80.0000 - overlap)) test_coordinates.append(Coordinate(30.0000, -80.0000 + overlap)) for coordinate in test_coordinates: print(coordinate) assert gps.is_overlapping(coordinate)
def test_gps_angles_make_sense(): gps = GPS(config) gps.current_coordinate = Coordinate(35.0000, 85.0000) test_fixtures = [] test_fixtures.append((Coordinate(35.0000, 86.0000), 90)) # desired is East test_fixtures.append((Coordinate(36.0000, 86.0000), 45)) # desired is North-East test_fixtures.append((Coordinate(36.0000, 85.0000), 0)) # desired is North test_fixtures.append((Coordinate(36.0000, 84.0000), -45)) # desired is North-West test_fixtures.append((Coordinate(35.0000, 84.0000), -90)) # desired is West test_fixtures.append((Coordinate(34.0000, 84.0000), -135)) # desired is South-West test_fixtures.append((Coordinate(34.0000, 85.0000), 180)) # desired is South test_fixtures.append((Coordinate(34.0000, 86.0000), 135)) # desired is South-East test_fixtures.append((Coordinate(35.0000, 85.0000), 0)) # desired is Unchanged for coordinate, expected_angle in test_fixtures: calculated_angle = gps.calculate_angle_to_node(coordinate) print("calc: {}, expect: {}".format(calculated_angle, expected_angle)) assert calculated_angle == expected_angle
def create_objects(config): # initialize nodelist nodelist = Nodelist(config) # start all processes gps = GPS(config) compass = Compass(config) arduino = ArduinoComm(config) gps.start() compass.start() arduino.start() # wait for arduino to be ready arduino.wait_for_readiness() # wait for gps to be fixed print("waiting for gps fix...") gps.wait_for_fix() if not (gps.is_properly_alive() and compass.is_properly_alive() and arduino.is_properly_alive()): print("Exception ({}): {}".format("GPS", gps.get_raised_exception())) print("Exception ({}): {}".format("COMPASS", compass.get_raised_exception())) print("Exception ({}): {}".format("ARDUINO", arduino.get_raised_exception())) # stop all processes gps.stop() compass.stop() arduino.stop() print("done now!") exit() print("gps fix found!") # wait for go button to be pressed print("waiting for go button press...") arduino.wait_for_button_press() print("go button pressed!") # get the first node node = nodelist.get_next_node() while not nodelist.all_nodes_visited() and gps.is_properly_alive( ) and compass.is_properly_alive() and arduino.is_properly_alive(): # if at coordinate, get next node and start from top of loop if gps.is_overlapping(node): node = nodelist.get_next_node() continue desiredHeading = gps.get_desired_heading(compass.get_heading(), node) print(node.get_coordinate()) print(gps.get_location()) print(gps.calculate_angle_to_node(node.get_coordinate())) print(compass.get_heading()) print("Desired: {}".format(desiredHeading)) arduino.commandTurn(desiredHeading) sleep(0.1) arduino.commandForward(node.get_throttle()) sleep(0.1) # stop car for i in range(0, 10): arduino.commandReset() sleep(0.005) sleep(2) # print possible exceptions print("Exception ({}): {}".format("GPS", gps.get_raised_exception())) print("Exception ({}): {}".format("COMPASS", compass.get_raised_exception())) print("Exception ({}): {}".format("ARDUINO", arduino.get_raised_exception())) # stop all processes gps.stop() compass.stop() arduino.stop() print("done now!")
def node_terminal(config): # start gps gps = GPS(config) gps.start() # start user input thread userInput = UserInput() userInput.start() # wait for gps to be fixed print("waiting for gps fix...") gps.wait_for_fix() print("gps fix found!") gpslist = [] while gps.is_properly_alive(): user_inp = userInput.returnMessage() if user_inp is not None: user_inp = user_inp.lower() if user_inp == "exit": break elif user_inp == "walk": gpslist = walkForNodes(gps) elif user_inp == "a": gpslist.append(gps.get_location()) elif user_inp == "s": pass elif user_inp == "c": pass sleep(0.2) gps.stop() userInput.stop() if gps.get_raised_exception() is not None: print(gps.get_raised_exception()) for item in gpslist: print item
def test_gps_is_not_overlapping(): gps = GPS(config) overlap = config["gps"]["minimum_overlap"] * 2 gps.current_coordinate = Coordinate(30.0000, -80.0000) test_coordinate = Coordinate(30.0000 + overlap, -80.0000) assert not gps.is_overlapping(test_coordinate)
def test_gps_is_maximally_overlapping(): gps = GPS(config) gps.current_coordinate = Coordinate(30.0000, -80.0000) test_coordinate = Coordinate(30.0000, -80.0000) assert gps.is_overlapping(test_coordinate)
def test_create_gps_object(): gps_object = GPS(fakeconfig) assert isinstance(gps_object, GPS)
def test_gps_relative_angle_to_goal(): gps = GPS(config) gps.current_coordinate = Coordinate(35.0000, 85.0000) test_fixtures = [] # Goal is to the East test_fixtures.append((Coordinate(35.0000, 86.0000), 90, 0)) # facing East test_fixtures.append((Coordinate(35.0000, 86.0000), 45, 45)) # facing North-East test_fixtures.append((Coordinate(35.0000, 86.0000), 0, 90)) # facing North test_fixtures.append((Coordinate(35.0000, 86.0000), -45, 135)) # facing North-West test_fixtures.append((Coordinate(35.0000, 86.0000), -90, 180)) # facing West test_fixtures.append( (Coordinate(35.0000, 86.0000), -135, -135)) # facing South-West test_fixtures.append((Coordinate(35.0000, 86.0000), 180, -90)) # facing South test_fixtures.append((Coordinate(35.0000, 86.0000), 135, -45)) # facing South-East # Goal is to the North test_fixtures.append((Coordinate(36.0000, 85.0000), 90, -90)) # facing East test_fixtures.append((Coordinate(36.0000, 85.0000), 45, -45)) # facing North-East test_fixtures.append((Coordinate(36.0000, 85.0000), 0, 0)) # facing North test_fixtures.append((Coordinate(36.0000, 85.0000), -45, 45)) # facing North-West test_fixtures.append((Coordinate(36.0000, 85.0000), -90, 90)) # facing West test_fixtures.append((Coordinate(36.0000, 85.0000), -135, 135)) # facing South-West test_fixtures.append((Coordinate(36.0000, 85.0000), 180, 180)) # facing South test_fixtures.append((Coordinate(36.0000, 85.0000), 135, -135)) # facing South-East # Goal is to the West test_fixtures.append((Coordinate(35.0000, 84.0000), 90, 180)) # facing East test_fixtures.append((Coordinate(35.0000, 84.0000), 45, -135)) # facing North-East test_fixtures.append((Coordinate(35.0000, 84.0000), 0, -90)) # facing North test_fixtures.append((Coordinate(35.0000, 84.0000), -45, -45)) # facing North-West test_fixtures.append((Coordinate(35.0000, 84.0000), -90, 0)) # facing West test_fixtures.append((Coordinate(35.0000, 84.0000), -135, 45)) # facing South-West test_fixtures.append((Coordinate(35.0000, 84.0000), 180, 90)) # facing South test_fixtures.append((Coordinate(35.0000, 84.0000), 135, 135)) # facing South-East # Goal is to the South test_fixtures.append((Coordinate(34.0000, 85.0000), 90, 90)) # facing East test_fixtures.append((Coordinate(34.0000, 85.0000), 45, 135)) # facing North-East test_fixtures.append((Coordinate(34.0000, 85.0000), 0, 180)) # facing North test_fixtures.append((Coordinate(34.0000, 85.0000), -45, -135)) # facing North-West test_fixtures.append((Coordinate(34.0000, 85.0000), -90, -90)) # facing West test_fixtures.append((Coordinate(34.0000, 85.0000), -135, -45)) # facing South-West test_fixtures.append((Coordinate(34.0000, 85.0000), 180, 0)) # facing South test_fixtures.append((Coordinate(34.0000, 85.0000), 135, 45)) # facing South-East # test if expectations are met for coordinate, heading, expected_angle in test_fixtures: calculated_angle = gps.get_desired_heading(heading, coordinate) print("calc: {}, expect: {}".format(calculated_angle, expected_angle)) assert calculated_angle == expected_angle