A.R.G.U.S 2.1.0
Adaptive Real-Time Guardian for Unsafe Situations
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
6#include "AppController.hpp"
7
8#include <exception>
9#include <iostream>
10#include <string>
11
12namespace {
13
14void printUsage(const char* program_name) {
15 std::cout
16 << "Usage:\n"
17 << " " << program_name << " Run Guardian FSM scenario demo\n"
18 << " " << program_name << " --button-test\n"
19 << " " << program_name << " --servo-calibrate\n"
20 << " " << program_name << " --servo-console\n"
21 << " " << program_name << " --motion-home\n"
22 << " " << program_name << " --motion-smoke-test [options]\n"
23 << " " << program_name << " --camera-backend-check [options]\n"
24 << " " << program_name << " --live-test [options]\n"
25 << "\nOptions:\n"
26 << " --button-test Run a GPIO button diagnostic loop\n"
27 << " --full-demo Deprecated alias for --live-test\n"
28 << " --servo-calibrate Run an interactive raw-pulse calibration console\n"
29 << " --servo-console Run an interactive servo console (for example: 'base 90')\n"
30 << " --motion-home Move all joints to logical 0 / home and exit\n"
31 << " --motion-smoke-test Run the motion-only servo smoke test (all joints by default)\n"
32 << " --camera-backend-check Capture a short sample and report backend/frame stats\n"
33 << " --base Smoke-test only the base servo\n"
34 << " --lower Smoke-test only the lower servo\n"
35 << " --upper Smoke-test only the upper servo\n"
36 << " --grip Smoke-test only the grip servo\n"
37 << "\nOptions for --live-test:\n"
38 << " --camera-index <n> Camera index (default: 0)\n"
39 << " --expected-marker-id <n> Expected ArUco marker ID (default: 23)\n"
40 << " --camera-backend <name> Camera backend: auto, libcamera2opencv, or opencv (default: auto)\n"
41 << " --auto-ack Auto-send operator acknowledge when frozen\n"
42 << " --help Show this message\n"
43 << "\nLive-test controls:\n"
44 << " space/button Operator acknowledge\n"
45 << " 0/1/2/3 Select mode/routine\n"
46 << " d/a Base left/right\n"
47 << " w/s Forward/backward\n"
48 << " i/k Up/down\n"
49 << " l/j Open/close gripper\n"
50 << " +/- Adjust camera focus (Pi Camera Module 3 only, -=autofocus)\n"
51 << " esc Quit\n";
52}
53
54bool parseSmokeJointFlag(const std::string& arg, AppController::SmokeJoint& joint) {
55 if (arg == "--base") {
57 return true;
58 }
59 if (arg == "--lower") {
61 return true;
62 }
63 if (arg == "--upper") {
65 return true;
66 }
67 if (arg == "--grip") {
69 return true;
70 }
71 return false;
72}
73
74bool parseIntArg(const char* text, int& value) {
75 try {
76 const std::string raw(text);
77 std::size_t parsed_count = 0;
78 const int parsed = std::stoi(raw, &parsed_count);
79 if (parsed_count != raw.size()) {
80 return false;
81 }
82 value = parsed;
83 return true;
84 } catch (const std::exception&) {
85 return false;
86 }
87}
88
89bool parseCameraBackendArg(const std::string& raw,
91 if (raw == "auto") {
93 return true;
94 }
95 if (raw == "opencv" || raw == "videocapture") {
97 return true;
98 }
99 if (raw == "libcamera2opencv" || raw == "libcamera" || raw == "cam2opencv") {
101 return true;
102 }
103 return false;
104}
105
106} // namespace
107
108int main(int argc, char* argv[]) {
109 bool run_button_test = false;
110 bool run_live_test = false;
111 bool run_servo_calibrate = false;
112 bool run_servo_console = false;
113 bool run_motion_home = false;
114 bool run_motion_smoke_test = false;
115 bool run_camera_backend_check = false;
118 bool smoke_joint_selected = false;
119
120 for (int i = 1; i < argc; ++i) {
121 const std::string arg(argv[i]);
122
123 if (arg == "--help") {
124 printUsage(argv[0]);
125 return 0;
126 }
127
128 if (arg == "--live-test") {
129 run_live_test = true;
130 continue;
131 }
132
133 if (arg == "--button-test") {
134 run_button_test = true;
135 continue;
136 }
137
138 if (arg == "--full-demo") {
139 std::cerr << "[CLI] --full-demo is deprecated; using --live-test."
140 << std::endl;
141 run_live_test = true;
142 continue;
143 }
144
145 if (arg == "--servo-calibrate") {
146 run_servo_calibrate = true;
147 continue;
148 }
149
150 if (arg == "--servo-console") {
151 run_servo_console = true;
152 continue;
153 }
154
155 if (arg == "--motion-home") {
156 run_motion_home = true;
157 continue;
158 }
159
160 if (arg == "--motion-smoke-test") {
161 run_motion_smoke_test = true;
162 continue;
163 }
164
165 if (arg == "--camera-backend-check") {
166 run_camera_backend_check = true;
167 continue;
168 }
169
170 if (parseSmokeJointFlag(arg, smoke_options.joint)) {
171 if (smoke_joint_selected) {
172 std::cerr << "Choose one smoke-test joint flag at a time." << std::endl;
173 printUsage(argv[0]);
174 return 1;
175 }
176 run_motion_smoke_test = true;
177 smoke_joint_selected = true;
178 continue;
179 }
180
181 if (arg == "--auto-ack") {
182 options.auto_ack = true;
183 continue;
184 }
185
186 if ((arg == "--camera-index" || arg == "--expected-marker-id" ||
187 arg == "--camera-backend") &&
188 i + 1 < argc) {
189 if (arg == "--camera-backend") {
190 if (!parseCameraBackendArg(argv[i + 1], options.backend_preference)) {
191 std::cerr << "Invalid camera backend for " << arg << ": "
192 << argv[i + 1] << std::endl;
193 return 1;
194 }
195
196 ++i;
197 continue;
198 }
199
200 int parsed_value = 0;
201 if (!parseIntArg(argv[i + 1], parsed_value)) {
202 std::cerr << "Invalid numeric value for " << arg << ": "
203 << argv[i + 1] << std::endl;
204 return 1;
205 }
206
207 if (arg == "--camera-index") {
208 options.camera_index = parsed_value;
209 } else {
210 options.expected_marker_id = parsed_value;
211 }
212
213 ++i;
214 continue;
215 }
216
217 std::cerr << "Unknown or incomplete argument: " << arg << std::endl;
218 printUsage(argv[0]);
219 return 1;
220 }
221
222 if ((run_button_test && run_live_test) ||
223 (run_button_test && run_servo_calibrate) ||
224 (run_button_test && run_servo_console) ||
225 (run_button_test && run_motion_home) ||
226 (run_button_test && run_motion_smoke_test) ||
227 (run_button_test && run_camera_backend_check) ||
228 (run_live_test && run_servo_calibrate) ||
229 (run_live_test && run_servo_console) ||
230 (run_live_test && run_motion_home) ||
231 (run_live_test && run_motion_smoke_test) ||
232 (run_live_test && run_camera_backend_check) ||
233 (run_servo_calibrate && run_servo_console) ||
234 (run_servo_calibrate && run_motion_home) ||
235 (run_servo_calibrate && run_motion_smoke_test) ||
236 (run_servo_calibrate && run_camera_backend_check) ||
237 (run_servo_console && run_motion_home) ||
238 (run_servo_console && run_motion_smoke_test) ||
239 (run_servo_console && run_camera_backend_check) ||
240 (run_motion_home && run_motion_smoke_test) ||
241 (run_motion_home && run_camera_backend_check) ||
242 (run_motion_smoke_test && run_camera_backend_check)) {
243 std::cerr << "Choose exactly one mode: --button-test, --live-test, --servo-calibrate, --servo-console, --motion-home, --motion-smoke-test, or --camera-backend-check."
244 << std::endl;
245 printUsage(argv[0]);
246 return 1;
247 }
248
249 AppController app_controller;
250 if (run_button_test) {
251 return app_controller.runButtonTest();
252 }
253
254 if (run_servo_calibrate) {
255 return app_controller.runServoCalibration();
256 }
257
258 if (run_servo_console) {
259 return app_controller.runInteractiveServoConsole();
260 }
261
262 if (run_motion_home) {
263 return app_controller.runMotionHomePose();
264 }
265
266 if (run_motion_smoke_test) {
267 return app_controller.runMotionSmokeTest(smoke_options);
268 }
269
270 if (run_camera_backend_check) {
271 return app_controller.runCameraBackendCheck(options);
272 }
273
274 if (run_live_test) {
275 return app_controller.runLiveMarkerTest(options);
276 }
277
278 return app_controller.runGuardianScenarioDemo();
279}
Top-level runtime mode controller for ARGUS.
Orchestrates runtime modes for ARGUS.
int runMotionSmokeTest(const MotionSmokeTestOptions &options)
Run motion-only smoke tests using the selected joint scope.
int runMotionHomePose()
Move the arm to the configured home pose and exit.
SmokeJoint
Joint selector used by motion smoke-test mode.
@ Base
Run smoke test for base joint only.
@ Upper
Run smoke test for upper joint only.
@ Lower
Run smoke test for lower joint only.
@ Grip
Run smoke test for gripper joint only.
int runCameraBackendCheck(const LiveTestOptions &options)
Run camera backend validation/check mode.
int runInteractiveServoConsole()
Run interactive servo console mode.
int runLiveMarkerTest(const LiveTestOptions &options)
Run live safety supervision mode.
int runServoCalibration()
Run interactive raw-pulse servo calibration mode.
int runButtonTest()
Run physical-button diagnostics.
int runGuardianScenarioDemo()
Run the scripted guardian scenario demonstration.
BackendPreference
Backend selection policy.
@ Auto
Auto-select backend based on platform/runtime constraints.
@ OpenCvVideoCapture
Force OpenCV VideoCapture backend.
@ Libcamera2OpenCv
Force libcamera2opencv callback backend.
int main(int argc, char *argv[])
Definition main.cpp:108
Options used by live test and camera backend check modes.
bool auto_ack
Auto-send acknowledge after freeze for testing.
CameraCapture::BackendPreference backend_preference
Requested camera backend policy.
int expected_marker_id
Expected marker ID (legacy CLI option).
int camera_index
Camera index passed to CameraCapture.
Options for the motion smoke-test mode.
SmokeJoint joint
Joint subset to smoke-test.