Skip to content

Commit

Permalink
PR #3008 from Arun-Prasad-V: Renamed GL GPU enable param
Browse files Browse the repository at this point in the history
  • Loading branch information
SamerKhshiboun authored Feb 16, 2024
2 parents c76358c + 5e835f7 commit c0a674c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 56 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,16 @@ User can set the camera name and camera namespace, to distinguish between camera
- 1 -> **copy**: Every gyro message will be attached by the last accel message.
- 2 -> **linear_interpolation**: Every gyro message will be attached by an accel message which is interpolated to gyro's timestamp.
- Note: When the param *unite_imu_method* is dynamically updated, re-enable either gyro or accel stream for the change to take effect.
- **accelerate_with_gpu**:
- GPU accelerated processing of PointCloud and Colorizer filters.
- integer:
- 0 --> **NO_GPU**: use only CPU for proccessing PointCloud and Colorizer filters
- 1 --> **GL_GPU**: use GLSL to accelerate GPU for processing PointCloud and Colorizer filters
- **accelerate_gpu_with_glsl**:
- Boolean: GPU accelerated with GLSL for processing PointCloud and Colorizer filters.
- Note:
- To have smooth transition between the processing blocks when this parameter is updated dynamically, the node will:
- Stop the video sensors
- Do necessary GLSL configuration
- And then, start the video sensors
- To enable GPU acceleration, turn ON `BUILD_ACCELERATE_WITH_GPU` during build:
- To enable GPU acceleration, turn ON `BUILD_ACCELERATE_GPU_WITH_GLSL` during build:
```bash
colcon build --cmake-args '-DBUILD_ACCELERATE_WITH_GPU=ON'
colcon build --cmake-args '-DBUILD_ACCELERATE_GPU_WITH_GLSL=ON'
```

#### Parameters that cannot be changed in runtime:
Expand Down
14 changes: 7 additions & 7 deletions realsense2_camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ find_package(tf2 REQUIRED)
find_package(diagnostic_updater REQUIRED)

find_package(realsense2 2.54.1)
if (BUILD_ACCELERATE_WITH_GPU)
if (BUILD_ACCELERATE_GPU_WITH_GLSL)
find_package(realsense2-gl 2.54.1)
endif()
if(NOT realsense2_FOUND)
Expand All @@ -144,7 +144,7 @@ set(SOURCES
src/tfs.cpp
)

if (BUILD_ACCELERATE_WITH_GPU)
if (BUILD_ACCELERATE_GPU_WITH_GLSL)
list(APPEND SOURCES src/gl_gpu_processing.cpp)
endif()

Expand Down Expand Up @@ -178,8 +178,8 @@ if(${rclcpp_VERSION} VERSION_GREATER_EQUAL "17.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRCLCPP_HAS_OnSetParametersCallbackType")
endif()

if (BUILD_ACCELERATE_WITH_GPU)
add_definitions(-DACCELERATE_WITH_GPU)
if (BUILD_ACCELERATE_GPU_WITH_GLSL)
add_definitions(-DACCELERATE_GPU_WITH_GLSL)
endif()

set(INCLUDES
Expand All @@ -195,7 +195,7 @@ set(INCLUDES
include/profile_manager.h
include/image_publisher.h)

if (BUILD_ACCELERATE_WITH_GPU)
if (BUILD_ACCELERATE_GPU_WITH_GLSL)
list(APPEND INCLUDES include/gl_window.h)
endif()

Expand All @@ -214,7 +214,7 @@ add_library(${PROJECT_NAME} SHARED
${SOURCES}
)

if (BUILD_ACCELERATE_WITH_GPU)
if (BUILD_ACCELERATE_GPU_WITH_GLSL)
set(link_libraries ${realsense2-gl_LIBRARY})
else()
set(link_libraries ${realsense2_LIBRARY})
Expand All @@ -238,7 +238,7 @@ set(dependencies
diagnostic_updater
)

if (BUILD_ACCELERATE_WITH_GPU)
if (BUILD_ACCELERATE_GPU_WITH_GLSL)
list(APPEND dependencies realsense2-gl)
else()
list(APPEND dependencies realsense2)
Expand Down
11 changes: 5 additions & 6 deletions realsense2_camera/include/base_realsense_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <ros_sensor.h>
#include <named_filter.h>

#if defined (ACCELERATE_WITH_GPU)
#if defined (ACCELERATE_GPU_WITH_GLSL)
#include <gl_window.h>
#endif

Expand Down Expand Up @@ -119,7 +119,6 @@ namespace realsense2_camera

public:
enum class imu_sync_method{NONE, COPY, LINEAR_INTERPOLATION};
enum class accelerate_with_gpu {NO_GPU, GL_GPU};

protected:
class float3
Expand Down Expand Up @@ -268,7 +267,7 @@ namespace realsense2_camera
void startRGBDPublisherIfNeeded();
void stopPublishers(const std::vector<rs2::stream_profile>& profiles);

#if defined (ACCELERATE_WITH_GPU)
#if defined (ACCELERATE_GPU_WITH_GLSL)
void initOpenGLProcessing(bool use_gpu_processing);
void shutdownOpenGLProcessing();
void glfwPollEventCallback();
Expand Down Expand Up @@ -354,11 +353,11 @@ namespace realsense2_camera
std::shared_ptr<diagnostic_updater::Updater> _diagnostics_updater;
rs2::stream_profile _base_profile;

#if defined (ACCELERATE_WITH_GPU)
#if defined (ACCELERATE_GPU_WITH_GLSL)
GLwindow _app;
rclcpp::TimerBase::SharedPtr _timer;
accelerate_with_gpu _accelerate_with_gpu;
bool _is_accelerate_with_gpu_changed;
bool _accelerate_gpu_with_glsl;
bool _is_accelerate_gpu_with_glsl_changed;
#endif

};//end class
Expand Down
2 changes: 1 addition & 1 deletion realsense2_camera/include/gl_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API

