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

Revision history [back]

click to hide/show revision 1
initial version

if you want change rate of the loop when the program run you must use Dynamic Reconfigure parameter
if you want to set rate of the loop when you run the program you can use this command:

rosrun publisher_package PublisherNode ra:=50

if you want change rate of the loop when the program run nide is runnig you must use Dynamic Reconfigure parameter
if you want to set rate of the loop when you run start the program node you can use this command:

rosrun publisher_package PublisherNode ra:=50

if you want change rate of the loop when the nide is runnig you must use Dynamic Reconfigure parameter
if you want to set rate of the loop when you start the node you can use this command:

rosrun publisher_package PublisherNode ra:=50

#include "ros/ros.h"
#include "performance_tests/SuperAwesome.h"  
#include <sstream>

int main(int argc, char **argv)
{
ros::init(argc, argv, "PublisherNode");
ros::NodeHandle nh;
int ra;
n.param("my_num", ra,100);

ros::Publisher msg_pub = nh.advertise<performance_tests::SuperAwesome>("publisher", 1000);
// I want to change the rate value through the value I receive in through ra.
ros::Rate rate(ra);

int count = 0;

while (ros::ok())
{
    performance_tests::SuperAwesome msg;
    std::stringstream s;

    s <<"Hello World " << count; 
    msg.data = s.str();

    ROS_INFO("%s",msg.data.c_str());
    msg_pub.publish(msg);
    ros::spinOnce();

    rate.sleep();

    count++;
}

return 0;
}

if you want change rate of the loop when the nide node is runnig you must use Dynamic Reconfigure parameter
if you want to set rate of the loop when you start the node you can use this command:

rosrun publisher_package PublisherNode ra:=50

#include "ros/ros.h"
#include "performance_tests/SuperAwesome.h"  
#include <sstream>

int main(int argc, char **argv)
{
ros::init(argc, argv, "PublisherNode");
ros::NodeHandle nh;
int ra;
n.param("my_num", ra,100);

ros::Publisher msg_pub = nh.advertise<performance_tests::SuperAwesome>("publisher", 1000);
// I want to change the rate value through the value I receive in through ra.
ros::Rate rate(ra);

int count = 0;

while (ros::ok())
{
    performance_tests::SuperAwesome msg;
    std::stringstream s;

    s <<"Hello World " << count; 
    msg.data = s.str();

    ROS_INFO("%s",msg.data.c_str());
    msg_pub.publish(msg);
    ros::spinOnce();

    rate.sleep();

    count++;
}

return 0;
}

if you want change rate of the loop when the node is runnig you must use Dynamic Reconfigure parameter
if you want to set rate of the loop when you start the node you can
use this command:command and code:

rosrun publisher_package PublisherNode ra:=50

#include "ros/ros.h"
#include "performance_tests/SuperAwesome.h"  
#include <sstream>

int main(int argc, char **argv)
{
ros::init(argc, argv, "PublisherNode");
ros::NodeHandle nh;
int ra;
n.param("my_num", ra,100);

ros::Publisher msg_pub = nh.advertise<performance_tests::SuperAwesome>("publisher", 1000);
// I want to change the rate value through the value I receive in through ra.
ros::Rate rate(ra);

int count = 0;

while (ros::ok())
{
    performance_tests::SuperAwesome msg;
    std::stringstream s;

    s <<"Hello World " << count; 
    msg.data = s.str();

    ROS_INFO("%s",msg.data.c_str());
    msg_pub.publish(msg);
    ros::spinOnce();

    rate.sleep();

    count++;
}

return 0;
}

use this command and code:

rosrun publisher_package PublisherNode ra:=50

#include "ros/ros.h"
#include "performance_tests/SuperAwesome.h"  
#include <sstream>

int main(int argc, char **argv)
{
ros::init(argc, argv, "PublisherNode");
ros::NodeHandle nh;
int ra;
n.param("my_num", n.param("ra", ra,100);

ros::Publisher msg_pub = nh.advertise<performance_tests::SuperAwesome>("publisher", 1000);
// I want to change the rate value through the value I receive in through ra.
ros::Rate rate(ra);

int count = 0;

while (ros::ok())
{
    performance_tests::SuperAwesome msg;
    std::stringstream s;

    s <<"Hello World " << count; 
    msg.data = s.str();

    ROS_INFO("%s",msg.data.c_str());
    msg_pub.publish(msg);
    ros::spinOnce();

    rate.sleep();

    count++;
}

return 0;
}

use this command and code:

rosrun publisher_package PublisherNode ra:=50_my_param:=1

#include "ros/ros.h"
#include "performance_tests/SuperAwesome.h"  
#include <sstream>

int main(int argc, char **argv)
{
ros::init(argc, argv, "PublisherNode");
ros::NodeHandle nh;
nh("~");
int ra;
n.param("ra", nh.param("my_param", ra,100);

ros::Publisher msg_pub = nh.advertise<performance_tests::SuperAwesome>("publisher", 1000);
// I want to change the rate value through the value I receive in through ra.
ros::Rate rate(ra);

int count = 0;

while (ros::ok())
{
    performance_tests::SuperAwesome msg;
    std::stringstream s;

    s <<"Hello World " << count; 
    msg.data = s.str();

    ROS_INFO("%s",msg.data.c_str());
    msg_pub.publish(msg);
    ros::spinOnce();

    rate.sleep();

    count++;
}

return 0;
}