From d19a3a4064e252d277c12936b4756b0b8b58adb3 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 18 Apr 2024 22:05:49 +0100 Subject: [PATCH] Remove test project --- app/test/src/LidarDevice.cpp | 31 --------------- app/test/src/LidarDevice.h | 38 ------------------ app/test/src/LidarScanner.h | 77 ------------------------------------ app/test/src/test.cpp | 59 --------------------------- app/test/xmake.lua | 12 ------ 5 files changed, 217 deletions(-) delete mode 100644 app/test/src/LidarDevice.cpp delete mode 100644 app/test/src/LidarDevice.h delete mode 100644 app/test/src/LidarScanner.h delete mode 100644 app/test/src/test.cpp delete mode 100644 app/test/xmake.lua diff --git a/app/test/src/LidarDevice.cpp b/app/test/src/LidarDevice.cpp deleted file mode 100644 index 311f10b2..00000000 --- a/app/test/src/LidarDevice.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "LidarDevice.h" - -#include -#include - -namespace car::system::lidar -{ - std::string LidarDevice::getLidarMessage() - { - rapidjson::Document output_json; - output_json.SetObject(); - rapidjson::Value data_array(rapidjson::kArrayType); - - this->scan_data = this->scan(); - - for (const Measure &measure : this->scan_data) - { - rapidjson::Value measure_object(rapidjson::kObjectType); - measure_object.AddMember("distance", measure.distance, output_json.GetAllocator()); - measure_object.AddMember("angle", measure.angle, output_json.GetAllocator()); - data_array.PushBack(measure_object, output_json.GetAllocator()); - } - - output_json.AddMember("data", data_array, output_json.GetAllocator()); - - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - output_json.Accept(writer); - return buffer.GetString(); - }; -} diff --git a/app/test/src/LidarDevice.h b/app/test/src/LidarDevice.h deleted file mode 100644 index ad464955..00000000 --- a/app/test/src/LidarDevice.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef LIDARDEVICE_H -#define LIDARDEVICE_H - -#pragma once - -#include - -#include - -using namespace rplidar; - -namespace car::system::lidar -{ - class LidarDevice - { - public: - virtual void initialize() const = 0; - virtual void start() const = 0; - - virtual std::vector scan() const = 0; - - std::string getLidarMessage(); - - std::vector getScanData() const - { - return this->scan_data; - } - - virtual void stop() const = 0; - virtual void terminate() const = 0; - virtual void disconnect() const = 0; - - private: - std::vector scan_data; - }; -} - -#endif \ No newline at end of file diff --git a/app/test/src/LidarScanner.h b/app/test/src/LidarScanner.h deleted file mode 100644 index 23003c7f..00000000 --- a/app/test/src/LidarScanner.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef LIDARSCANNER_H -#define LIDARSCANNER_H - -#pragma once - -#include "LidarDevice.h" - -#include -#include - -#include -#include - -using namespace rplidar; - -namespace car::system::lidar -{ - class LidarScanner final : public LidarDevice - { - public: - [[nodiscard]] static tl::expected, nullptr_t> create(const std::string& lidar_port) - { - auto maybe_lidar = RPLidar::create(lidar_port); - if (maybe_lidar.has_value()) - { - return std::make_unique(std::move(maybe_lidar.value())); - } - else - { - return tl::make_unexpected(nullptr); - } - } - - LidarScanner(std::unique_ptr lidar) : lidar(std::move(lidar)) {}; - - void initialize() const final override - { - }; - - void start() const final override - { - this->lidar->start_motor(); - this->scan_generator = this->lidar->iter_scans(); - }; - - std::vector scan() const final override - { - assert(std::holds_alternative()>>(this->scan_generator) && "LidarScanner::scan() called before start()"); - const auto& scan_generator = std::get()>>(this->scan_generator); - return scan_generator(); - }; - - void stop() const final override - { - this->scan_generator = nullptr; - this->lidar->stop(); - this->lidar->stop_motor(); - } - - void disconnect() const final override - { - this->lidar->disconnect(); - } - - void terminate() const final override - { - this->stop(); - this->disconnect(); - } - - private: - std::unique_ptr lidar; - mutable std::variant()>, nullptr_t> scan_generator = nullptr; - }; -} - -#endif \ No newline at end of file diff --git a/app/test/src/test.cpp b/app/test/src/test.cpp deleted file mode 100644 index 2a3430ca..00000000 --- a/app/test/src/test.cpp +++ /dev/null @@ -1,59 +0,0 @@ - -#include -#include -#include - -#include "LidarScanner.h" - -int main() { - using namespace car::system::lidar; - auto maybe_lidar_scanner = LidarScanner::create("COM3"); - if (!maybe_lidar_scanner.has_value()) { - std::cout << "Unable to open lidar\n"; - return EXIT_FAILURE; - } - auto &lidar_scanner = maybe_lidar_scanner.value(); - lidar_scanner->start(); - for (int i = 0; i < 10; i++) - { - std::cout << lidar_scanner->getLidarMessage() << std::endl; - } - lidar_scanner->terminate(); - return EXIT_SUCCESS; -} - -int test() -{ - using namespace rplidar; - spdlog::set_level(spdlog::level::off); - - // auto lidar_result = RPLidar::create("/dev/ttyUSB0"); // For Linux - auto lidar_result = RPLidar::create("COM3"); // For Windows - if (!lidar_result.has_value()) - { - std::cout << "Unable to open lidar\n"; - return 0; - } - auto &lidar = lidar_result.value(); - std::cout << "Connected to lidar\n"; - - std::function()> scanGenerator = lidar->iter_scans(); - for (int i = 0; i < 100; i++) - { - std::vector scan = scanGenerator(); - std::cout << "Got " << scan.size() << " Measures!\n"; - for (const Measure &measure : scan) - { - // Access individual measurements in the scan - bool newScan = measure.newScan; - int quality = measure.quality; - float angle = measure.angle; - float distance = measure.distance; - } - } - - lidar->stop(); - lidar->stop_motor(); - lidar->disconnect(); - return 1; -} \ No newline at end of file diff --git a/app/test/xmake.lua b/app/test/xmake.lua deleted file mode 100644 index 00a2166a..00000000 --- a/app/test/xmake.lua +++ /dev/null @@ -1,12 +0,0 @@ -includes("../other/rplidar/xmake.lua") -add_requires("rapidjson") - -target("lLidar") - set_kind("binary") - set_languages("c++17") - - add_headerfiles("src/**.h") - add_files("src/**.cpp") - - add_packages("rapidjson") - add_deps("rplidar") \ No newline at end of file