public SettingsChangedEventArgs(Drone drone)
        {
            if (drone == null)
            {
                throw new ArgumentNullException(nameof(drone));
            }

            this.Settings = drone.Settings;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Schickt einen Settings-Befehl an die Drohne.
        /// </summary>
        public void SendConfig(DroneSettings config)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            SendPacket(new PacketSetConfig(config), true);
            Settings = config;
        }
Ejemplo n.º 3
0
        public SettingsForm(Drone drone)
        {
            InitializeComponent();

            this.drone = drone;
            this.info = drone.Info;
            this.data = drone.Settings;

            Bind(nameTextBox, "data.DroneName");
            Bind(saveConfigCheckBox, "data.SaveConfig");

            Bind(firmwareVersionTextBox, "info.BuildVersion");
            Bind(buildDateTextBox, "info.BuildName");

            Bind(modelTextBox, "info.ModelName");
            Bind(idTextBox, "info.SerialCode");
            Bind(gyroSensorTextBox, "info.GyroSensor");
            Bind(magnetometerTextBox, "info.Magnetometer");

            Bind(minValueTextBox, "data.ServoMin");
            Bind(idleValueTextBox, "data.ServoIdle");
            Bind(hoverValueTextBox, "data.ServoHover");
            Bind(maxValueTextBox, "data.ServoMax");

            Bind(safeMotorValueTextBox, "data.SafeServoValue");
            Bind(safeTemperatureTextBox, "data.MaxTemperature");
            Bind(safePitchTextBox, "data.SafePitch");
            Bind(safeRollTextBox, "data.SafeRoll");

            Bind(pitchKpTextBox, "data.PitchPid.Kp");
            Bind(pitchKiTextBox, "data.PitchPid.Ki");
            Bind(pitchKdTextBox, "data.PitchPid.Kd");

            Bind(rollKpTextBox, "data.RollPid.Kp");
            Bind(rollKiTextBox, "data.RollPid.Ki");
            Bind(rollKdTextBox, "data.RollPid.Kd");

            Bind(yawKpTextBox, "data.YawPid.Kp");
            Bind(yawKiTextBox, "data.YawPid.Ki");
            Bind(yawKdTextBox, "data.YawPid.Kd");

            Bind(enableStabilizationCheckBox, "data.EnableStabilization");
            Bind(negativeMixingCheckBox, "data.NegativeMixing");
            Bind(keepMotorsOnCheckBox, "data.KeepMotorsOn");

            Bind(maxThrustForFlyingTextBox, "data.MaxThrustForFlying");
            Bind(onlyArmWhenStillCheckBox, "data.OnlyArmWhenStill");

            Bind(gyroUseDmpCheckBox, "data.GyroUseDMP");
            Bind(gyroUseRawCheckBox, "data.GyroUseRaw");
            Bind(engineUseGyroCheckBox, "data.EngineUseGyro");

            drone.OnSettingsChange += Drone_OnSettingsChange;
            drone.OnInfoChange += Drone_OnInfoChange;
        }
Ejemplo n.º 4
0
        public static DroneSettings Read(PacketBuffer packetBuffer)
        {
            int size = Marshal.SizeOf(typeof(DroneSettings));

            byte[] buffer = new byte[size];
            packetBuffer.Read(buffer, 0, buffer.Length);

            GCHandle      handle   = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            DroneSettings settings = (DroneSettings)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DroneSettings));

            handle.Free();

            return(settings);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Schickt einen Settings-Befehl an die Drohne.
        /// </summary>
        public void SendConfig(DroneSettings config)
        {
            if (IsDisposed)
                throw new ObjectDisposedException(GetType().Name);

            SendPacket(new PacketSetConfig(config), true);
            Settings = config;
        }
Ejemplo n.º 6
0
 private void UpdateSettings(DroneSettings settings)
 {
     servoGraph.BaseLine = settings.ServoHover;
     servoGraph.ValueMin = 0;
     servoGraph.ValueMax = settings.ServoMax;
 }
Ejemplo n.º 7
0
        private void HandlePacket(byte[] packet)
        {
            // jedes Drohnen Paket ist mindestens HeaderSize Bytes lang und fangen mit "FLY" an
            using (MemoryStream stream = new MemoryStream(packet))
            {
                PacketBuffer buffer = new PacketBuffer(stream);

                if (packet.Length < HeaderSize || buffer.ReadByte() != 'F' || buffer.ReadByte() != 'L' || buffer.ReadByte() != 'Y')
                {
                    return;
                }

                int revision = buffer.ReadInt();

                bool       isGuaranteed = buffer.ReadByte() > 0;
                PacketType type         = (PacketType)buffer.ReadByte();

                if (Config.VerbosePacketReceive &&
                    type != PacketType.Ack &&
                    (type != PacketType.Ping || Config.LogPingPacket))
                {
                    Log.Verbose("[{0}] Received: [{1}] {2}, size: {3} bytes", Address.ToString(), revision, type, packet.Length);
                }

                switch (type)
                {
                case PacketType.Ping:
                    if (packet.Length < HeaderSize + sizeof(long))
                    {
                        throw new InvalidDataException("Packet is not long enough.");
                    }

                    bool wasNotConnected = !CheckConnection();

                    lastPing = Environment.TickCount;

                    long time = buffer.ReadLong();     // time ist der Wert von stopwatch zum Zeitpunkt des Absenden des Pakets
                    Ping = (int)(stopwatch.ElapsedMilliseconds - time);

                    if (wasNotConnected)
                    {
                        OnConnected?.Invoke(this, EventArgs.Empty);
                    }

                    RemovePacketToAcknowlegde(revision);
                    break;

                case PacketType.Ack:
                    IPacket acknowlegdedPacket;
                    if (!packetsToAcknowledge.TryGetValue(revision, out acknowlegdedPacket))
                    {
                        if (Config.VerbosePacketReceive)
                        {
                            Log.Verbose("[{0}] Unknown acknowlegde: [{1}]", Address.ToString(), revision);
                        }
                        break;
                    }

                    if (Config.VerbosePacketReceive)
                    {
                        Log.Verbose("[{0}] Acknowlegde: [{1}] {2}", Address.ToString(), revision, acknowlegdedPacket.Type);
                    }

                    RemovePacketToAcknowlegde(revision);
                    break;

                case PacketType.Info:
                    Info     = new DroneInfo(buffer);
                    Settings = DroneSettings.Read(buffer);

                    RemovePacketToAcknowlegde(revision);
                    break;

                default:
                    throw new InvalidDataException("Invalid packet type to get sent by cluster.");
                }
            }
        }
