Ask Your Question
0

problem getting topic remaps in the code

asked 2013-04-03 05:33:58 -0500

navderm gravatar image

updated 2013-04-03 05:53:40 -0500

I am unable to get topic names using

ros::param::get(info_topic, input_info_topic_);

where info_topic and input_info_topic_ are:

  std::string input_info_topic_;
  std::string namespace_ = pnh_.getNamespace();
  std::string info_topic = namespace_ + "/input_info_topic";

A little more detail :

My classes are :

namespace mynamespace 
{   
   class A : public nodelet::Nodelet
   {    
        ...
        boost::shared_ptr<ClassD> di;
   };
}

namespace mynamespace
{
    class ClassD
    {
        //constructor
        ClassD(ros::NodeHandle& n, ros::NodeHandle& pnh);

        //all the ros::param::get() are in definition of this class. 
    };
}

When I try to remap topics, it doesn't work. The end result is always an empty string and hence I can't get any images in. What am I doing wrong.

I have tried to provide all the information that might be relevant. If I am missing something kindly please let me know.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2013-04-03 06:10:43 -0500

dornhege gravatar image

I'm not sure, what exactly you want to achieve, but I think you are working manually against ROS internals. You should never need to make such constructions as you have done.

Depending on what you want to do, here is what an easier solution should look like:

If you want to get the parameter from within you node's namespace, do not construct that full name by yourself. Just get the parameter from a private node handle, e.g.

ros::NodeHandle pnh("~");
pnh.getParam("input_info_topic", input_info_topic_);

However, as the variable you are requesting is named: ...topic, this leads to another thing. If you want to use this variable to subscribe or publish to a custom topic, you should never set this via parameters! Instead, always use the topic under the same name in the code and rely on remapping of topics to change that. If the topic is supposed to be in the node's namespace, construct a publisher/subscriber from a private node handle.

edit flag offensive delete link more

Comments

Hey. Thanks for the reply. I am not able to get the parameters using pnh.getParam(...) either. I just wonder if the problem is because the class split into two. I can't seem to communicate with ros param server at all.

navderm gravatar imagenavderm ( 2013-04-03 06:51:24 -0500 )edit

Also, in case I need to publish/subscribe using imageTransport, do I initiate the image Transport in private namespace ? I am using ImageTransport::CameraPublisher to publish and ImageTransport to subscribe to images

navderm gravatar imagenavderm ( 2013-04-03 06:53:55 -0500 )edit

I haven't used image transport, but you should be able to just initialize that with the private nodehandle. BTW: If you are writing a driver, according to the newest REP (https://github.com/ros-infrastructure/rep/blob/master/rep-0135.rst) using a namespace is not necessary and should be avoided.

dornhege gravatar imagedornhege ( 2013-04-03 07:08:27 -0500 )edit

About the getParam(). That should work for nodes. I've seen that you use a nodelet, maybe that changes things.

dornhege gravatar imagedornhege ( 2013-04-03 07:09:53 -0500 )edit

No I am not writing a driver. The only problem I see is that the parameter isn't being passed in correctly. I can't get the parameter loaded correctly even just as a plain string before I do any topic calls etc. I tried private_nodehandle.param <std::string>("st", "/image_raw", "NOT SET")

navderm gravatar imagenavderm ( 2013-04-03 07:19:57 -0500 )edit

and it is always not set. I tried nodehandle.param , it is still NOT SET. If I can get that parameter read properly, I think I would have solved more than half the problem. I see depth_image_proc doing the exact same thing but they have 1 class and i have 2 broken classes. Nothing changes otherwise

navderm gravatar imagenavderm ( 2013-04-03 07:21:39 -0500 )edit

Remove the '/' in the parameter name.

dornhege gravatar imagedornhege ( 2013-04-03 07:30:00 -0500 )edit

Yeah I tried that too The current most educated code is : std::string input_info_topic ; pnh.param<std::string>("input_info_topic", input_info_topic", "NOT SET")

Still doesn't work . I'll try to keep figuring out why its not working. May be something in the nodelet launch file.

navderm gravatar imagenavderm ( 2013-04-03 07:43:15 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-04-03 05:33:58 -0500

Seen: 650 times

Last updated: Apr 03 '13