Example #1
0
        private void ChangeState(LearnForm.State state)
        {
            if (_nowState != state)
            {
                switch (state)
                {
                    case LearnForm.State.TakeOff:
                        DroneSingleton._droneClient.Takeoff();
                        _commandStartTime = DateTime.Now;
                        _isCounting = true;
                        break;
                    case LearnForm.State.Hover:
                        DroneSingleton._droneClient.Hover();
                        _commandStartTime = DateTime.Now;
                        _isCounting = true;
                        break;
                    case LearnForm.State.Up:
                        DroneSingleton._droneClient.Progress(FlightMode.Progressive, gaz: 0.25f);
                        _commandStartTime = DateTime.Now;
                        _isCounting = true;
                        break;
                    case LearnForm.State.Down:
                        DroneSingleton._droneClient.Progress(FlightMode.Progressive, gaz: -0.25f);
                        _commandStartTime = DateTime.Now;
                        _isCounting = true;
                        break;
                    case LearnForm.State.Forward:
                        _commandStartTime = DateTime.Now;
                        DroneSingleton._droneClient.Progress(FlightMode.Progressive, pitch: -0.05f);
                        _isForwarding = true;
                        _isCounting = true;
                        break;
                    case LearnForm.State.Left:
                        DroneSingleton._droneClient.Progress(FlightMode.Progressive, roll: -0.05f);
                        CountTime();
                        break;
                    case LearnForm.State.Right:
                        DroneSingleton._droneClient.Progress(FlightMode.Progressive, roll: 0.05f);
                        CountTime();
                        break;
                    case LearnForm.State.TurnLeft:
                        DroneSingleton._droneClient.Progress(FlightMode.Progressive, yaw: -0.25f);
                        break;
                    case LearnForm.State.TurnRight:
                        DroneSingleton._droneClient.Progress(FlightMode.Progressive, yaw: 0.25f);
                        break;
                    case LearnForm.State.Wait:
                        DroneSingleton._droneClient.Hover();
                        _waitStartTime = DateTime.Now;
                        _waitting = true;
                        break;

                }
                _nowState = state;
            }
            else
            {
                if (_isCounting && _nowCommand == _nowState)
                {
                    _commandEndTime = DateTime.Now;
                    TimeSpan costTime = _commandEndTime.Subtract(_commandStartTime);
                    if (_totalTime.CompareTo(costTime) <= 0)
                    {
                        _isCounting = false;
                        if (_isReturn)
                            _commandIndex--;
                        else
                            _commandIndex++;
                        ReadCommand();
                        return;
                    }
                }
                if (_waitting)
                {
                    _waitEndTime = DateTime.Now;
                    TimeSpan costTime = _waitEndTime.Subtract(_waitStartTime);
                    if (_waitTimeLimit.CompareTo(costTime) <= 0)
                    {
                        if (_backHomeWait)
                        {
                            _isForwarding = false;
                            _turning = false;
                            _needWait = true;
                            _backHomeWait = false;
                            _turnBack = true;
                        }
                        _waitting = false;
                        _needWait = false;
                        return;
                    }
                }
            }
        }
Example #2
0
 public void OnClickPlaneStatePanelStartLearnButton()
 {
     LearnForm form = new LearnForm(this);
     form.SetComboBoxSource(_planeStatePanel.ComboBoxItemSource);
     SwitchForm(form);
 }