Beispiel #1
0
        private void btnSwitchCam_Click(object sender, EventArgs e)
        {
            var configuration = new Settings();

            configuration.Video.Channel = VideoChannelType.Next;
            _droneClient.Send(configuration);
        }
Beispiel #2
0
        void SetConfig()
        {
            var sendConfigTask = new Task(() =>
            {
                Debug("Updating drone settings ...");

                if (_configuration == null)
                {
                    _configuration = new Settings();
                }
                Settings configuration = _configuration;

                if (string.IsNullOrEmpty(configuration.Custom.SessionId) ||
                    configuration.Custom.SessionId == "00000000")
                {
                    // set new session, application and profile
                    _droneClient.AckControlAndWaitForConfirmation(); // wait for the control confirmation

                    configuration.Custom.SessionId = Settings.NewId();
                    _droneClient.Send(configuration);

                    _droneClient.AckControlAndWaitForConfirmation();

                    configuration.Custom.ProfileId = Settings.NewId();
                    _droneClient.Send(configuration);

                    _droneClient.AckControlAndWaitForConfirmation();

                    configuration.Custom.ApplicationId = Settings.NewId();
                    _droneClient.Send(configuration);

                    _droneClient.AckControlAndWaitForConfirmation();
                }

                configuration.Control.Outdoor            = this.Details.OutdoorFlight;
                configuration.Control.FlightWithoutShell = this.Details.OutdoorHull;

                configuration.Control.AltitudeMax = (int)this.Details.AltitudeLimit;

                //if (this.Details.OutdoorFlight == false)
                {
                    //configuration.Control.ControlVzMax = 1f; // (float)this.Details.VerticalSpeedMax;
                    configuration.Control.ControlYaw = 0.10f; // (float)this.Details.RotationSpeedMax;
                    //configuration.Control.EulerAngleMax = 0.1f; // (float)this.Details.TiltAngleMax;
                }
                //else
                //{
                //    _configuration.Control.OutdoorControlVzMax = (float)this.Details.VerticalSpeedMax;
                //    _configuration.Control.OutdoorControlYaw = (float)this.Details.RotationSpeedMax;
                //    _configuration.Control.OutdoorEulerAngleMax = (float)this.Details.TiltAngleMax;
                //}

                this._droneClient.Send(configuration);

                Debug("New drone settings sent!");
            });

            sendConfigTask.Start();
        }
Beispiel #3
0
 private void OnConfigurationUpdated(DroneConfiguration configuration)
 {
     if (configuration.Video.Codec != VideoCodecType.H264_360P ||
         configuration.Video.BitrateCtrlMode != VideoBitrateControlMode.Dynamic)
     {
         _droneClient.Send(configuration.Video.Codec.Set(VideoCodecType.H264_360P).ToCommand());
         _droneClient.Send(configuration.Video.BitrateCtrlMode.Set(VideoBitrateControlMode.Dynamic).ToCommand());
     }
 }
Beispiel #4
0
 private void OnConfigurationUpdated(DroneConfiguration configuration)
 {
     if (configuration.Video.Codec != VideoCodecType.H264_360P_SLRS || configuration.Video.MaxBitrate != 100 || configuration.Video.BitrateCtrlMode != VideoBitrateControlMode.Dynamic)
     {
         droneClient.Send(configuration.Video.Codec.Set(VideoCodecType.H264_360P_SLRS).ToCommand());
         droneClient.Send(configuration.Video.MaxBitrate.Set(100).ToCommand());
         droneClient.Send(configuration.Video.BitrateCtrlMode.Set(VideoBitrateControlMode.Dynamic).ToCommand());
     }
 }
Beispiel #5
0
    /// <summary>
    /// Switchs the drone camera.
    /// </summary>
    /// <param name="Type">Video channel type.</param>
    private void switchDroneCamera(AR.Drone.Client.Configuration.VideoChannelType Type)
    {
        var configuration = new AR.Drone.Client.Configuration.Settings();

        configuration.Video.Channel = Type;
        droneClient.Send(configuration);
    }
