ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
You should create your own node that will do this. You can do this in c++ or python.
Follow the Writing a Simple Publisher and Subscriber tutorial that teaches you how to make a publisher and subscriber node. You are only concerned with making a publisher node, but if you haven't done these tutorials, you should.
Here's the c++ version: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29
Here's the python version: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28python%29
Here is an example with UNTESTED CODE of how you would do this in c++:
#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
// Advertize the publisher on the topic you like
ros::Publisher pub = n.advertise<geometry_msgs::Twist>("my_topic_name", 1000);
/**
* A count of how many messages we have sent. This is used to create
* a unique string for each message.
*/
int count = 0;
while (ros::ok())
{
/**
* This is a message object. You stuff it with data, and then publish it.
*/
geometry_msgs::Twist myTwistMsg
// Here you build your twist message
myTwistMsg.linear.x = 1;
myTwistMsg.linear.y = 2;
myTwistMsg.linear.z = 3;
ros::Time beginTime = ros::Time::now();
ros::Duration secondsIWantToSendMessagesFor = ros::Duration(3);
ros::Time endTime = secondsIWantToSendMessagesFor + beginTime;
while(ros::Time::now() < endTime )
{
pub.publish(msg);
// Time between messages, so you don't blast out an thousands of
// messages in your 3 secondperiod
ros::Duration(0.1).sleep();
}
return 0;
}
2 | No.2 Revision |
You should create your own node that will do this. You can do this in c++ or python.
Follow the Writing a Simple Publisher and Subscriber tutorial that teaches you how to make a publisher and subscriber node. You are only concerned with making a publisher node, but if you haven't done these tutorials, you should.
Here's the c++ version: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29
Here's the python version: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28python%29
Here is an example with UNTESTED CODE of how you would do this in c++:
#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
// Advertize the publisher on the topic you like
ros::Publisher pub = n.advertise<geometry_msgs::Twist>("my_topic_name", 1000);
/**
* A count of how many messages we have sent. This is used to create
* a unique string for each message.
*/
int count = 0;
while (ros::ok())
{
/**
* This is a message object. You stuff it with data, and then publish it.
*/
geometry_msgs::Twist myTwistMsg
// Here you build your twist message
myTwistMsg.linear.x = 1;
myTwistMsg.linear.y = 2;
myTwistMsg.linear.z = 3;
ros::Time beginTime = ros::Time::now();
ros::Duration secondsIWantToSendMessagesFor = ros::Duration(3);
ros::Time endTime = secondsIWantToSendMessagesFor + beginTime;
while(ros::Time::now() < endTime )
{
pub.publish(msg);
// Time between messages, so you don't blast out an thousands of
// messages in your 3 secondperiod
ros::Duration(0.1).sleep();
}
return 0;
}
3 | No.3 Revision |
You should create your own node that will do this. You can do this in c++ or python.
Follow the Writing a Simple Publisher and Subscriber tutorial that teaches you how to make a publisher and subscriber node. You are only concerned with making a publisher node, but if you haven't done these tutorials, you should.
Here's the c++ version: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29
Here's the python version: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28python%29
Here is an example with UNTESTED CODE of how you would do this in c++:
#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
// Advertize the publisher on the topic you like
ros::Publisher pub = n.advertise<geometry_msgs::Twist>("my_topic_name", 1000);
while (ros::ok())
{
/**
* This is a message object. You stuff it with data, and then publish it.
*/
geometry_msgs::Twist myTwistMsg
// Here you build your twist message
myTwistMsg.linear.x = 1;
myTwistMsg.linear.y = 2;
myTwistMsg.linear.z = 3;
ros::Time beginTime = ros::Time::now();
ros::Duration secondsIWantToSendMessagesFor = ros::Duration(3);
ros::Time endTime = secondsIWantToSendMessagesFor beginTime + beginTime;
secondsIWantToSendMessagesFor;
while(ros::Time::now() < endTime )
{
pub.publish(msg);
// Time between messages, so you don't blast out an thousands of
// messages in your 3 secondperiod
ros::Duration(0.1).sleep();
}
return 0;
}