Robotics StackExchange | Archived questions

rosbag::RecorderOptions and rosbag::Recoder specifying directory for bag files

Hi all, I have a problem about a class whose name is Recorder in the recorder.h file. As you know, with the help of RecorderOptions struct and Recorder class, we are able to start "rosbag record" process from our programs instead of running a command line such as "rosbag record -a". After a few trials, I succeeded to start getting .bag files properly. You can observe the basic code block where you can see how I implemented for better undestanding sake.

int main(int argc, char **argv)
{
    // Initiate new ROS node named "talker"
    ros::init(argc, argv, "bag_recorder_XX_node");

    //create a node handle: it is reference assigned to a new node
    ros::NodeHandle nh;

    rosbag::RecorderOptions options;
    options.prefix = bag_name ; // Set the prefix for the bag file name.
    options.append_date = true; // Append date to the bag file name.
    options.record_all = false ; 
    options.split = true ; 
    options.max_splits = 2 ; 
    options.max_duration = ros::Duration(120) ; 

    // Specify the topics you want to record.
    options.topics.push_back("/chatter");
    options.topics.push_back("/rosout");

    rosbag::Recorder recorder(options);
    ROS_INFO("Starting rosbag recording...");

    recorder.run() ; 
}

However, If I want to specify the location where bag files should be saved, I encounter with a problems. As far as I understand, there is no built-in solution for that. Also classes that I use don't have such metots/fields to satisfy my goal. The directory where I want bag files get recorded will be determined in run-time. For example, I have a folder called Bags in the home directory, once I run my bagrecorder program, I create a folder in the Bags called 202307191045 for instance, then I expect the bag files get recorded there for more readable and easier to manage among bag files after all. How can I achieve this goal?

Thanks everyone in advance! ROS1-Kinetic-Ubuntu16.04-recorder.h

Note: I cannot use /launch/cwd attribute since directory is determined in run-time.

Asked by serhat on 2023-07-19 02:35:58 UTC

Comments

Answers