Exemplo n.º 1
0
            void doModeScans()
            {
                int iMode  = _wicoControl.IMode;
                int iState = _wicoControl.IState;

//                StatusLog("clear", textPanelReport);
//                StatusLog(moduleName + ":SCAN!", textPanelReport);
                _program.Echo("Scan:iState=" + iState.ToString());

                switch (iState)
                {
                case 0:
                {         // init camera scan for asteroids/objects
                    _program.ResetMotion();
                    scanElapsedMs = 0;

                    // initialize cameras
                    scanfrontScanner  = new QuadrantCameraScanner(_program, _cameras.GetForwardCameras(), 5000);
                    scanbackScanner   = new QuadrantCameraScanner(_program, _cameras.GetBackwardCameras(), 5000);
                    scanleftScanner   = new QuadrantCameraScanner(_program, _cameras.GetLeftCameras(), 5000);
                    scanrightScanner  = new QuadrantCameraScanner(_program, _cameras.GetRightCameras(), 5000);
                    scantopScanner    = new QuadrantCameraScanner(_program, _cameras.GetUpCameras(), 5000);
                    scanbottomScanner = new QuadrantCameraScanner(_program, _cameras.GetDownwardCameras(), 5000);

                    _wicoControl.SetState(410);        // iState = 410;
                    _wicoControl.WantFast();
                    break;
                }

                case 410:
                {
//                            StatusLog("Long Range Scan", textPanelReport);
                    if (scanfrontScanner == null)         // in case we reload/compile in this state..
                    {
                        _wicoControl.WantFast();
                        iState = 0;
                        return;
                    }
                    _wicoControl.WantMedium();
                    scanElapsedMs += _program.Runtime.TimeSinceLastRun.TotalMilliseconds;
                    // use for timeout...

                    // do camera scans

                    if (scanfrontScanner.DoScans())
                    {
                        _asteroids.AsteroidProcessLDEI(scanfrontScanner.myLDEI);
                    }
                    if (scanbackScanner.DoScans())
                    {
                        _asteroids.AsteroidProcessLDEI(scanbackScanner.myLDEI);
                    }
                    if (scanleftScanner.DoScans())
                    {
                        _asteroids.AsteroidProcessLDEI(scanleftScanner.myLDEI);
                    }
                    if (scanrightScanner.DoScans())
                    {
                        _asteroids.AsteroidProcessLDEI(scanrightScanner.myLDEI);
                    }
                    if (scantopScanner.DoScans())
                    {
                        _asteroids.AsteroidProcessLDEI(scantopScanner.myLDEI);
                    }
                    if (scanbottomScanner.DoScans())
                    {
                        _asteroids.AsteroidProcessLDEI(scanbottomScanner.myLDEI);
                    }

                    // TODO: if missing cameras on a side(s), rotate ship to point cameras at that side
                    // TODO: Flags for other options (TBD)
                    // TODO: scan range
                    // TODO: stop on first hit (by type?)
                    // TODO: all sides or specific sides?

                    string s = "";
                    s += "Front: ";
                    if (scanfrontScanner.DoneScanning())
                    {
                        s += "DONE!";
                    }
                    else
                    {
                        s += scanfrontScanner.SCAN_DISTANCE.ToString("0") + " meters";
                    }
                    s += " " + scanfrontScanner.myLDEI.Count + " objects";
                    s += "\n";

                    s += "Back: ";
                    if (scanbackScanner.DoneScanning())
                    {
                        s += "DONE!";
                    }
                    else
                    {
                        s += scanbackScanner.SCAN_DISTANCE.ToString("0") + " meters";
                    }
                    s += " " + scanbackScanner.myLDEI.Count + " objects";
                    s += "\n";

                    s += "Left: ";
                    if (scanleftScanner.DoneScanning())
                    {
                        s += "DONE!";
                    }
                    else
                    {
                        s += scanleftScanner.SCAN_DISTANCE.ToString("0") + " meters";
                    }
                    s += " " + scanleftScanner.myLDEI.Count + " objects";
                    s += "\n";

                    s += "Right: ";
                    if (scanrightScanner.DoneScanning())
                    {
                        s += "DONE!";
                    }
                    else
                    {
                        s += scanrightScanner.SCAN_DISTANCE.ToString("0") + " meters";
                    }
                    s += " " + scanrightScanner.myLDEI.Count + " objects";
                    s += "\n";

                    s += "Top: ";
                    if (scantopScanner.DoneScanning())
                    {
                        s += "DONE!";
                    }
                    else
                    {
                        s += scantopScanner.SCAN_DISTANCE.ToString("0") + " meters";
                    }
                    s += " " + scantopScanner.myLDEI.Count + " objects";
                    s += "\n";

                    s += "Bottom: ";
                    if (scanbottomScanner.DoneScanning())
                    {
                        s += "DONE!";
                    }
                    else
                    {
                        s += scanbottomScanner.SCAN_DISTANCE.ToString("0") + " meters";
                    }
                    s += " " + scanbottomScanner.myLDEI.Count + " objects";
                    s += "\n";

                    if (_asteroids.AsteroidFindNearest() < 0)
                    {
                        s += "No Known Asteroid";
                    }
                    else
                    {
                        s += "FOUND at least one asteroid!";
                    }

//                            StatusLog(s, textPanelReport);
                    _program.Echo(s);

                    if (
                        scanfrontScanner.DoneScanning() &&
                        scanbackScanner.DoneScanning() &&
                        scanleftScanner.DoneScanning() &&
                        scanrightScanner.DoneScanning() &&
                        scantopScanner.DoneScanning() &&
                        scanbottomScanner.DoneScanning()
                        )
                    {
                        _wicoControl.SetMode(ScansDoneMode, ScansDoneState);

                        // reset to default for possible next run
                        ScansDoneMode  = WicoControl.MODE_NAVNEXTTARGET;
                        ScansDoneState = 0;
                    }
                    break;
                }
                }
            }