ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS 2 Subscribing to custom message type [closed]

asked 2020-12-04 07:20:03 -0600

Schloern93 gravatar image

Hello,

I use the following Intel package to run my Intel Ralsense cameras. https://github.com/IntelRealSense/rea...

I am now trying to subscribe to the topics that are opened by the realsense2_camera_node. I am still quite new to ROS and don't see what exactly I am doing wrong.

I have created a new package "tracking_pos" with which I want to subscribe the topic "/t265/accel/sample". The topic is published properly and I can view it with the command "ros2 topic echo" on the terminal.

Below is my code

#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "realsense2_camera_msgs/msg/extrinsics.hpp"

using std::placeholders::_1;

class TrackingNode : public rclcpp::Node
{
public:
  TrackingNode()
    : Node("tracking_node")
{ 
  t265_linear_vel_sub_ = this->create_subscription<realsense2_camera_msgs::msg::Extrinsics>(
        "/t265/accel/sample", 10, std::bind(&TrackingNode::tracking_linear_vel_callback, this, _1));
}
private:
void tracking_linear_vel_callback(const realsense2_camera_msgs::msg::Extrinsics msg)
{
RCLCPP_INFO(this->get_logger(), "linear_vel_Callback");
} 
rclcpp::Subscription<realsense2_camera_msgs::msg::Extrinsics>::SharedPtr t265_linear_vel_sub_;    
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<TrackingNode>());
  rclcpp::shutdown();
  return 0;
}

CMakeList.txt

 cmake_minimum_required(VERSION 3.5)
 project(tracking_pos)

 # Default to C99
 if(NOT CMAKE_C_STANDARD)
   set(CMAKE_C_STANDARD 99)
 endif()

 # Default to C++14
 if(NOT CMAKE_CXX_STANDARD)
   set(CMAKE_CXX_STANDARD 14)
 endif()

 if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
   add_compile_options(-Wall -Wextra -Wpedantic)
 endif()

 # find dependencies
 find_package(ament_cmake REQUIRED)
 find_package(rclcpp REQUIRED)
 find_package(std_msgs REQUIRED)
 find_package(realsense2_camera_msgs REQUIRED)

 add_executable(tracking src/tracking_node.cpp)
 ament_target_dependencies(tracking rclcpp std_msgs realsense2_camera_msgs)

 if(BUILD_TESTING)
   find_package(ament_lint_auto REQUIRED)
   ament_lint_auto_find_test_dependencies()
 endif()

 install(TARGETS
   tracking
   DESTINATION lib/${PROJECT_NAME})

 ament_package()

Relevant sections from the Package.xml

   <buildtool_depend>ament_cmake</buildtool_depend>

   <depend>rclcpp</depend>
   <depend>std_msgs</depend>

   <exec_depend>realsense2_camera_msgs</exec_depend>
   <build_depend>realsense2_camera_msgs</build_depend>

   <test_depend>ament_lint_auto</test_depend>
   <test_depend>ament_lint_common</test_depend>

   <export>
     <build_type>ament_cmake</build_type>
   </export>
 </package>

The project cannot be built like this. My question now is how to specify the data type in the subscriber correctly to receive the published data of the topic. Many thanks for the help in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Schloern93
close date 2020-12-04 08:19:52.251836

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-12-04 08:18:46 -0600

Schloern93 gravatar image

I solved the problem.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-12-04 07:20:03 -0600

Seen: 544 times

Last updated: Dec 04 '20