feat: add bag record and playback support

This commit is contained in:
slz
2026-06-16 16:57:46 +08:00
parent 9126013267
commit d801d5670b
5 changed files with 115 additions and 7 deletions
@@ -164,7 +164,8 @@ typedef struct {
class OBCameraNode {
public:
OBCameraNode(rclcpp::Node* node, std::shared_ptr<ob::Device> device,
std::shared_ptr<Parameters> parameters, bool use_intra_process = false);
std::shared_ptr<Parameters> parameters, bool use_intra_process = false,
bool is_playback_device = false);
template <class T>
void setAndGetNodeParameter(
@@ -932,6 +933,11 @@ class OBCameraNode {
bool hw_d2c_color_undistortion_configured_ = false;
bool has_first_color_frame_ = false;
bool use_intra_process_ = false;
// True when device_ is an ob::PlaybackDevice. Real-device-only hardware
// tuning (heartbeat, USB3 retry, laser, sync config, etc.) is skipped in
// setupDevices() for playback devices since those SDK components aren't
// registered for a recorded .bag file.
bool is_playback_device_ = false;
std::string cloud_frame_id_;
std::mutex depth_filter_mutex_;
std::vector<std::shared_ptr<ob::Filter>> depth_filter_list_;
@@ -31,6 +31,7 @@
#include <std_srvs/srv/empty.hpp>
#include <backward_ros/backward.hpp>
#include "libobsensor/hpp/Device.hpp"
#include "libobsensor/hpp/RecordPlayback.hpp"
namespace orbbec_camera {
@@ -57,6 +58,8 @@ class OBCameraNodeDriver : public rclcpp::Node {
void initializeDevice(const std::shared_ptr<ob::Device>& device);
void initializeBagPlayback();
void startDevice(const std::shared_ptr<ob::DeviceList>& list);
void connectNetDevice(const std::string& net_device_ip, int net_device_port);
@@ -155,5 +158,13 @@ class OBCameraNodeDriver : public rclcpp::Node {
std::string force_ip_gateway_; // e.g. "192.168.1.1"
std::atomic<bool> force_ip_success_{false};
std::string device_type_;
// bag recording
std::string bag_record_filename_;
bool bag_record_compression_ = true;
std::shared_ptr<ob::RecordDevice> record_device_ = nullptr;
// bag playback
std::string bag_filename_;
bool bag_loop_ = false;
std::shared_ptr<ob::PlaybackDevice> playback_device_ = nullptr;
};
} // namespace orbbec_camera