Displaying Data

Hi, does anyone know how to display motor input and output power data to the brain using V5 text? I want to display these values and then download them to an SD card to graph the data.

While I’m not too sure about storing data and being able to download it afterwards, displaying data on the Brain’s screen is pretty easy to do. Below is just a very very simple example.

int main() {
  vexcodeInit();
  
  Brain.Screen.print("Motor (21) current: %f", Motor21.current());
}

%f is the format specifier for a float, and so it’ll be replaced with the current value for Motor21 when being printed onto the brain. By adding extra numbers before the f, you can set how many decimal places you want to print. For example, %.2f would only print 2 decimal places, and %2.3 would print a minimum of two characters with 3 decimal places.

You can change what %f is replaced with by changing what comes after the comma, so you could also print temperatures and power levels, amongst other readings. You might also want to put it into a loop and keep printing these readings, as well.

Other format specifiers

Should you want to include other data types, other format specifiers for these are as follows:

  • %d -> Integer
  • %o -> Octal
  • %s -> String
  • %x -> Hexadecimal integer
  • %c -> Character

As for the other half of your query, I didn’t think it was possible to write to the SD card with the brain, so I don’t really know how that could be done.

1 Like

I would use Brain.Screen.printAt(int x, int y, string fmt, args…) instead, since you have absolute control over where the text displays.

Writing to the sd card can be done with code like the following:

void WriteToSD(std::string out) {
    if(!(Brain.SDCard.isInserted())) return; //Prevent memory permission error
    FILE* f;
    f = fopen("file.txt", "a"); //Open the file in append mode
    fprintf(f, out);
    fclose(f);
}

I wouldn’t use this exact code because it was written by a vexforum user at 4:30 AM, but something like that should work.

3 Likes

int main() {

vexcodeInit();
Motor1.spin(vex::directionType::fwd);
Brain.Screen.print(“Motor (1) power: %.3f”, Motor1.power());

}
Above is my code. It is printing to the screen and the motor is rotating, but I am only getting 0 for my values. Any idea why?

int main() {
  vexcodeInit();

  Motor1.spin(forward);
  while(1 == 1){
    Brain.Screen.print("Motor 1 power: %.3f", Motor1.power());
    wait(0.1, seconds);
    Brain.Screen.clearLine();
  }
}

Try putting this into a loop and seeing what happens; there might be a very slight delay before the motor starts spinning. I have a V5 brain on me, but unfortunately no motors to test with right now.

1 Like

That seemed to work! Do you know how to display the values in a list, so that as they are displayed they stay on the screen?

Never mind, I was able to figure that out. My only other question is how do you display the current and power values separately at the same time.

I figured it out. The code below lists power and current simultaneously every 5 seconds in two separate rows on the brain’s screen. I’m not to sure how to loop it so that it keeps printing in a list because when the coordinates for the printing are specified, VEXCode doesn’t seem to let you create a new line. This longer way will have to do. Thanks so much for the help @Seb!

int main() {
vexcodeInit();

Motor1.spin(forward);
while(1 == 1){
Brain.Screen.printAt( 15, 15, “Motor 1 power: %.3f”, Motor1.power());
Brain.Screen.printAt( 245, 15, “Motor 1 current: %.3f”, Motor1.current());
wait(5.0, seconds);
Brain.Screen.printAt( 15, 35, “Motor 1 power: %.3f”, Motor1.power());
Brain.Screen.printAt( 245, 35, “Motor 1 current: %.3f”, Motor1.current());
wait(5.0, seconds);
Brain.Screen.printAt( 15, 55, “Motor 1 power: %.3f”, Motor1.power());
Brain.Screen.printAt( 245, 55, “Motor 1 current: %.3f”, Motor1.current());
wait(5.0, seconds);
Brain.Screen.printAt( 15, 75, “Motor 1 power: %.3f”, Motor1.power());
Brain.Screen.printAt( 245, 75, “Motor 1 current: %.3f”, Motor1.current());
wait(5.0, seconds);
Brain.Screen.printAt( 15, 95, “Motor 1 power: %.3f”, Motor1.power());
Brain.Screen.printAt( 245, 95, “Motor 1 current: %.3f”, Motor1.current());
wait(5.0, seconds);
Brain.Screen.printAt( 15, 115, “Motor 1 power: %.3f”, Motor1.power());
Brain.Screen.printAt( 245, 115, “Motor 1 current: %.3f”, Motor1.current());
wait(20.0, seconds);
}
}