Exemplo n.º 1
0
 private void speedCorrection(POIData poiDate, Point obj)
 {
     if (obj.X < 10 || obj.X > viewPort.Width - 10 ||
         obj.Y < 10 || obj.Y > viewPort.Height - 10 ||
         poiDate.dist >= 90)
     {
         poiDate.speed = 100;
         lowSpeedCor   = 0;
         if (currentSpeed != 100)
         {
             simpleKeyPress((byte)Keys.D0);
         }
     }
     else if (poiDate.dist >= 70 && poiDate.dist < 80)
     {
         poiDate.speed = 70;
         lowSpeedCor   = 1;
         if (currentSpeed != 70)
         {
             simpleKeyPress((byte)Keys.D7);
         }
     }
     else if (poiDate.dist >= 50 && poiDate.dist < 60)
     {
         poiDate.speed = 50;
         lowSpeedCor   = 4;
         if (currentSpeed != 50)
         {
             simpleKeyPress((byte)Keys.D5);
         }
     }
     else if (poiDate.dist >= 10 && poiDate.dist < 40)
     {
         poiDate.speed = 30;
         lowSpeedCor   = 6;
         if (currentSpeed != 30)
         {
             simpleKeyPress((byte)Keys.D3);
         }
     }
     currentSpeed = poiDate.speed;
     //if (currentSpeed > 30)
     //    flapsToPos(1);
     //else flapsToPos(4);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Робота бота в Mode.Default
 /// </summary>
 /// <param name="token">Источник признака отмены</param>
 private bool botWork(CancellationToken token)
 {
     if (bc == null)
     {
         bc = new KeyboardTimerBotControl(cv.ViewPort);
     }
     Task.Run(() =>
     {
         POIData defPOI = new POIData(new Point(-1, -1), -1);
         while (true)
         {
             sw.Restart();
             if (token.IsCancellationRequested)
             {
                 if (bc != null)
                 {
                     bc.release();
                 }
                 break;
             }
             var obj = cv.detectObj();
             var com = bc.moveTo(obj);
             if (obj == null)
             {
                 obj = defPOI;
             }
             else
             {
                 obj.command = com;
             }
             sw.Stop();
             obj.fps = 1000 / sw.ElapsedMilliseconds;
             if (onDataReport != null)
             {
                 onDataReport(obj);
             }
         }
     }, token);
     return(true);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Перемещается к точке
        /// </summary>
        /// <param name="obj">Данные приследуемого объекта</param>
        /// <returns>Возвращает выполняемые команды. Если их нет, то 'not found'</returns>
        public string moveTo(POIData poiDate)
        {
            if (poiDate == null)
            {
                return("not found");
            }

            if (!timer.Enabled)
            {
                timer.Enabled = true;
            }

            var obj     = poiDate.pt;
            var command = string.Empty;

            //yawMoves(obj, ref command);

            rollMoves(obj, ref command);

            pitchMoves(obj, ref command);

            if (botSpeedChange)
            {
                speedCorrection(poiDate, obj);
            }
            if (botKill)
            {
                fire(obj, ref command);
            }

            if (command == string.Empty)
            {
                command = "streight";
            }

            return(command);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Находит объект
        /// </summary>
        /// <returns>Возвращает координаты объекта. Если оюъект не найден возвращает null.</returns>
        public POIData detectObj()
        {
            var           frame            = sc.PrintWindow(winDiscript);
            var           processedFrameSt = ProcessImage(frame);
            var           processedFrame   = processedFrameSt.Canny(180, 120);
            List <PointF> pList            = new List <PointF>();

            using (VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint())
            {
                CvInvoke.FindContours(processedFrame, contours, null, RetrType.External, ChainApproxMethod.ChainApproxSimple);
                int count = contours.Size;
                for (int i = 0; i < count; i++)
                {
                    using (VectorOfPoint contour = contours[i])
                        using (VectorOfPoint approxContour = new VectorOfPoint())
                        {
                            CvInvoke.ApproxPolyDP(contour, approxContour, CvInvoke.ArcLength(contour, true) * 0.05, true);
                            double area = CvInvoke.ContourArea(approxContour, false);
                            for (int k = 0; k < approxContour.Size; k++)
                            {
                                pList.Add(approxContour[k]);
                            }
                        }
                }
            }
            var rec = PointCollection.BoundingRectangle(pList.ToArray());

            if (recWhenBigDist.IsEmpty)
            {
                recWhenBigDist = rec;
            }

            if (recWhenBigDist.Width - rec.Width > 3)
            {
                distLess100 = true;
            }
            else
            {
                distLess100 = false;
            }

            if (rec.Width > 0)
            {
                if (++distReqest > 20)
                {
                    filtDist = recognizeSpeed(rec, processedFrameSt);
                    if (filtDist > 1)
                    {
                        distReqest = 0;
                        if (prevDist - filtDist >= 15)
                        {
                            situation = 1;
                        }
                        if (Math.Abs(prevDist - filtDist) > 1 && Math.Abs(prevDist - filtDist) < 15)
                        {
                            situation = 2;
                        }
                        prevDist = filtDist;
                    }
                    else
                    {
                        if (distLess40)
                        {
                            situation = 3;
                        }
                    }
                }
                var pd = new POIData(rec.Location, filtDist);
                distLess40    = filtDist < 40;
                pd.noFiltDist = noFiltDist;
                pd.situation  = situation;

                return(pd);
            }
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Перемещается к точке
        /// </summary>
        /// <param name="obj">poi</param>
        /// <returns></returns>
        public string moveTo(POIData poiDate)
        {
            keybd_event(currentKey, 0, KEYEVENTF_KEYUP, 0);

            if (poiDate == null)
            {
                return("not found");
            }

            var obj     = poiDate.pt;
            var command = "";

            if (uRec.Contains(obj))
            {
                currentKey = com_down;
                flyUp      = true;
                sw.Restart();
                command = "up";
            }
            else if (dRec.Contains(obj))
            {
                currentKey = com_up;
                command    = "down";
            }
            else if (lRec.Contains(obj) || dlRec.Contains(obj))
            {
                currentKey = com_left;
                command    = "left";
            }
            else if (esLRec.Contains(obj))
            {
                currentKey = com_esLeft;
                command    = "easy-left";
            }
            else if (rRec.Contains(obj) || drRec.Contains(obj))
            {
                currentKey = com_right;
                command    = "right";
            }
            else if (esRRec.Contains(obj))
            {
                currentKey = com_esRight;
                command    = "easy-right";
            }
            else if (cRec.Contains(obj))
            {
                command = "straight";
                return(command);
            }

            keybd_event(currentKey, 0, 0, 0);

            if (currentKey != com_down)
            {
                if (flyUp && sw.ElapsedMilliseconds < 300)
                {
                    keybd_event(com_down, 0, 0, 0);
                }
                else
                {
                    flyUp = false;
                    keybd_event(com_down, 0, KEYEVENTF_KEYUP, 0);
                }
            }


            //if (poiDate.dist.Length > 1)
            //{
            //    int dist = 0;
            //    dist = Convert.ToInt32(poiDate.dist);
            //    if (dist > 10)
            //    {
            //        midDist += dist;
            //        if (++dcount > 60)
            //        {
            //            dcount = 0;
            //            midDistMemor = midDist / 60;
            //        }
            //    }
            //}
            //poiDate.midDist = midDistMemor;


            return(command);
        }