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

Creating generic topic subscribers with ShapeShifter

asked 2018-05-30 21:47:42 -0500

dheeranet gravatar image

updated 2018-05-31 00:23:41 -0500

jayess gravatar image

Hi all, I'm having trouble creating a generic topic subcriber that simply records the last time a message was published. Here are the relevant parts of my current code:

void cb_record_message_time(const ros::MessageEvent<topic_tools::ShapeShifter>& msg, uint64_t& message_time){
    ros::Time time = ros::Time::now();
    message_time = 1000 * (uint64_t)time.sec + (uint64_t)time.nsec / 1e6;
}

int main(int argc, char **argv) {
   ros::init(argc, argv, "topic_health_check");
   ros::NodeHandle nh;

   std::vector<std::string> topic_names = {
     "/topic/1",
     "/topic/2",
     "/topic/3"
   };

  uint64_t topic_message_times[256]; // if this is a std::vector then std::ref(topic_message_times[i]) doesn't work
  std::vector<ros::Subscriber> topic_subs;

for(int i = 0; i < topic_names.size(); i++) {
     topic_message_times[i] = 0;

     ros::Subscriber sub = nh.subscribe<topic_tools::ShapeShifter>(topic_names[i], 1, boost::bind(cb_record_message_time, _1, std::ref(topic_message_times[i])));
     topic_subs.push_back(sub);
   }
}

The ShapeShifter docs are sparse, the given example at http://wiki.ros.org/ros_type_introspe... doesn't compile, and most other examples on the web use nh.subscribe without the template type <> which also doesn't compile (I'm on Kinetic, not sure if that makes a difference). Any thoughts? Thanks!

Edit:: This is the error I get:

CMakeFiles/health_check.dir/src/health_check.cpp.o: In function ros::serialization::PreDeserialize<topic_tools::ShapeShifter>::notify(ros::serialization::PreDeserializeParams<topic_tools::ShapeShifter> const&)': health_check.cpp:(.text._ZN3ros13serialization14PreDeserializeIN11topic_tools12ShapeShifterEE6notifyERKNS0_20PreDeserializeParamsIS3_EE[_ZN3ros13serialization14PreDeserializeIN11topic_tools12ShapeShifterEE6notifyERKNS0_20PreDeserializeParamsIS3_EE]+0x24a): undefined reference to topic_tools::ShapeShifter::morph(std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&)' CMakeFiles/health_check.dir/src/health_check.cpp.o: In function boost::detail::sp_if_not_array<topic_tools::ShapeShifter>::type boost::make_shared<topic_tools::ShapeShifter>()': health_check.cpp:(.text._ZN5boost11make_sharedIN11topic_tools12ShapeShifterEJEEENS_6detail15sp_if_not_arrayIT_E4typeEDpOT0_[_ZN5boost11make_sharedIN11topic_tools12ShapeShifterEJEEENS_6detail15sp_if_not_arrayIT_E4typeEDpOT0_]+0x77): undefined reference to topic_tools::ShapeShifter::ShapeShifter()' CMakeFiles/health_check.dir/src/health_check.cpp.o: In function ros::SubscriptionCallbackHelperT<boost::shared_ptr<topic_tools::ShapeShifter const> const&, void>::getTypeInfo()': health_check.cpp:(.text._ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv[_ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv]+0x9): undefined reference totypeinfo for topic_tools::ShapeShifter' collect2: error: ld returned 1 exit status
edit retag flag offensive close merge delete

Comments

1

What part of your code isn't working? what error are you getting?

ahendrix gravatar image ahendrix  ( 2018-05-30 22:48:31 -0500 )edit

._ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv[_ZN3ros27SubscriptionCallbackHelperTIRKN5boost10shared_ptrIKN11topic_tools12ShapeShifterEEEvE11getTypeInfoEv]+0x9): undefined reference to `typeinfo for topic_tools::ShapeShifter'

dheeranet gravatar image dheeranet  ( 2018-05-31 00:13:51 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-05-31 01:41:52 -0500

gvdhoorn gravatar image

updated 2021-09-30 14:11:05 -0500

That is a linker error, not a compilation problem. You're not linking against the libraries that are required.


Edit: since this is now an answer: make sure to link against topic_tools (ie: add it to find_package(catkin REQUIRED COMPONENTS ..). That's what provides ShapeShifter.

edit flag offensive delete link more

Comments

Demangled symbol:

ros::SubscriptionCallbackHelperT<boost::shared_ptr<topic_tools::ShapeShifter const> const&, void>::getTypeInfo()[ros::SubscriptionCallbackHelperT<boost::shared_ptr<topic_tools::ShapeShifter const> const&, void>::getTypeInfo()] 0x9)
gvdhoorn gravatar image gvdhoorn  ( 2018-05-31 01:42:35 -0500 )edit

@gvdhoorn Thanks! I got it to work.

dheeranet gravatar image dheeranet  ( 2018-05-31 04:31:26 -0500 )edit

@dheeranet How did you solve the problem? I'm stuck with a similar problem

teshansj gravatar image teshansj  ( 2018-08-31 01:55:21 -0500 )edit

@gvdhoorn Can you please explain in detail that where to change because I am also getting same error.

void topicCallback(const ShapeShifter::ConstPtr &msg, const std::string &topic_name)
{
  uint32_t length = msg->size();
  sizes+=length;

  auto time = std::chrono::system_clock::now();
  double diff = std::chrono::duration<double>(time-last).count();
  last=time;
  times+=diff;
}

 boost::function<void(const ShapeShifter::ConstPtr &)> callback;
  callback = [topic_name](const ShapeShifter::ConstPtr &msg)
  {
    topicCallback(msg, topic_name);
  };

  ros::Subscriber subscriber = nh.subscribe(topic_name, 10, callback);
Aakin gravatar image Aakin  ( 2021-09-29 16:46:09 -0500 )edit

The problem is most likely in your CMakeLists.txt, which we don't see.

In any case, just to clarify: my answer here wasn't actually an answer, it was a comment. It appears to have been converted to an answer. That's why there is nothing more than a quick hint.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-30 02:04:21 -0500 )edit

CMakeLists.txt:-

cmake_minimum_required(VERSION 2.8.3)
project(roshz)

find_package(catkin REQUIRED COMPONENTS
  roscpp
)

catkin_package(
    INCLUDE_DIRS
    CATKIN_DEPENDS roscpp
  )

include_directories(include ${catkin_INCLUDE_DIRS})
link_directories(${catkin_LIBRARY_DIRS})
add_definitions(${catkin_DEFINITIONS})

add_compile_options(-std=c++11)
add_executable(${PROJECT_NAME}
  src/roshz.cpp
  src/statistics.cpp
  src/tp.cpp
)

target_link_libraries(${PROJECT_NAME}
  ${catkin_LIBRARIES}
)

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

@gvdhoorn

Aakin gravatar image Aakin  ( 2021-09-30 09:45:57 -0500 )edit

You already have #q387669. Why keep posting here as well?

gvdhoorn gravatar image gvdhoorn  ( 2021-09-30 13:12:34 -0500 )edit

Might make sense to post in both places. Google seems to rank this post higher so more people land here I think

dheeranet gravatar image dheeranet  ( 2021-09-30 13:49:27 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-30 21:43:10 -0500

Seen: 1,742 times

Last updated: Sep 30 '21