def testParamtersIsWrappedCorrectly(self): print("test paramters.......") laser = ydlidar.CYdLidar() port = "/dev/ydlidar" laser.setlidaropt(ydlidar.LidarPropSerialPort, port) ret, result = laser.getlidaropt_toString(ydlidar.LidarPropSerialPort) self.assertTrue(ret) self.assertEqual(port, result) baudrate = 230400 laser.setlidaropt(ydlidar.LidarPropSerialBaudrate, baudrate) ret, baud = laser.getlidaropt_toInt(ydlidar.LidarPropSerialBaudrate) self.assertTrue(ret) self.assertEqual(baudrate, baud) maxRange = 16.0 laser.setlidaropt(ydlidar.LidarPropMaxRange, maxRange) ret, mRange = laser.getlidaropt_toFloat(ydlidar.LidarPropMaxRange) self.assertTrue(ret) self.assertEqual(maxRange, mRange) intensity = False laser.setlidaropt(ydlidar.LidarPropIntenstiy, intensity) ret, quality = laser.getlidaropt_toBool(ydlidar.LidarPropIntenstiy) self.assertTrue(ret) self.assertEqual(intensity, quality)
import os import ydlidar import time import sys if __name__ == "__main__": ydlidar.os_init() ports = ydlidar.lidarPortList() port = "/dev/ydlidar" for key, value in ports.items(): port = value laser = ydlidar.CYdLidar() laser.setlidaropt(ydlidar.LidarPropSerialPort, port) laser.setlidaropt(ydlidar.LidarPropSerialBaudrate, 512000) laser.setlidaropt(ydlidar.LidarPropLidarType, ydlidar.TYPE_TOF) laser.setlidaropt(ydlidar.LidarPropDeviceType, ydlidar.YDLIDAR_TYPE_SERIAL) laser.setlidaropt(ydlidar.LidarPropScanFrequency, 10.0) laser.setlidaropt(ydlidar.LidarPropSampleRate, 20) laser.setlidaropt(ydlidar.LidarPropSingleChannel, False) ret = laser.initialize() if ret: ret = laser.turnOn() scan = ydlidar.LaserScan() while ret and ydlidar.os_isOk(): r = laser.doProcessSimple(scan) if r: print("Scan received[", scan.stamp, "]:", scan.points.size(), "ranges is [", 1.0 / scan.config.scan_time, "]Hz") else: print("Failed to get Lidar Data.")