Beispiel #6
0
        private void OnNavigationData(NavigationData data)
        {
            if (_initialized)
            {
                return;
            }

            if (data.State.HasFlag(NavigationState.Command))
            {
                _client.Send(new ControlCommand(ControlMode.AckControlMode));
            }
            else
            {
                _client.Send(new ControlCommand(ControlMode.CfgGetControlMode));
                _initialized = true;
            }
        }
        public void SendTo(DroneClient client)
        {
            ATCommand command;

            while (_queue.TryDequeue(out command))
            {
                client.Send(command);
            }
        }
Beispiel #8
0
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        Debug.Log("Start DroneObserver");
        // initialize data array
        data          = new byte[width * height * 3];
        cameraTexture = new Texture2D(width, height);
        // Initialize drone
        videoPacketDecoderWorker = new VideoPacketDecoderWorker(PixelFormat.RGB24, true, OnVideoPacketDecoded);
        videoPacketDecoderWorker.Start();

        droneClient = new DroneClient("192.168.1.1");
        //droneClient = new DroneClient ("127.0.0.1");
        droneClient.UnhandledException     += HandleUnhandledException;
        droneClient.VideoPacketAcquired    += OnVideoPacketAcquired;
        droneClient.NavigationDataAcquired += navData => navigationData = navData;

        droneClient.FlatTrim();

        videoPacketDecoderWorker.UnhandledException += HandleUnhandledException;
        droneClient.Start();

        Settings settings = new Settings();

        settings.Video.Codec = VideoCodecType.H264_720P;
        droneClient.Send(settings);
        droneClient.AckControlAndWaitForConfirmation();

        switchDroneCamera(AR.Drone.Client.Configuration.VideoChannelType.Horizontal);

        isDroneConnected = droneClient.IsConnected;

        if (!isDroneConnected)
        {
            Debug.LogError("Drone not Connected. Retry!!!");
        }
        if (isDroneConnected)
        {
            Debug.LogWarning("Drone Connected!!!");
        }

        // determine connection
        wlanClient = new WlanClient();
    }
Beispiel #9
0
        public Settings GetConfiguration(CancellationToken token)
        {
            using (var tcpClient = new TcpClient(_client.NetworkConfiguration.DroneHostname, ControlPort))
                using (NetworkStream stream = tcpClient.GetStream())
                {
                    _client.AckControlAndWaitForConfirmation();

                    _client.Send(ControlCommand.CfgGetControlMode);

                    var       buffer          = new byte[NetworkBufferSize];
                    Stopwatch swConfigTimeout = Stopwatch.StartNew();
                    while (swConfigTimeout.ElapsedMilliseconds < ConfigTimeout)
                    {
                        token.ThrowIfCancellationRequested();

                        int offset = 0;
                        if (tcpClient.Available == 0)
                        {
                            Thread.Sleep(20);
                        }
                        else
                        {
                            offset += stream.Read(buffer, offset, buffer.Length);
                            swConfigTimeout.Reset();
                            swConfigTimeout.Start();

                            // config eof check
                            if (offset > 0 && buffer[offset - 1] == 0x00)
                            {
                                string s = System.Text.Encoding.UTF8.GetString(buffer, 0, offset);

                                return(Settings.Parse(s));
                            }
                        }
                    }

                    throw new TimeoutException();
                }
        }
Beispiel #10
0
 /// <summary>
 /// This method let the drone calibrate.
 /// Must be happen every flight for an accurate flight.
 /// </summary>
 public void Calibrate()
 {
     _droneClient.Send(CalibrateCommand.Magnetometer);
 }