Ejemplo n.º 8
0
 private void UpdateValueBounds(DroneSettings settings)
 {
     changingValues = true;
     valueTrackBar.Minimum = settings.ServoMin;
     valueTrackBar.Maximum = settings.ServoMax;
     valueTrackBar.Value = settings.ServoMin;
     servoValueNumericUpDown.Value = settings.ServoMin;
     SetServoValueToAll();
     changingValues = false;
 }
 public SettingsChangedEventArgs(Drone drone)
 {
     this.Settings = drone.Settings;
 }
Ejemplo n.º 10
0
 private void UpdateSettings(DroneSettings settings)
 {
     droneSettingsPropertyGrid.SelectedObject = settings;
 }
Ejemplo n.º 11
0
 private void Drone_OnSettingsChange(object sender, SettingsChangedEventArgs e)
 {
     data = e.Settings;
     UpdateValues();
 }
Ejemplo n.º 12
0
        private void HandlePacket(byte[] packet)
        {
            // jedes Drohnen Paket ist mindestens HeaderSize Bytes lang und fangen mit "FLY" an
            using (MemoryStream stream = new MemoryStream(packet))
            {
                PacketBuffer buffer = new PacketBuffer(stream);

                if (packet.Length < HeaderSize || buffer.ReadByte() != 'F' || buffer.ReadByte() != 'L' || buffer.ReadByte() != 'Y')
                {
                    return;
                }

                int revision = buffer.ReadInt();

                bool       isGuaranteed = buffer.ReadByte() > 0;
                PacketType type         = (PacketType)buffer.ReadByte();

                if (Config.VerbosePacketReceive &&
                    type != PacketType.Ack &&
                    (Config.LogPingPacket || type != PacketType.Ping) &&
                    (Config.LogNoisyPackets || !type.IsNosiy()))
                {
                    Log.Verbose("[{0}] Received:    [{1}] {2}, size: {3} bytes", Address.ToString(), revision, type, packet.Length);
                }

                switch (type)
                {
                case PacketType.Ping:
                    bool wasNotConnected = !CheckConnection();
                    lastPing = Environment.TickCount;

                    long time = 0;
                    if (packet.Length >= HeaderSize + sizeof(long))
                    {
                        time = buffer.ReadLong();     // time ist der Wert von stopwatch zum Zeitpunkt des Absenden des Pakets
                    }
                    else
                    {
                        Log.Error("Invalid ping packet received with length: {0}", packet.Length);
                    }

                    int ping = (int)(stopwatch.ElapsedMilliseconds - time);
                    if (ping < 0)
                    {
                        Log.Warning("Invalid ping value received: {0}", ping);
                        ping = 0;
                    }
                    Ping = ping;

                    if (wasNotConnected)
                    {
                        OnConnected?.Invoke(this, EventArgs.Empty);
                    }

                    RemovePacketToAcknowledge(revision);
                    break;

                case PacketType.Ack:
                    IPacket acknowlegdedPacket;
                    if (!packetsToAcknowledge.TryGetValue(revision, out acknowlegdedPacket))
                    {
                        if (Config.VerbosePacketReceive)
                        {
                            Log.Verbose("[{0}] Unknown acknowledge: [{1}]", Address.ToString(), revision);
                        }
                        break;
                    }

                    if (Config.VerbosePacketReceive)
                    {
                        Log.Verbose("[{0}] Acknowledge: [{1}] {2}", Address.ToString(), revision, acknowlegdedPacket.Type);
                    }

                    RemovePacketToAcknowledge(revision);
                    break;

                case PacketType.Info:
                    Info     = new DroneInfo(buffer);
                    Settings = DroneSettings.Read(buffer);

                    if (firstInfo)
                    {
                        Log.Info("Received drone info for first time...");
                        Log.WriteProperties(LogLevel.Info, Info);

                        firstInfo = false;
                    }

                    RemovePacketToAcknowledge(revision);
                    break;

                default:
                    throw new InvalidDataException("Invalid packet type received.");
                }
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Schickt einen Settings-Befehl an die Drohne.
 /// </summary>
 public void SendConfig(DroneSettings config)
 {
     SendPacket(new PacketSetConfig(config), true);
     Settings = config;
 }