Skip to content

Commit

Permalink
Improve scanner creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Jan 5, 2024
1 parent 9098661 commit 74d6d8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 14 additions & 2 deletions app/raspberry_pi/src/car/system/lidar/LidarScanner.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <RPLidar.h>
#include <spdlog/spdlog.h>
#include <tl/expected.hpp>

using namespace rplidar;

Expand All @@ -17,9 +18,20 @@ namespace car::system::lidar
class LidarScanner : public LidarDevice
{
public:
LidarScanner(const std::string &lidar_port) : lidar(RPLidar::create(lidar_port).value())
static tl::expected<std::unique_ptr<LidarScanner>, nullptr_t> create(const std::string &lidar_port)
{
};
auto maybe_lidar = RPLidar::create(lidar_port);
if (maybe_lidar.has_value())
{
return std::make_unique<LidarScanner>(std::move(maybe_lidar.value()));
}
else
{
return tl::make_unexpected(nullptr);
}
}

LidarScanner(std::unique_ptr<RPLidar> lidar) : lidar(std::move(lidar)){};

~LidarScanner(){};

Expand Down
14 changes: 9 additions & 5 deletions app/raspberry_pi/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ int main()
using namespace rplidar;

// spdlog::set_level(spdlog::level::off);

std::string websocket_url = getWebSocketUrl();
spdlog::info("Got websocket url: {}", websocket_url);

//std::unique_ptr<LidarDummy> scanner = std::make_unique<LidarDummy>();
std::unique_ptr<LidarScanner> scanner = std::make_unique<LidarScanner>(GET_CONFIG_VALUE(lidar_port));
std::unique_ptr<LidarDummy> scanner = std::make_unique<LidarDummy>();
// auto maybe_scanner = LidarScanner::create(GET_CONFIG_VALUE(lidar_port));
// if (!maybe_scanner.has_value())
// {
// spdlog::error("Unable to connect to the Lidar Scanner");
// }
// std::unique_ptr<LidarScanner> &scanner = maybe_scanner.value();

std::unique_ptr<MessagingSystem> messaging_system = std::make_unique<MessagingSystem>(websocket_url);

Expand All @@ -51,8 +56,7 @@ int main()
websocket_url,
std::move(scanner),
std::move(messaging_system),
std::move(movement_system)
);
std::move(movement_system));

// The CarConsole object will display the UI and handle user input:
CarConsole car_console(std::move(car_system));
Expand Down

0 comments on commit 74d6d8f

Please sign in to comment.