Example #1
0
        /// <summary>
        /// Scan task
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private void Scan(ScanMode mode, CancellationToken cancellationToken)
        {
            // Main loop
            while (!cancellationToken.IsCancellationRequested)
            {
                // Try to start lidar
                if (!StartLidar(mode))
                {
                    // Reset and try to start again in a while to avoid high CPU load if something breaks
                    lidar.Reset();
                    Thread.Sleep(1000);
                    continue;
                }

                // Run lidar
                if (!RunLidar(cancellationToken))
                {
                    // Reset and try to start again
                    lidar.Reset();
                    continue;
                }
            }

            // Stop lidar
            StopLidar();
        }