def generate_commands(program,
                      drone_config_map: Dict[str, DroneConfig] = None,
                      boundary_checker: BoundaryChecker = None,
                      collision_checker: CollisionChecker = None,
                      has_checks: bool = True,
                      symbol_table: SymbolTable = None,
                      function_table: FunctionTable = None):
    if drone_config_map is None:
        drone_config_map = {"DEFAULT": DefaultDroneConfig()}
    if boundary_checker is None:
        boundary_checker = BoundaryChecker(BoundaryConfig.no_limit())
    if collision_checker is None:
        collision_checker = CollisionChecker(drone_config_map,
                                             DefaultCollisionConfig())
    if symbol_table is None:
        symbol_table = SymbolTable()
    if function_table is None:
        function_table = FunctionTable()
    state_updater_map = {
        name: StateUpdater(config)
        for name, config in drone_config_map.items()
    }

    tree = _parse_program(program)

    drone_commands = Compiler(drone_config_map, symbol_table,
                              function_table).visit(tree)

    if has_checks:
        boundary_checker.check(drone_commands, state_updater_map)
        collision_checker.check(drone_commands, state_updater_map)

    return drone_commands
Example #2
0
 def test_check_should_call_update_states_and_check_drone_commands_with_correct_parameters(
         self):
     boundary_checker = BoundaryChecker(self.boundary_config)
     boundary_checker._update_states_and_check_drone_commands = Mock()
     drone_state_map = {"DRONE1": State(), "DRONE2": State(x_meters=1)}
     drones_involved = {"DRONE1", "DRONE2"}
     boundary_checker.check([], self.state_updater_map)
     boundary_checker._update_states_and_check_drone_commands.assert_called_once_with(
         [], self.state_updater_map, drone_state_map, drones_involved)