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

dynamically create,compile and import msg files

asked 2011-06-29 04:51:42 -0500

jduewel gravatar image

updated 2011-09-03 15:35:23 -0500

kwc gravatar image


i'm trying to create and dynamically compile msg files to use them while the node is running. Somehow it works only for the first msg file which i create,compile and import. Every file which i try to import after the first one gets an import error.

Here is a very simple example of what im trying to do:

#!/usr/bin/env python
PKG = 'janus'
msgPath = "/home/jan/Desktop/Janus/trunk/janus/msg" #my Path to the msg folder

import os
import codecs
import roslib; roslib.load_manifest(PKG)


fobj ="test"+".msg", 'w')
fobj.write("float32 buttons")
exec('os.system("rosmake %s")' %PKG)
exec('from %s.msg import test' %PKG)

fobj1 ="test1"+".msg", 'w')
fobj1.write("float32 buttons")
exec('os.system("rosmake %s")' %PKG)
exec('from %s.msg import test1' %PKG)

So why it imports the first file, but not the second? :( hope you can help me thx

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-06-29 05:19:01 -0500

kwc gravatar image

You need to reload the Python module. After the first call, Python has loaded 'janus' and will not go back out to disk.

Note: in general, you have to be careful when calling reload as it can result in inconsistent modules. It should be fine if you are just fetching msg files.

edit flag offensive delete link more


Ive read the manual carefully, but i still dont know which module to reload.
jduewel gravatar image jduewel  ( 2011-06-29 11:38:44 -0500 )edit
From your code, it looks like 'janus' is the module.
kwc gravatar image kwc  ( 2011-06-29 13:48:18 -0500 )edit

Question Tools


Asked: 2011-06-29 04:51:42 -0500

Seen: 547 times

Last updated: Jun 29 '11