#if defined (ACCELERATE_WITH_GPU)
#if defined (ACCELERATE_GPU_WITH_GLSL)

#define GL_SILENCE_DEPRECATION
#define GLFW_INCLUDE_GLU
Expand Down
2 changes: 1 addition & 1 deletion realsense2_camera/launch/rs_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{'name': 'config_file', 'default': "''", 'description': 'yaml config file'},
{'name': 'json_file_path', 'default': "''", 'description': 'allows advanced configuration'},
{'name': 'initial_reset', 'default': 'false', 'description': "''"},
{'name': 'accelerate_with_gpu', 'default': "0", 'description': '[0-No_GPU, 1-GL_GPU]'},
{'name': 'accelerate_gpu_with_glsl', 'default': "false", 'description': 'enable GPU acceleration with GLSL'},
{'name': 'rosbag_filename', 'default': "''", 'description': 'A realsense bagfile to run from as a device'},
{'name': 'log_level', 'default': 'info', 'description': 'debug log level [DEBUG|INFO|WARN|ERROR|FATAL]'},
{'name': 'output', 'default': 'screen', 'description': 'pipe node output [screen|log]'},
Expand Down
8 changes: 4 additions & 4 deletions realsense2_camera/src/base_realsense_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ BaseRealSenseNode::BaseRealSenseNode(rclcpp::Node& node,
_imu_sync_method(imu_sync_method::NONE),
_is_profile_changed(false),
_is_align_depth_changed(false)
#if defined (ACCELERATE_WITH_GPU)
#if defined (ACCELERATE_GPU_WITH_GLSL)
,_app(1280, 720, "RS_GLFW_Window"),
_accelerate_with_gpu(accelerate_with_gpu::NO_GPU),
_is_accelerate_with_gpu_changed(false)
_accelerate_gpu_with_glsl(false),
_is_accelerate_gpu_with_glsl_changed(false)
#endif
{
if ( use_intra_process )
Expand Down Expand Up @@ -234,7 +234,7 @@ void BaseRealSenseNode::setupFilters()
_cv_mpc.notify_one();
};

#if defined (ACCELERATE_WITH_GPU)
#if defined (ACCELERATE_GPU_WITH_GLSL)
_colorizer_filter = std::make_shared<NamedFilter>(std::make_shared<rs2::gl::colorizer>(), _parameters, _logger);
_pc_filter = std::make_shared<PointcloudFilter>(std::make_shared<rs2::gl::pointcloud>(), _node, _parameters, _logger);
#else
Expand Down
2 changes: 1 addition & 1 deletion realsense2_camera/src/gl_gpu_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using namespace realsense2_camera;
using namespace std::chrono_literals;

#if defined (ACCELERATE_WITH_GPU)
#if defined (ACCELERATE_GPU_WITH_GLSL)

void BaseRealSenseNode::initOpenGLProcessing(bool use_gpu_processing)
{
Expand Down
14 changes: 7 additions & 7 deletions realsense2_camera/src/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ void BaseRealSenseNode::getParameters()
_base_frame_id = (static_cast<std::ostringstream&&>(std::ostringstream() << _camera_name << "_" << _base_frame_id)).str();
_parameters_names.push_back(param_name);

#if defined (ACCELERATE_WITH_GPU)
param_name = std::string("accelerate_with_gpu");
_parameters->setParam<int>(param_name, int(accelerate_with_gpu::NO_GPU),
#if defined (ACCELERATE_GPU_WITH_GLSL)
param_name = std::string("accelerate_gpu_with_glsl");
_parameters->setParam<bool>(param_name, false,
[this](const rclcpp::Parameter& parameter)
{
accelerate_with_gpu temp_value = accelerate_with_gpu(parameter.get_value<int>());
if (_accelerate_with_gpu != temp_value)
bool temp_value = parameter.get_value<bool>();
if (_accelerate_gpu_with_glsl != temp_value)
{
_accelerate_with_gpu = temp_value;
_accelerate_gpu_with_glsl = temp_value;
std::lock_guard<std::mutex> lock_guard(_profile_changes_mutex);
_is_accelerate_with_gpu_changed = true;
_is_accelerate_gpu_with_glsl_changed = true;
}
_cv_mpc.notify_one();
});
Expand Down
42 changes: 20 additions & 22 deletions realsense2_camera/src/rs_node_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ using namespace rs2;

void BaseRealSenseNode::setup()
{
#if defined (ACCELERATE_WITH_GPU)
bool use_gpu_processing = (_accelerate_with_gpu == accelerate_with_gpu::GL_GPU);
initOpenGLProcessing(use_gpu_processing);
_is_accelerate_with_gpu_changed = false;
#if defined (ACCELERATE_GPU_WITH_GLSL)
initOpenGLProcessing(_accelerate_gpu_with_glsl);
_is_accelerate_gpu_with_glsl_changed = false;
#endif
setDynamicParams();
startDiagnosticsUpdater();
Expand All @@ -47,15 +46,15 @@ void BaseRealSenseNode::monitoringProfileChanges()
_cv_mpc.wait_for(lock, std::chrono::milliseconds(time_interval),
[&]{return (!_is_running || _is_profile_changed
|| _is_align_depth_changed
#if defined (ACCELERATE_WITH_GPU)
|| _is_accelerate_with_gpu_changed
#if defined (ACCELERATE_GPU_WITH_GLSL)
|| _is_accelerate_gpu_with_glsl_changed
#endif
);});

if (_is_running && (_is_profile_changed
|| _is_align_depth_changed
#if defined (ACCELERATE_WITH_GPU)
|| _is_accelerate_with_gpu_changed
#if defined (ACCELERATE_GPU_WITH_GLSL)
|| _is_accelerate_gpu_with_glsl_changed
#endif
))
{
Expand All @@ -71,8 +70,8 @@ void BaseRealSenseNode::monitoringProfileChanges()
_is_profile_changed = false;
_is_align_depth_changed = false;

#if defined (ACCELERATE_WITH_GPU)
_is_accelerate_with_gpu_changed = false;
#if defined (ACCELERATE_GPU_WITH_GLSL)
_is_accelerate_gpu_with_glsl_changed = false;
#endif
}
}
Expand Down Expand Up @@ -354,13 +353,12 @@ void BaseRealSenseNode::updateSensors()
try{
stopRequiredSensors();

#if defined (ACCELERATE_WITH_GPU)
if (_is_accelerate_with_gpu_changed)
#if defined (ACCELERATE_GPU_WITH_GLSL)
if (_is_accelerate_gpu_with_glsl_changed)
{
shutdownOpenGLProcessing();

bool use_gpu_processing = (_accelerate_with_gpu == accelerate_with_gpu::GL_GPU);
initOpenGLProcessing(use_gpu_processing);
initOpenGLProcessing(_accelerate_gpu_with_glsl);
}
#endif

Expand Down Expand Up @@ -394,15 +392,15 @@ void BaseRealSenseNode::stopRequiredSensors()
// and we are on a video sensor. TODO: explore better options to monitor and update changes
// without resetting the whole sensors and topics.
if (is_profile_changed || (is_video_sensor && (_is_align_depth_changed
#if defined (ACCELERATE_WITH_GPU)
|| _is_accelerate_with_gpu_changed
#if defined (ACCELERATE_GPU_WITH_GLSL)
|| _is_accelerate_gpu_with_glsl_changed
#endif
)))
{
std::vector<stream_profile> active_profiles = sensor->get_active_streams();
if (is_profile_changed
#if defined (ACCELERATE_WITH_GPU)
|| _is_accelerate_with_gpu_changed
#if defined (ACCELERATE_GPU_WITH_GLSL)
|| _is_accelerate_gpu_with_glsl_changed
#endif
)
{
Expand Down Expand Up @@ -440,8 +438,8 @@ void BaseRealSenseNode::startUpdatedSensors()
bool is_video_sensor = (sensor->is<rs2::depth_sensor>() || sensor->is<rs2::color_sensor>());

if (is_profile_changed || (is_video_sensor && (_is_align_depth_changed
#if defined (ACCELERATE_WITH_GPU)
|| _is_accelerate_with_gpu_changed
#if defined (ACCELERATE_GPU_WITH_GLSL)
|| _is_accelerate_gpu_with_glsl_changed
#endif
)))
{
Expand All @@ -459,8 +457,8 @@ void BaseRealSenseNode::startUpdatedSensors()
}

if (is_profile_changed
#if defined (ACCELERATE_WITH_GPU)
|| _is_accelerate_with_gpu_changed
#if defined (ACCELERATE_GPU_WITH_GLSL)
|| _is_accelerate_gpu_with_glsl_changed
#endif
)
{
Expand Down

0 comments on commit c0a674c

Please sign in to comment.