Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #100 from intel/refactor
Browse files Browse the repository at this point in the history
update eloquent
  • Loading branch information
ahuizxc authored Dec 16, 2019
2 parents 32f19ca + e41d491 commit 47b313c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions realsense_ros/include/realsense/rs_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class RealSenseBase
void printSupportedStreamProfiles();
void printActiveStreamProfiles();
void printStreamProfiles(const std::vector<rs2::stream_profile> & profile_list);

void startWorkThread();
protected:
Result toggleStream(const stream_index_pair & stream, const rclcpp::Parameter & param);
Result changeResolution(const stream_index_pair & stream, const rclcpp::Parameter & param);
Expand All @@ -100,7 +100,8 @@ class RealSenseBase
rs2::pipeline pipeline_;
rs2::config cfg_;
std::string base_frame_id_;

rs2::frame_queue frame_data;
std::thread work_thread_;
std::shared_ptr<tf2_ros::StaticTransformBroadcaster> static_tf_broadcaster_;
rclcpp::TimerBase::SharedPtr timer_;
std::map<stream_index_pair, bool> enable_ = {{COLOR, false}, {DEPTH, false},
Expand Down
17 changes: 16 additions & 1 deletion realsense_ros/src/rs_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ RealSenseBase::RealSenseBase(rs2::context ctx, rs2::device dev, rclcpp::Node & n
RealSenseBase::~RealSenseBase()
{
pipeline_.stop();
if (work_thread_.joinable()) {
work_thread_.join();
}
}

void RealSenseBase::startWorkThread()
{
work_thread_ = std::thread([=]() {
while (true) {
rs2::frame frame = frame_data.wait_for_frame();
publishTopicsCallback(frame);
}
});
}

void RealSenseBase::startPipeline()
Expand All @@ -64,7 +77,9 @@ void RealSenseBase::startPipeline()
RCLCPP_WARN(node_.get_logger(), "No TF is available. Enable base stream (Depth or Pose) first.");
}

pipeline_.start(cfg_, std::bind(&RealSenseBase::publishTopicsCallback, this, std::placeholders::_1));
frame_data = rs2::frame_queue(5);
pipeline_.start(cfg_, frame_data);
startWorkThread();
}

void RealSenseBase::setupStream(const stream_index_pair & stream)
Expand Down

0 comments on commit 47b313c

Please sign in to comment.