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

roslaunch prevents node from creating/writing to file

asked 2012-07-05 13:12:02 -0600

this post is marked as community wiki

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

For our current project, we created a launch file that initializes several nodes, one of which is supposed to create a log file, open it, write a header line at the beginning of the file, and then close the file.

When we run the nodes individually from terminal, this function works fine, but when the project is run from a launch file, the log file is never created. Do nodes run from a launch file not have permission to create new log files?

Function to create log file:

char Beacon::createLogFile(char *logDataFileName)

{

int status;
status = mkdir("Log", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);

if (status == -1)
{
        // error; it might be that the directory already exists
        if (errno == EEXIST)
        {
            // no problem
        }
        else if (errno == EACCES)
        {
            printf("Permission\n");
                return 1;
        }
}
else
{
        // Directory successfully created

}

FILE* logData_f_stream;
logData_f_stream = fopen(logDataFileName, "w");

fprintf(logData_f_stream, "NodeID Latitude Longitude Time OWTT\n");
fclose(logData_f_stream);


return 0;

}

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2012-07-05 13:13:34 -0600

this post is marked as community wiki

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

You should look for your log file in your ~/.ros directory when starting nodes from launch files.

edit flag offensive delete link more

Comments

or alternatively, set absolute path for the file name, so you know exactly where to look.

weiin gravatar image weiin  ( 2012-07-05 17:13:15 -0600 )edit
1

Be careful with absolute paths though because this will make your code less portable if/when other people start using your work or if/when you try to use your own code on a different computer with a different directory structure.

Thomas D gravatar image Thomas D  ( 2012-07-06 06:07:32 -0600 )edit
2

answered 2012-07-05 20:56:04 -0600

ipso gravatar image

Just as some additional information to the answer of Thomas D: the 'current working directory' of the nodes launched via roslaunch gets set to the $HOME/.ros directory by default. See 'Is there a way for roslaunch to run nodes in the current directory?' on ros-users for a discussion.

The cwd attribute of the node tag in a launch file can be used to change this behaviour:

cwd="ROS_HOME|node"(optional)

If 'node', the working directory of the node will be set to the same directory as the node's executable. In C Turtle, the default is 'ROS_HOME'. In Box Turtle (ROS 1.0.x), the default is 'ros-root'. The use of 'ros-root' is deprecated in C Turtle.

See the roslaunch/XML/node#Attributes wiki page and also this ticket.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-07-05 13:12:02 -0600

Seen: 2,604 times

Last updated: Jul 05 '12