Ask Your Question
0

Should I write a bash script in my package for setting Environment Variable $ROS_HOME?

asked 2017-04-26 12:58:41 -0500

Orhan gravatar image

updated 2017-04-26 13:00:57 -0500

I have a node that takes images with OpenCV, saves files under the /home/user0/Images/. When I run this node via rosrun, it saves succesfully. And also tried with roslaunch:

 <node name="my_node" pkg="my_pkg" type="my_node" output="screen" cwd="ROS_HOME"/>

But it needs running

~$ export ROS_HOME=$HOME

command before calling that launch file.

Should I write a bash script in my package for setting $ROS_HOME and put that script into my launch file? Or; setting $ROS_HOME in my .bashrc file option is good?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-04-26 23:01:33 -0500

Geoff gravatar image

If you change ROS_HOME you will change where things like log files produced by roslaunch go (see http://wiki.ros.org/ROS/EnvironmentVa... ).

Use a parameter to specify a location for files written by a node. There is a good tutorial available here. This will let you pass the destination for directories to the node using the parameter server. The parameter can be given a good default value, and you can set a customised value in the launch file using the param tag.

You can go further and add an argument to the launch file using the arg tag, which you can then pass to the parameter for the node in the launch file (the example on that page shows you how). That will let you set the value of the parameter on the command line when you call roslaunch.

So in your node, you would have something like this:

std::string dest_dir;
nh.param("~destination_dir", dest_dir, "images");

And in your launch file, something like this:

<arg name="image_output_dir" value="other_images"/>
<node name="my_node" pkg="my_pkg" type="my_node" output="screen">
    <param name="destination_dir" value="$(arg image_output_dir)"/>
</node>

And if you want to get really fancy, you can use dynamic_reconfigure to let you change the destination directory for images at runtime, without restarting the node.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-04-26 12:58:41 -0500

Seen: 243 times

Last updated: Apr 26 '17