Esempio n. 1
0
        private ICrazyradioDriver SetupCrazyflieDriver()
        {
            IEnumerable <ICrazyradioDriver> crazyradioDrivers = null;

            try
            {
                // Scan for connected Crazyradio USB dongles
                crazyradioDrivers = CrazyradioDriver.GetCrazyradios();
            }
            catch (Exception ex)
            {
                WriteToConsole("Error getting Crazyradio USB dongle devices connected to computer.");
            }

            // If we found any
            if (crazyradioDrivers != null && crazyradioDrivers.Any())
            {
                // Use first available Crazyradio dongle
                var crazyradioDriver = crazyradioDrivers.First();

                try
                {
                    // Initialize driver
                    crazyradioDriver.Open();

                    // Scan for any Crazyflie quadcopters ready for communication
                    var scanResults = crazyradioDriver.ScanChannels();
                    if (scanResults.Any())
                    {
                        // Use first online Crazyflie quadcopter found
                        var firstScanResult = scanResults.First();

                        // Set CrazyradioDriver's DataRate and Channel to that of online Crazyflie
                        var dataRateWithCrazyflie = firstScanResult.DataRate;
                        var channelWithCrazyflie  = firstScanResult.Channels.First();
                        crazyradioDriver.DataRate = dataRateWithCrazyflie;
                        crazyradioDriver.Channel  = channelWithCrazyflie;

                        return(crazyradioDriver);
                    }
                    else
                    {
                        WriteToConsole("No Crazyflie quadcopters available for communication.");
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    WriteToConsole("Error initializing Crazyradio USB dongle for communication with a Crazyflie quadcopter.");
                    throw;
                }
            }
            else
            {
                WriteToConsole("No Crazyradio USB dongles found!");
                return(null);
            }
        }
Esempio n. 2
0
        private static ICrazyradioDriver GetCrazyDriver()
        {
            IEnumerable <ICrazyradioDriver> crazyradioDrivers = null;

            crazyradioDrivers = CrazyradioDriver.GetCrazyradios();

            if (crazyradioDrivers != null && crazyradioDrivers.Any())
            {
                return(crazyradioDrivers.First());
            }

            throw new Exception("No Crazyradio USB dongles found!");
        }
Esempio n. 3
0
        public void Initailize()
        {
            crazyradioDrivers = null;

            try
            {
                // Scan and return a collection of Crazyradio USB dongles connected to the computer.
                crazyradioDrivers = CrazyradioDriver.GetCrazyradios();

                if (crazyradioDrivers == null || !crazyradioDrivers.Any())
                {
                    throw new Exception("No Crazyradio USB dongle devices found using GetCrazyradio method call.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error getting Crazyradios.", ex);
            }
        }
        private ICrazyradioDriver SetupCrazyflieDriver()
        {
            IEnumerable <ICrazyradioDriver> crazyradioDrivers = null;

            try
            {
                // Scan for connected Crazyradio USB dongles
                crazyradioDrivers = CrazyradioDriver.GetCrazyradios();
            }
            catch (Exception ex)
            {
                var msg = "Error getting Crazyradio USB dongle devices connected to computer.";
                _log.Error(msg, ex);
                throw new ApplicationException(msg, ex);
            }

            // If we found any
            if (crazyradioDrivers != null && crazyradioDrivers.Any())
            {
                try
                {
                    // Use first available Crazyradio dongle
                    var crazyradioDriver = crazyradioDrivers.First();
                    crazyradioDriver.Open();
                    return(crazyradioDriver);
                }
                catch (Exception ex)
                {
                    _log.Error("Failed to enable crazy radio", ex);
                    throw new ApplicationException("Failed to enable crazy radio");
                }
            }
            else
            {
                _log.Error("no crarzyradio USB dongle device found");
                throw new ApplicationException("no crazyradio found. check if usb device connected and libusb driver installed");
            }
        }
Esempio n. 5
0
        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;
                }
            }
        }