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

manupe94's profile - activity

2018-08-08 01:42:42 -0500 marked best answer How to publish messages on a topic of type rosgraph_msgs/Clock?

Hello!

I want to give values to a topic with this type of mesage (rosgraph_msgs/Clock)

I create a variable called "reloj" for example:

rosgraph_msgs::Clock reloj;

How do I give a value to that variable?, because it has two parts (secs and nsecs)

For example in float64 I give it the value this way

std_msgs::Float64 variable;

variable.data = 0;

I would like to do the same but in rosgraph_msgs/Clock, one value for "secs" and one for "nsecs"

I tried: reloj.clock.secs = 1; reloj.clock.nsecs = 100;

reloj.clock_secs = 1; reloj.clock_nsecs = 100;

But this does not work

I found that putting the following does work

reloj.clock = {5,88};

but when creating the node executable, I get this warning:

warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 reloj.clock = {5,88};

I use ROS kinetic and roscpp (c++)

this is the code in c++

#include "ros/ros.h"
#include "rosgraph_msgs/Clock.h"
rosgraph_msgs::Clock reloj;
int main(int argc, char **argv)
{
ros::init(argc, argv, "pubsubclock");
ros::NodeHandle n;
ros::Publisher publicador;
publicador  = n.advertise<rosgraph_msgs::Clock>("topico_pub", 1000);
reloj.clock = {5,88};
ros::Rate loop_rate(10);
while (ros::ok()) {
publicador.publish(reloj);
ros::spinOnce();
loop_rate.sleep();
}  
return 0;
}

thank you very much

2017-10-08 21:12:02 -0500 received badge  Famous Question (source)
2017-10-08 21:12:02 -0500 received badge  Notable Question (source)
2017-04-24 21:42:42 -0500 received badge  Supporter (source)
2017-04-24 21:40:40 -0500 received badge  Popular Question (source)
2017-04-24 11:35:59 -0500 edited question How to publish messages on a topic of type rosgraph_msgs/Clock?

How to publish messages on a topic of type rosgraph_msgs/Clock? Hello! I want to give values to a topic with this type

2017-04-24 11:35:59 -0500 received badge  Editor (source)
2017-04-24 11:33:54 -0500 commented question How to publish messages on a topic of type rosgraph_msgs/Clock?

I updated the message

2017-04-24 11:32:51 -0500 edited question How to publish messages on a topic of type rosgraph_msgs/Clock?

How to publish messages on a topic of type rosgraph_msgs/Clock? Hello! I want to give values to a topic with this type

2017-04-24 10:00:51 -0500 asked a question How to publish messages on a topic of type rosgraph_msgs/Clock?

How to publish messages on a topic of type rosgraph_msgs/Clock? Hello! I want to give values to a topic with this type

2017-04-24 10:00:51 -0500 asked a question How to publish messages on a topic of type rosgraph_msgs/Clock?

How to publish messages on a topic of type rosgraph_msgs/Clock? Hello! I want to give values to a topic with this type