#ifndef VSLAM_VSLAM_COMMON_H #define VSLAM_VSLAM_COMMON_H // Dinh nghia lai cac kieu ban tin thuong dung, thay cho sensor_msgs / // geometry_msgs / nav_msgs. Khuon mau: xloc_cpp/include/xloc_common.h. // // HAI QUY TAC BAT BUOC cho moi struct trong file nay: // // 1. KHONG chua kieu Eigen fixed-size (Eigen::Vector3d, Matrix4d, ...). // Dung double x, y, z. Eigen fixed-size co yeu cau can chinh 16/32 byte; // dat chung trong struct di qua bien .so la nguon loi alignment kinh dien // tren arm64 khi hai phia compile voi EIGEN_MAX_ALIGN_BYTES khac nhau. // Chuyen sang Eigen o trong ham, khong o trong kieu du lieu. // // 2. KHONG include header cua ROS, PCL, OpenCV hay RTAB-Map. File nay phai // compile duoc voi mot Eigen-less, PCL-less toolchain. Cac lib phia tren // tu chuyen doi sang kieu cua ho o bien cua minh. // // Vung du lieu lon (anh, point cloud, scan) luon di qua he thong duoi dang // std::shared_ptr. Khong bao gio copy. Xem channel.h. #include #include #include #include #include "vslam/unix_time.h" namespace vslam { // --------------------------------------------------------------------------- // Trang thai tra ve // --------------------------------------------------------------------------- enum class StatusCode : int32_t { kOk = 0, kInvalidArgument = 1, kNotFound = 2, kFailedPrecondition = 3, kUnavailable = 4, kTimeout = 5, kInternal = 6, kUnauthenticated = 7, }; struct StatusResponse { StatusCode code = StatusCode::kOk; std::string message; bool ok() const { return code == StatusCode::kOk; } explicit operator bool() const { return ok(); } static StatusResponse Ok() { return {}; } static StatusResponse Error(StatusCode c, std::string m) { return StatusResponse{c, std::move(m)}; } }; // --------------------------------------------------------------------------- // std_msgs // --------------------------------------------------------------------------- struct Header { uint32_t seq = 0; UnixTime stamp; std::string frame_id; }; // --------------------------------------------------------------------------- // geometry_msgs // --------------------------------------------------------------------------- struct Point { double x = 0.0, y = 0.0, z = 0.0; }; struct Vector3 { double x = 0.0, y = 0.0, z = 0.0; }; struct Quaternion { double x = 0.0, y = 0.0, z = 0.0, w = 1.0; }; struct Pose { Point position; Quaternion orientation; }; struct Pose2D { double x = 0.0, y = 0.0, theta = 0.0; }; struct PoseStamped { Header header; Pose pose; }; struct PoseWithCovariance { Pose pose; double covariance[36] = {}; // row-major 6x6: x y z roll pitch yaw }; struct PoseWithCovarianceStamped { Header header; PoseWithCovariance pose; }; struct Twist { Vector3 linear; Vector3 angular; }; struct TwistWithCovariance { Twist twist; double covariance[36] = {}; }; // Phep bien doi cung. Dung trong TransformTree. struct Transform { Vector3 translation; Quaternion rotation; }; struct TransformStamped { Header header; // header.frame_id = frame CHA std::string child_frame_id; Transform transform; }; // --------------------------------------------------------------------------- // nav_msgs // --------------------------------------------------------------------------- struct Odometry { Header header; // header.frame_id = frame tham chieu (vd "odom") std::string child_frame_id; // vd "base_footprint" PoseWithCovariance pose; TwistWithCovariance twist; }; // value: -1 = chua biet, 0..100 = xac suat bi chiem. // Bo cuc giong nav_msgs/OccupancyGrid: hang chinh, goc o (origin), o (0,0) // nam o phan tu data[0]. struct OccupancyGrid { Header header; float resolution = 0.05f; // met / o uint32_t width = 0; uint32_t height = 0; Pose origin; // goc duoi-trai cua o (0,0), trong frame header std::vector data; // size = width * height }; // --------------------------------------------------------------------------- // sensor_msgs // --------------------------------------------------------------------------- struct Imu { Header header; Quaternion orientation; double orientation_covariance[9] = {}; // [0] < 0 nghia la khong co orientation Vector3 angular_velocity; // rad/s double angular_velocity_covariance[9] = {}; Vector3 linear_acceleration; // m/s^2 double linear_acceleration_covariance[9] = {}; }; struct FluidPressure { Header header; double fluid_pressure = 0.0; // Pa double variance = 0.0; }; struct Temperature { Header header; double temperature = 0.0; // do C double variance = 0.0; }; // BA NGU NGHIA CUA MOT TIA -- doc truoc khi cham vao bat cu code nao doc scan. // Duoc dinh nghia o scan_sanitizer va safety_monitor dua vao dung ba thu nay: // // NaN : khong do duoc (duoi range_min, hoac driver tra 0). // +inf : do duoc nhung khong co phan xa (vuot range_max). // range_max + 1.0 : SENTINEL -- tia bi che boi than robot, da bi cat co // y boi sector mask. KHAC HAN voi hai truong hop tren: // day khong phai "khong thay gi", ma la "khong duoc // phep nhin". safety_monitor dem rieng so tia nay // (front_blanked) va khong tinh vao front_usable. // // Nham ba thu nay lai lam robot hoac dung im (SCAN_SPARSE) hoac dam vao tuong. struct LaserScan { Header header; float angle_min = 0.0f; // rad float angle_max = 0.0f; float angle_increment = 0.0f; float time_increment = 0.0f; // giay giua hai tia float scan_time = 0.0f; // giay giua hai sweep float range_min = 0.0f; // met float range_max = 0.0f; std::vector ranges; std::vector intensities; // co the rong }; struct CameraInfo { Header header; uint32_t width = 0; uint32_t height = 0; double k[9] = {}; // ma tran noi 3x3, hang chinh double d[5] = {}; // meo anh (plumb bob) uint32_t binning_x = 1; uint32_t binning_y = 1; double fx() const { return k[0]; } double fy() const { return k[4]; } double cx() const { return k[2]; } double cy() const { return k[5]; } // Noi suy sau khi decimate: crop_decimate cua image_proc cap nhat binning // chu KHONG chia lai K. Consumer phai tu bu, dung nhu image_geometry lam. double fx_binned() const { return k[0] / static_cast(binning_x); } double fy_binned() const { return k[4] / static_cast(binning_y); } double cx_binned() const { return k[2] / static_cast(binning_x); } double cy_binned() const { return k[5] / static_cast(binning_y); } }; enum class PixelFormat : uint8_t { kMono8 = 0, // 8UC1 -- infra1 / infra2 kMono16 = 1, // 16UC1 -- depth thang do theo depth_scale kFloat32 = 2, // 32FC1 -- depth met }; // Anh KHONG so huu bo nho khi den tu librealsense: `data` tro vao buffer cua // SDK va `keep_alive` giu rs2::frame song. Xem realsense_driver. struct Image { Header header; uint32_t width = 0; uint32_t height = 0; uint32_t step = 0; // byte moi hang PixelFormat format = PixelFormat::kMono8; float depth_scale = 0.001f; // met moi don vi, chi co nghia voi kMono16 const uint8_t* data = nullptr; std::shared_ptr keep_alive; // giu nguon buffer song size_t size_bytes() const { return static_cast(step) * height; } }; struct PointXYZ { float x = 0.0f, y = 0.0f, z = 0.0f; }; // Cloud phang (khong to chuc theo anh). Cac buoc loc tra ve kieu nay. struct PointCloudXYZ { Header header; std::vector points; bool is_dense = false; // false nghia la co the co NaN }; // --------------------------------------------------------------------------- // Bi danh cho con tro chia se -- moi thu di qua Channel deu la kieu nay. // --------------------------------------------------------------------------- using LaserScanPtr = std::shared_ptr; using ImuPtr = std::shared_ptr; using ImagePtr = std::shared_ptr; using PointCloudXYZPtr = std::shared_ptr; using OccupancyGridPtr = std::shared_ptr; using OdometryPtr = std::shared_ptr; } // namespace vslam #endif // VSLAM_VSLAM_COMMON_H