Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Outputing files to the PC with ofstream in Autonomous (http://www.chiefdelphi.com/forums/showthread.php?t=143032)

Coupon4504 02-02-2016 01:56 PM

Outputing files to the PC with ofstream in Autonomous
 
In by Test function, I have the following code to output gyro values. I was wanting to record values every 10 miliseconds and save them to a file to plot, where I would experiment with different PID values.
Code:

void Test()
{
        static const double Kp = 0.03;
        gyro->Reset();
        std::ofstream file("gyro.txt");
        while(true)
        {
                double angle = gyro->GetAngle();
                static int revolutions = 0;
                if(file.is_open())
                {
                        file << revolutions << '\t';
                        file << -angle * Kp << '\n';
                        SmartDashboard::PutString("Error: ", " ");
                }else
                {
                        SmartDashboard::PutString("Error: ", "Cannot load file");
                }
                Wait(0.01);
                revolutions++;
        }
        file.close();
}

The problem is file.is_open() always returns false. Is there something else I need to do to get files to be created?


All times are GMT -5. The time now is 10:17 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi