Guide: How to graph motor data

I have gotten a few questions about how I graphed my motor data in a spreadsheet, so I decsided to make a quick guide.

The goal is collect and display motor data.

I use #include <iostream> to output the data to terminal.

Now formating is really important. I use comma separated values formatting because it allows me to use a .csv file to store my data. (I wonder what csv stands for :man_shrugging: :man_shrugging:).

Time is really important to graph when things happen, but it doesn’t necessarily have to be the brain’s timer. If you want you could have a timer related to when a shot is fired.

Then add the propper motor inforation you wan to output.

I use a code block that looks simliar to this depending on what I want to output inside the driver ctrl while loop(just make sure it loops).

  std::cout << Brain.Timer.value() << " , " 
  << Motor18.velocity(rpm) << " , " <<  Motor18.torque(Nm) << " , " 
  << Motor18.current() << " , " << Motor18.voltage(volt)
  << std::endl; 

This outputs the: time , velocity , torque , current , voltage

Run the test and the program will output the data in terminal. Now I copy all the data to clipboard and paste it into a csv file or Excel (not sure exactly how this works for windows bc I use a mac).

Issues that arise for me is that if I try to output too much data at once the data doesn’t sent correctly to the terminal. I solved that by increasing the amount of wait time for the loop.

21 Likes

Does this work in both vexcode pro and pros?

I think it would work for both. Its just C++ printing to terminal.

Yeah you just have to keep the controller or the brain plugged in.

1 Like

Sorry if this is reviving an old thread but what did you use to graph it?

Microsoft Excel and Google Sheets both support drawing graphs given rows/columns of data (and they support .csv files so it is really easy to import what you have collected from your robot).

In the example below (Excel), I have a column labeled “output” that contains arbitrary values. You would probably use your collected information instead. Under the Insert tab, there is a button to generate a line graph with the selected data.

In Sheets, the process is similar. Under the Insert tab, you would click on Chart to insert the graph. It should default to a line format, but you may have to change it in the chart options.

3 Likes

Thank you! Is there a way to directly take it from the brain or do I need to type up all the numbers?

The original post contains a great way to do it!

“CSV” stands for “Comma-Separated Values” which is why you want to, well, print the values with comma separations to the terminal.

Example CSV File:

Column1,Column2,Column3
1,2,3
4,5,6
7,8,9

Imported into Excel/Sheets:
image

Just use similar code, copy all of the data from the terminal, save it in a .csv file, and then open it in your favorite spreadsheets software.

2 Likes

You could also use a library called Graphy if you’re using pros. Look it up on GitHub it has all the instructions for the setup which is quite easy. It didn’t work for me tho for some reason so I just copied and pasted the 4 files necessary into the right folders and it works fine.

Ohhhh. Thank You for all your help so far! When it says that “the program will output data to the terminal” what does it mean by the terminal?

It is referring to this area in VEXcode Pro (it’s at the bottom):

image


Example Code:

#include "vex.h"
#include <iostream>

using namespace vex;

int main() {
  vexcodeInit();
  // std:endl is used to flush the output buffer
  std::cout << "Hello World!" << std::endl;
}

Output:

image

1 Like

Ah ok. Is there an equivalent of that in just regular Vexcode or should I download PROS?

That IS VEXcode… not pros

2 Likes

Oh is there a difference between vexcode pro and pros? I only ever used block vexcode before.

In VEXcode V5, there is an output console that is accessible by clicking the speedometer icon at the top right (directly next to the button you use to set the devices connected to the brain).

Python:

from vex import *

print("Hello World!")

C++:

#include "vex.h"
#include <iostream>

using namespace vex;

int main() {
  std::cout << "Hello World!" << std::endl;
}

Output:

The nice thing about VEXcode V5 is that you are given buttons to save or copy your output.

1 Like

Ok thank you! I will try it when I get back to school.

I do a similar thing but with flywheel speeds to make sensing easier; instead of copying the output from the terminal I just do “pros terminal > log.csv”. If you were using a cli you could probably do the equivalent