Example #1
0
        public Boolean init()
        {
            close();
            isRunning = true;
            Boolean is_connected = false;

            try
            {
                semaphoreDriver.WaitOne();
                rplidar = new RplidarNative();
                driver  = RplidarNative.createDriver();
                if (driver > 0)
                {
                    //is_connected = RplidarNative.connect(driver, Constants.LIDAR_DEFAULT_PORT);
                    if (is_connected)
                    {
                        RplidarNative.startScan(driver);
                    }
                    else
                    {
                        errorMessage = "Failed to bind serial port " + Constants.LIDAR_DEFAULT_PORT + " for RpLidar driver.";
                    }
                }
                else
                {
                    errorMessage = "Failed to create RpLidar driver.";
                }
                semaphoreDriver.Release();
            }
            catch (ThreadInterruptedException e)
            {
                Console.WriteLine(e.Message);
            }
            return(is_connected);
        }
Example #2
0
        static void Main(String[] args)
        {
            RplidarNative rplidar = new RplidarNative();
            long          driver  = RplidarNative.createDriver();

            if (driver == 0)
            {
                Console.WriteLine("Failed to create driver...");
                return;
            }

            StringBuilder serialPort   = new StringBuilder("\\\\.\\COM3");
            bool          is_connected = RplidarNative.connect(driver, serialPort);

            if (!is_connected)
            {
                Console.WriteLine("Failed to bind " + serialPort);
                RplidarNative.disposeDriver(driver);
                return;
            }

            bool is_healthy = RplidarNative.checkHealth(driver);

            if (!is_healthy)
            {
                Console.WriteLine("RpLidar is not healthy.");
                RplidarNative.disposeDriver(driver);
                return;
            }

            RplidarNative.startScan(driver);
            MeasurementNode[] nodes = RplidarNative.getScanData(driver);
            if (nodes == null)
            {
                Console.WriteLine("No scan result.");
            }
            else
            {
                foreach (MeasurementNode node in nodes)
                {
                    Console.WriteLine(node.angle + " " + node.distance + " " + node.sync_quality);
                }
            }
            RplidarNative.stopScan(driver);
            RplidarNative.disposeDriver(driver);
        }