Get one frame (spin) of lidar data

Hello @pjhkb083gak9,
you are on the right track.
notice that because the recording always starts asynchronously to the LiDAR run, the first spin that was recorded reaches the “scanComplete” flag to be true while not the whole spin was recorded ( in this specific recording only half of the spin was recorded) - so if you wish to extract a full 360 deg spin, you should ignore the first spin (the first time the updateFrame is being called in the sample code).

So, I suggest you put your code right aside to the calling of updateFrame function (where the status == DW_SUCCESS condition is satisfied from dwSensorLidar_readPacket) and use a similar class variable to m_pointCloud for accumulating the data you wish to have for the relevant point cloud spin.

also, please consider the following code to replace with updateFrame function in order to draw a specific LiDAR spin number (spinNumToDraw ):

void updateFrame(uint32_t accumulatedPoints, uint32_t packetCount,
                     dwTime_t hostTimestamp, dwTime_t sensorTimestamp)
    {
    	static int spinNum = 0;
    	static const int spinNumToDraw = 5; // ignoring spin 0 so this value should be higher than 0
    	if( spinNum < spinNumToDraw) // waiting for the spin number we want to draw
    		spinNum++;
    	else if(spinNum == spinNumToDraw)
    	{
    		spinNum++;
			m_pointCloudBufferSize = accumulatedPoints;
			// Grab properties, in case they were changed while running
			dwSensorLidar_getProperties(&m_lidarProperties, m_lidarSensor);
			dwRenderEngine_setBuffer(m_pointCloudBuffer,
									 DW_RENDER_ENGINE_PRIMITIVE_TYPE_POINTS_3D,
									 m_pointCloud.get(),
									 sizeof(dwLidarPointXYZI),
									 0,
									 m_pointCloudBufferSize,
									 m_renderEngine);

			m_message1 = "Host timestamp    (us) " + std::to_string(hostTimestamp);
			m_message2 = "Sensor timestamp (us) " + std::to_string(sensorTimestamp);
			m_message3 = "Packets per scan         " + std::to_string(packetCount);
			m_message4 = "Points per scan           " + std::to_string(accumulatedPoints);
			m_message5 = "Frequency (Hz)           " + std::to_string(m_lidarProperties.spinFrequency);
			m_message6 = "Lidar Device               " + std::string{m_lidarProperties.deviceString};
			m_message7 = "Press ESC to exit";

    	}
    }
1 Like