Ask Your Question
0

Creating generic topic subscribers with ShapeShifter

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

dheeranet gravatar image

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

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 imageahendrix ( 2018-05-30 22:48:31 -0600 )edit

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

dheeranet gravatar imagedheeranet ( 2018-05-31 00:13:51 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

gvdhoorn gravatar image

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

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 imagegvdhoorn ( 2018-05-31 01:42:35 -0600 )edit

@gvdhoorn Thanks! I got it to work.

dheeranet gravatar imagedheeranet ( 2018-05-31 04:31:26 -0600 )edit

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

teshansj gravatar imageteshansj ( 2018-08-31 01:55:21 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 547 times

Last updated: May 31 '18