Skip to content

Commit 945f55c

Browse files
authored
Add param to change filter levels (#20)
This feature was added in royale 3.21, see: https://pmdtec.com/picofamily/2019/02/22/royale_release_v321/ The new filter level "Full" includes some additional filters (i.e. smoothing, hole filling etc.) that improve the depth image smoothness.
1 parent 30940b8 commit 945f55c

5 files changed

+70
-1
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ string(REPLACE " " ";" cxx_flags "${CMAKE_CXX_FLAGS} ${additional_cxx_flags}")
5252
MESSAGE( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})
5353
MESSAGE( STATUS "additional_cxx_flags: " ${additional_cxx_flags})
5454
MESSAGE( STATUS "cxx_flags: ${cxx_flags}")
55+
MESSAGE( STATUS "royale version: ${royale_VERSION}")
5556

5657

5758
################################################
@@ -102,6 +103,7 @@ target_link_libraries(pico_flexx_nodelet
102103
)
103104
add_dependencies(pico_flexx_nodelet ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
104105
target_compile_options(pico_flexx_nodelet PUBLIC ${cxx_flags})
106+
target_compile_definitions(pico_flexx_nodelet PUBLIC royale_VERSION_MAJOR=${royale_VERSION_MAJOR} royale_VERSION_MINOR=${royale_VERSION_MINOR})
105107

106108
add_executable(pico_flexx_driver src/pico_flexx_driver.cpp)
107109
target_link_libraries(pico_flexx_driver
@@ -110,6 +112,7 @@ target_link_libraries(pico_flexx_driver
110112
)
111113
add_dependencies(pico_flexx_driver ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
112114
target_compile_options(pico_flexx_driver PUBLIC ${cxx_flags})
115+
target_compile_definitions(pico_flexx_driver PUBLIC royale_VERSION_MAJOR=${royale_VERSION_MAJOR} royale_VERSION_MINOR=${royale_VERSION_MINOR})
113116

114117

115118

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Features:
3131
## Dependencies
3232

3333
- ROS Indigo or Kinetic (or newer should also work)
34-
- [Royale SDK](http://www.pmdtec.com/picoflexx/)
34+
- [Royale SDK](http://www.pmdtec.com/picoflexx/) (recommended: latest version, at least 3.21)
3535

3636
## Status
3737

cfg/pico_flexx_driver.cfg

+9
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@ exposure_modes = gen.enum([ gen.const("MANUAL", int_t, 0, "Manual exposure mode"
2121
gen.const("AUTOMATIC", int_t, 1, "Automatic exposure mode")
2222
], "Possible exposure modes")
2323

24+
# Royale allows to set different filter levels. Internally these represent
25+
# different configurations of the processing pipeline.
26+
filter_levels = gen.enum([ gen.const("Off", int_t, 0, "Turn off all filtering of the data (validation will still be enabled)"),
27+
gen.const("Legacy", int_t, 200, "Standard settings for older cameras"),
28+
gen.const("Full", int_t, 255, "Enable all filters that are available for this camera"),
29+
gen.const("Custom", int_t, 256, "Value returned by getFilterLevel if the processing parameters differ from all of the presets")
30+
], "Possible filter levels")
31+
2432
gen.add("use_case", int_t, 0x01, "Use cases for the sensor", 0, 0, 9, edit_method=use_cases)
2533
gen.add("exposure_mode", int_t, 0x02, "Exposure mode for the sensor", 0, 0, 1, edit_method=exposure_modes)
2634
gen.add("exposure_mode_stream2", int_t, 0x04, "Exposure mode for the sensor (stream 2)", 0, 0, 1, edit_method=exposure_modes)
2735
gen.add("exposure_time", int_t, 0x08, "Exposure time", 1000, 1, 2000)
2836
gen.add("exposure_time_stream2", int_t, 0x10, "Exposure time (stream 2)", 1000, 1, 2000)
2937
gen.add("max_noise", double_t, 0x20, "Max allowed noise", 0.07, 0.0, 0.1)
3038
gen.add("range_factor", double_t, 0x40, "Range of factor times standard deviation arround mean", 2.0, 0.0, 7.0)
39+
gen.add("filter_level", int_t, 0x80, "Filter level", 200, 0, 256, edit_method=filter_levels)
3140

3241
exit(gen.generate(PACKAGE, "pico_flexx_driver", "pico_flexx_driver"))

launch/pico_flexx_driver.launch

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<arg name="exposure_mode_stream2" default="1"/>
1818
<!-- Maximum allowed noise. Data with higher noise will be filtered out. -->
1919
<arg name="max_noise" default="0.07"/>
20+
<!-- Filter level (0 = Off, 200 = Legacy, 255 = Full) -->
21+
<arg name="filter_level" default="200"/>
2022
<!-- Range of the 16-Bit mono image which should be mapped to the 0-255 range of the 8-Bit mono image. The resulting range is `range_factor` times the standard deviation arround mean. -->
2123
<arg name="range_factor" default="2.0"/>
2224
<!-- Queue size for publisher. -->
@@ -58,6 +60,7 @@
5860
<param name="exposure_time_stream2" type="int" value="$(arg exposure_time_stream2)"/>
5961
<param name="exposure_mode_stream2" type="int" value="$(arg exposure_mode_stream2)"/>
6062
<param name="max_noise" type="double" value="$(arg max_noise)"/>
63+
<param name="filter_level" type="int" value="$(arg filter_level)"/>
6164
<param name="range_factor" type="double" value="$(arg range_factor)"/>
6265
<param name="queue_size" type="int" value="$(arg queue_size)"/>
6366
<param name="base_name_tf" type="str" value="$(arg base_name_tf)"/>

src/pico_flexx_driver.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,18 @@ class PicoFlexx : public royale::IDepthDataListener, public royale::IExposureLis
420420
lockStatus.unlock();
421421
}
422422

423+
if(level & (0x01 | 0x80))
424+
{
425+
// setting use case resets filter level, so we have to do it again here
426+
OUT_INFO("reconfigured filter_level: " << FG_CYAN << config.filter_level << NO_COLOR);
427+
if (setFilterLevel(config.filter_level))
428+
{
429+
this->config.filter_level = config.filter_level;
430+
} else {
431+
config.filter_level = this->config.filter_level;
432+
}
433+
}
434+
423435
if(level & (0x01 | 0x02 | 0x04))
424436
{
425437
royale::Pair<uint32_t, uint32_t> limits;
@@ -849,6 +861,48 @@ class PicoFlexx : public royale::IDepthDataListener, public royale::IExposureLis
849861
return true;
850862
}
851863

864+
bool setFilterLevel(const int level, const royale::StreamId streamId = 0)
865+
{
866+
#if (defined(royale_VERSION_MAJOR) && defined(royale_VERSION_MINOR) \
867+
&& (royale_VERSION_MAJOR > 3 || (royale_VERSION_MAJOR == 3 && royale_VERSION_MINOR >= 21)))
868+
const royale::FilterLevel desiredLevel = (royale::FilterLevel) level;
869+
royale::FilterLevel currentLevel;
870+
if (cameraDevice->getFilterLevel(currentLevel) != royale::CameraStatus::SUCCESS)
871+
{
872+
OUT_ERROR("could not get filter level!");
873+
return false;
874+
}
875+
OUT_INFO("current filter level: " << FG_CYAN << (int) currentLevel << NO_COLOR);
876+
this->config.filter_level = (int) currentLevel;
877+
878+
if (desiredLevel == currentLevel)
879+
{
880+
OUT_INFO("filter level unchanged");
881+
return false;
882+
}
883+
if (desiredLevel == royale::FilterLevel::Custom)
884+
{
885+
OUT_INFO("filter level 'Custom' can only be read, not set");
886+
return false;
887+
}
888+
if (currentLevel == royale::FilterLevel::Custom)
889+
{
890+
OUT_INFO("current filter level is 'Custom', will not overwrite");
891+
return false;
892+
}
893+
if (cameraDevice->setFilterLevel(desiredLevel, streamId) != royale::CameraStatus::SUCCESS)
894+
{
895+
OUT_ERROR("could not set filter level!");
896+
return false;
897+
}
898+
OUT_INFO("filter level changed to: " << FG_YELLOW << (int) desiredLevel);
899+
return true;
900+
#else
901+
OUT_ERROR("setting the filter level requires royale >= 3.21!");
902+
return false;
903+
#endif
904+
}
905+
852906
bool createCameraInfo(const royale::LensParameters &params)
853907
{
854908
if(params.distortionRadial.size() != 3)

0 commit comments

Comments
 (0)