Ask Your Question
-1

subsribe to two integer type msgs with one call back function

asked 2016-11-27 08:47:27 -0500

anadgopi1994 gravatar image

updated 2016-11-27 09:06:14 -0500

I tried to subscribe to two integer types .But lot of errors are showing .Please help me to correct the code code:

#include <ros/ros.h>

#include <std_msgs/Int8.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>

using namespace std_msgs;

using namespace message_filters;

void callback(const Int8ConstPtr& angle,const Int8ConstPtr& range_data) {

}
   int main( int argc, char** argv )
   {
    ros::init(argc, argv, "basic_shapes");
     ros::NodeHandle n;
     ros::Rate r(1);
 message_filters::Subscriber<Int8> sub1(n,"angle", 1);
message_filters::Subscriber<Int8> sub2(n,"range_data", 1);
TimeSynchronizer<Int8,Int8> sync(sub1,sub2,10);
sync.registerCallback(boost::bind(&callback,_1, _2));

ros::spin();
return 0;

}

error msgs: /opt/ros/indigo/include/message_filters/sync_policies/exact_time.h: In instantiation of ‘void message_filters::sync_policies::ExactTime<m0, m1,="" m2,="" m3,="" m4,="" m5,="" m6,="" m7,="" m8="">::add(const typename boost::mpl::at_c<typename message_filters::policybase<m0,="" m1,="" m2,="" m3,="" m4,="" m5,="" m6,="" m7,="" m8="">::Events, i>::type&) [with int i = 0; M0 = std_msgs::Int8_<std::allocator<void> >; M1 = std_msgs::Int8_<std::allocator<void> >; M2 = message_filters::NullType; M3 = message_filters::NullType; M4 = message_filters::NullType; M5 = message_filters::NullType; M6 = message_filters::NullType; M7 = message_filters::NullType; M8 = message_filters::NullType; typename boost::mpl::at_c<typename message_filters::policybase<m0,="" m1,="" m2,="" m3,="" m4,="" m5,="" m6,="" m7,="" m8="">::Events, i>::type = ros::MessageEvent<const std_msgs::int8_<std::allocator<void=""> > >]’: /opt/ros/indigo/include/message_filters/synchronizer.h:358:5: required from ‘void message_filters::Synchronizer<policy>::cb(const typename boost::mpl::at_c<typename policy::events,="" i="">::type&) [with int i = 0; Policy = message_filters::sync_policies::ExactTime<std_msgs::int8_<std::allocator<void> >, std_msgs::Int8_<std::allocator<void> >, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType>; typename boost::mpl::at_c<typename policy::events,="" i="">::type = ros::MessageEvent<const std_msgs::int8_<std::allocator<void=""> > >]’ /opt/ros/indigo/include/message_filters/synchronizer.h:290:138: required from ‘void message_filters::Synchronizer<policy>::connectInput(F0&, F1&, F2&, F3&, F4&, F5&, F6&, F7&, F8&) [with F0 = message_filters::Subscriber<std_msgs::int8_<std::allocator<void> > >; F1 = message_filters::Subscriber<std_msgs::int8_<std::allocator<void> > >; F2 = message_filters::NullFilter<message_filters::nulltype>; F3 = message_filters::NullFilter<message_filters::nulltype>; F4 = message_filters::NullFilter<message_filters::nulltype>; F5 = message_filters::NullFilter<message_filters::nulltype>; F6 = message_filters::NullFilter<message_filters::nulltype>; F7 = message_filters::NullFilter<message_filters::nulltype>; F8 = message_filters::NullFilter<message_filters::nulltype>; Policy = message_filters::sync_policies::ExactTime<std_msgs::int8_<std::allocator<void> >, std_msgs::Int8_<std::allocator<void> >, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType>]’ /opt/ros/indigo/include/message_filters/synchronizer.h:282:52: required from ‘void message_filters::Synchronizer<policy>::connectInput(F0&, F1&, F2&, F3&, F4&, F5&, F6&, F7&) [with F0 = message_filters::Subscriber<std_msgs::int8_<std::allocator<void> > >; F1 = message_filters::Subscriber<std_msgs::int8_<std::allocator<void> > >; F2 = message_filters::NullFilter<message_filters::nulltype>; F3 = message_filters::NullFilter<message_filters::nulltype>; F4 = message_filters::NullFilter<message_filters::nulltype>; F5 = message_filters::NullFilter<message_filters::nulltype>; F6 = message_filters::NullFilter<message_filters::nulltype>; F7 = message_filters::NullFilter<message_filters::nulltype>; Policy = message_filters::sync_policies::ExactTime<std_msgs::int8_<std::allocator<void> >, std_msgs::Int8_<std::allocator<void> >, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType>]’ /opt/ros/indigo/include/message_filters/synchronizer.h:275 ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-11-27 08:57:33 -0500

NEngelhard gravatar image

updated 2016-11-27 09:00:20 -0500

"The TimeSynchronizer filter synchronizes incoming channels by the timestamps contained in their headers,"

No header -> No TimeSynchronizer

And please:

  1. invest some seconds to check your spelling
  2. don't post irrelevant code (commented includes??)
  3. format code as such (use to 101010-Button)
  4. "But lot of errors are showing" The is no ROS-interface to chrystal balls yet, so please post the error messages.
edit flag offensive delete link more

Comments

i edited my post and put the error messages in the post,Now can you please help me to resolve this problem.

anadgopi1994 gravatar image anadgopi1994  ( 2016-11-27 09:07:18 -0500 )edit

I already answered the question. and @gvdhoorn also told you in your first thread "If both messages have headers"... And you broke the code formatting and still have typos in the question.

NEngelhard gravatar image NEngelhard  ( 2016-11-27 09:47:18 -0500 )edit

Both message have the header #include <std_msgs int8.h="">.I didn't understand what you are saying?Can you clarify

anadgopi1994 gravatar image anadgopi1994  ( 2016-11-27 10:26:06 -0500 )edit

Please fix your question (formatting, typos)

NEngelhard gravatar image NEngelhard  ( 2016-11-27 10:31:41 -0500 )edit

I already corrected my question

anadgopi1994 gravatar image anadgopi1994  ( 2016-11-27 10:51:42 -0500 )edit

neither is the code formatted correctly nor have you removed the typos. I'm sorry to be a bit pedantic, but you want some help here and some effort on your side should be visible.

NEngelhard gravatar image NEngelhard  ( 2016-11-27 12:06:56 -0500 )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: 2016-11-27 08:47:27 -0500

Seen: 161 times

Last updated: Nov 27 '16