1.安装配置
git clone https://github.com/Livox-SDK/Livox-SDK.git
cd Livox-SDK
cd build && cmake ..
make
sudo make install
2.取流
在/Livox-SDK/sample/lidar_lvx_file目录下修改CMakeList.txt信息,添加opencv pcl之类
cmake_minimum_required(VERSION 3.0)
set(DEMO_NAME lidar_lvx_sample)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
add_definitions(${PCL_DEFINITIONS})
message(STATUS "pcl status:")
message(STATUS " version: ${pcl_VERSION}")
message(STATUS " libraries: ${PCL_LIBS}")
message(STATUS " include path: ${PCL_INCLUDE_DIRS}")
add_executable(${DEMO_NAME} main.cpp lvx_file.cpp)
target_link_libraries(${DEMO_NAME}
PRIVATE
${PROJECT_NAME}_static
${PCL_LIBRARIES}
)
其数据类型参加SDK介绍部分,具体和livox型号有关,并且单帧的数据和积分时间有关
typedef pcl::PointXYZRGBA PointT;
typedef pcl::PointCloud<PointT> PointCloud;
PointCloud::Ptr cloud(new PointCloud);
for(int i=0; i<nump; i++)200ms是存储最低时间,nump表示存储nump*200ms的数据作为一张
{
std::list<LvxBasePackDetail> point_packet_list_temp;去掉for循环只取单帧数据
{
std::unique_lock<std::mutex> lock(mtx);
point_pack_condition.wait_for(lock, milliseconds(kDefaultFrameDurationTime) - (steady_clock::now() - last_time));
last_time = steady_clock::now();
point_packet_list_temp.swap(point_packet_list);
}
if(point_packet_list_temp.empty()) {
printf("Point cloud packet is empty.\n");
break;
}
for(auto iter=point_packet_list_temp.begin();iter!=point_packet_list_temp.end();iter++)
{
if(iter->data_type !=2) continue;jiang0624
// std::cout<<"size:"<<(int)iter->pack_size<<std::endl;
// std::cout<<"device_index:"<<(int)iter->device_index<<std::endl;
// std::cout<<"version:"<<(int)iter->version<<std::endl;
// std::cout<<"port_id:"<<(int)iter->port_id<<std::endl;
// std::cout<<"lidar_index:"<<(int)iter->lidar_index<<std::endl;
// std::cout<<"rsvd:"<<(int)iter->rsvd<<std::endl;
// std::cout<<"error_code:"<<(int)iter->error_code<<std::endl;
// std::cout<<"timestamp:"<<(int)iter->timestamp_type<<std::endl;
// std::cout<<"data_type:"<<(int)iter->data_type<<std::endl;
int **rawPoint=new int *[96];
for(int raw=0;raw<96;raw++)
{
rawPoint[raw]=new int[length];
}
//memset((char*)&rawPoint[0][0],0,96*length*sizeof(int));
for (int flag=0;flag<length*96;flag++)
{
rawPoint[flag/length][flag%length]=iter->raw_point[flag];
}
for(int j=0;j<96;j++)
{
// POINTS.push_back(Dec4ToBin(rawPoint[j][0],rawPoint[j][1],rawPoint[j][2],rawPoint[j][3]));//x
// POINTS.push_back(Dec4ToBin(rawPoint[j][4],rawPoint[j][5],rawPoint[j][6],rawPoint[j][7]));//y
// POINTS.push_back(Dec4ToBin(rawPoint[j][8],rawPoint[j][9],rawPoint[j][10],rawPoint[j][11]));//z
PointT p;
p.x=(float)(Dec4ToBin(rawPoint[j][0],rawPoint[j][1],rawPoint[j][2],rawPoint[j][3]))/1000.0;
p.y=(float)(Dec4ToBin(rawPoint[j][4],rawPoint[j][5],rawPoint[j][6],rawPoint[j][7]))/1000.0;
p.z=(float)(Dec4ToBin(rawPoint[j][8],rawPoint[j][9],rawPoint[j][10],rawPoint[j][11]))/1000.0;
p.rgba = rawPoint[j][12];
//std::cout<<p.x<<", "<<p.y<<", "<<p.z<<std::endl;
cloud->points.push_back(p);
//std::cout<<cloud->size()<<std::endl;
}
for(int raw2=0;raw2<96;raw2++)
{
delete []rawPoint[raw2];
}
delete [] rawPoint;
}
}
其中解算部分
int DecToBin(uint8_t dec1)
{
int result=0,temp=dec1,j=1;
while(temp)
{
result=result+j*(temp%2);
temp=temp/2;
j=j*10;
}
return result;
}
int Dec4ToBin(uint8_t Dec1,uint8_t Dec2,uint8_t Dec3,uint8_t Dec4)
{
int result1 = DecToBin(Dec1);
int result2 = DecToBin(Dec2);
int result3 = DecToBin(Dec3);
int result4 = DecToBin(Dec4);
// std::cout<<result1<<","<<result2<<","<<result3<<","<<result4<<std::endl;
char *resultChar = (char *)malloc(32);
sprintf(resultChar,"%.8d%.8d%.8d%.8d",result4,result3,result2,result1);//补位到8
// std::cout<<resultChar<<std::endl;
int i=0,n=0,m=1,result=0;
while (resultChar[i++])
n++;
for (i = 0; i<n; i++)
{
result = result + (resultChar[n - i - 1] - '0')*m;
m *= 2;
}
free(resultChar);
return result;
}