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

import a 'roshlet' from another roshlet

asked 2012-03-15 10:29:10 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.


If I have two rosh scripts - lets say and that work perfectly when invoked independently (rosrun rosh rosh - is there a simple mechanism for importing one into the other that ensures the globals() have been set up during the import.


#### ####

def getpoint():
  return msg.geometry_msg.PointStamped()

#### ####
import b


The problem is that if I 'rosrun rosh rosh', global variables like msg, actions, etc in module a are set up but these do not carry across when I 'import b'. As a result, b will not load (with an error the msg is not defined).

edit retag flag offensive close merge delete


I had a typo in the program that bhaskara replied to. I've fixed this typo but the question still remains: how can a roshlet be imported from another roshlet?

Benjamin Johnston gravatar image Benjamin Johnston  ( 2012-03-20 10:33:28 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2012-03-20 10:46:22 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

The msg/actions/etc... variables are only setup in the global namespace, so its not currently possible to do what you are doing automatically. rosh, and roshlets even moreso, are fairly experimental. The current workaround is to pass in the symbols as parameters to the functions you are calling. Another possibility is patch rosh to enable easier initialization of globals() in submodules.

edit flag offensive delete link more

answered 2012-03-16 06:48:27 -0600

bhaskara gravatar image

Well, as written, is wrong: a.getpoint() should be b.getpoint(). This isn't specific to rosh, just how python modules work.

edit flag offensive delete link more

Question Tools


Asked: 2012-03-15 10:29:10 -0600

Seen: 190 times

Last updated: Mar 20 '12