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

import a 'roshlet' from another roshlet

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

this post is marked as community wiki

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

Hi,

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

e.g.,

#### b.py ####

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

#### a.py ####
import b

actions.foo_controller.move_to(b.getpoint())

The problem is that if I 'rosrun rosh rosh a.py', 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

Comments

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 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

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

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
3

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

bhaskara gravatar image

Well, as written, a.py 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

Stats

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

Seen: 192 times

Last updated: Mar 20 '12