25#include <core/VioManager.h>
26#include <core/VioManagerOptions.h>
29#include <modal_pipe.h>
30#include <modal_json.h>
31#include <modal_flow.h>
32#include <voxl_common_config.h>
58static void _quit(
int ret);
74static int connect_client_pipes(
void);
88static int create_server_pipes(
void);
99static void print_usage(
const char *program_name);
125static void _quit(
int ret)
127 printf(
"QUIT REQUESTED\n");
131 printf(
"Setting process-wide thread cancelation policy...\n");
132 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
133 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
137 printf(
"Forcibly closing all pipe connections...\n");
138 pipe_server_close_all();
139 pipe_client_close_all();
143 printf(
"Waiting for threads to terminate...\n");
146 printf(
"Shutting down cameras...\n");
148 printf(
"Camera shutdown complete\n");
158 printf(
"Exiting Cleanly\n");
160 printf(
"error code: %d\n", ret);
163 printf(
"Forcibly exiting process now!\n");
188static int connect_client_pipes(
void)
190 fprintf(stderr,
"connecting client pipes\n");
196 fprintf(stderr,
"failed to connect imu service\n");
199 fprintf(stderr,
"imu pipe name: %s\n",
imu_name);
203 printf(
"Initializing camera system with %d cameras\n",
cameras_used);
209 fprintf(stderr,
"failed to connect cam service\n");
217 for (
const auto &camera :
voxl::CameraManager::getInstance().getAllCameras())
256static int create_server_pipes(
void)
259 int flags = SERVER_FLAG_EN_CONTROL_PIPE;
262 pipe_info_t info_extended =
268 EXT_VIO_RECOMMENDED_READ_BUF_SIZE,
272 if (pipe_server_create(
EXTENDED_CH, info_extended, 0))
274 printf(
"pipe_server_create(EXTENDED_CH, info_extended, flags) failed\n");
279 cJSON *json = pipe_server_get_info_json_ptr(
EXTENDED_CH);
280 cJSON_AddStringToObject(json,
"imu",
imu_name);
288 pipe_info_t info_simple =
294 VIO_RECOMMENDED_PIPE_SIZE,
298 if (pipe_server_create(
SIMPLE_CH, info_simple, flags))
300 printf(
"pipe_server_create(SIMPLE_CH, info_simple, flags) failed\n");
305 json = pipe_server_get_info_json_ptr(
SIMPLE_CH);
306 cJSON_AddStringToObject(json,
"imu",
imu_name);
314 pipe_info_t info_status =
320 VIO_RECOMMENDED_PIPE_SIZE,
324 if (pipe_server_create(
OVSTATUS_CH, info_status, flags))
326 printf(
"pipe_server_create(SIMPLE_CH, info_status, flags) failed\n");
342static void print_usage(
const char *program_name)
344 printf(
"Usage: %s [OPTIONS]\n", program_name);
345 printf(
"VOXL OpenVINS Server - Visual Inertial Odometry System\n\n");
346 printf(
"Options:\n");
347 printf(
" -d, --debug Enable debug output and detailed logging\n");
348 printf(
" -v, --verbose Enable verbose output and status information\n");
349 printf(
" -c, --config Configuration only mode (load and validate config)\n");
350 printf(
" -i, --imu-body Enable IMU body measurements\n");
351 printf(
" -h, --help Display this help message\n\n");
352 printf(
"Examples:\n");
353 printf(
" %s Run server with default settings\n", program_name);
354 printf(
" %s -d Run server with debug output enabled\n", program_name);
355 printf(
" %s -v -c Load configuration only with verbose output\n", program_name);
356 printf(
" %s --imu-body Run with IMU body measurements enabled\n", program_name);
357 printf(
" %s --debug --verbose Run with both debug and verbose output\n", program_name);
364using namespace ov_msckf;
394int main(
int argc,
char *argv[])
398 const char *short_options =
"dvhci";
399 struct option long_options[] = {
400 {
"debug", no_argument, 0,
'd'},
401 {
"verbose", no_argument, 0,
'v'},
402 {
"help", no_argument, 0,
'h'},
403 {
"config", no_argument, 0,
'c'},
404 {
"imu-body", no_argument, 0,
'i'},
408 while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
413 printf(
"Debug mode enabled\n");
419 printf(
"Verbose mode enabled\n");
425 printf(
"Configuration only mode enabled\n");
431 printf(
"IMU body measurements enabled\n");
435 print_usage(argv[0]);
439 print_usage(argv[0]);
446 printf(
"Error: Unexpected arguments provided\n");
447 print_usage(argv[0]);
454 printf(
"config_file_read() < 0\n");
461 printf(
"Configuration loaded successfully. Exiting due to config-only mode.\n");
469 fprintf(stderr,
"ERROR cam_config_file_read\n");
473 printf(
"Camera configuration synchronized successfully\n");
476 auto& oclMgr = VoxlOCLManager::instance();
478 std::cerr <<
"OpenCL init failed!\n";
482 std::string config_path = std::string(
folder_base) +
"/estimator_config.yaml";
486 auto parser = std::make_shared<ov_core::YamlParser>(config_path);
489 std::string verbosity =
"SILENT";
490 parser->parse_config(
"verbosity", verbosity);
493 ov_core::Printer::setPrintLevel(ov_core::Printer::DEBUG);
495 ov_core::Printer::setPrintLevel(ov_core::Printer::SILENT);
510 std::cerr <<
"ERROR: could not kill existing process" << std::endl;
515 if (enable_signal_handler() == -1)
517 std::cerr <<
"ERROR: failed to start signal handler" << std::endl;
519 kill(getpid(), SIGKILL);
530 pipe_set_process_priority(THREAD_PRIORITY_RT_MED);
533 set_cpu_affinity(cpu_set_big_cores_and_gold_core());
534 print_cpu_affinity();
541 if (create_server_pipes() < 0)
543 printf(
"connect_client_pipes < 0\n");
548 if (connect_client_pipes() < 0)
550 printf(
"connect_client_pipes < 0\n");
566 printf(
"Quiting OpenVINS server\n");
Camera management system for VOXL OpenVINS.
int connect_imu_service(void)
Creates IMU pipe client and associated callbacks.
IMU interface and data handling for VOXL OpenVINS.
Common definitions and utilities for the VOXL OpenVINS server.
int main(int argc, char *argv[])
Main entry point for VOXL OpenVINS server.
int en_verbose
Enable verbose output.
int cameras_used
Number of cameras currently in use.
int camera_pipe_channels[MAX_CAM_CNT]
Camera pipe channels array.
volatile int main_running
Main process running flag.
char folder_base[CHAR_BUF_SIZE]
Base folder for yaml configuration files.
ov_msckf::VioManagerOptions vio_manager_options
VIO manager options.
char imu_name[64]
IMU device name.
voxl::img_ringbuf_packet * img_ringbuf
Image ring buffer for processing.
bool en_imu_body
Enable IMU body measurements.
std::unique_ptr< ov_msckf::VioManager > vio_manager
Main VIO manager instance.
int en_debug
Enable debug output.
std::vector< cam_info > cam_info_vec
Vector of camera configuration information.
int config_only
Configuration only mode.
Global variable declarations and constants for VOXL OpenVINS server.
#define OV_VIO_EXTENDED_NAME
Name for extended VIO data pipe.
#define SIMPLE_CH
MPA server channel for simple VIO data output.
std::atomic< uint8_t > vio_state
Current VIO system state.
#define EXTENDED_CH
MPA server channel for extended VIO data output.
std::atomic< uint32_t > vio_error_codes
VIO error codes.
#define OV_VIO_SIMPLE_LOCATION
Location for simple VIO data pipe.
#define OV_STATUS_LOCATION
Location for status information pipe.
#define OV_STATUS_NAME
Name for status information pipe.
#define OV_VIO_SIMPLE_NAME
Name for simple VIO data pipe.
#define OV_VIO_EXTENDED_LOCATION
Location for extended VIO data pipe.
#define PROCESS_NAME
Process name for the VOXL OpenVINS server.
#define OV_VIO_CONTROL_COMMANDS
Control commands available for VIO system.
#define OVSTATUS_CH
MPA server channel for status information.
#define MAX_CAM_CNT
Maximum number of cameras supported by VOXL2.
void shutdown()
Shut down all cameras and clean up resources.
bool initialize(const std::vector< cam_info > &camera_configs)
Initialize the camera manager with camera configurations.
static CameraManager & getInstance()
Get the singleton instance of the CameraManager.
static Publisher & getInstance()
Get singleton instance.
void start()
Start the publisher.
Main namespace for VOXL OpenVINS server components.
int sync_cam_config(void)
Synchronize camera configuration with system services.
int read_server_config(void)
Read and parse server configuration file.