Ask Your Question
0

roscore using Java swing

asked 2015-05-13 13:32:30 -0500

maha gravatar image

updated 2015-05-14 09:37:06 -0500

gvdhoorn gravatar image

Hello, I wanna run roscore from my java swing class and i keep getting this error:

Traceback (most recent call last):
  File "/opt/ros/fuerte/bin/roscore", line 62, in <module>
       import roslaunch
ImportError: No module named roslaunch

although when i run it from the terminal it works fine.

thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-05-14 09:40:03 -0500

gvdhoorn gravatar image

updated 2015-05-15 01:34:49 -0500

Most likely you have not setup your environment correctly. The Java program could be using a 'clean' shell to execute your command, while in your shell you've sourced the relevant setup.bash.

I'm not sure whether it is enough to run the Java program from a shell in which you've sourced setup.bash or if you need to configure the methods you use to invoke roscore in such a way that the embedded shell is configured correctly. I'll leave that for you.


Edit:

I'm sorry... is there anything that u suggest I could do to fix the problem? if there's any.. could you please be specific with the steps? I cannot understand what u r saying.

This is all rather unrelated to ROS, but: for java.lang.ProcessBuilder the following can be found in the documentation:

This class is used to create operating system processes.

[..]

Each process builder manages these process attributes:

[..]

  • an environment, which is a system-dependent mapping from variables to values. The initial value is a copy of the environment of the current process (see System.getenv())).

So it would appear that at least ProcessBuilder will pass on the entire environment of the shell the Java program was started in to the shell that is used to start your roscore in. That means that it should be sufficient to start your program in a shell where you've already done source /opt/ros/fuerte/setup.bash, and everything "should work".

In case of Eclipse, starting it from the shell (terminal window) where you sourced setup.bash should also work. You can do that using /path/to/eclipse/installation/eclipse.

If you cannot do that (because of deployment or whatever), you can use ProcessBuilder's methods to setup the required environment variables first, and then start roscore. This is documented at the end of the intro in the documentation of ProcessBuilder:

 ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
 Map<String, String> env = pb.environment();
 env.put("VAR1", "myValue");
 env.remove("OTHERVAR");
 env.put("VAR2", env.get("VAR1") + "suffix");
 pb.directory(new File("myDir"));
 Process p = pb.start();
edit flag offensive delete link more

Comments

can you explain how can I run my java program from a shell? I'm using eclipse.

maha gravatar image maha  ( 2015-05-14 13:46:49 -0500 )edit

Run Eclipse from a properly setup shell? The one you sourced setup.bash in? But that will still not guarantee that that shell's environment will be passed on to the one Java uses to start roscore in.

gvdhoorn gravatar image gvdhoorn  ( 2015-05-14 15:58:02 -0500 )edit

I'm sorry... is there anything that u suggest I could do to fix the problem? if there's any.. could you please be specific with the steps? I cannot understand what u r saying.

maha gravatar image maha  ( 2015-05-14 16:26:30 -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

1 follower

Stats

Asked: 2015-05-13 13:32:30 -0500

Seen: 198 times

Last updated: May 15 '15