VINS-Mono代码注释——数据结构

本文档用于VINS-Mono的代码学习与记录,主要参考博客VINS-Mono代码解读——各种数据结构 sensor_msgs
这部分不是特明白,后续再进行学习注解

一、std_msgs/Header

位置:std_msgs/Header.msg
一般在Image/PointCloud/IMU等各种传感器数据结构中都会出现的头信息

//序列ID:连续增加ID
uint32 seq 
//时间戳
time stamp 
//坐标系ID
string frame_id 

二、sensor_msgs::ImageConstPtr

位置:sensor_msgs/Image.msg
在feature_trackers_node.cpp中回调函数img_callback的输入,表示一幅图。

//头信息
std_msgs/Header header 
//图像高度,行数
uint32 height 
//图像宽度、列数       
uint32 width         
//#像素编码通道含义、顺序、大小
//取自include/sensor_msgs/image_encodings.h
string encoding       
// #大端big endian(从低地址到高地址的顺序存放数据的高位字节到低位字节)和小端little endian
uint8 is_bigendian   
//#全行长度(字节)
uint32 step         
//实际矩阵数据,尺寸为 (step * rows)
uint8[] data         

三、sensor_msgs::PointCloudPtr feature_points

位置:sensor_msgs/PointCloud.msg
在feature_trackers.cpp中img_callback()中创建feature_points并封装,在main()中发布为话题“/feature_tracker/feature”,包含一帧图像中特征点信息。

//头信息
//#feature_points->header = img_msg->header;
//#feature_points->header.frame_id = "world";
std_msgs/Header header
//3D点(x,y,z)
geometry_msgs/Point32[] points
//[特征点的ID,像素坐标u,v,速度vx,vy]
//#feature_points->channels.push_back(id_of_point);
//#feature_points->channels.push_back(u_of_point);
//#feature_points->channels.push_back(v_of_point);
//#feature_points->channels.push_back(velocity_x_of_point);
//#feature_points->channels.push_back(velocity_y_of_point);
//#如img_msg->channels[0].values[i]表示第i个特征点的ID值
sensor_msgs/ChannelFloat32[] channels

sensor_msgs::PointCloud msg_match_points

这个东西数据格式和之前的feature_points一样,但是channels不一样。
在keyframe.cpp中的findConnection()中建立并封装成msg_match_points,
在pose_graph_node.cpp的main()中发布话题“/pose_graph/match_points”
主要包含重定位的两帧间匹配点和匹配关系(变换矩阵)

std_msgs/Header header #头信息
	#msg_match_points.header.stamp = ros::Time(time_stamp);

geometry_msgs/Point32[] points #3D点(x,y,z)

sensor_msgs/ChannelFloat32[] channels  #[重定位帧的平移向量T的x,y,z,旋转四元数w,x,y,z和索引值]
	#t_q_index.values.push_back(T.x());
	#t_q_index.values.push_back(T.y());
	#t_q_index.values.push_back(T.z());
	#t_q_index.values.push_back(Q.w());
	#t_q_index.values.push_back(Q.x());
	#t_q_index.values.push_back(Q.y());
	#t_q_index.values.push_back(Q.z());
	#t_q_index.values.push_back(index);
	#msg_match_points.channels.push_back(t_q_index);

四、sensor_msgs::ImuConstPtr

位置:sensor_msgs/Imu.msg
IMU信息的标准数据结构

Header header	#头信息

geometry_msgs/Quaternion orientation	#四元数[x,y,z,w]
float64[9] orientation_covariance		# Row major about x, y, z axes

geometry_msgs/Vector3 angular_velocity	#角速度[x,y,z]轴
float64[9] angular_velocity_covariance	# 对应协方差矩阵,Row major(行主序) about x, y, z axes

geometry_msgs/Vector3 linear_acceleration	#线性加速度[x,y,z]
float64[9] linear_acceleration_covariance	# 对应协方差矩阵 Row major x, y z 

代码块中的组合结构

1.measurements

std::vector<std::pair<std::vector<sensor_msgs::ImuConstPtr>,sensor_msgs::PointCloudConstPtr>> measurements;

estimator_node.cpp中getMeasurements()函数将对imu和图像数据进行初步对齐得到的数据结构,确保图像关联着对应时间戳内的所有IMU数据。

sensor_msgs::PointCloudConstPtr 表示某一帧图像的feature_points

std::vector<sensor_msgs::ImuConstPtr> 表示当前帧和上一帧时间间隔中的所有IMU数据
将两者组合成一个数据结构,并构建元素为这种结构的vector进行存储

2.map<int, vector<pair<int, Eigen::Matrix<double, 7, 1>>>> image

在estimator.cpp中的process()中被建立,在Estimator::processImage()中被调用
作用是建立每个特征点(camera_id,[x,y,z,u,v,vx,vy])构成的map,索引为feature_id

			for (unsigned int i = 0; i < img_msg->points.size(); i++)
            {
                int v = img_msg->channels[0].values[i] + 0.5;
                int feature_id = v / NUM_OF_CAM;
                int camera_id = v % NUM_OF_CAM;
                double x = img_msg->points[i].x;
                double y = img_msg->points[i].y;
                double z = img_msg->points[i].z;
                double p_u = img_msg->channels[1].values[i];
                double p_v = img_msg->channels[2].values[i];
                double velocity_x = img_msg->channels[3].values[i];
                double velocity_y = img_msg->channels[4].values[i];
                ROS_ASSERT(z == 1);
                Eigen::Matrix<double, 7, 1> xyz_uv_velocity;
                xyz_uv_velocity << x, y, z, p_u, p_v, velocity_x, velocity_y;
                image[feature_id].emplace_back(camera_id,  xyz_uv_velocity);
            }

3.map<double, ImageFrame> all_image_frame

在estimator.h中作为class Estimator的属性
键是图像帧的时间戳,值是图像帧类
图像帧类可由图像帧的特征点与时间戳构造,此外还保存了位姿Rt,预积分对象pre_integration,是否是关键帧。

class ImageFrame
{
    public:
        ImageFrame(){};
        ImageFrame(const map<int, vector<pair<int, Eigen::Matrix<double, 7, 1>>>>& _points, double _t):t{_t},is_key_frame{false}
        {
            points = _points;
        };
        map<int, vector<pair<int, Eigen::Matrix<double, 7, 1>> > > points;
        double t;
        Matrix3d R;
        Vector3d T;
        IntegrationBase *pre_integration;
        bool is_key_frame;
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值