V5 Robotic Brain SD CARD?!?

My team just received the V5 tech and its nice and works well so far, but after inspecting the robotic brain we have found the robotic brain has a port for the SD card. We where curios so we looked in the manual (picture book) and couldn’t find anything useful. I’m assuming it has to deal with the storage of 8 programs, but 8 programs should not be that big of space to require a SD card. PLEASE HELP MEEEEEEEEEEE. :slight_smile:

Excuse me gamma…
276-4810-v5-robot-brain-right.jpg

The programs are stored on the Brain’s own memory. The SD card will be able to be used for other storage, but I don’t think it’s implemented yet.

It is extra space, separate from the 8 programs. If you had a program that needed to load how to draw something on the screen, you could save that inside the SD card and read it from your program.

It seems like PROS supports using it already
https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html?highlight=file%20access

2 Likes

It is supported in (as far as I know) all programming solutions, I’m not sure if we support sub-directories yet, need to check on that.
In VCS we have some simplified methods but you can also use standard file IO such as


    // create a file with long filename
    std::ofstream ofs ("a_long_filename_debug.txt", std::ofstream::out);
    ofs << "lorem ipsum\r\n";
    ofs << "this was a test of a file with long file name\r\n";
    ofs.close();

1 Like

@jpearman oh cool, no idea how I missed that in the API doc!

Just to add on, PROS supports fopen, open, std:ofstream, and any other standard library I/O library function. With PROS, you could use the extra space to store scripts, data logs, or images to display on the screen using LVGL.

One thing to be aware of. Reading or writing large files can block other operations for some significant time. Read everything you need into memory at program start to avoid disrupting real time control of motors etc. VCS has some simplified methods on the brain class to help with reading and writing, these work with the SD Card by reading or writing in smaller chunks and call the scheduler in-between so other threads can run

1 Like

We implemented this code but it gives 2 errors (below). Any suggestions?

33%20PM

Its for storing files. Your program can write to it.

Also, the “PLEASE HELP MEEEEEEEE” and emoji add nothing to the conversation. Stop.

You probably need to add

#include <fstream>

to the beginning of your file

Thanks! I implemented this, and it almost works. I still get an error, though it now looks like this:
16%20PM
I’m confused due to the lack of an error message and would love any further guidance you may have.

Make the std::ofstream global for now, there’s a bug in the VCS makefile that means streams allocated on the stack sometimes don’t link correctly.

1 Like

We did that, and the code ran without errors, yet when we removed the SD card from the brain and accessed it from the computer, the file doesn’t show. For reference, here is the relevant code (FRM is a list of integers).
Capturecode1 Capturecode2

Not sure what you did there, only std::ofstream ofs; needs to be global

I just tried this in VCS and it works.

#include "robot-config.h"

#include <cstdio>
#include <iostream>
#include <iomanip>
#include <fstream>

std::ofstream ofs;

int main() {
    if( Brain.SDcard.isInserted() ) {
      // create a file with long filename
      ofs.open("a_long_filename_debug.txt", std::ofstream::out);
      ofs << "lorem ipsum\r\n";
      ofs << "this was a test of a file with long file name\r\n";
      ofs.close();

      Brain.Screen.printAt(10, 40, "done");
    }
    else {
      Brain.Screen.printAt(10, 40, "No SD Card");        
    }
}
1 Like

Thank you so much! This did what we wanted it to.

Im not very good at c++ and i dont know how this all works, but i can Frankenstein programs together. I was wondering if to write to the file you had to have the ‘\r\n’, because i want to write a variable to the file and the only way i know how to do that is to put the name of the variable, just have no quotes around it. So is there another way to write to the file without the need of ‘\r\n’. Sorry if this is a stupid question or if its been asked before.

All those characters mean is add a new line at the end of the text.

Given a variable with the value 1234 printed 5 times without appending

\r\n

would look like

12341234123412341234

and with would look like

1234
1234
1234
1234
1234

(I personally had never seen \r\n and have always seen \n but supposedly its a windows vs linux thing)

to use a variable in @jpearman 's example all you would need to do is

int banana = 5;
ofs << banana <<"\r\n”;
1 Like

Thank you so much, this really helped.

In case anyone’s curious here’s an abbreviated version of the story typed mostly from memory:

ASCII is the standard for Latin character encoding in North America. It was originally designed to control teletype machines. Teletype machines are basically typewriters, but where the keyboard and the ‘typewriter part’ are separate devices connected by a telegraph line and potentially in different cities or wherever.

In order to control a typewriter remotely, ASCII needed codes not just for all the characters it could produce, but also all the other functions a typewriter could perform, as well as a few additional transmission-related messages. Such codes are referred to as ‘control characters’.

When you’re using a typewriter and you run out of room on a line and hit the return key, the typewriter actually does 2 distinct things:

  1. It moves the carriage back to the leftmost position (a ‘carriage return’).
  2. It moves the paper down one line (a ‘line feed’).

Because these are different functions actuated by different mechanisms, each got its own ASCII character. That’s what \r and \n are — \r is the ‘carriage return’ character and \n is the ‘line feed’ character. Thus in the original application of ASCII every line ended with \r\n.

Then computers came along, and the companies designing them generally decided to use ASCII to encode their text, because it was an existing and relatively simple standard. But, there was the question of what to do about line endings.

Microsoft looked at \r\n line endings and said “well, that’s the existing standard, we might as well stick to it”. So DOS and Windows use \r\n line endings.

Early Unix developers looked at \r\n line endings and said “that’s stupid, we don’t need two characters at the end of every line, let’s just use \n instead”. So UNIX, Linux, and all the systems based on it use \n line endings.

Apple looked at \r\n line endings and said “that’s stupid, we don’t need two characters at the end of every line, let’s just use \r instead”. So classic Mac OS used \r line endings.

(Note that Mac OS X threw out all the classic Mac OS code and started from scratch with Unix-y underpinnings, so modern macOS uses \n line endings. Nothing really uses only \r any more.)

This mostly worked fine until the internet made it much more common to need to open files created on other types of computers. Opening and parsing files with line endings different than those native to your system can create all sorts of interesting problems.

Today’s text editors and other programs are mostly smart enough to figure out what line ending type is being used and convert as necessary to avoid problems without bothering the user about it. But, it’s not uncommon to encounter line-ending-related problems when doing stuff on the command line.

3 Likes

and for those who really want to see how a teletype works, go over to curiousmarc’s youtube channel. ( Marc Verdiell - CTO, Samtec Optical Group )

He has also just spent several months restoring an original Apollo guidance computer, I hope one day to meet the guy, I love what he’s doing.

2 Likes