Skip to content

Commit

Permalink
modify structure
Browse files Browse the repository at this point in the history
  • Loading branch information
qintonguav committed Mar 23, 2019
1 parent e72b5f7 commit 0716d54
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 66 deletions.
116 changes: 67 additions & 49 deletions vins_estimator/src/estimator/estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,82 @@ Estimator::Estimator(): f_manager{Rs}
{
ROS_INFO("init begins");
clearState();
}

Estimator::~Estimator()
{
if (MULTIPLE_THREAD)
{
processThread.join();
printf("join thread \n");
}
}

void Estimator::clearState()
{
prevTime = -1;
curTime = 0;
openExEstimation = 0;
initP = Eigen::Vector3d(0, 0, 0);
initR = Eigen::Matrix3d::Identity();
inputImageCnt = 0;
initFirstPoseFlag = false;

for (int i = 0; i < WINDOW_SIZE + 1; i++)
{
Rs[i].setIdentity();
Ps[i].setZero();
Vs[i].setZero();
Bas[i].setZero();
Bgs[i].setZero();
dt_buf[i].clear();
linear_acceleration_buf[i].clear();
angular_velocity_buf[i].clear();

if (pre_integrations[i] != nullptr)
{
delete pre_integrations[i];
}
pre_integrations[i] = nullptr;
}

for (int i = 0; i < NUM_OF_CAM; i++)
{
tic[i] = Vector3d::Zero();
ric[i] = Matrix3d::Identity();
}

first_imu = false,
sum_of_back = 0;
sum_of_front = 0;
frame_count = 0;
solver_flag = INITIAL;
initial_timestamp = 0;
all_image_frame.clear();

if (tmp_pre_integration != nullptr)
delete tmp_pre_integration;
if (last_marginalization_info != nullptr)
delete last_marginalization_info;

tmp_pre_integration = nullptr;
last_marginalization_info = nullptr;
last_marginalization_parameter_blocks.clear();

f_manager.clearState();

failure_occur = 0;
}

void Estimator::setParameter()
{
while(!accBuf.empty())
accBuf.pop();
while(!gyrBuf.empty())
gyrBuf.pop();
while(!featureBuf.empty())
featureBuf.pop();

for (int i = 0; i < NUM_OF_CAM; i++)
{
tic[i] = TIC[i];
Expand All @@ -43,10 +108,11 @@ void Estimator::setParameter()
std::cout << "MULTIPLE_THREAD is " << MULTIPLE_THREAD << '\n';
if (MULTIPLE_THREAD)
{
processThread = std::thread(&Estimator::processMeasurements, this);
processThread = std::thread(&Estimator::processMeasurements, this);
}
}


void Estimator::inputImage(double t, const cv::Mat &_img, const cv::Mat &_img1)
{
inputImageCnt++;
Expand Down Expand Up @@ -250,54 +316,6 @@ void Estimator::initFirstPose(Eigen::Vector3d p, Eigen::Matrix3d r)
}


void Estimator::clearState()
{
for (int i = 0; i < WINDOW_SIZE + 1; i++)
{
Rs[i].setIdentity();
Ps[i].setZero();
Vs[i].setZero();
Bas[i].setZero();
Bgs[i].setZero();
dt_buf[i].clear();
linear_acceleration_buf[i].clear();
angular_velocity_buf[i].clear();

if (pre_integrations[i] != nullptr)
{
delete pre_integrations[i];
}
pre_integrations[i] = nullptr;
}

for (int i = 0; i < NUM_OF_CAM; i++)
{
tic[i] = Vector3d::Zero();
ric[i] = Matrix3d::Identity();
}

first_imu = false,
sum_of_back = 0;
sum_of_front = 0;
frame_count = 0;
solver_flag = INITIAL;
initial_timestamp = 0;
all_image_frame.clear();

if (tmp_pre_integration != nullptr)
delete tmp_pre_integration;
if (last_marginalization_info != nullptr)
delete last_marginalization_info;

tmp_pre_integration = nullptr;
last_marginalization_info = nullptr;
last_marginalization_parameter_blocks.clear();

f_manager.clearState();

failure_occur = 0;
}

void Estimator::processIMU(double t, double dt, const Vector3d &linear_acceleration, const Vector3d &angular_velocity)
{
if (!first_imu)
Expand Down
2 changes: 1 addition & 1 deletion vins_estimator/src/estimator/estimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Estimator
{
public:
Estimator();

~Estimator();
void setParameter();

// interface
Expand Down
23 changes: 8 additions & 15 deletions vins_estimator/src/featureTracker/feature_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ void FeatureTracker::setMask()
}
}

void FeatureTracker::addPoints()
{
for (auto &p : n_pts)
{
cur_pts.push_back(p);
ids.push_back(n_id++);
track_cnt.push_back(1);
}
}

double FeatureTracker::distance(cv::Point2f &pt1, cv::Point2f &pt2)
{
//printf("pt1: %f %f pt2: %f %f\n", pt1.x, pt1.y, pt2.x, pt2.y);
Expand Down Expand Up @@ -195,12 +185,15 @@ map<int, vector<pair<int, Eigen::Matrix<double, 7, 1>>>> FeatureTracker::trackIm
}
else
n_pts.clear();
ROS_DEBUG("detect feature costs: %fms", t_t.toc());
ROS_DEBUG("detect feature costs: %f ms", t_t.toc());

ROS_DEBUG("add feature begins");
TicToc t_a;
addPoints();
ROS_DEBUG("selectFeature costs: %fms", t_a.toc());
for (auto &p : n_pts)
{
cur_pts.push_back(p);
ids.push_back(n_id++);
track_cnt.push_back(1);
}
//printf("feature cnt after add %d\n", (int)ids.size());
}

cur_un_pts = undistortedPts(cur_pts, m_camera[0]);
Expand Down
1 change: 0 additions & 1 deletion vins_estimator/src/featureTracker/feature_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class FeatureTracker
FeatureTracker();
map<int, vector<pair<int, Eigen::Matrix<double, 7, 1>>>> trackImage(double _cur_time, const cv::Mat &_img, const cv::Mat &_img1 = cv::Mat());
void setMask();
void addPoints();
void readIntrinsicParameter(const vector<string> &calib_file);
void showUndistortion(const string &name);
void rejectWithF();
Expand Down

0 comments on commit 0716d54

Please sign in to comment.