Ejemplo n.º 1
0
class PathPlannerTest(unittest.TestCase):
    def setUp(self):
        self.path_planner = PathPlanner()
        # will need a map:
        map_maker = MapMaker()
        map_maker.set_map()
        map_maker.calibrate_map()
        lowres_map = map_maker.get_lowres_map()

        self.path_planner.set_map(lowres_map)
        self.path_planner.set_start_node()
        self.path_planner.set_end_node()

    '''
    Function: 
    Tests:
    Calls:
    Notes:
    '''

    def testCalculate_angular_movement(self):
        # Test different movements for different start and end angles in pi/4 incerements

        # if you start at 0 and have increasing targets, these are the correct movements. You can shift back one each time you increase the starting angle
        correct_movements = [
            0, -pi / 4, -pi / 2, -pi * (3 / 4), -pi, pi * (3 / 4), pi / 2,
            pi / 4
        ]

        for i in range(0, 8):
            # Test targets from 0 to 2pi in pi/4 increments
            target = pi * i / 4
            print("TARGET PI * {}/4".format(i))
            for j in range(0, 8):
                # Test starting place from 0 to 2pi for each target
                current = pi * (j / 4)
                movement = self.path_planner.calculate_angular_movement(
                    current, target)
                self.assertEqual(correct_movements[j - i], movement)

    def testPos_from_coordinates(self):
        coord_zero = [0, 0]
        predicted_pos = self.path_planner.pos_from_coordinates(coord_zero)
        pos_zero = [0, 0]

        self.assertEqual(predicted_pos, pos_zero)
Ejemplo n.º 2
0
class RoverMovementTest():
    def __init__(self):
        self.path_planner = PathPlanner()

        # will need a map:
        map_maker = MapMaker()
        map_maker.set_map()
        map_maker.calibrate_map()
        lowres_map = map_maker.get_lowres_map()
        self.path_planner.set_map(lowres_map)

    def width_test(self, test=False):
        # create path along bottom of map (left to right)
        # assume rover placed parallel to x axis, moving positive (angle 0)
        path = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0]]
        for i in range(0, len(path)):
            path[i] = self.path_planner.pos_from_coordinates(path[i])
        self.path_planner.path = path
        self.path_planner.start_node = Node(pos=self.path_planner.path[0])
        self.path_planner.end_node = Node(pos=self.path_planner.path[-1])

        current_coord = self.path_planner.coordinates_from_pos(
            self.path_planner.start_node.pos)
        current_angle = 0

        while len(self.path_planner.path) > 1:
            if test:
                message, current_coord, current_angle = self.path_planner.get_action(
                    current_coord, current_angle, test=True)
                print(message +
                      " STEPS LEFT:{}".format(len(self.path_planner.path)))
            else:
                message = self.path_planner.get_action(current_coord,
                                                       current_angle,
                                                       test=False)
                print("PathPlanner: Message sent")
        return

    def one_step_test(self, test=False):
        path = [[0, 0], [1, 0]]
        for i in range(0, len(path)):
            path[i] = self.path_planner.pos_from_coordinates(path[i])
        self.path_planner.path = path
        self.path_planner.start_node = Node(pos=self.path_planner.path[0])
        self.path_planner.end_node = Node(pos=self.path_planner.path[-1])

        current_coord = self.path_planner.coordinates_from_pos(
            self.path_planner.start_node.pos)
        current_angle = 0

        if test:
            message, current_coord, current_angle = self.path_planner.get_action(
                current_coord, current_angle, test=True)
            print(message +
                  " STEPS LEFT:{}".format(len(self.path_planner.path)))
        else:
            message = self.path_planner.get_action(current_coord,
                                                   current_angle,
                                                   test=False)
            print("PathPlanner: Message sent")

        return