예제 #1
0
        public void LeapController_FrameReady(object sender, Leap.FrameEventArgs e)
        {
            try
            {
                var handRight = e.frame.RightHand();
                if (handRight != null)
                {
                }

                var handLeft = e.frame.LeftHand();
                if (handLeft != null)
                {
                    // move forward, backward
                    var direction = handLeft.Direction.Normalized;
                    var cross     = direction.Cross(Leap.Vector.Forward);
                    var angle     = direction.AngleTo(Leap.Vector.Forward) * 180.0f / Math.PI * (cross.y > 0 ? 1 : -1) - 10.0f;

                    //this.leapPitchLabel.Text    = angle.ToString("0.00");
                    //this.leapYawLabel.Text      = cross.y.ToString("0.00");
                    //this.leapRollLabel.Text     = cross.z.ToString("0.00");
                }

                var isDetectedLeft  = (handLeft != null);
                var isDetectedRight = (handRight != null);

                this.handLeftDetectionLabel.Invoke(new MethodInvoker(delegate()
                {
                    this.handLeftDetectionLabel.Text = isDetectedLeft ? "인식중입니다." : "인식되지 않은 상태입니다.";
                }));

                this.handLeftDetectionProgressbar.Invoke(new MethodInvoker(delegate()
                {
                    this.handLeftDetectionProgressbar.Value    = isDetectedLeft ? 15 : 0;
                    this.handLeftDetectionProgressbar.animated = isDetectedLeft;
                }));

                this.handRightDetectionLabel.Invoke(new MethodInvoker(delegate()
                {
                    this.handRightDetectionLabel.Text = isDetectedRight ? "인식중입니다." : "인식되지 않은 상태입니다.";
                }));

                this.handRightDetectionProgressbar.Invoke(new MethodInvoker(delegate()
                {
                    this.handRightDetectionProgressbar.Value    = isDetectedRight ? 15 : 0;
                    this.handRightDetectionProgressbar.animated = isDetectedRight;
                }));
            }
            catch (Exception)
            { }
        }
예제 #2
0
        public void LeapController_FrameReady(object sender, Leap.FrameEventArgs e)
        {
            try
            {
                var frame         = e.frame;
                var isLeftActive  = (frame.LeftHand() != null);
                var isRightActive = (frame.RightHand() != null);
                this.leapLeftDetectingLabel.Invoke(new MethodInvoker(delegate()
                {
                    this.leapLeftDetectingLabel.Text = isLeftActive ? "왼손 인식중" : "왼손 인식 안됨";
                }));

                this.leapRightDetectingLabel.Invoke(new MethodInvoker(delegate()
                {
                    this.leapRightDetectingLabel.Text = isRightActive ? "오른손 인식중" : "오른손 인식 안됨";
                }));
            }
            catch (Exception)
            {
            }
        }
예제 #3
0
        private void LeapController_FrameReady(object sender, Leap.FrameEventArgs e)
        {
            if (this.Patrol.Reader.IsEnabled())
            {
                return;
            }

            if (this.AutoFlight.IsFlying)
            {
                return;
            }

            var handRight = e.frame.RightHand();

            if (handRight != null)
            {
                // move left, right
                var angle_rotated = handRight.PalmNormal.AngleTo(Leap.Vector.Down) * (180 / Math.PI);
                var cross_rotated = handRight.PalmNormal.Cross(Leap.Vector.Down);

                if (angle_rotated > MainForm.LEAPMOTION_MINIMUM_MOVE_SIDE_ANGLE)
                {
                    var percent = (angle_rotated - MainForm.LEAPMOTION_MINIMUM_MOVE_SIDE_ANGLE) / (90.0f - MainForm.LEAPMOTION_MINIMUM_MOVE_SIDE_ANGLE);
                    this._pcmd.roll = (int)(percent * this.defaultView.sideExpandedBar.droneTab.GetDroneSpeed() * (cross_rotated.z > 0 ? 1 : -1));
                }
                else
                {
                    this._pcmd.roll = 0;
                }



                // move up, down
                if (handRight.PalmPosition.y > MainForm.LEAPMOTION_MINIMUM_UP_POSITION)
                {
                    this._pcmd.gaz = 25;
                }
                else if (handRight.PalmPosition.y < MainForm.LEAPMOTION_MINIMUM_DOWN_POSITION)
                {
                    this._pcmd.gaz = -25;
                }
                else
                {
                    this._pcmd.gaz = 0;
                }



                // move forward, backward
                var direction        = (handRight.PalmPosition - Leap.Vector.Zero).Normalized;
                var angle_forward    = direction.AngleTo(Leap.Vector.Up) * (180 / Math.PI);
                var cross_forward    = direction.Cross(Leap.Vector.Up);
                var calibrated_angle = MainForm.LEAPMOTION_CALIBRATION_FORWARD_VALUE + angle_forward * (cross_forward.x > 0 ? 1 : -1);
                if (Math.Abs(calibrated_angle) > MainForm.LEAPMOTION_MINIMUM_FORWARD_ANGLE)
                {
                    this._pcmd.pitch = 5 * (calibrated_angle > 0 ? 1 : -1);
                }
                else
                {
                    this._pcmd.pitch = 0;
                }
            }
            else
            {
                this._pcmd.roll  = 0;
                this._pcmd.gaz   = 0;
                this._pcmd.pitch = 0;
            }

            var handLeft = e.frame.LeftHand();

            if (handLeft != null)
            {
                // rotate left, right
                var direction = handLeft.Direction.Normalized;
                var cross     = direction.Cross(Leap.Vector.Forward);
                var angle     = direction.AngleTo(Leap.Vector.Forward) * 180.0f / Math.PI * (cross.y < 0 ? 1 : -1) + MainForm.LEAPMOTION_CALIBRATION_ROTATION_VALUE;

                if (Math.Abs(angle) > MainForm.LEAPMOTION_MINIMUM_ROTATION_ANGLE)
                {
                    angle = Math.Max(60, Math.Abs(angle)) * (angle > 0 ? 1 : -1);
                    var percent = (Math.Abs(angle) - MainForm.LEAPMOTION_MINIMUM_ROTATION_ANGLE) / (60.0f - MainForm.LEAPMOTION_MINIMUM_ROTATION_ANGLE);
                    this._pcmd.yaw = (int)(percent * this.defaultView.sideExpandedBar.droneTab.GetDroneSpeed()) * (angle > 0.0f ? 1 : -1);
                }
                else
                {
                    this._pcmd.yaw = 0;
                }
            }
            else
            {
                this._pcmd.yaw = 0;
            }

            if (this._pcmd.pitch == 0 && this._pcmd.roll == 0)
            {
                this._pcmd.flag  = 0;
                this._pcmd.pitch = 0;
                this._pcmd.roll  = 0;
            }
            else
            {
                this._pcmd.flag = 1;
                this._pcmd.yaw  = 0;
                this._pcmd.gaz  = 0;
            }

            this.defaultView.sideExpandedBar.droneTab.updatePcmdUI(this._pcmd);
        }