Download tests/cpp/test_sensors.cpp from kimjunhan/vkgs-sim: direct link, hf CLI and curl.
- Browser
- Download file 3.25 kB
-
https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/tests/cpp/test_sensors.cpp
- Command line
-
hf download hf://kimjunhan/vkgs-sim/tests/cpp/test_sensors.cpp
-
curl -L -o test_sensors.cpp https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/tests/cpp/test_sensors.cpp
3.25 kB
| // sensors.hpp ์ํ (tests/test_sensors_cpp.py ๊ฐ ๋ณต์ ์๋๋ฅผ ๋ง๋ค์ด ๋๊ธด๋ค): ํ์ง(z 0) + x = 20 ์ ๋ฒฝ. | |
| using namespace vkgs; | |
| 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; | |
| } | |