CameraRealSense2: added json preset file option (#513)

This commit is contained in:
matlabbe
2020-04-01 12:25:28 -04:00
parent dcc15f7555
commit b95195d8bb
5 changed files with 108 additions and 29 deletions

View File

@@ -77,6 +77,7 @@ public:
void setResolution(int width, int height, int fps = 30);
void publishInterIMU(bool enabled);
void setDualMode(bool enabled, const Transform & extrinsics);
void setJsonConfig(const std::string & json);
// T265 related parameters
void setImagesRectified(bool enabled);
void setOdomProvided(bool enabled);
@@ -131,6 +132,7 @@ private:
bool publishInterIMU_;
bool dualMode_;
Transform dualExtrinsics_;
std::string jsonConfig_;
static Transform realsense2PoseRotation_;
static Transform realsense2PoseRotationInv_;

View File

@@ -484,6 +484,32 @@ bool CameraRealSense2::init(const std::string & calibrationFolder, const std::st
return false;
}
if (!jsonConfig_.empty())
{
if (dev_[0]->is<rs400::advanced_mode>())
{
std::stringstream ss;
std::ifstream in(jsonConfig_);
if (in.is_open())
{
ss << in.rdbuf();
std::string json_file_content = ss.str();
auto adv = dev_[0]->as<rs400::advanced_mode>();
adv.load_json(json_file_content);
UINFO("JSON file is loaded! (%s)", jsonConfig_.c_str());
}
else
{
UWARN("JSON file provided doesn't exist! (%s)", jsonConfig_.c_str());
}
}
else
{
UWARN("A json config file is provided (%s), but device does not support advanced settings!", jsonConfig_.c_str());
}
}
ctx_->set_devices_changed_callback([this](rs2::event_information& info)
{
for(size_t i=0; i<dev_.size(); ++i)
@@ -991,6 +1017,13 @@ void CameraRealSense2::setDualMode(bool enabled, const Transform & extrinsics)
#endif
}
void CameraRealSense2::setJsonConfig(const std::string & json)
{
#ifdef RTABMAP_REALSENSE2
jsonConfig_ = json;
#endif
}
void CameraRealSense2::setImagesRectified(bool enabled)
{
#ifdef RTABMAP_REALSENSE2