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

std::ofstream

asked 2011-06-22 20:22:14 -0500

frferrara gravatar image

updated 2011-06-22 21:05:46 -0500

Hello everybody,

I have a question regarding ROS launch files and writing a file using the standard library ofstream.

I wrote a program that uses a camera. I want to store the runtime of some operations for further analysis and I put this data in a matrix made of standard vectors. Except for the writing of the files, everything works perfectly.

When I load the parameters using "rosparam load" and then start my software using "rosrun", everything works fine.

If I start all the programs using a launch file, the file won't be neither created nor written to if it already exists. There is no problem with the file opening. And everything was working on Cturtle.

What might be the problem?

Thank you in advance

Francesco

Code:

#include <std_msgs/Time.h>  // ros::Time for the calculation of the ball detection runtime
#include <geometry_msgs/PointStamped.h> // message type used for the communication with the OROCOS component
#include <std_msgs/Float32.h> // message type used for publishing the runtime
#include <ros/ros.h> // ros headers
#include <sensor_msgs/image_encodings.h> // message type used for the CvBridge
#include <image_transport/image_transport.h> // subscribe to and publish images
#include <cv_bridge/cv_bridge.h> // convert from ROS image to opencv image
#include <opencv2/imgproc/imgproc.hpp> // opencv headers
#include <opencv2/highgui/highgui.hpp> // opencv headers
// headers for storing the operation runtimes in a file
#include <vector>
#include <iostream>
#include <fstream>
#include <CMgreenBallDetector.hpp> // Ball detector header

namespace enc = sensor_msgs::image_encodings;

CMgreenBallDetector::CMgreenBallDetector (ros::NodeHandle &n):
                n_(n),
                it_(n),
                it2_(n),
                it3_(n)
{
    // Set the variables to publish or not publish certain topics (0: not publish, another int: publish)
    this->n_.getParam ("/CMgreenBallDetector/detectedBall", pub[0]);
    this->n_.getParam ("/CMgreenBallDetector/algorithmRuntime", pub[1]);
    this->n_.getParam ("/CMgreenBallDetector/thresholded", pub[2]);
    this->n_.getParam ("/CMgreenBallDetector/dilated", pub[3]);

    if (pub[0] != 0)
    {
        // advertise a topic for the detected ball image
        image_pub_ = it_.advertise ("CMgreen_ball_detected", 1);
    }

    if (pub[2] != 0)
    {
        // advertise a topic for the thresholded image
        image_pub2_ = it2_.advertise ("thresholded", 1);
    }

    if (pub[3] != 0)
    {
        // advertise a topic for the dilated image
        image_pub3_ = it3_.advertise ("dilated", 1);
    }

    // subscribe to the color image topic delivered by the camera in order to detect the ball in it
    image_sub_ = it_.subscribe ("/camera/image_color", 1, &CMgreenBallDetector::detectionCallback, this);

    // advertise a topic for the data of the detected ball, i.e. ball center coordinates, ball radius and timestamp
    pub_ball = n.advertise<geometry_msgs::PointStamped> ("CMgreen_ball_data", 1);

    if (pub[1] != 0)
    {
        // advertise a topic for the runtime
        pub_runtime = n.advertise<std_msgs::Float32> ("CMgbd_runtime", 1);
    }

    // Read the parameters from the parameter server
    this->n_.getParam ("/CMgreenBallDetector/h_min", h_min);
    this->n_.getParam ("/CMgreenBallDetector/h_max", h_max);
    this->n_.getParam ("/CMgreenBallDetector/s_min", s_min);
    this->n_.getParam ("/CMgreenBallDetector/s_max", s_max);
    this->n_.getParam ("/CMgreenBallDetector/v_min", v_min);
    this->n_.getParam ("/CMgreenBallDetector/v_max", v_max);

    // Define the ranges for the color filtering in the HSV color space
    // green ball
    hsv_min = cv::Scalar_<double>(h_min, s_min, v_min, 0);
    hsv_max = cv::Scalar_<double>(h_max, s_max, v_max, 0);

    // Get the camera resolution parameters
    this->n_.getParam ("/CMgreenBallDetector ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
4

answered 2011-06-22 22:12:17 -0500

dornhege gravatar image

You are writing a file to the current working directory. roslaunch changes that. Look in your .ros directory. You should find the file there.

edit flag offensive delete link more

Comments

Thanks a lot! It was there!
frferrara gravatar image frferrara  ( 2011-06-22 23:45:36 -0500 )edit

Question Tools

Stats

Asked: 2011-06-22 20:22:14 -0500

Seen: 2,641 times

Last updated: Jun 22 '11