-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlidar_main.cpp
More file actions
71 lines (54 loc) · 1.97 KB
/
lidar_main.cpp
File metadata and controls
71 lines (54 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// main.cpp
#include "dummy_task.hpp"
#include "time_util.hpp"
#include "uds_util.hpp"
#include <thread>
#include <iostream>
#include <fstream>// 저장용
#include <sched.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
// 전역 로그 버퍼 변수들 정의
std::vector<std::string> log_buffer;
std::mutex log_mutex;
int main() {
struct sched_param param;
param.sched_priority = 99;
if (sched_setscheduler(0, SCHED_FIFO, ¶m) == -1) {
perror("sched_setscheduler 실패");
return 1;
}
DummyTask lidar_func("Lidar_Function", 1515); // 11ms × 1136 = 12496 iteration
std::ofstream cycle_file("lidar_cycle_times.csv");// 저장용
cycle_file << "cycle_elapsed_ms\n";// 저장용
// UDS 송신자(클라이언트)로 연결
const char* uds_path = "/tmp/lidar_to_localization.sock";
int uds_fd = connect_uds_client(uds_path);
// 연결이 성립된 후에만 아래 작업(반복문) 시작
sleep(1);
std::cout <<"-------[lidar main start]-----------------------------------------------------------------------------------" <<std::endl;
auto cycle_start = current_time_ms();
std::thread t2([&] {
lidar_func.run_once();
});
t2.join();
auto cycle_elapsed = current_time_ms() - cycle_start;
auto end_time = current_time_ms(); // 원래 current_system_time_ms 사용했었음
// 작업이 끝난 후, work_start_time을 UDS로 송신
std::string msg = std::to_string(end_time);
write(uds_fd, msg.c_str(), msg.size());
cycle_file << cycle_elapsed << "\n";// 저장용
cycle_file.flush();
// 다음 사이클을 위해 ready 플래그 리셋
lidar_func.reset();
// 마지막에 END 신호 전송
write(uds_fd, "END", 3);
// END 전송 후 잠시 대기 (수신자가 처리할 시간)
sleep(1);
cycle_file.close();// 저장용
// 모든 로그를 한번에 출력
flush_logs();
close(uds_fd);
return 0;
}