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

Publish messages using frame timestamp #105

Open
wants to merge 5 commits into
base: eloquent
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
4 changes: 4 additions & 0 deletions realsense_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ set(CMAKE_CXX_FLAGS "-fPIE -fPIC -D_FORTIFY_SOURCE=2 -fstack-protector -Wformat

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rcl REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(nav_msgs REQUIRED)
Expand Down Expand Up @@ -100,6 +101,7 @@ target_link_libraries(${PROJECT_NAME}
)

ament_target_dependencies(${PROJECT_NAME}
rcl
ruffsl marked this conversation as resolved.
Show resolved Hide resolved
rclcpp
rclcpp_components
nav_msgs
Expand Down Expand Up @@ -133,6 +135,7 @@ install(

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
find_package(rcl REQUIRED)
find_package(rclcpp REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
Expand Down Expand Up @@ -162,6 +165,7 @@ if(BUILD_TESTING)
realsense2
${PROJECT_NAME})
ament_target_dependencies(${target}
"rcl"
"rclcpp"
"nav_msgs"
"sensor_msgs"
Expand Down
1 change: 1 addition & 0 deletions realsense_ros/include/realsense/rs_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class RealSenseBase
Result toggleStream(const stream_index_pair & stream, const rclcpp::Parameter & param);
Result changeResolution(const stream_index_pair & stream, const rclcpp::Parameter & param);
Result changeFPS(const stream_index_pair & stream, const rclcpp::Parameter & param);
rclcpp::Time frameToTime(const rs2::frame & frame);

typedef struct VideoStreamInfo
{
Expand Down
2 changes: 2 additions & 0 deletions realsense_ros/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<depend>realsense_msgs</depend>
<depend>image_transport</depend>

<build_depend>rcl</build_depend>

<exec_depend>launch_ros</exec_depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
5 changes: 5 additions & 0 deletions realsense_ros/src/rs_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <sstream>
#include "rcl/time.h"
#include "realsense/rs_base.hpp"

namespace realsense
Expand Down Expand Up @@ -457,4 +458,8 @@ Result RealSenseBase::changeFPS(const stream_index_pair & stream, const rclcpp::
}
return result;
}

rclcpp::Time RealSenseBase::frameToTime(const rs2::frame & frame) {
return rclcpp::Time(RCL_MS_TO_NS(frame.get_timestamp()));
}
} // namespace realsense
2 changes: 1 addition & 1 deletion realsense_ros/src/rs_d435.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ RealSenseD435::RealSenseD435(rs2::context ctx, rs2::device dev, rclcpp::Node & n
void RealSenseD435::publishTopicsCallback(const rs2::frame & frame)
{
rs2::frameset frameset = frame.as<rs2::frameset>();
rclcpp::Time t = node_.now();
rclcpp::Time t = frameToTime(frame);
if (enable_[COLOR] && (image_pub_[COLOR]->get_subscription_count() > 0 || camera_info_pub_[COLOR]->get_subscription_count() > 0)){
auto frame = frameset.get_color_frame();
publishImageTopic(frame, t);
Expand Down
2 changes: 1 addition & 1 deletion realsense_ros/src/rs_d435i.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RealSenseD435I::RealSenseD435I(rs2::context ctx, rs2::device dev, rclcpp::Node &

void RealSenseD435I::publishTopicsCallback(const rs2::frame & frame)
{
rclcpp::Time t = node_.now();
rclcpp::Time t = frameToTime(frame);
if (frame.is<rs2::frameset>()) {
RealSenseD435::publishTopicsCallback(frame);
} else if (frame.is<rs2::motion_frame>()) {
Expand Down
2 changes: 1 addition & 1 deletion realsense_ros/src/rs_t265.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ RealSenseT265::RealSenseT265(rs2::context ctx, rs2::device dev, rclcpp::Node & n

void RealSenseT265::publishTopicsCallback(const rs2::frame & frame)
{
rclcpp::Time t = node_.now();
rclcpp::Time t = frameToTime(frame);

if (frame.is<rs2::frameset>()) {
auto frameset = frame.as<rs2::frameset>();
Expand Down