Beispiel #11
0
        /// <summary>
        /// Sends the changed settings from the UI to the drone
        /// </summary>
        private void SendDroneConfig()
        {
            if (droneClient.IsConnected)
            {
                OnChangeDroneSettingsBegin();
                var sendConfigTask = new Task(() =>
                {
                    if (settings == null)
                    {
                        settings = new Settings();
                    }

                    if (string.IsNullOrEmpty(settings.Custom.SessionId) ||
                        settings.Custom.SessionId == "00000000")
                    {
                        // set new session, application and profile
                        droneClient.AckControlAndWaitForConfirmation(); // wait for the control confirmation

                        settings.Custom.SessionId = Settings.NewId();
                        droneClient.Send(settings);

                        droneClient.AckControlAndWaitForConfirmation();

                        settings.Custom.ProfileId = Settings.NewId();
                        droneClient.Send(settings);

                        droneClient.AckControlAndWaitForConfirmation();

                        settings.Custom.ApplicationId = Settings.NewId();
                        droneClient.Send(settings);

                        droneClient.AckControlAndWaitForConfirmation();
                    }

                    settings.General.NavdataDemo    = false;
                    settings.General.NavdataOptions = NavdataOptions.All;

                    settings.Video.BitrateCtrlMode = VideoBitrateControlMode.Dynamic;
                    settings.Video.Bitrate         = 2000;
                    settings.Video.MaxBitrate      = 4000;

                    //settings.Leds.LedAnimation = new LedAnimation(LedAnimationType.BlinkGreenRed, 2.0f, 2);
                    //settings.Control.FlightAnimation = new FlightAnimation(FlightAnimationType.Wave);

                    // record video to usb
                    //settings.Video.OnUsb = true;
                    // usage of MP4_360P_H264_720P codec is a requirement for video recording to usb
                    //settings.Video.Codec = VideoCodecType.MP4_360P_H264_720P;
                    // start
                    //settings.Userbox.Command = new UserboxCommand(UserboxCommandType.Start);
                    // stop
                    //settings.Userbox.Command = new UserboxCommand(UserboxCommandType.Stop);


                    //send all changes in one pice
                    droneClient.Send(settings);
                });
                sendConfigTask.Start();
                sendConfigTask.Wait();
                OnChangeDroneSettingsEnd();
            }
        }
Beispiel #12
0
        public void Configure(DroneConfiguration droneConfiguration)
        {
            Task <Settings> configurationTask = droneClient.GetConfigurationTask();

            configurationTask.ContinueWith(
                delegate(Task <Settings> task)
            {
                if (task.Exception != null)
                {
                    Trace.TraceWarning("Get configuration task is faulted with exception: {0}",
                                       task.Exception.InnerException.Message);
                    return;
                }

                settings = task.Result;
            });
            configurationTask.Start();

            var sendConfigTask = new Task(() =>
            {
                if (settings == null)
                {
                    settings = new Settings();
                }

                if (string.IsNullOrEmpty(settings.Custom.SessionId) ||
                    settings.Custom.SessionId == "00000000")
                {
                    // set new session, application and profile
                    droneClient.AckControlAndWaitForConfirmation(); // wait for the control confirmation

                    settings.Custom.SessionId = Settings.NewId();
                    droneClient.Send(settings);

                    droneClient.AckControlAndWaitForConfirmation();

                    settings.Custom.ProfileId = Settings.NewId();
                    droneClient.Send(settings);

                    droneClient.AckControlAndWaitForConfirmation();

                    settings.Custom.ApplicationId = Settings.NewId();
                    droneClient.Send(settings);

                    droneClient.AckControlAndWaitForConfirmation();
                }

                settings.General.NavdataDemo    = false;
                settings.General.NavdataOptions = NavdataOptions.All;

                //settings.Video.BitrateCtrlMode = VideoBitrateControlMode.Dynamic;
                settings.Video.Bitrate    = 1000;
                settings.Video.MaxBitrate = 2000;

                settings.Leds.LedAnimation       = new LedAnimation(LedAnimationType.BlinkGreenRed, 2.0f, 2);
                settings.Control.FlightAnimation = new FlightAnimation(FlightAnimationType.Wave);


                //start
                settings.Userbox.Command = new UserboxCommand(UserboxCommandType.Start);
                //stop
                settings.Userbox.Command = new UserboxCommand(UserboxCommandType.Stop);

                //send all changes in one pice
                droneClient.Send(settings);

                droneClient.FlatTrim(); // calibrates the drone on flat surface
            });

            sendConfigTask.Start();
        }
Beispiel #13
0
        private void btnSwitchCam_Click(object sender, EventArgs e)
        {
            ATCommand command = _droneClient.Configuration.Video.Channel.Set(VideoChannelType.Next).ToCommand();

            _droneClient.Send(command);
        }
Beispiel #14
0
 public void flightWithoutShell(bool flag)
 {
     settings.Control.FlightWithoutShell = flag;
     _client.Send(settings);
 }
 public void SendTo(DroneClient client)
 {
     ATCommand command;
     while (_queue.TryDequeue(out command)) client.Send(command);
 }