Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ros jammy #8

Open
wants to merge 9 commits into
base: master
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
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ official [ROS 2 installation guide](https://docs.ros.org/en/galactic/Installatio
```bash
Assuming you have sourced the ros environment, same below
sudo apt install libgflags-dev ros-$ROS_DISTRO-image-geometry ros-$ROS_DISTRO-camera-info-manager\
ros-$ROS_DISTRO-image-transport ros-$ROS_DISTRO-image-publisher libgoogle-glog-dev libusb-1.0-0-dev libeigen3-dev
ros-$ROS_DISTRO-image-transport ros-$ROS_DISTRO-image-publisher libgoogle-glog-dev libusb-1.0-0-dev libeigen3-dev nlohmann-json3-dev

```

Expand Down
20 changes: 20 additions & 0 deletions astra_camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif ()

# Some includes changed between Humble and Jammy, so this next code checks for the ROS version to define a macro variable
# in the Cpp/Hpp files, the correct header files can be included based on this macro
set(ROS_FOUND FALSE)
if(DEFINED ENV{ROS_DISTRO})
set(FOUND_ROS_DISTRO $ENV{ROS_DISTRO})
set(ROS_FOUND TRUE)
endif()
if(ROS_FOUND)
# message("Using ROS distro: " $ENV{ROS_DISTRO})
if($ENV{ROS_DISTRO} STREQUAL "humble")
add_compile_definitions(ROS2_HUMBLE)
elseif($ENV{ROS_DISTRO} STREQUAL "jammy")
add_compile_definitions(ROS2_JAMMY)
endif()
else()
message("ROS distro is unknown. Compilation might fail. Fallback to humble")
add_compile_definitions(ROS2_HUMBLE)
endif()


# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake REQUIRED)
Expand Down
1 change: 1 addition & 0 deletions astra_camera/include/astra_camera/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <string>
#include <cstdlib>
#include <cstdint>

#define OB_ROS_MAJOR_VERSION 1
#define OB_ROS_MINOR_VERSION 1
Expand Down
7 changes: 5 additions & 2 deletions astra_camera/include/astra_camera/ob_camera_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@


#include <opencv2/opencv.hpp>
#if defined(ROS2_HUMBLE)
#include <cv_bridge/cv_bridge.h>
#elif defined(ROS2_JAMMY)
#include <cv_bridge/cv_bridge.hpp>
#endif
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <sensor_msgs/point_cloud2_iterator.hpp>
#include <tf2_ros/static_transform_broadcaster.h>
Expand Down Expand Up @@ -219,8 +223,7 @@ class OBCameraNode {
std::map<stream_index_pair, openni::VideoMode> stream_video_mode_;
std::map<stream_index_pair, std::vector<openni::VideoMode>> supported_video_modes_;
std::map<stream_index_pair, int> unit_step_size_;
std::map<stream_index_pair, rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr>
image_publishers_;
std::map<stream_index_pair, image_transport::Publisher> image_publishers_;
std::map<stream_index_pair, rclcpp::Publisher<sensor_msgs::msg::CameraInfo>::SharedPtr>
camera_info_publishers_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
#include <rclcpp/rclcpp.hpp>
#include <image_transport/image_transport.hpp>
#include <sensor_msgs/image_encodings.hpp>
#include <image_geometry/pinhole_camera_model.h>
#if defined(ROS2_HUMBLE)
#include <image_geometry/pinhole_camera_model.h>
#elif defined(ROS2_JAMMY)
#include <image_geometry/pinhole_camera_model.hpp>
#endif
#include <sensor_msgs/point_cloud2_iterator.hpp>
#include <memory>
#include "depth_traits.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@
#include <sensor_msgs/image_encodings.hpp>
#include <sensor_msgs/point_cloud2_iterator.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <image_geometry/pinhole_camera_model.h>
#if defined(ROS2_HUMBLE)
#include <cv_bridge/cv_bridge.h>
#include <image_geometry/pinhole_camera_model.h>
#elif defined(ROS2_JAMMY)
#include <cv_bridge/cv_bridge.hpp>
#include <image_geometry/pinhole_camera_model.hpp>
#endif

#include <cv_bridge/cv_bridge.h>
#include <opencv4/opencv2/imgproc/imgproc.hpp>
#include <memory>
#include <limits>
Expand Down
8 changes: 7 additions & 1 deletion astra_camera/include/astra_camera/ros_param_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@
#include <rclcpp/rclcpp.hpp>

namespace astra_camera {
#if defined(ROS2_HUMBLE) // Jammy changed the name, just moving 'Set' forwards
using OnSetCallback = rclcpp::node_interfaces::NodeParametersInterface::OnParametersSetCallbackType;
#elif defined(ROS2_JAMMY)
using OnSetCallback = rclcpp::node_interfaces::NodeParametersInterface::OnSetParametersCallbackType;
#endif

class ParametersBackend {
public:
explicit ParametersBackend(rclcpp::Node* node);
~ParametersBackend();
void addOnSetParametersCallback(
rclcpp::node_interfaces::NodeParametersInterface::OnParametersSetCallbackType callback);
OnSetCallback callback);

private:
rclcpp::Node* node_;
Expand Down
2 changes: 1 addition & 1 deletion astra_camera/include/astra_camera/uvc_camera_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class UVCCameraDriver {
rclcpp::Service<SetBool>::SharedPtr set_uvc_mirror_srv_;
rclcpp::Service<SetBool>::SharedPtr toggle_uvc_camera_srv_;

rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr image_publisher_;
image_transport::Publisher image_publisher_;
rclcpp::Publisher<sensor_msgs::msg::CameraInfo>::SharedPtr camera_info_publisher_;
sensor_msgs::msg::CameraInfo camera_info_;
std::unique_ptr<camera_info_manager::CameraInfoManager> camera_info_manager_ = nullptr;
Expand Down
Empty file modified astra_camera/scripts/install.sh
100644 → 100755
Empty file.
12 changes: 7 additions & 5 deletions astra_camera/src/ob_camera_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

#include "astra_camera/ob_camera_node.h"
#include "astra_camera/utils.h"
#include <cv_bridge/cv_bridge.h>
#if defined(ROS2_HUMBLE)
#include <cv_bridge/cv_bridge.h>
#elif defined(ROS2_JAMMY)
#include <cv_bridge/cv_bridge.hpp>
#endif
namespace astra_camera {

void OBCameraNode::init() {
Expand Down Expand Up @@ -383,9 +387,7 @@ void OBCameraNode::setupPublishers() {
std::string topic = name + "/image_raw";
auto image_qos = image_qos_[stream_index];
auto image_qos_profile = getRMWQosProfileFromString(image_qos);
image_publishers_[stream_index] = node_->create_publisher<sensor_msgs::msg::Image>(
topic,
rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(image_qos_profile), image_qos_profile));
image_publishers_[stream_index] = image_transport::create_publisher(node_, topic, image_qos_profile);
topic = name + "/camera_info";
auto camera_info_qos = camera_info_qos_[stream_index];
auto camera_info_qos_profile = getRMWQosProfileFromString(camera_info_qos);
Expand Down Expand Up @@ -531,7 +533,7 @@ void OBCameraNode::onNewFrameCallback(const openni::VideoFrameRef& frame,
image_msg->height = stream_index == DEPTH ? height * depth_scale_ : height;
image_msg->step = image_msg->width * unit_step_size_[stream_index];
image_msg->is_bigendian = false;
image_publisher->publish(*image_msg);
image_publisher.publish(image_msg);
sensor_msgs::msg::CameraInfo camera_info;
if (stream_index == DEPTH) {
camera_info = getDepthCameraInfo();
Expand Down
4 changes: 4 additions & 0 deletions astra_camera/src/point_cloud_proc/point_cloud_xyz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@

#include <image_transport/image_transport.hpp>
#include <sensor_msgs/image_encodings.hpp>
#if defined(ROS2_HUMBLE)
#include <image_geometry/pinhole_camera_model.h>
#elif defined(ROS2_JAMMY)
#include <image_geometry/pinhole_camera_model.hpp>
#endif
#include "astra_camera/point_cloud_proc/point_cloud_xyz.h"

namespace astra_camera {
Expand Down
10 changes: 7 additions & 3 deletions astra_camera/src/point_cloud_proc/point_cloud_xyzrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@
#include <sensor_msgs/image_encodings.hpp>
#include <sensor_msgs/point_cloud2_iterator.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <image_geometry/pinhole_camera_model.h>
#include <cv_bridge/cv_bridge.h>
#if defined(ROS2_HUMBLE)
#include <cv_bridge/cv_bridge.h>
#include <image_geometry/pinhole_camera_model.h>
#elif defined(ROS2_JAMMY)
#include <cv_bridge/cv_bridge.hpp>
#include <image_geometry/pinhole_camera_model.hpp>
#endif
#include <opencv2/imgproc/imgproc.hpp>

#include <memory>
#include <string>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion astra_camera/src/ros_param_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ParametersBackend::~ParametersBackend() {
}

void ParametersBackend::addOnSetParametersCallback(
rclcpp::node_interfaces::NodeParametersInterface::OnParametersSetCallbackType callback) {
OnSetCallback callback) {
ros_callback_ = node_->add_on_set_parameters_callback(std::move(callback));
}

Expand Down
10 changes: 6 additions & 4 deletions astra_camera/src/uvc_camera_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

#include <utility>
#include <opencv2/opencv.hpp>
#if defined(ROS2_HUMBLE)
#include <cv_bridge/cv_bridge.h>
#elif defined(ROS2_JAMMY)
#include <cv_bridge/cv_bridge.hpp>
#endif
#include "astra_camera/uvc_camera_driver.h"
#include "astra_camera/utils.h"

Expand Down Expand Up @@ -87,9 +91,7 @@ UVCCameraDriver::UVCCameraDriver(rclcpp::Node* node, std::shared_ptr<Parameters>
camera_info_manager_ = std::make_unique<camera_info_manager::CameraInfoManager>(
node_, "rgb_camera", color_info_url_);
}
image_publisher_ = node_->create_publisher<sensor_msgs::msg::Image>(
"color/image_raw",
rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(color_qos_profile_), color_qos_profile_));
image_publisher_ = image_transport::create_publisher(node_, "color/image_raw", color_qos_profile_);
camera_info_publisher_ = node_->create_publisher<sensor_msgs::msg::CameraInfo>(
"color/camera_info", rclcpp::QoS(rclcpp::QoSInitialization::from_rmw(color_info_qos_profile_),
color_info_qos_profile_));
Expand Down Expand Up @@ -395,7 +397,7 @@ void UVCCameraDriver::frameCallback(uvc_frame_t* frame) {
cv_image_ptr->image = cv_img;
image = *(cv_image_ptr->toImageMsg());
}
image_publisher_->publish(image);
image_publisher_.publish(image);
auto camera_info = getCameraInfo();
camera_info.header.stamp = image.header.stamp;
camera_info.header.frame_id = image.header.frame_id;
Expand Down