Exemplo n.º 1
0
  public void onFrame(Controller controller) {

    Frame currFrame = controller.frame();
    Frame prevFrame = controller.frame(1);

    // get orientation of palm to decide orientation of robotic arm
    Double currOrt = getPalmOrientation(currFrame);
    Double prevOrt = getPalmOrientation(prevFrame);

    // track index finger and thumb to determine arm grip movement
    Double currGripDist = getGripDistance(currFrame);
    Double prevGripDist = getGripDistance(prevFrame);

    // check for gripper locking
    gripperLocked = checkGripperLock(currFrame);

    // use the command interface to send updated position of
    // arm and gripper
    if (frameCount == MAX_FRAME_COUNT) {

      // Update arm position
      if (currOrt > 0 && prevOrt > 0) {
        Double delta = currOrt - prevOrt;
        if (Math.abs(delta) > 0.01) {
          Integer pos = (int) (ARM_RATIO * (currOrt - LEAP_PALM_LOW)) + ARM_LOW;
          if (pos >= ARM_LOW && pos <= ARM_HIGH) {
            commander.sendXbee(pos);
            System.out.println("Sending to arm: " + pos);
          }
        } else {
          // User is not moving palm, check for movement between
          // forefinger and thumb
          if (currGripDist > 0 && prevGripDist > 0 && !gripperLocked) {
            Double dGrip = currGripDist - prevGripDist;
            if (Math.abs(dGrip) > 0.1) {
              Integer pos = (int) (GRIP_RATIO * (currGripDist - LEAP_GRIP_LOW)) + GRIP_LOW;
              int mid = (GRIP_LOW + GRIP_HIGH) / 2;
              pos = mid - (pos - mid);
              if (pos >= GRIP_LOW && pos <= GRIP_HIGH) {
                commander.sendXbee(pos);
                System.out.println("Sending to gripper: " + pos);
              }
            }
          }
        }
      }
      frameCount = 0; // reset frame counter
    } else {
      frameCount++;
    }
  }
  public PacienteFrame(Paciente paciente) {
    super(
        paciente.getNombre()
            + " "
            + paciente.getApellido1()
            + " "
            + paciente.getApellido2()
            + " (Paciente)");
    this.paciente = paciente;
    this.crearAcciones();
    this.setSize(800, 600);
    this.setMinimumSize(new Dimension(800, 600));
    this.setLocation(50, 25);
    this.setJMenuBar(crearBarraMenu());
    this.getContentPane().add(crearToolBar(), BorderLayout.NORTH);
    this.getContentPane().add(crearPanelVentana(), BorderLayout.CENTER);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setVisible(true);

    gestor = new GestorMano();
    gestor.addObserver(this);

    leapListener = new LeapMotionListener(gestor);
    controlador = new Controller();

    controlador.addListener(leapListener);
  }
Exemplo n.º 3
0
  /**
   * Create a new board
   *
   * @param c
   */
  public Board(Game c) {
    // add leap motion controller
    leapAdapter = new SensorAdapter(c);
    sensorListener = new SensorListener(leapAdapter);
    shootListener = new ShootListener(leapAdapter);
    leapController = new Controller();
    leapController.addListener(sensorListener);
    leapController.addListener(shootListener);

    addKeyListener(new KeyboardAdapter(c, this));

    this.menu = new Menu(this, c);
    setFocusable(true);
    setDoubleBuffered(true);
    this.c = c;
    c.setPlayer(ItemFactory.createPlayer());
    c.setBackground(ItemFactory.createBackground());
  }
