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); }
public void run() { while (Thread.CurrentThread.ThreadState != ThreadState.Suspended && isRunning) { try { Thread.Sleep(Constants.LIDAR_SLEEP_INTERVAL); } catch (ThreadInterruptedException e) { Console.WriteLine(e.Message); continue; } // Restart driver if necessary. // if (!isHealthy() && !init()) { // logger.debug("LidarRunnable is not healthy: " + errorMessage()); // continue; // } MeasurementNode[] oneScan = null; try { semaphoreDriver.WaitOne(); if (rplidar != null && driver > 0) { oneScan = RplidarNative.getScanData(driver); } // oneScan = getScanDataForTesting(); semaphoreDriver.Release(); } catch (ThreadInterruptedException e) { Console.WriteLine(e.Message); } if (oneScan == null) { errorMessage = "RpLidar reports no scan result."; continue; } addOneScanToCache(oneScan); reportSuccess(); } }