public void controlState() {
    final Mat image = camera.getLastFrame();
    final ComputerVisionSummary summaryOfImage = ComputerVisionSummary.produceFullSummary(image);

    final double wallThresholdDistance = 10;

    // if wall is close, and we are not currently avoiding walls, then avoid walls
    if ((summaryOfImage.getDistanceToBlueWall() <= wallThresholdDistance)
        && !(currentStateController.getStateMachineType() == StateMachineType.AVOID_WALLS
            && !currentStateController.isDone())) {
      avoidWalls();
    }

    // else if see ball, and not currently collecting one, then collect ball
    else if ((summaryOfImage.isGreenBall() || summaryOfImage.isRedBall())
        && !(currentStateController.getStateMachineType() == StateMachineType.COLLECT_GROUND_BALLS
            && !currentStateController.isDone())) {
      collectGroundBalls();
    }

    // if see reactor and have green balls then score
    // if see interface wall and have red balls then score over wall
    // if see energy silo then collect ball

  }
  private void avoidWalls() {
    currentStateController.stop();
    final AvoidWallStateController avoidWallController = new AvoidWallStateController(robotModel);

    currentStateController = avoidWallController;

    Thread avoidWallThread =
        new Thread(
            new Runnable() {
              public void run() {
                avoidWallController.controlState();
              }
            });

    avoidWallThread.start();
  }
  private void collectGroundBalls() {
    currentStateController.stop();
    final BallCollectionStateController ballCollectionController =
        new BallCollectionStateController(robotModel, camera);

    currentStateController = ballCollectionController;

    Thread ballCollectionThread =
        new Thread(
            new Runnable() {
              public void run() {
                while (!ballCollectionController.isDone()) {
                  ballCollectionController.controlState();
                }
              }
            });

    ballCollectionThread.start();
  }
Пример #4
0
  public static void main(String[] args) {

    StateMachine<MotekContext> stateMachineOne = GetIvrStateMachine();
    // step call started welcome msg played
    MotekContext contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", "call"));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());

    // welcome msg played and new UserMenu given
    contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", ""));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());

    // help option chosen and help sent
    contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", "1"));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());

    // help played and lesson one sent
    contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", ""));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());

    // lesson one played and lesson menu played
    contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", ""));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());

    // lesson two selected played and lesson two sent
    contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", "2"));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());

    // played lesson two  and lesson menu provided
    contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", ""));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());

    // lesson three selected and lesson three sent
    contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", "2"));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());

    // played lesson three played  and sent chapter finished
    contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", ""));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());

    // played chapter finished and sent course finished text
    contextOne = new MotekContext();
    contextOne.setRequest(new MotekRequest("9880202527", ""));
    stateMachineOne.move(contextOne);
    System.out.println(contextOne.getResponse().getMessage());
  }