I have a very simple program in pros which prints to an sd card:
void initialize()
{
pros::lcd::initialize();
pros::lcd::set_text(1, "Hello PROS User!");
pros::lcd::set_text(2, "Hello PROS User!");
pros::lcd::register_btn1_cb(on_center_button);
pros::lcd::clear();
pros::delay(222);
qlog.push("hi");
pros::screen::print(pros::E_TEXT_MEDIUM,3,"hi");
qlog.push("hello world");
std::cout << "hi" << std::endl;
pros::delay(222);
if (pros::usd::is_installed())
{
std::cout << "is installed" << std::endl;
}
else
{
std::cout << "is not installed" << std::endl;
}
pros::delay(1000);
std::ofstream output("file.txt");
std::cout << qlog.front() << std::endl;
if (output.is_open())
{
std::cout << "output is open" << std::endl;
output << qlog.front() << std::endl;
qlog.pop();
output << "c" << std::endl;
qlog.pop();
output.close();
}
else
{
std::cout << "output is not open" << std::endl;
}
}
Every time I run this code, the SD card is empty and this is what prints to the terminal:
hi
is installed
hi
output is not open
The sd card is installed, recognised by the brain, in the FAT 32 format and is under 16gb. Also fstream, iostream and queue are included (not shown here)
Can someone please explain what is going wrong?
I also found out that this program here does indeed print to sdcard on vexcode but it doesn’t on pros. The code I used is below.
Forvexcode:
#include "iostream"
#include "vex.h"
#include "fstream"
#include "string"
using namespace vex;
int main()
{
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
std::ofstream output("output.txt", std::ofstream::out);
int count1 = 0;
int count2 = 0;
int count3 = 200;
while(count3 >0)
{
count1++;
count2 --;
count3 --;
task::sleep(20);
output << count1 << std::endl;
output << count2 << std::endl;
output << count3 << std::endl;
output << "vex::task::sleep(20)" << std::endl;
}
output.close();
Brain.Screen.printAt(100,100,"DONE!!");
}
and for PROS:
#include "main.h"
#include <fstream>
#include <iostream>
void initialize()
{
pros::lcd::initialize();
pros::lcd::set_text(1, "Hello PROS User!");
pros::lcd::clear();
pros::delay(500);
std::ofstream output("output.txt", std::ofstream::out);
int count1 = 0;
int count2 = 0;
int count3 = 200;
while(count3 >0)
{
count1++;
count2 --;
count3 --;
pros::delay(20);
output << count1 << std::endl;
output << count2 << std::endl;
output << count3 << std::endl;
output << "vex::task::sleep(20)" << std::endl;
}
output.close();
pros::lcd::set_text(5, "Done!");
}
void disabled() {}
void competition_initialize() {}
void autonomous() {}
void opcontrol() {}
LArk
April 30, 2023, 1:30pm
3
The problem is your path needs to start with usd/
, so your path should be instead usd/output.txt
, rather than just output.txt
.
For more information on printing to a micro SD card with PROS, you can refer to this page .
1 Like