File size: 3,245 Bytes
4c75661 | 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 | // sensors.hpp ์ํ (tests/test_sensors_cpp.py ๊ฐ ๋ณต์
์๋๋ฅผ ๋ง๋ค์ด ๋๊ธด๋ค): ํ์ง(z 0) + x = 20 ์ ๋ฒฝ.
#include <cmath>
#include <cstdio>
#include "sensors.hpp"
using namespace vkgs;
#define CHECK(c) \
do { \
if (!(c)) { std::printf("์คํจ %s:%d %s\n", __FILE__, __LINE__, #c); return 1; } \
} while (0)
int main(int, char** argv) {
VoxelWorld w;
w.load(argv[1]);
// 1) ๊ด์ : ์์์ ์๋๋ก โ ์ง๋ฉด ์นธ ์์ชฝ ๋ฉด (z 0 ~ 0.2 ์นธ) ์ ๋ฟ๋๋ค
float o[3] = {5.1f, 0.1f, 3.0f}, down[3] = {0, 0, -1}, fwd[3] = {1, 0, 0};
float t = w.raycast(o, down, 50);
CHECK(t > 2.7f && t < 3.05f);
float o2[3] = {5.1f, 0.1f, 1.0f};
float tw = w.raycast(o2, fwd, 50); // ๋ฒฝ x = 20
CHECK(std::abs(tw - (20.0f - 5.1f)) < 0.25f);
// 2) ๋ผ์ด๋ค: ์ง๋ฉด ์ ์ z โ 0, ๋ฒฝ ์ ์ x โ 20, ์๋ ์ฑ๋(โ30.67ยฐ) ์ ์ง๋ฉด ๊ฑฐ๋ฆฌ โ 1.84 / sin(30.67ยฐ)
LidarConfig lc;
lc.noise = 0;
EgoState e; // ์์ , ๋์ชฝ(+x)
auto pts = lidar_scan(w, {}, lc, e);
CHECK(pts.size() > 20000);
int ground = 0, wall = 0;
float r0 = 0;
int n0 = 0;
for (const auto& p : pts) {
if (std::abs(p.p[2] - 0.2f) < 0.25f) ++ground;
if (std::abs(p.p[0] - 20.0f) < 0.3f && p.p[2] > 0.5f) ++wall;
if (p.ring == 0) r0 += p.range, ++n0;
}
std::printf("lidar %zu์ , ์ง๋ฉด %d, ๋ฒฝ %d, 0๋ฒ ๋ง ํ๊ท ๊ฑฐ๋ฆฌ %.2f (๊ธฐ๋ %.2f)\n", pts.size(), ground, wall, r0 / n0,
(1.84f - 0.1f) / std::sin(30.67f * 3.14159265f / 180.0f));
CHECK(ground > 10000 && wall > 500);
CHECK(std::abs(r0 / n0 - (1.84f - 0.1f) / std::sin(30.67f * 3.14159265f / 180.0f)) < 0.1f);
// 3) ๊ฐ์ฒด ์์๊ฐ ๋ฒฝ๋ณด๋ค ์์ ์์ผ๋ฉด ๊ฐ๋ฆฐ๋ค
std::vector<SensorBox> boxes{{10.0f, 0.0f, 0.2f, 0.0f, 2.0f, 1.0f, 1.6f, -5.0f, 0.0f}}; // x 10, ๋ค๊ฐ์ค๋ ์ฐจ (โ5 m/s)
auto pts2 = lidar_scan(w, boxes, lc, e);
int on_box = 0;
for (const auto& p : pts2) on_box += p.object == 0;
CHECK(on_box > 50);
// 4) ๋ ์ด๋ (์): ์์ฐจ 10 m/s ๋ก ์ ์ง โ ์ ์ ๋ฒฝ์ vr โ โ10 cosฮธ, ๋ค๊ฐ์ค๋ ์ฐจ๋ vr โ โ15
RadarConfig rc;
rc.mount = {"RADAR_FRONT", {3.4f, 0, 0.5f}, {0, 0, 0}};
rc.noise_range = rc.noise_vel = 0;
e.v = 10;
auto det = radar_scan(w, boxes, rc, e);
CHECK(!det.empty() && int(det.size()) <= rc.max_points);
bool car = false, wall_ok = true;
for (const auto& d : det) {
if (d.object == 0 && std::abs(d.azimuth) < 3) car = car || std::abs(d.vr + 15.0f) < 0.5f;
if (d.object < 0 && std::abs(d.azimuth) < 30) {
float expect = -10.0f * d.s[0] / std::sqrt(d.s[0] * d.s[0] + d.s[1] * d.s[1] + d.s[2] * d.s[2]);
wall_ok = wall_ok && std::abs(d.vr - expect) < 0.3f;
}
CHECK(d.object >= 0 || d.p[2] >= e.z + rc.min_height - 1e-3f); // ๋
ธ๋ฉด ๋ฐ์ฌ๋ ์๋ค
}
std::printf("radar %zu์ , ๋ค๊ฐ์ค๋ ์ฐจ vr โ15 %s, ์ ์ ๋ฐ์ฌ ๋ํ๋ฌ %s\n", det.size(), car ? "ok" : "์์", wall_ok ? "ok" : "์ด๊ธ๋จ");
CHECK(car && wall_ok);
std::printf("ok\n");
return 0;
}
|