Beispiel #1
0
        private void SendControl()
        {
            CommanderPacket commanderPacket = new CommanderPacket(roll, pitch, yaw, thrust);
            IPacket         ackPacket       = crazyRadioMessenger.SendMessage(commanderPacket);

            UpdateCommandValues();
        }
        private static void Main(string[] args)
        {
            SetUpLogging();

            IEnumerable <ICrazyradioDriver> crazyradioDrivers = null;

            try
            {
                Log.Debug("Starting Crazyradio USB dongle tests.");

                crazyradioDrivers = CrazyradioDriver.GetCrazyradios();
            }
            catch (Exception ex)
            {
                Log.Error("Error getting Crazyradios.", ex);
            }

            if (crazyradioDrivers != null && crazyradioDrivers.Any())
            {
                var crazyradioDriver = crazyradioDrivers.First();

                try
                {
                    crazyradioDriver.Open();

                    var scanResults = crazyradioDriver.ScanChannels();
                    if (scanResults.Any())
                    {
                        var firstScanResult = scanResults.First();

                        var dataRateWithCrazyflie = firstScanResult.DataRate;
                        var channelWithCrazyflie  = firstScanResult.Channels.First();

                        crazyradioDriver.DataRate = dataRateWithCrazyflie;
                        crazyradioDriver.Channel  = channelWithCrazyflie;

                        var pingPacket      = new PingPacket();
                        var pingPacketBytes = pingPacket.GetBytes();

                        var crazyRadioMessenger = new CrazyradioMessenger(crazyradioDriver);

                        var loop = true;
                        while (loop)
                        {
                            // test 2 (using CTRP lib)
                            {
                                Log.InfoFormat("Ping Packet Bytes: {0}", BitConverter.ToString(pingPacketBytes));

                                var ackPacket      = crazyRadioMessenger.SendMessage(new PingPacket());
                                var ackPacketBytes = ackPacket.GetBytes();

                                Log.InfoFormat("ACK Response Bytes (using CTRP): {0}", BitConverter.ToString(ackPacketBytes));
                            }

                            if (Console.KeyAvailable && Console.ReadKey().Key == ConsoleKey.Spacebar)
                            {
                                loop = false;
                            }
                        }
                    }
                    else
                    {
                        Log.Warn("No Crazyflie Quadcopters found!");
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Error testing Crazyradio.", ex);
                }
                finally
                {
                    crazyradioDriver.Close();
                }
            }
            else
            {
                Log.Warn("No Crazyradio USB dongles found!");
            }

            Log.Info("Sleepy time...Hit space to exit.");

            var sleep = true;

            while (sleep)
            {
                if (Console.KeyAvailable && Console.ReadKey().Key == ConsoleKey.Spacebar)
                {
                    sleep = false;
                }
            }
        }