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

Trying to write test pgm for TimeSync

asked 2013-09-27 18:35:34 -0500

rnunziata gravatar image

updated 2013-09-28 03:36:03 -0500

Update: changed code according to ans. Still will not compile.

#include <string>
#include <ros/ros.h>
#include <geometry_msgs/PoseStamped.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>


using namespace message_filters;

class SynchronizerTest
{
public:
  SynchronizerTest()
  {
    setTest();
  }


void handelerSynchronizerTest(geometry_msgs::PoseStampedConstPtr& msg1, geometry_msgs::PoseStampedConstPtr& msg2)
{
    ROS_INFO("HERE made it to handeler");
}

void setTest()
{
     Subscriber<geometry_msgs::PoseStamped> j1_sub(n, "/SynchronizerTest1", 10);
     Subscriber<geometry_msgs::PoseStamped> j2_sub(n, "/SynchronizerTest2", 10);
     TimeSynchronizer<geometry_msgs::PoseStamped, geometry_msgs::PoseStamped> sync(j1_sub, j2_sub, 10);
     sync.registerCallback(boost::bind(&SynchronizerTest::handelerSynchronizerTest, this, _1, _2));
     ROS_INFO("Test set");
}


private:

 ros::NodeHandle n;

};  // Enodof Class



int main(int argc, char **argv)
{ 
  ros::init(argc, argv, "SynchronizerTest");
  ros::NodeHandle n;
  ros::Rate loop_rate(10);
  int count = 0;

  SynchronizerTest sp;
  ros::Publisher pub1 = n.advertise<geometry_msgs::PoseStamped>("SynchronizerTest1", 10);
  ros::Publisher pub2 = n.advertise<geometry_msgs::PoseStamped>("SynchronizerTest2", 10);
  while (ros::ok())
  {
     geometry_msgs::PoseStamped msg;     
     msg.header.stamp = ros::time::now();
     pub1.publish(msg);
     pub2.publish(msg);
     ros::spinOnce();
     loop_rate.sleep();
     ++count;
  }

  return 0;
}

Trying to write test pgm for TimeSync but why does it not support std_msgs:String.

/opt/ros/hydro/include/message_filters/sync_policies/exact_time.h:126:102: error: ‘value’ is not a member of ‘ros::message_traits::TimeStamp<std_msgs::String_<std::allocator<void> >, void>’

This compile error is generated by the following code:

#include <string>
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>


using namespace message_filters;

class SynchronizerTest
{
public:
  SynchronizerTest()
  {
    setTest();
  }


void handelerSynchronizerTest(std_msgs::StringConstPtr& msg1, std_msgs::StringConstPtr& msg2)
{
    ROS_INFO("HERE made it to handeler");
}

void setTest()
{
     Subscriber<std_msgs::String> j1_sub(n, "/SynchronizerTest1", 10);
     Subscriber<std_msgs::String> j2_sub(n, "/SynchronizerTest2", 10);
     TimeSynchronizer<std_msgs::String, std_msgs::String> sync(j1_sub, j2_sub, 10);
     sync.registerCallback(boost::bind(&SynchronizerTest::handelerSynchronizerTest, this, _1, _2));
     ROS_INFO("Test set");
}


private:

 ros::NodeHandle n;

};  // Enodof Class



int main(int argc, char **argv)
{ 
  ros::init(argc, argv, "SynchronizerTest");
  ros::NodeHandle n;
  ros::Rate loop_rate(10);
  int count = 0;

  SynchronizerTest sp;
  ros::Publisher pub1 = n.advertise<std_msgs::String>("SynchronizerTest1", 10);
  ros::Publisher pub2 = n.advertise<std_msgs::String>("SynchronizerTest2", 10);
  while (ros::ok())
  {
     std_msgs::String msg;
     std::stringstream ss;
     ss << "hello world " << count;
     msg.data = ss.str();
     pub1.publish(msg);
     pub2.publish(msg);
     ros::spinOnce();
     loop_rate.sleep();
     ++count;
  }

  return 0;
}
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2013-09-27 23:40:54 -0500

Seems you are trying to synchronize messages that do not have std_msgs/Header and thus time stamp as well. Without knowing the time stamp it is obviously impossible to synchronize anything.

Usually the message types that have a time stamp are called xxxStamped like, for example, geometry_msgs/PoseStamped.

edit flag offensive delete link more

Comments

std_msgs::String is used in cases to send topics but then why no header. BTW I made changes and code still will not compile ...errors way to cryptic to understand. Will post updated code.

rnunziata gravatar image rnunziata  ( 2013-09-28 03:32:14 -0500 )edit
0

answered 2013-09-28 03:46:15 -0500

rnunziata gravatar image

OK...I left out the const in the parameters defs on the handler...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-09-27 18:35:34 -0500

Seen: 812 times

Last updated: Sep 28 '13