Ejemplo n.º 1
0
inline void operator<<=(ssr::Orientation &dst, const Leap::Vector &src) {
  dst.pitch = src.pitch();
  dst.roll = src.roll();
  dst.yaw = src.yaw();
}
Ejemplo n.º 2
0
void LeapMotion_Listener::onFrame(const Controller& controller) {

	boolean debug = false;
	//std::cin.get();

	const float min_roll_left = 15.0f, max_roll_left = std::numeric_limits<float>::max();
	const float min_roll_right = std::numeric_limits<float>::lowest(), max_roll_right = -15.0f;
	
	const float min_pitch_up = 25.0f, max_pitch_up = std::numeric_limits<float>::max();
	const float min_pitch_down = std::numeric_limits<float>::lowest(), max_pitch_down = -5.0f;

	const float min_y_down = 0.0f, max_y_down = 70.0f;
	const float min_y_up = 190.0f, max_y_up = std::numeric_limits<float>::max();

	const float min_x_left = std::numeric_limits<float>::lowest(), max_x_left = -90.0f;
	const float min_x_right = 90.0f, max_x_right = std::numeric_limits<float>::max();

	//const float min_yaw_left_finger = std::numeric_limits<float>::lowest(), max_yaw_left_finger = -45.0f;
	//const float min_yaw_right_finger = 10.0f, max_yaw_right_finger = std::numeric_limits<float>::max();

	
	// Get the most recent frame and report some basic information
	const Frame frame = controller.frame();
	
	if (!frame.hands().isEmpty()) 
	{
		const Hand hand = frame.hands()[0];
		const Leap::Vector normal = hand.palmNormal();
		const Leap::Vector direction = hand.direction();
	
		const float pitch = direction.pitch() * RAD_TO_DEG;
		const float roll = normal.roll() * RAD_TO_DEG;
		const float yaw = direction.yaw() * RAD_TO_DEG;

		const float y_palm = hand.palmPosition().y;
		const float x_palm = hand.palmPosition().x;

		float x_drone = 0.0f, y_drone = 0.0f, z_drone = 0.0f, turn_drone = 0.0f;

		if(y_palm>min_y_down && y_palm<max_y_down)
			y_drone = -1.0f;
		else if(y_palm>min_y_up && y_palm<max_y_up)
			y_drone = 1.0f;

		if(x_palm>min_x_left && x_palm<max_x_left)
			turn_drone = -1.0f;
		else if(x_palm>min_x_right && x_palm<max_x_right)
			turn_drone = 1.0f;

		if(pitch>min_pitch_up && pitch<max_pitch_up)
			z_drone = 1.0f;
		else if(pitch>min_pitch_down && pitch<max_pitch_down)
			z_drone = -1.0f;

		if(roll>min_roll_right && roll< max_roll_right)
			x_drone = 1.0f;
		else if(roll>min_roll_left && roll< max_roll_left)
			x_drone = -1.0f;

		/*if(roll>min_yaw_left_finger && roll<max_yaw_left_finger)
			std::cout<<"turn_left";
		else if(roll>min_yaw_right_finger && roll<max_yaw_right_finger)
			std::cout<<"turn_right";
			*/

		if(x_drone != 0.0f || y_drone != 0.0f || z_drone != 0.0f || turn_drone != 0.0f)
		{
			int _speed_drone = 10;
			At_Command _command; 


			if(x_drone !=0.0f &&  z_drone != 0.0f)
			{
				float margin = 0.25f;
				(x_drone < 0)? x_drone += margin : x_drone -= margin;
				(z_drone < 0)? z_drone += margin : z_drone -= margin;
			}

			if(y_drone != 0.0f)
				_command = At_Command(0, y_drone, 0, 0, Point(_speed_drone, 100), _input_type);
			
			else if(turn_drone != 0.0f)
				_command = At_Command(0, 0, 0, turn_drone, Point(_speed_drone, 100),  _input_type);

			else
				_command = At_Command(x_drone, y_drone, z_drone, turn_drone, Point(_speed_drone, 100),  _input_type);

			_multiple_Input_Devices->prepare_to_send(_command);

			if(debug)
			{
				if(x_drone < 0.0f)
					cout<<"Go_Left ";
				else if(x_drone > 0.0f)
					cout<<"Go_Right ";

				if(y_drone > 0.0f)
					cout<<"UP ";
				else if(y_drone < 0.0f)
					cout<<"DOWN ";

				if(z_drone > 0.0f)
					cout<<"FW ";
				else if(z_drone < 0.0f)
					cout<<"BW ";

				if(turn_drone > 0.0f)
					cout<<"turn_Right ";
				else if(turn_drone < 0.0f)
					cout<<"Turn_Left ";
				std::cout<<std::endl;
			}
		}
	}	
}
Ejemplo n.º 3
0
void SampleListener::onFrame(const Leap::Controller& controller) {
  // Get the most recent frame and report some basic information
  const Leap::Frame frame = controller.frame();
  std::cout << "Frame id: " << frame.id()
            << ", timestamp: " << frame.timestamp()
            << ", hands: " << frame.hands().count()
            << ", extended fingers: " << frame.fingers().extended().count()
            << ", tools: " << frame.tools().count()
            << ", gestures: " << frame.gestures().count() << std::endl;

  Leap::HandList hands = frame.hands();
  for (Leap::HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
    // Get the first hand
    const Leap::Hand hand = *hl;
    std::string handType = hand.isLeft() ? "Left hand" : "Right hand";
    std::cout << std::string(2, ' ') << handType << ", id: " << hand.id()
              << ", palm position: " << hand.palmPosition() << std::endl;
    // Get the hand's normal vector and direction
    const Leap::Vector normal = hand.palmNormal();
    const Leap::Vector direction = hand.direction();

    // Calculate the hand's pitch, roll, and yaw angles
    std::cout << std::string(2, ' ') <<  "pitch: " << direction.pitch() * Leap::RAD_TO_DEG << " degrees, "
              << "roll: " << normal.roll() * Leap::RAD_TO_DEG << " degrees, "
              << "yaw: " << direction.yaw() * Leap::RAD_TO_DEG << " degrees" << std::endl;

    // Get the Arm bone
    Leap::Arm arm = hand.arm();
    std::cout << std::string(2, ' ') <<  "Arm direction: " << arm.direction()
              << " wrist position: " << arm.wristPosition()
              << " elbow position: " << arm.elbowPosition() << std::endl;

    // Get fingers
    const Leap::FingerList fingers = hand.fingers();
    for (Leap::FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
      const Leap::Finger finger = *fl;
      std::cout << std::string(4, ' ') <<  fingerNames[finger.type()]
                << " finger, id: " << finger.id()
                << ", length: " << finger.length()
                << "mm, width: " << finger.width() << std::endl;

      // Get finger bones
      for (int b = 0; b < 4; ++b) {
        Leap::Bone::Type boneType = static_cast<Leap::Bone::Type>(b);
        Leap::Bone bone = finger.bone(boneType);
        std::cout << std::string(6, ' ') <<  boneNames[boneType]
                  << " bone, start: " << bone.prevJoint()
                  << ", end: " << bone.nextJoint()
                  << ", direction: " << bone.direction() << std::endl;
      }
    }
  }

  // Get tools
  const Leap::ToolList tools = frame.tools();
  for (Leap::ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) {
    const Leap::Tool tool = *tl;
    std::cout << std::string(2, ' ') <<  "Tool, id: " << tool.id()
              << ", position: " << tool.tipPosition()
              << ", direction: " << tool.direction() << std::endl;
  }

  // Get gestures
  const Leap::GestureList gestures = frame.gestures();
  for (int g = 0; g < gestures.count(); ++g) {
    Leap::Gesture gesture = gestures[g];

    switch (gesture.type()) {
      case Leap::Gesture::TYPE_CIRCLE:
      {
        Leap::CircleGesture circle = gesture;
        std::string clockwiseness;

        if (circle.pointable().direction().angleTo(circle.normal()) <= Leap::PI/2) {
          clockwiseness = "clockwise";
        } else {
          clockwiseness = "counterclockwise";
        }

        // Calculate angle swept since last frame
        float sweptAngle = 0;
        if (circle.state() != Leap::Gesture::STATE_START) {
          Leap::CircleGesture previousUpdate = Leap::CircleGesture(controller.frame(1).gesture(circle.id()));
          sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * Leap::PI;
        }
        std::cout << std::string(2, ' ')
                  << "Circle id: " << gesture.id()
                  << ", state: " << stateNames[gesture.state()]
                  << ", progress: " << circle.progress()
                  << ", radius: " << circle.radius()
                  << ", angle " << sweptAngle * Leap::RAD_TO_DEG
                  <<  ", " << clockwiseness << std::endl;
        break;
      }
      case Leap::Gesture::TYPE_SWIPE:
      {
        Leap::SwipeGesture swipe = gesture;
        std::cout << std::string(2, ' ')
          << "Swipe id: " << gesture.id()
          << ", state: " << stateNames[gesture.state()]
          << ", direction: " << swipe.direction()
          << ", speed: " << swipe.speed() << std::endl;
        break;
      }
      case Leap::Gesture::TYPE_KEY_TAP:
      {
        Leap::KeyTapGesture tap = gesture;
        std::cout << std::string(2, ' ')
          << "Key Tap id: " << gesture.id()
          << ", state: " << stateNames[gesture.state()]
          << ", position: " << tap.position()
          << ", direction: " << tap.direction()<< std::endl;
        break;
      }
      case Leap::Gesture::TYPE_SCREEN_TAP:
      {
        Leap::ScreenTapGesture screentap = gesture;
        std::cout << std::string(2, ' ')
          << "Screen Tap id: " << gesture.id()
          << ", state: " << stateNames[gesture.state()]
          << ", position: " << screentap.position()
          << ", direction: " << screentap.direction()<< std::endl;
        break;
      }
      default:
        std::cout << std::string(2, ' ')  << "Unknown gesture type." << std::endl;
        break;
    }
  }

  if (!frame.hands().isEmpty() || !gestures.isEmpty()) {
    std::cout << std::endl;
  }

}