VOXL OpenVINS Server 0.7.0
Visual Inertial Odometry Server for VOXL Platform
Loading...
Searching...
No Matches
VoxlCommon.h
Go to the documentation of this file.
1/**
2 * @file VoxlCommon.h
3 * @brief Common definitions and utilities for the VOXL OpenVINS server
4 * @author Joao Leonardo Silva Cotta (@zauberflote1)
5 * @date 2025
6 * @version 1.0
7 *
8 * This header file contains common definitions, data structures, and utility functions
9 * used throughout the VOXL OpenVINS server. It provides the foundation for camera
10 * management, IMU handling, and general system utilities.
11 *
12 * The file includes:
13 * - Camera mode enumerations and conversion functions
14 * - Image data structures for tracking
15 * - Camera information structures
16 * - Utility functions for timing and memory management
17 * - Mathematical helper functions
18 */
19
20#ifndef VOXL_COMMON_H
21#define VOXL_COMMON_H
22#pragma once
23
24// Standard includes
25#include <stdint.h>
26#include <vector>
27#include <opencv2/opencv.hpp>
28#include <functional>
29#include <Eigen/Core>
30#include <Eigen/Dense>
31#include <modal_pipe.h>
32#include <unistd.h>
33#include <time.h>
34#include <math.h>
35#include <string.h>
36#include <iomanip>
37#include <iostream>
38#include <fstream>
39
40// ============================================================================
41// CONSTANTS AND MACROS
42// ============================================================================
43
44/**
45 * @brief Arbitrary string buffer size for names and identifiers
46 *
47 * Used for camera names, tracking names, and other string identifiers
48 * throughout the system.
49 */
50#define CM_CHAR_BUF_SIZE 64
51
52/**
53 * @brief Convert degrees to radians
54 *
55 * Macro for converting angle measurements from degrees to radians.
56 */
57#ifndef DEG_TO_RAD
58#define DEG_TO_RAD (M_PI / 180.0)
59#endif
60
61/**
62 * @brief Convert radians to degrees
63 *
64 * Macro for converting angle measurements from radians to degrees.
65 */
66#ifndef RAD_TO_DEG
67#define RAD_TO_DEG (180.0 / M_PI)
68#endif
69
70/**
71 * @brief Maximum size for image data buffer
72 *
73 * Calculated for 1280x800 resolution with 3 channels and 2 bytes per pixel
74 */
75constexpr size_t MAX_IMAGE_SIZE = 1280 * 800 * 3 * 2;
76
77// ============================================================================
78// ENUMERATIONS
79// ============================================================================
80
81/**
82 * @enum camera_mode
83 * @brief Camera operation modes for the VIO system
84 *
85 * This enumeration defines the different camera modes supported by the system.
86 * The mode determines how multiple cameras are used in the visual-inertial
87 * odometry pipeline.
88 */
89typedef enum camera_mode
90{
91 UNKNOWN = -1, ///< Unknown or invalid camera mode
92 MONO = 0, ///< Single camera mode
93 STEREO = 1, ///< Stereo camera mode (both cameras active)
94 STEREO_LEFT_ONLY = 2, ///< Stereo setup with only left camera active
95 STEREO_RIGHT_ONLY = 3 ///< Stereo setup with only right camera active
97
98// ============================================================================
99// UTILITY FUNCTIONS
100// ============================================================================
101
102/**
103 * @brief Convert camera mode enumeration to string representation
104 *
105 * This function converts a camera_mode enumeration value to its corresponding
106 * string representation for logging and debugging purposes.
107 *
108 * @param cm Camera mode enumeration value
109 * @return String representation of the camera mode
110 */
111static std::string camera_mode_as_string(camera_mode cm)
112{
113 if (cm == MONO)
114 {
115 return "MONO";
116 }
117 else if (cm == STEREO)
118 {
119 return "STEREO";
120 }
121 else if (cm == STEREO_LEFT_ONLY)
122 {
123 return "STEREO_LEFT_ONLY";
124 }
125 else if (cm == STEREO_RIGHT_ONLY)
126 {
127 return "STEREO_RIGHT_ONLY";
128 }
129 else
130 return "UNKNOWN";
131}
132
133// ============================================================================
134// DATA STRUCTURES
135// ============================================================================
136
137/**
138 * @struct cam_info
139 * @brief Camera information and calibration data
140 *
141 * This structure contains all the configuration and calibration information
142 * for a single camera in the VIO system, including intrinsic parameters,
143 * extrinsic parameters, and operational settings.
144 */
145typedef struct cam_info
146{
147 char name[128]; ///< Camera name identifier
148 char tracking_name[128]; ///< Name used for tracking operations
149 camera_mode mode; ///< Camera operation mode
150 bool is_occluded_on_takeoff; ///< Flag indicating if camera is occluded on takeoff
151 size_t cam_id; ///< Unique camera identifier
152} cam_info;
153
154// ============================================================================
155// TIMING AND SYSTEM UTILITIES
156// ============================================================================
157
158/**
159 * @brief Get monotonic time in nanoseconds
160 *
161 * This function provides a high-precision monotonic timestamp for timing
162 * measurements and synchronization. It uses the CLOCK_MONOTONIC clock
163 * which is not affected by system time changes.
164 *
165 * Used across main projects for consistent timing measurements.
166 *
167 * @return Monotonic time in nanoseconds, or -1 on error
168 */
169static int64_t _apps_time_monotonic_ns()
170{
171 struct timespec ts;
172 if (clock_gettime(CLOCK_MONOTONIC, &ts))
173 {
174 fprintf(stderr, "ERROR calling clock_gettime\n");
175 return -1;
176 }
177 return (int64_t)ts.tv_sec * 1000000000 + (int64_t)ts.tv_nsec;
178}
179
180#endif // VOXL_COMMON_H
constexpr size_t MAX_IMAGE_SIZE
Maximum size for image data buffer.
Definition VoxlCommon.h:75
camera_mode
Camera operation modes for the VIO system.
Definition VoxlCommon.h:90
@ STEREO_LEFT_ONLY
Stereo setup with only left camera active.
Definition VoxlCommon.h:94
@ MONO
Single camera mode.
Definition VoxlCommon.h:92
@ UNKNOWN
Unknown or invalid camera mode.
Definition VoxlCommon.h:91
@ STEREO_RIGHT_ONLY
Stereo setup with only right camera active.
Definition VoxlCommon.h:95
@ STEREO
Stereo camera mode (both cameras active)
Definition VoxlCommon.h:93
Camera information and calibration data.
Definition VoxlCommon.h:146
char name[128]
Camera name identifier.
Definition VoxlCommon.h:147
bool is_occluded_on_takeoff
Flag indicating if camera is occluded on takeoff.
Definition VoxlCommon.h:150
char tracking_name[128]
Name used for tracking operations.
Definition VoxlCommon.h:148
camera_mode mode
Camera operation mode.
Definition VoxlCommon.h:149
size_t cam_id
Unique camera identifier.
Definition VoxlCommon.h:151