How to pass topic names as input argument in the command line terminal?
Hello ! I have a problem that states "Read a rosbag, to parse a topic, that is passed as an input argument" How do I pass the input argument using "rosrun" in the command line terminal?
My code snippet:
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>i
#include<tf/tfMessage.h>
using namespace std;
void topicCallBack(const sensor_msgs::PointCloud2::ConstPtr&msg)
{
cout<<"Reading message of type PointCloud2\n"<<Header is:"<< msg->header;
if(msg->width)
cout<< "\nInpoint Cloud\nwidth is"<<msg->width;
//THIS LINE WILL NOT WORK AS MSG IS OF TYPE POINT CLOUD
if(msg->transforms.transform.translation)
cout<< " reading message of type TF\n";
}
int main(int argc, char **argv)
{
ros::init(argc, argv,"parser");
ros::NodeHandle nh;
//intializing the subscriber
ros::Subscriber sub = nh.subscribe("/camera/depth/points",1000, topicCallBack);
ros::spin();
return 0;
}
Here I have given my topic name as "/camera/depth/points" which publishes the message of type sensor_msgs/PointCloud2. But in my command line terminal, if I pass the topic name as "/tf", how do I ask it to publish the message of type tf/tfMessage because the subscriber is of type PointCloud2? In total, I have three topics that publish messages of type PointCloud2, tf, odom messages. But I am not able to see, how to pass different topic names in the command line argument and publish the respective message type Thanks!
So: what have you tried yourself, what didn't work, what did you expect would happen and what are your hypotheses? We're not here to do your homework for you. We will gladly help you solve problems you encountered while trying to solve this yourself however.
Is this a duplicate of How to pass topic name as the input argument using rosrun?
@gvdhoorn I have edited my details adding my work. Yeah, I am sorry I forgot to delete that question. Removed the older question now. Thanks!