-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a80cd6
commit ed50104
Showing
20 changed files
with
556 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> | ||
// Everyone is permitted to copy and distribute verbatim copies | ||
// of this license document, but changing it is not allowed. | ||
// This file is part of vio-hello-world Copyright (C) 2023 ZJU | ||
// You should have received a copy of the GNU General Public License | ||
// along with vio-hello-world. If not, see <https://www.gnu.org/licenses/>. | ||
// Author: weihao([email protected]), M.S at Zhejiang University | ||
|
||
#include <cv_bridge/cv_bridge.h> | ||
#include <gflags/gflags.h> | ||
#include <glog/logging.h> | ||
#include <ros/ros.h> | ||
#include <sensor_msgs/CameraInfo.h> | ||
#include <sensor_msgs/Image.h> | ||
#include <sensor_msgs/Imu.h> | ||
#include <sensor_msgs/image_encodings.h> | ||
|
||
#include <thread> | ||
|
||
#include "feat/harris/harris.h" | ||
#include "tceres/problem.h" | ||
#include "tceres/solver.h" | ||
#include "vio_hw/internal/world_manager.hpp" | ||
|
||
DEFINE_string(config_file_path, "../vio_hw/params/kitti/kitti_00-02.yaml", "config file path"); | ||
DEFINE_string(kitti_dataset_path, | ||
"/home/weihao/dataset/kitti/data_odometry_gray/dataset/sequences/00", | ||
"kitti dataset path"); | ||
void LoadKittiImagesTimestamps(const std::string &str_path_to_sequence, | ||
std::vector<std::string> &str_image_left_vec_path, | ||
std::vector<std::string> &str_image_right_vec_path, | ||
std::vector<double> ×tamps_vec); | ||
class SensorManager | ||
{ | ||
public: | ||
explicit SensorManager(viohw::WorldManager *slam_manager) : slam_world_(slam_manager) { | ||
LOG(INFO) << "Sensor Manager is create."; | ||
LoadKittiImagesTimestamps(fLS::FLAGS_kitti_dataset_path, image_left_vec_path, | ||
image_right_vec_path, vec_timestamp); | ||
}; | ||
|
||
~SensorManager() = default; | ||
|
||
void syncProcess() { | ||
LOG(INFO) << "Start the measurement reader thread"; | ||
const size_t num_images = image_left_vec_path.size(); | ||
for (int ni = 0; ni < num_images; ni++) { | ||
if (slam_world_->getParams()->slam_setting_.stereo_mode_) { | ||
std::lock_guard<std::mutex> lock(img_mutex_); | ||
double timestamp = vec_timestamp[ni]; | ||
cv::Mat image0 = cv::imread(image_left_vec_path[ni], cv::IMREAD_GRAYSCALE); | ||
cv::Mat image1 = cv::imread(image_right_vec_path[ni], cv::IMREAD_GRAYSCALE); | ||
assert(!image0.empty() && !image1.empty()); | ||
slam_world_->addNewStereoImages(timestamp, image0, image1); | ||
} | ||
std::chrono::milliseconds dura(40); | ||
std::this_thread::sleep_for(dura); | ||
} | ||
} | ||
|
||
private: | ||
std::queue<cv::Mat> img0_buf_; | ||
std::queue<cv::Mat> img1_buf_; | ||
std::mutex img_mutex_; | ||
std::vector<std::string> image_left_vec_path, image_right_vec_path; | ||
std::vector<double> vec_timestamp; | ||
viohw::WorldManager *slam_world_; | ||
}; | ||
|
||
int main(int argc, char **argv) { | ||
google::InitGoogleLogging("hello_world_vio"); | ||
FLAGS_stderrthreshold = google::INFO; | ||
FLAGS_colorlogtostderr = true; | ||
google::ParseCommandLineFlags(&argc, &argv, true); | ||
ros::init(argc, argv, "hello_world_vio"); | ||
|
||
auto params = std::make_shared<viohw::Setting>(FLAGS_config_file_path); | ||
std::cout << *params << std::endl; | ||
viohw::WorldManager world_manager(params); | ||
// Start the SLAM thread | ||
std::thread estimate_thread(&viohw::WorldManager::run, &world_manager); | ||
|
||
SensorManager sensor_manager(&world_manager); | ||
// Start the sensor measurement grab thread | ||
std::thread sensor_grab_thread(&SensorManager::syncProcess, &sensor_manager); | ||
|
||
ros::spin(); | ||
return 0; | ||
} | ||
|
||
inline void LoadKittiImagesTimestamps(const std::string &str_path_to_sequence, | ||
std::vector<std::string> &str_image_left_vec_path, | ||
std::vector<std::string> &str_image_right_vec_path, | ||
std::vector<double> ×tamps_vec) { | ||
using namespace std; | ||
string strPathTimeFile = str_path_to_sequence + "/times.txt"; | ||
|
||
std::ifstream fTimes(strPathTimeFile, ios::in | ios::app); | ||
|
||
if (!fTimes.is_open()) LOG(FATAL) << "Open Failed"; | ||
while (!fTimes.eof()) { | ||
string s; | ||
getline(fTimes, s); | ||
if (!s.empty()) { | ||
stringstream ss; | ||
ss << s; | ||
double t; | ||
ss >> t; | ||
timestamps_vec.push_back(t); | ||
} | ||
} | ||
|
||
string strPrefixLeft = str_path_to_sequence + "/image_0/"; | ||
string strPrefixRight = str_path_to_sequence + "/image_1/"; | ||
|
||
const size_t nTimes = timestamps_vec.size(); | ||
str_image_left_vec_path.resize(nTimes); | ||
str_image_right_vec_path.resize(nTimes); | ||
|
||
for (int i = 0; i < nTimes; i++) { | ||
stringstream ss; | ||
ss << setfill('0') << setw(6) << i; | ||
str_image_left_vec_path[i] = strPrefixLeft + ss.str() + ".png"; | ||
str_image_right_vec_path[i] = strPrefixRight + ss.str() + ".png"; | ||
} | ||
fTimes.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
%YAML 1.0 | ||
--- | ||
|
||
#-------------------------------------------------------------------------------------------- | ||
# Camera Parameters. | ||
#-------------------------------------------------------------------------------------------- | ||
|
||
Camera: | ||
topic.left.right: [ "/cam0/image_raw", "/cam1/image_raw" ] | ||
model.left.right: [ "pinhole","pinhole" ] | ||
left.resolution: [ 1241, 376 ] | ||
right.resolution: [ 1241, 376 ] | ||
left.K: [718.856, 718.856, 607.1928, 185.2157] | ||
right.K: [718.856, 718.856, 607.1928, 185.2157] | ||
left.distortion.coefficient: [0.0, 0.0, 0.0, 0.0] | ||
right.distortion.coefficient: [0.0, 0.0, 0.0, 0.0] | ||
|
||
FeatureAndTracker: | ||
feature.Type: 0 | ||
tracker.Type: 0 | ||
# common params | ||
max.kps.num: 500 | ||
max.kps.distance: 20 | ||
use.clahe: 1 | ||
clahe.val: 3 | ||
track.keyframetoframe: 0 | ||
use.brief: 1 | ||
# param for gftt | ||
kp.quality.level: 0.001 | ||
# param for KLT | ||
klt.use.prior: 1 | ||
klt.win.size: 9 | ||
klt.pyr.level: 3 | ||
|
||
klt.max.iter: 30 | ||
klt.max.px.precision: 0.01 | ||
klt.max.fb.dist: 0.5 | ||
klt.err: 30. | ||
|
||
IMU: | ||
topic: "/imu0" | ||
acc_n: 0.1 | ||
acc_w: 0.2 | ||
gyr_n: 0.3 | ||
gyr_w: 0.4 | ||
|
||
SLAM: | ||
stereo.mode: 1 | ||
use.imu: 1 | ||
force.realtime: 1 | ||
use.Rviz: 1 | ||
use.Pangolin: 0 | ||
|
||
# Camera Extrinsic parameters T_b_ci ( v_b = T_b_ci * v_ci ) | ||
Extrinsic: | ||
camera.num: 2 | ||
body_T_cam0: !!opencv-matrix | ||
rows: 4 | ||
cols: 4 | ||
dt: d | ||
data: [1., 0., 0., 0., | ||
0., 1., 0., 0., | ||
0., 0., 1., 0., | ||
0., 0., 0., 1.] | ||
|
||
body_T_cam1: !!opencv-matrix | ||
rows: 4 | ||
cols: 4 | ||
dt: d | ||
data: [1., 0., 0., 0.537165718864418, | ||
0., 1., 0., 0., | ||
0., 0., 1., 0., | ||
0., 0., 0., 1.] | ||
|
||
|
Oops, something went wrong.