Exemplo n.º 4
0
  public static void recog(ArrayList<UserGesture> gestureList, Controller controller)
      throws IOException, InterruptedException, AWTException {
    System.out.println("started recog");

    long[] timer = new long[gestureList.size()];
    int[] matched = new int[gestureList.size()];

    int[] matched_attributes = new int[100];
    String[] gestureStatus = new String[100];

    while (MapperGUI.statusRecognizing == true) {

      Thread.sleep(5);
      frame = controller.frame();
      currentHand = frame.hands().get(0);
      for (int gestureIterator = 0; gestureIterator < gestureList.size(); gestureIterator++) {
        if (frame.hands().isEmpty()) break;
        if (matched[gestureIterator] == 0) {
          System.out.println("NEW STARTFRAME");
          //	if((startFrame.get(gestureIterator)))startFrame.remove(gestureIterator);
          startFrame.add(gestureIterator, frame);
          timer[gestureIterator] = System.currentTimeMillis();
        }
        // System.out.println("timer start"+timer);
        //	for (int nodeIterator = matched[gestureIterator] + 1; nodeIterator < gestureList
        //	.get(gestureIterator).NodeList.size();) {
        if (matched[gestureIterator] == gestureList.get(gestureIterator).NodeList.size() - 1) {
          Robot.execute(gestureIterator);

          // System.out.println("RECOGNITION SUCCESS for gesture number "+ gestureIterator + " ,
          // action goes here");

          if (Recorderv2.gestureList.get(Recorderv2.gestureCount - 1).cont == true) {
            matched[gestureIterator] = matched[gestureIterator] - 1;
            timer[gestureIterator] = System.currentTimeMillis();
            matched_attributes[gestureIterator] = 0;
          } else {
            matched[gestureIterator] = 0;
            timer[gestureIterator] = 0;
            matched_attributes[gestureIterator] = 0;
          }

          break;
        }

        currentNode =
            Recorderv2.gestureList.get(gestureIterator).NodeList.get(matched[gestureIterator]);
        if (System.currentTimeMillis() < (timer[gestureIterator] + 200)) {

          if (gestureList.get(gestureIterator).attributes.contains("XY")) {
            if ((currentHand.palmPosition().getX()
                        - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX())
                    < currentNode.hand0_x_denorm + deviationX
                && (currentHand.palmPosition().getX()
                        - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX())
                    > currentNode.hand0_x_denorm - deviationX
                && (currentHand.palmPosition().getY()
                        - startFrame.get(gestureIterator).hands().get(0).palmPosition().getY())
                    < currentNode.hand0_y_denorm + deviationY
                && (currentHand.palmPosition().getY()
                        - startFrame.get(gestureIterator).hands().get(0).palmPosition().getY())
                    > currentNode.hand0_y_denorm - deviationY) {
              // System.out.println(frame.hands().get(0).palmPosition().normalized());
              matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1;
            }
          }
          if (gestureList.get(gestureIterator).attributes.contains("XZ")) {
            if ((currentHand.palmPosition().getX()
                        - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX())
                    < currentNode.hand0_x_denorm + deviationX
                && (currentHand.palmPosition().getX()
                        - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX())
                    > currentNode.hand0_x_denorm - deviationX
                && (currentHand.palmPosition().getZ()
                        - startFrame.get(gestureIterator).hands().get(0).palmPosition().getZ())
                    < currentNode.hand0_z_denorm + deviationZ
                && (currentHand.palmPosition().getZ()
                        - startFrame.get(gestureIterator).hands().get(0).palmPosition().getZ())
                    > currentNode.hand0_z_denorm - deviationZ) {
              // System.out.println(frame.hands().get(0).palmPosition().normalized());
              matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1;
            }
          }

          if (gestureList.get(gestureIterator).attributes.contains("frontmost_finger_XY")) {
            if ((currentHand.fingers().frontmost().tipPosition().getX()
                        - startFrame
                            .get(gestureIterator)
                            .hands()
                            .get(0)
                            .fingers()
                            .frontmost()
                            .tipPosition()
                            .getX())
                    < currentNode.hand0_frontmost_x + deviationX
                && (currentHand.fingers().frontmost().tipPosition().getX()
                        - startFrame
                            .get(gestureIterator)
                            .hands()
                            .get(0)
                            .fingers()
                            .frontmost()
                            .tipPosition()
                            .getX())
                    > currentNode.hand0_frontmost_x - deviationX
                && (currentHand.fingers().frontmost().tipPosition().getY()
                        - startFrame
                            .get(gestureIterator)
                            .hands()
                            .get(0)
                            .fingers()
                            .frontmost()
                            .tipPosition()
                            .getY())
                    < currentNode.hand0_frontmost_y + deviationY
                && (currentHand.fingers().frontmost().tipPosition().getY()
                        - startFrame
                            .get(gestureIterator)
                            .hands()
                            .get(0)
                            .fingers()
                            .frontmost()
                            .tipPosition()
                            .getY())
                    > currentNode.hand0_frontmost_y - deviationY) {
              // System.out.println(frame.hands().get(0).palmPosition().normalized());
              matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1;
            }
          }
          if (gestureList.get(gestureIterator).attributes.contains("frontmost_finger_XZ")) {
            if ((currentHand.fingers().frontmost().tipPosition().getX()
                        - startFrame
                            .get(gestureIterator)
                            .hands()
                            .get(0)
                            .fingers()
                            .frontmost()
                            .tipPosition()
                            .getX())
                    < currentNode.hand0_frontmost_x + deviationX
                && (currentHand.fingers().frontmost().tipPosition().getX()
                        - startFrame
                            .get(gestureIterator)
                            .hands()
                            .get(0)
                            .fingers()
                            .frontmost()
                            .tipPosition()
                            .getX())
                    > currentNode.hand0_frontmost_x - deviationX
                && (currentHand.fingers().frontmost().tipPosition().getZ()
                        - startFrame
                            .get(gestureIterator)
                            .hands()
                            .get(0)
                            .fingers()
                            .frontmost()
                            .tipPosition()
                            .getZ())
                    < currentNode.hand0_frontmost_z + deviationZ
                && (currentHand.fingers().frontmost().tipPosition().getZ()
                        - startFrame
                            .get(gestureIterator)
                            .hands()
                            .get(0)
                            .fingers()
                            .frontmost()
                            .tipPosition()
                            .getZ())
                    > currentNode.hand0_frontmost_z - deviationZ) {
              // System.out.println(frame.hands().get(0).palmPosition().normalized());
              matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1;
            }
          }

          if (gestureList.get(gestureIterator).attributes.contains("roll")) {
            if ((currentHand.palmNormal().roll()
                        - startFrame.get(gestureIterator).hands().get(0).palmNormal().roll())
                    < currentNode.hand0_roll + deviationRoll
                && (currentHand.palmNormal().roll()
                        - startFrame.get(gestureIterator).hands().get(0).palmNormal().roll())
                    > currentNode.hand0_roll - deviationRoll) {
              // System.out.println(frame.hands().get(0).palmPosition().normalized());
              matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1;
            }
          }
          if (gestureList.get(gestureIterator).attributes.contains("yaw")) {
            if ((currentHand.palmNormal().yaw()
                        - startFrame.get(gestureIterator).hands().get(0).palmNormal().yaw())
                    < currentNode.hand0_yaw + deviationYaw
                && (currentHand.palmNormal().yaw()
                        - startFrame.get(gestureIterator).hands().get(0).palmNormal().yaw())
                    > currentNode.hand0_yaw - deviationYaw) {
              // System.out.println(frame.hands().get(0).palmPosition().normalized());
              matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1;
            }
          }

          if (gestureList.get(gestureIterator).attributes.contains("pitch")) {
            if ((currentHand.palmNormal().pitch()
                        - startFrame.get(gestureIterator).hands().get(0).palmNormal().pitch())
                    < currentNode.hand0_pitch + deviationPitch
                && (currentHand.palmNormal().pitch()
                        - startFrame.get(gestureIterator).hands().get(0).palmNormal().pitch())
                    > currentNode.hand0_pitch - deviationPitch) {
              // System.out.println(frame.hands().get(0).palmPosition().normalized());
              matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1;
            }
          }
          if (matched_attributes[gestureIterator]
                  == Recorderv2.gestureList.get(gestureIterator).attributes.size()
              && matched_attributes[gestureIterator] != 0) {

            matched[gestureIterator] = matched[gestureIterator] + 1;
            timer[gestureIterator] = System.currentTimeMillis() + 200;
            matched_attributes[gestureIterator] = 0;
            System.out.println(
                "matched node number "
                    + matched[gestureIterator]
                    + " of gesture "
                    + gestureIterator
                    + " with "
                    + gestureList
                        .get(gestureIterator)
                        .NodeList
                        .get(matched[gestureIterator])
                        .hand0_x_denorm
                    + "with "
                    + (frame.hands().get(0).palmPosition().getX()
                        - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX()));

          } else {
            matched_attributes[gestureIterator] = 0;
          }

        } else {
          matched_attributes[gestureIterator] = 0;
          matched[gestureIterator] = 0;
          timer[gestureIterator] = 0;
        }

        //	}

      }

      if (MapperGUI.statusRecognizing == false) break;
    }

    System.out.println("stopped recog");
    // MapperGUI.runningRecognizing = false;

    return;
  }
