-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathHAL.cpp
More file actions
52 lines (44 loc) · 1.25 KB
/
HAL.cpp
File metadata and controls
52 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "HAL.hpp"
#include <chrono>
using namespace std::chrono_literals;
std::shared_ptr<MotorsNode> HAL::motors_node_ = nullptr;
std::shared_ptr<CameraNode> HAL::camera_node_ = nullptr;
HAL::HAL() : Node("hal_node")
{
motors_node_ = std::make_shared<MotorsNode>("/cmd_vel", 4.0, 0.3);
camera_node_ = std::make_shared<CameraNode>("/cam_f1_left/image_raw");
spin_thread_ = std::thread([]() {
rclcpp::executors::MultiThreadedExecutor executor;
executor.add_node(HAL::motors_node_);
executor.add_node(HAL::camera_node_);
while (rclcpp::ok()) {
executor.spin_some();
std::this_thread::sleep_for(11ms);
}
});
spin_thread_.detach();
}
void HAL::setV(const float velocity)
{
if (motors_node_) {
motors_node_->sendV(static_cast<double>(velocity));
}
}
void HAL::setW(const float velocity)
{
if (motors_node_) {
motors_node_->sendW(static_cast<double>(velocity));
}
}
std::shared_ptr<Image> HAL::getImage()
{
if (!camera_node_) {
return nullptr;
}
auto image = camera_node_->getImage();
while (!image && rclcpp::ok()) {
std::this_thread::sleep_for(5ms);
image = camera_node_->getImage();
}
return image;
}