corot / world_canvas

ROS framework for storing and accessing semantic information about the world, with an initial emphasis on needs and use cases for mobile robots.
10 stars 19 forks source link

Can I publish a topic with type known at runtime? #5

Closed corot closed 10 years ago

corot commented 10 years ago

Yes:

    topic_name = rospy.get_param('~topic_name')
    topic_type = rospy.get_param('~topic_type')

    topic_class = roslib.message.get_message_class(topic_type)

    object_pub = rospy.Publisher(topic_name, topic_class, latch = True)

but.... as roslib.message import get_message_class internally imports the module containing the topic type, it must be in the Python path, what will not always be the case: the code running on the server is not supposed to have access to all the annotations' message definitions that he must handle.

Or will he??? I think this will impose a hard (but reasonable) constraint to the world canvas server use.

jihoonl commented 10 years ago

rosbridge_library has a dynamic message loader which you might be interested in. https://github.com/RobotWebTools/rosbridge_suite/blob/develop/rosbridge_library/src/rosbridge_library/internal/ros_loader.py#L40-L45

Forget this if it does not fit in the purpose.

stonier commented 10 years ago

@corot why would the server need the message definitions? I thought they would just be taking some fields and storing these in the database - e.g. relevant ones here would be

I can't see where it would actually need the message definition.

stonier commented 10 years ago

Some code that might be useful. C++ and python relaying of unknown topics at a lower level (xmlrpc/master level):

https://github.com/stonier/multimaster_experimental/tree/master/foreign_relay/src/nodes

corot commented 10 years ago

Yes, yes. You are right, but at some point all the solutions I have inspected import the package containing the messages. Or, as foreign_relay does, reads from the master the published topics and get topic type from there (what cannot be done in the WC server: he will publish already unpublished topics).

But I'm not worry too much about this: In most cases, the messages will be already in the server workspace, and if not, the only victim is PublishAnnotations, who will answer: "Message type not available for publishing"

stonier commented 10 years ago

I suspect the client library will require the message package import floating around on the ROS_PACKAGE_PATH as well. It will have to pack binary data into these message type instances.

corot commented 10 years ago

right. but in the client it's not a problem: if the client wants some kinds of annotations is because he knows them.

2014-06-12 3:14 GMT+02:00 Daniel Stonier notifications@github.com:

I suspect the client library will require the message package import floating around on the ROS_PACKAGE_PATH as well. It will have to pack binary data into these message type instances.

— Reply to this email directly or view it on GitHub https://github.com/corot/world_canvas/issues/5#issuecomment-45819774.

corot commented 10 years ago

We can close this.