-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added multi-threaded scan matching using OpenMP #14
base: master
Are you sure you want to change the base?
Changes from all commits
b4507e0
b4cca52
3c4d465
93e79ba
824a57b
4513db7
fb10ec9
e0f3e15
d249561
17d9948
f05b787
eb1f0f5
ea1556c
7070ea9
6e2221f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
find_package(OpenMP REQUIRED) | ||
if(OPENMP_FOUND) | ||
set(OpenMP_LIBS gomp) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") | ||
endif() | ||
|
||
add_library(gridfastslam | ||
gfsreader.cpp | ||
gridslamprocessor.cpp | ||
gridslamprocessor_tree.cpp | ||
motionmodel.cpp | ||
) | ||
target_link_libraries(gridfastslam scanmatcher sensor_range) | ||
|
||
target_link_libraries(gridfastslam scanmatcher sensor_range ${OpenMP_LIBS}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should not be changed I believe. |
||
|
||
install(TARGETS gridfastslam DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
#include <gmapping/scanmatcher/scanmatcher.h> | ||
#include "motionmodel.h" | ||
|
||
#include <omp.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't be necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's necessary because I'm calling the |
||
|
||
|
||
namespace GMapping { | ||
|
||
|
@@ -305,11 +307,10 @@ namespace GMapping { | |
// stream in which to write the messages | ||
std::ostream& m_infoStream; | ||
|
||
|
||
// the functions below performs side effect on the internal structure, | ||
//should be called only inside the processScan method | ||
private: | ||
|
||
std::vector<double> durations; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is that a member and not created before the for loop in the scanMatch function ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because I want to store the execution time of each function call. so it has to be valid outside the function's scope as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just use two members such as sumscore and update_count to compute the average execution time, since the execution time of each function call is of little use? |
||
/**scanmatches all the particles*/ | ||
inline void scanMatch(const double *plainReading); | ||
/**normalizes the particle weights*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,20 @@ | |
If the scan matching fails, the particle gets a default likelihood.*/ | ||
inline void GridSlamProcessor::scanMatch(const double* plainReading){ | ||
// sample a new pose from each scan in the reference | ||
|
||
double avg_duration = 0; | ||
double sumScore=0; | ||
for (ParticleVector::iterator it=m_particles.begin(); it!=m_particles.end(); it++){ | ||
double start = omp_get_wtime(); | ||
|
||
#pragma omp parallel for reduction(+:sumScore) | ||
for (int i = 0; i < m_particles.size(); i++){ | ||
OrientedPoint corrected; | ||
double score, l, s; | ||
score=m_matcher.optimize(corrected, it->map, it->pose, plainReading); | ||
|
||
score=m_matcher.optimize(corrected, m_particles[i].map, m_particles[i].pose, plainReading); | ||
// it->pose=corrected; | ||
if (score>m_minimumScore){ | ||
it->pose=corrected; | ||
m_particles[i].pose=corrected; | ||
// m_infoStream << "Pose was corrected!" << std::endl; | ||
} else { | ||
if (m_infoStream){ | ||
m_infoStream << "Scan Matching Failed, using odometry. Likelihood=" << l <<std::endl; | ||
|
@@ -25,18 +30,29 @@ inline void GridSlamProcessor::scanMatch(const double* plainReading){ | |
} | ||
} | ||
|
||
m_matcher.likelihoodAndScore(s, l, it->map, it->pose, plainReading); | ||
m_matcher.likelihoodAndScore(s, l, m_particles[i].map, m_particles[i].pose, plainReading); | ||
sumScore+=score; | ||
it->weight+=l; | ||
it->weightSum+=l; | ||
m_particles[i].weight+=l; | ||
m_particles[i].weightSum+=l; | ||
|
||
//set up the selective copy of the active area | ||
//by detaching the areas that will be updated | ||
m_matcher.invalidateActiveArea(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with these two lines:
They change map and matcher and they are designed to work sequentially. I suppose we should split this loop in two,
Also, EDIT:
|
||
m_matcher.computeActiveArea(it->map, it->pose, plainReading); | ||
m_matcher.computeActiveArea(m_particles[i].map, m_particles[i].pose, plainReading); | ||
} | ||
if (m_infoStream) | ||
|
||
double duration = omp_get_wtime() - start; | ||
durations.push_back(duration); | ||
for(int i = 0; i < durations.size(); i++) { | ||
avg_duration += durations[i]; | ||
} | ||
if(durations.size() > 0) avg_duration /= durations.size(); | ||
|
||
|
||
if (m_infoStream) { | ||
m_infoStream << "Average Scan Matching Score=" << sumScore/m_particles.size() << std::endl; | ||
m_infoStream << "Average Scan Matching Time=" << avg_duration << "s" << std::endl; | ||
} | ||
} | ||
|
||
inline void GridSlamProcessor::normalize(){ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary, please have a look at https://cmake.org/cmake/help/v3.0/module/FindOpenMP.html and http://stackoverflow.com/questions/17633513/cmake-cannot-find-openmp