Mapping -> Localization without reloading database

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Mapping -> Localization without reloading database

jseng
Hi, I usually run rtabmap in localization, but would like to temporarily switch to Mapping mode and then back to Localization.  Is there a way to prevent reloading the database when switching back to Localization?  I started out in Localization, so the entire database is already loaded.  Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Mapping -> Localization without reloading database

matlabbe
Administrator
Hi,

good question. Currently the code does this when switching from mapping to localization:
// The easiest way to make sure that the mapping session is saved
// is to save the memory in the database and reload it.
if((_memoryChanged || _linksChanged) && _dbDriver)
{
	UWARN("Switching from Mapping to Localization mode, the database will be saved and reloaded.");
	bool memoryChanged = _memoryChanged;
	bool linksChanged = _linksChanged;
	this->clear();
	_memoryChanged = memoryChanged;
	_linksChanged = linksChanged;
	this->loadDataFromDb(false);
	UWARN("Switching from Mapping to Localization mode, the database is reloaded!");
}
We do this because of the multiple options available in RTAB-Map about how memory is managed. It is just easier (and safer) to close everything and reload clean in read-only mode (localization). Knowing that sensor data are already loaded, we could still clear everything (to backup and update working memory stamps) but keep in RAM the sensor data, which should not have changed (raw keypoints and local occupancy grids)... reloading only the visual word vocabulary. I'll make some tests to see what is the actual time used to reload the sensor data. I'll update this thread soon.

cheers,
Mathieu
Reply | Threaded
Open this post in threaded view
|

Re: Mapping -> Localization without reloading database

matlabbe
Administrator
I did some tests and looking at the code, and because of this line:
// From SLAM to localization, change map id
this->incrementMapId();
we don't really need to clear and reload everything. Try commenting the clear/reload lines like this:
// From SLAM to localization, change map id
this->incrementMapId();

// The easiest way to make sure that the mapping session is saved
// is to save the memory in the database and reload it.
//if((_memoryChanged || _linksChanged) && _dbDriver)
//{
//UWARN("Switching from Mapping to Localization mode, the database will be saved and reloaded.");
//	bool memoryChanged = _memoryChanged;
//	bool linksChanged = _linksChanged;
//	this->clear();
//	_memoryChanged = memoryChanged;
//	_linksChanged = linksChanged;
//	this->loadDataFromDb(false);
//	UWARN("Switching from Mapping to Localization mode, the database is reloaded!");
//}

I tested with robot mapping demo and it seems to work, instantaneous switching from mapping to localization (like the reverse way) while saving the new data (added in mapping mode) to database when closing. Try this on your side and see if it doesn't break something else. I will still keep the old way for now (clearing and reload), but I will try commenting this in other projects with other configurations to see if it seems to be a valid fix or not.

cheers,
Mathieu
Reply | Threaded
Open this post in threaded view
|

Re: Mapping -> Localization without reloading database

jseng
Great!  I will try that out.