Skip to content
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

Dev presets #46

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/devices/realsense2/realsense2Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cstdint>

Expand Down Expand Up @@ -588,6 +589,13 @@ bool realsense2Driver::initializeRealsenseDevice()
}
if (!pipelineStartup())
return false;

if (m_usePreset)
{
if(!setPreset(m_presetName))
yCError(REALSENSE2) << "Unable to set preset: "<< m_presetName;
}

m_initialized = true;

//TODO: if more are connected?!
Expand Down Expand Up @@ -835,6 +843,27 @@ bool realsense2Driver::open(Searchable& config)
m_stereoMode = config.find("stereoMode").asBool();
}

if (config.check("usePreset")) {
m_usePreset = config.find("usePreset").asBool();
yCInfo(REALSENSE2) << "Enabled Using Presets";
}
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add { here?

yCInfo(REALSENSE2) << "Presets disabled";

if (m_usePreset)
{
std::string presetName = config.find("presetName").asString();
std::transform(presetName.begin(), presetName.end(), presetName.begin(), ::toupper);
if (presetsMap.find(presetName) == presetsMap.end()) {
yCError(REALSENSE2) << "Value " << presetName << " not allowed as camera preset, see documentation for supported values.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok that this is not a fatal error?
The log of such devices usually is not checked and the user may expect to have the presets enabled if the device is correctly running

}
else
{
m_presetName = presetsMap.at(presetName);
yCInfo(REALSENSE2) << "Found requested preset: " << presetName;
}
}

if (!m_paramParser.parseParam(config, params))
{
yCError(REALSENSE2) << "Failed to parse the parameters";
Expand Down Expand Up @@ -1679,3 +1708,19 @@ int realsense2Driver::width() const
{
return m_infrared_intrin.width*2;
}

bool realsense2Driver::setPreset(rs2_rs400_visual_preset preset)
{
try
{
auto sensor = m_profile.get_device().first<rs2::depth_sensor>();
sensor.set_option(rs2_option::RS2_OPTION_VISUAL_PRESET,
preset);
}
catch(const std::exception& e)
{
yCError(REALSENSE2) << "Error while setting preset: " << e.what();
return false;
}
return true;
}
14 changes: 13 additions & 1 deletion src/devices/realsense2/realsense2Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <yarp/dev/IRGBDSensor.h>
#include <yarp/dev/RGBDSensorParamParser.h>
#include <librealsense2/rs.hpp>
#include <librealsense2/rs_advanced_mode.hpp>


class realsense2Driver :
Expand All @@ -37,7 +38,15 @@ class realsense2Driver :
typedef yarp::os::Stamp Stamp;
typedef yarp::os::Property Property;
typedef yarp::sig::FlexImage FlexImage;

const std::map<std::string, rs2_rs400_visual_preset> presetsMap{
{"CUSTOM", rs2_rs400_visual_preset::RS2_RS400_VISUAL_PRESET_CUSTOM},
{"DEFAULT", rs2_rs400_visual_preset::RS2_RS400_VISUAL_PRESET_DEFAULT},
{"HAND", rs2_rs400_visual_preset::RS2_RS400_VISUAL_PRESET_HAND},
{"HIGH_ACCURACY", rs2_rs400_visual_preset::RS2_RS400_VISUAL_PRESET_HIGH_ACCURACY},
{"PRESET_HIGH_DENSITY", rs2_rs400_visual_preset::RS2_RS400_VISUAL_PRESET_HIGH_DENSITY},
{"MEDIUM_DENSITY", rs2_rs400_visual_preset::RS2_RS400_VISUAL_PRESET_MEDIUM_DENSITY},
{"REMOVE_IR_PATTERN", rs2_rs400_visual_preset::RS2_RS400_VISUAL_PRESET_REMOVE_IR_PATTERN}
};

public:
realsense2Driver();
Expand Down Expand Up @@ -116,6 +125,7 @@ class realsense2Driver :
bool pipelineRestart();
bool setFramerate(const int _fps);
void fallback();
bool setPreset(rs2_rs400_visual_preset preset);


// realsense classes
Expand Down Expand Up @@ -149,5 +159,7 @@ class realsense2Driver :
float m_scale;
bool m_rotateImage180{false};
std::vector<cameraFeature_id_t> m_supportedFeatures;
bool m_usePreset{false};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add this new flag in the documentation ? In the README is sufficient

rs2_rs400_visual_preset m_presetName;
};
#endif
Loading