-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathruntime.cpp
More file actions
120 lines (96 loc) · 3.48 KB
/
Copy pathruntime.cpp
File metadata and controls
120 lines (96 loc) · 3.48 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "kernel/capturer.hpp"
#include "kernel/control_system.hpp"
#include "kernel/identifier.hpp"
#include "kernel/pose_estimator.hpp"
#include "kernel/visualization.hpp"
#include "module/debug/framerate.hpp"
#include "utility/image/armor.hpp"
#include "utility/panic.hpp"
#include "utility/rclcpp/configuration.hpp"
#include "utility/rclcpp/node.hpp"
#include "utility/rclcpp/parameters.hpp"
#include "utility/singleton/running.hpp"
#include <csignal>
#include <yaml-cpp/yaml.h>
using namespace rmcs;
auto main() -> int {
using namespace std::chrono_literals;
std::signal(SIGINT, [](int) { util::set_running(false); });
auto rclcpp_node = util::RclcppNode { "AutoAim" };
auto handle_result = [&](auto runtime_name, const auto& result) {
if (!result.has_value()) {
rclcpp_node.error("Failed to init '{}'", runtime_name);
rclcpp_node.error(" {}", result.error());
util::panic(std::format("Failed to initialize {}", runtime_name));
}
};
auto framerate = FramerateCounter {};
framerate.set_interval(5s);
/// Runtime
///
auto capturer = kernel::Capturer {};
auto identifier = kernel::Identifier {};
auto pose_estimator = kernel::PoseEstimator {};
auto visualization = kernel::Visualization {};
auto control_system = kernel::ControlSystem {};
/// Configure
///
auto configuration = util::configuration();
auto use_visualization = configuration["use_visualization"].as<bool>();
auto use_painted_image = configuration["use_painted_image"].as<bool>();
// CAPTURER
{
auto config = configuration["capturer"];
auto result = capturer.initialize(config);
handle_result("capturer", result);
}
// IDENTIFIER
{
auto config = configuration["identifier"];
const auto path = std::filesystem::path { util::Parameters::share_location() }
/ std::filesystem::path { config["model_location"].as<std::string>() };
config["model_location"] = path.string();
auto result = identifier.initialize(config);
handle_result("identifier", result);
}
// POSE ESTIMATOR
{
auto config = configuration["pose_estimator"];
auto result = pose_estimator.initialize(config);
handle_result("pose_estimator", result);
}
// VISUALIZATION
if (use_visualization) {
auto config = configuration["visualization"];
auto result = visualization.initialize(config);
handle_result("visualization", result);
}
for (;;) {
if (!util::get_running()) [[unlikely]]
break;
if (auto image = capturer.fetch_image()) {
auto armors_2d = identifier.sync_identify(*image);
if (!armors_2d.has_value()) {
continue;
}
if (use_painted_image) {
for (const auto& armor_2d : *armors_2d)
util::draw(*image, armor_2d);
}
if (visualization.initialized()) {
visualization.send_image(*image);
}
auto armor_3d = std::ignore;
auto future_state = std::ignore;
using namespace rmcs::util;
control_system.update_state({
.timestamp = Clock::now(),
});
if (framerate.tick()) {
rclcpp_node.info("Framerate: {}hz", framerate.fps());
}
}
rclcpp_node.spin_once();
}
rclcpp_node.shutdown();
}