-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello_tof.cpp
62 lines (49 loc) · 974 Bytes
/
hello_tof.cpp
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
// Test file for time of flight sensors
// 2024-04-12
#include "tof.h"
#include "rodos.h"
#include <math.h>
#define R2D 57.2957795131
class tof_thread : public StaticThread<>
{
private:
int period = 10; // millis
public:
tof_thread(const char* thread_name) : StaticThread(thread_name){}
void init();
void run();
};
void init_params()
{
if(tof::init(TOF_IDX_ALL) == TOF_STATUS_OK)
{
PRINTF("VL53L4CD initialized!\n");
}
else
{
PRINTF("VL53L4CD error :(\n");
}
tof::enable_median_filter();
}
void tof_thread::init()
{
tof::int_xshunt();
}
void tof_thread::run()
{
tof::wakeup();
init_params();
TIME_LOOP(1 * SECONDS, period * MILLISECONDS)
{
int distance[4];
if(tof::get_distance(distance) == TOF_STATUS_OK)
{
PRINTF("%d, %d, %d, %d\n", distance[0], distance[1], distance[2], distance[3]);
}
else
{
PRINTF("ToF ranging error!\n");
}
}
}
tof_thread test_tof_thread("lidar_thread");