Skip to content

Commit

Permalink
Remove python
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Dec 9, 2023
1 parent ec22c19 commit 1816924
Showing 1 changed file with 46 additions and 66 deletions.
112 changes: 46 additions & 66 deletions libraries/RPLidar/test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,80 +1,60 @@
//#include <RPLidar.h>
#include <RPLidar.h>
#include <memory>
#include <spdlog/spdlog.h>
#include <pybind11/embed.h>

//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;
//}
int run_native() {
using namespace rplidar;
spdlog::set_level(spdlog::level::debug);

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.attr("stop")();
lidar.attr("stop_motor")();
lidar.attr("disconnect")();
lidar->stop();
lidar->stop_motor();
lidar->disconnect();
return 0;
}

int main()
{
run_python();
run_native();
return 1;
}

0 comments on commit 1816924

Please sign in to comment.