View Single Post
  #1   Spotlight this post!  
Unread 02-02-2016, 01:56 PM
Coupon4504 Coupon4504 is offline
Registered User
FRC #4504
 
Join Date: Jan 2015
Location: Blount County, Tennessee
Posts: 5
Coupon4504 is an unknown quantity at this point
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?

Last edited by Coupon4504 : 02-02-2016 at 02:58 PM.
Reply With Quote