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

How to pass topic names as input argument in the command line terminal?

asked 2016-12-18 13:55:58 -0500

Joy16 gravatar image

updated 2016-12-18 20:26:19 -0500

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!

edit retag flag offensive close merge delete

Comments

2

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.

gvdhoorn gravatar image gvdhoorn  ( 2016-12-18 14:44:12 -0500 )edit
gvdhoorn gravatar image gvdhoorn  ( 2016-12-18 14:44:57 -0500 )edit

@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!

Joy16 gravatar image Joy16  ( 2016-12-18 20:27:24 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-12-16 14:19:14 -0500

Reading command line parameters is explained in the ROS CPP Tutorial on parameters. To give my_param the value val, use:

rosrun package node _my_param:=val
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-12-18 13:55:58 -0500

Seen: 833 times

Last updated: Dec 16 '18