-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,77 @@ | ||
#include <RPLidar.h> | ||
//#include <RPLidar.h> | ||
#include <memory> | ||
#include <spdlog/spdlog.h> | ||
#include <pybind11/embed.h> | ||
|
||
using namespace rplidar; | ||
int main() | ||
{ | ||
spdlog::set_level(spdlog::level::debug); | ||
//int run_native() { | ||
// using namespace rplidar; | ||
// spdlog::set_level(spdlog::level::debug); | ||
// | ||
// // auto lidar_result = RPLidar::create("/dev/ttyUSB0"); | ||
// auto lidar_result = RPLidar::create("COM3"); | ||
// if (!lidar_result.has_value()) | ||
// { | ||
// return 0; | ||
// } | ||
// auto& lidar = std::move(lidar_result.value()); | ||
// | ||
// auto info_result = lidar->get_info(); | ||
// if (!info_result.has_value()) | ||
// { | ||
// std::cout << info_result.error(); | ||
// return 0; | ||
// } | ||
// auto& info = info_result.value(); | ||
// std::cout << fmt::format("model: {}, firmware: ({}, {}), hardware: {}, serialnumber: {}\n", info.model, info.firmware.first, info.firmware.second, info.hardware, info.serialNumber); | ||
// | ||
// auto health_result = lidar->get_health(); | ||
// if (!health_result.has_value()) | ||
// { | ||
// std::cout << health_result.error(); | ||
// return 0; | ||
// } | ||
// auto& health = health_result.value(); | ||
// std::cout << fmt::format("({}, {})\n", health.status, health.errorCode); | ||
// | ||
// // std::function<std::vector<Measure>()> scanGenerator = lidar->iter_scans(); | ||
// // for (int i = 0; i < 10; i++) | ||
// // { | ||
// // std::vector<Measure> 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 0; | ||
//} | ||
|
||
void run_python() { | ||
namespace py = pybind11; | ||
py::scoped_interpreter guard{}; | ||
|
||
// auto lidar_result = RPLidar::create("/dev/ttyUSB0"); | ||
auto lidar_result = RPLidar::create("COM3"); | ||
if (!lidar_result.has_value()) | ||
{ | ||
return 0; | ||
} | ||
auto& lidar = std::move(lidar_result.value()); | ||
auto rplidar = py::module_::import("rplidar"); | ||
auto RPLidar = rplidar.attr("RPLidar"); | ||
auto lidar = RPLidar.call("COM3"); | ||
|
||
auto info_result = lidar->get_info(); | ||
if (!info_result.has_value()) | ||
{ | ||
std::cout << info_result.error(); | ||
return 0; | ||
} | ||
auto& info = info_result.value(); | ||
std::cout << fmt::format("model: {}, firmware: ({}, {}), hardware: {}, serialnumber: {}\n", info.model, info.firmware.first, info.firmware.second, info.hardware, info.serialNumber); | ||
auto info = lidar.attr("get_info")(); | ||
py::print(info); | ||
|
||
auto health_result = lidar->get_health(); | ||
if (!health_result.has_value()) | ||
{ | ||
std::cout << health_result.error(); | ||
return 0; | ||
} | ||
auto& health = health_result.value(); | ||
std::cout << fmt::format("({}, {})\n", health.status, health.errorCode); | ||
auto health = lidar.attr("get_health")(); | ||
py::print(health); | ||
|
||
// std::function<std::vector<Measure>()> scanGenerator = lidar->iter_scans(); | ||
// for (int i = 0; i < 10; i++) | ||
// { | ||
// std::vector<Measure> 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(); | ||
int main() | ||
{ | ||
run_python(); | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
add_requires("serial", "spdlog") | ||
add_requires("tl_expected") | ||
|
||
target("RPLidar") | ||
set_kind("static") | ||
add_files("src/*.cpp") | ||
add_headerfiles("include/(**.h)") | ||
add_headerfiles("include/(**.hpp)") | ||
add_includedirs("include") | ||
add_packages("serial", "spdlog") | ||
add_packages("tl_expected") | ||
add_requires("pybind11", "python", {configs = {headeronly = true}}) | ||
|
||
-- target("RPLidar") | ||
-- set_kind("static") | ||
-- add_files("src/*.cpp") | ||
-- add_headerfiles("include/(**.h)") | ||
-- add_headerfiles("include/(**.hpp)") | ||
-- add_includedirs("include") | ||
-- add_packages("serial", "spdlog") | ||
-- add_packages("tl_expected") | ||
|
||
target("test") | ||
set_kind("binary") | ||
add_files("test/*.cpp") | ||
add_includedirs("include") | ||
add_packages("serial", "spdlog") | ||
add_packages("tl_expected") | ||
add_deps("RPLidar") | ||
-- add_deps("RPLidar") | ||
add_packages("pybind11", "python") | ||
|