Exemplo n.º 5
0
  public void onFrame(Controller controller) {

    currentFrame = controller.frame();

    boolean handsFlipped = false;

    for (int i = 0; i < 2; i++) {
      currentHand = currentFrame.hands().get(i);
      if (currentHand.isValid()) {

        for (int n = 0; n < 2; n++) {
          if (currentHand.id() == handIds[n] && n != i) handsFlipped = true;
        }

        int num = i;
        if (handsFlipped) num = ((num == 0) ? 1 : 0);

        hands[num] = currentHand;
        handIds[num] = currentHand.id();

        if (!currentHand.tools().empty()) {
          tools[num] = currentHand.tools().get(0);
        }

        FingerList fings = currentHand.fingers();

        if (fings.count() >= 3) handOpen[num] = true;
        else handOpen[num] = false;

        for (int f = 0; f < 5; f++) {
          if (f < fings.count()) {
            Finger finger = fings.get(f);
            fingers[f + (5 * num)] = finger;
          } else fingers[f + (5 * num)] = new Finger();
        }

      } else {
        int num = i;
        if (handsFlipped) num = ((num == 0) ? 1 : 0);
        hands[num] = new Hand();
        handOpen[num] = false;
      }
    }

    if (isConnected) {

      data = new StringBuilder();

      for (int i = 0; i < hands.length; i++) {
        if (OS.contains("Linux")) {
          data.append(HAND_NAMES[i] + "-x " + Math.round(hands[i].palmPosition().getX()) + "\n");
          data.append(
              HAND_NAMES[i]
                  + "-y "
                  + Math.round((hands[i].palmPosition().getY() - 220) * 1.6)
                  + "\n");
          data.append(HAND_NAMES[i] + "-z " + Math.round(hands[i].palmPosition().getZ()) + "\n");
        } else {
          data.append(
              HAND_NAMES[i] + "-x " + Math.round(hands[i].stabilizedPalmPosition().getX()) + "\n");
          data.append(
              HAND_NAMES[i]
                  + "-y "
                  + Math.round((hands[i].stabilizedPalmPosition().getY() - 220) * 1.6)
                  + "\n");
          data.append(
              HAND_NAMES[i] + "-z " + Math.round(hands[i].stabilizedPalmPosition().getZ()) + "\n");
        }
        data.append(HAND_NAMES[i] + "-visible " + hands[i].isValid() + "\n");
        data.append(HAND_NAMES[i] + "-open " + handOpen[i] + "\n");
      }

      for (int i = 0; i < fingers.length; i++) {
        data.append(
            FINGER_NAMES[i] + "-x " + Math.round(fingers[i].stabilizedTipPosition().getX()) + "\n");
        data.append(
            FINGER_NAMES[i]
                + "-y "
                + Math.round((fingers[i].stabilizedTipPosition().getY() - 220) * 1.6)
                + "\n");
        data.append(
            FINGER_NAMES[i] + "-z " + Math.round(fingers[i].stabilizedTipPosition().getZ()) + "\n");
        data.append(FINGER_NAMES[i] + "-visible " + fingers[i].isValid() + "\n");
      }

      for (int i = 0; i < tools.length; i++) {
        data.append(
            TOOL_NAMES[i] + "-x " + Math.round(tools[i].stabilizedTipPosition().getX()) + "\n");
        data.append(
            TOOL_NAMES[i]
                + "-y "
                + Math.round((tools[i].stabilizedTipPosition().getY() - 220) * 1.6)
                + "\n");
        data.append(
            TOOL_NAMES[i] + "-z " + Math.round(tools[i].stabilizedTipPosition().getZ()) + "\n");
        data.append(TOOL_NAMES[i] + "-visible " + tools[i].isValid() + "\n");
      }
    }
  }