How do i provide command line parameter for publisher written in c++. I tried similar to what i did with python publisher but it doesn't work. I used getparam in c++.
#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;
std::string ra; //I want to accept an Integer value
if (nh.getParam("/ra", ra))
{
ROS_INFO("Got param: %s", ra.c_str());
}
else
{
ROS_INFO("Failed to get param ");
}
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(100);
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;
}
I would like to change the publisher rate through command line parameter similar to what I do in python publisher. i.e,
rosrun publisher_package publisher.py _rate:=50
How can I do the same in c++ publisher
Originally posted by Brolin on ROS Answers with karma: 35 on 2018-12-22
Post score: 0
Original comments
Comment by jayess on 2018-12-22:
Can you please update your question so that it's a minimum working example? If I were to copy and paste your code and try to compile it (which I tried), it wouldn't work due to a custom class that's not defined.