Skip to content

Mobile Platform Data Storing

ka-yeon edited this page Jul 6, 2021 · 12 revisions

Mobile Platform Data Storing

πŸ’Ύcam, lidar, gps, imu, can 닀섯가지 μ„Όμ„œ 데이터 λͺ¨λ‘ csv 파일둜 μ €μž₯λœλ‹€.


경둜 μˆ˜μ •

MobilePlatform/Sensing/~SensingThread.cpp

// <make csv file>
string path = "csv file이 μ €μž₯될 μœ„μΉ˜μ™€ μ €μž₯ν•˜κ³  싢은 csv file 이름";
fstream dataFile;
dataFile.open(path, ios::out);

string path = " "에 csv file이 μ €μž₯될 μœ„μΉ˜μ™€ μ €μž₯ν•˜κ³  싢은 csv file 이름을 적어쀀닀.


μ €μž₯ κ³Όμ •

1. 폴더 생성

MobilePlatform/Sensing/main.cpp

β”œβ”€ diva2
β”‚  β”œβ”€ DIVA2_DATA
β”‚  β”‚      └─ YYYYMDD_0
β”‚  β”‚            β”œβ”€ GPS
β”‚  β”‚            β”œβ”€ IMU
β”‚  β”‚            β”œβ”€ CAN
β”‚  β”‚            β”œβ”€ CAM
β”‚  β”‚            β”‚   └─ JPG
β”‚  β”‚            └─ LiDAR
β”‚  β”‚                └─ PCD

mainλ¬Έμ—μ„œ /home/diva2 경둜 μ•ˆμ—

μœ„μ™€ 같이 DIVA2_DATA/YYYYMDD_0 폴더가 μƒμ„±λ˜λ©°,

κ·Έ 폴더 μ•ˆμ— GPS, IMU, CAN, CAM, LiDAR 폴더가 μƒμ„±λœλ‹€.

CAM/JPG, LiDAR/PCD 폴더도 ν•¨κ»˜ μƒμ„±λœλ‹€.

    time_t system_time;
    struct tm* systime;
    system_time = time(NULL);
    systime = localtime(&system_time);

    string tm_year = to_string(systime->tm_year + 1900);
    string tm_month = to_string(systime->tm_mon+1);
    string tm_date = to_string(systime->tm_mday);
    if(tm_date.size() == 1){
        tm_date = "0"+tm_date;
    }

    string timestamp;
    timestamp = tm_year + tm_month + tm_date;

    string command = "mkdir -p /home/diva2/DIVA2_DATA/"+timestamp+"_0/CAM/JPG"+ " /home/diva2/DIVA2_DATA/"+timestamp+"_0/LiDAR/PCD" + " /home/diva2/DIVA2_DATA/"+timestamp+"_0/GPS" + " /home/diva2/DIVA2_DATA/"+timestamp+"_0/IMU" + " /home/diva2/DIVA2_DATA/"+timestamp+"_0/CAN";
    const char *c = command.c_str();
    system(c);
    cout<<"makedirectory"<<endl;

2. 각각의 μ„Όμ„œ threadμ—μ„œ 데이터 μ €μž₯

μ˜ˆμ‹œ : GpsSensingThread.cpp

닀섯가지 μ„Όμ„œ λ°μ΄ν„°λŠ” 이와 같은 λ°©μ‹μœΌλ‘œ csv ν˜•μ‹μœΌλ‘œ μ €μž₯λœλ‹€.

// <make csv file>
    string path = "csv file이 μ €μž₯될 μœ„μΉ˜μ™€ μ €μž₯ν•˜κ³  싢은 csv file 이름";
    fstream dataFile;
    dataFile.open(path, ios::out);

μ •ν•΄μ€€ 파일λͺ…μœΌλ‘œ csv 파일이 μƒμ„±λœλ‹€.


while (1)
    {
        ...
        ...
        ...

            char cSn[50];

            //timestamp
            auto time = chrono::system_clock::now();
            auto mill = chrono::duration_cast<chrono::milliseconds>(time.time_since_epoch());
            long long currentTimeMillis = mill.count();
            int msc = currentTimeMillis % 1000;
            long nowTime = currentTimeMillis / 1000;
            tm *ts = localtime(&nowTime);

            sprintf(cSn, "%04d%02d%02d%02d%02d%02d%03d",
                    ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec, msc);
            // <save csv file>
            cout << cSn << endl;
            dataFile << cSn << "," << strBuff[2] << "," << strBuff[4] << "," << strBuff[8] << std::endl;

        }
    }
    // <close csv file>
    dataFile.close();

csv 파일 μ•ˆμ— sensingν•œ 데이터듀을 μ €μž₯ν•œλ‹€. lidar와 cam은 csv νŒŒμΌμ—λŠ” timestamp만 μ €μž₯ν•˜κ³ , 원본 사진과 pcd νŒŒμΌμ€ λ”°λ‘œ JPG, PCD 폴더 μ•ˆμ— μ €μž₯ν•œλ‹€.


μ €μž₯ λͺ©λ‘

gps - timestamp, latitude(μœ„λ„), longitude(경도), horixontaldilutionofprecision(μˆ˜ν‰μœ„μΉ˜μ˜€μ°¨)

imu - timestamp, scaledaccelx(xμΆ• acceleration), scaledaccely(yμΆ• acceleration), scaleaccelz(zμΆ• acceleration)

can - timestamp, handle_angle(ν•Έλ“€ 각도), turnlight(λ°©ν–₯ μ§€μ‹œλ“±), vehiclespeed(νšŒμ „μ†λ„κ³„), gear(κΈ°μ–΄ λͺ¨λ“œ)

cam - timestamp

lidar - timestamp

camκ³Ό lidarλŠ” μ·¨λ“ν•œ 원본 νŒŒμΌλ“€μ΄ ν•¨κ»˜ μ €μž₯λœλ‹€.
cam은 DIVA2_DATA/YYYYMDD_0/CAM/JPG 폴더 μ•ˆμ— CAM_timestamp.jpg 파일λͺ…μœΌλ‘œ, lidarλŠ” DIVA2_DATA/YYYYMDD_0/LiDAR/PCD 폴더 μ•ˆμ— LiDAR_timestamp.pcd 파일λͺ…μœΌλ‘œ μ €μž₯λœλ‹€.