I’m doing a science experiment with some VEX parts and a cortex. I have everything in place, like sensors and stuff. However, I don’t know how to, one, record data from the sensors every nth millisecond and store it (maybe an array? idk), and, two, how to export data into a file that Excel can use (it will be annoying if I have to copy and paste each data piece into a chart and I really don’t want to do that). Thank you in advance.
The datalogging feature of RobotC is probably your best bet.
However, I’d strongly recommend instead using a 3rd party serial datalogging utility on the computer with custom serial data and formatting coming from the Cortex (likely through PROS). You’ll likely have better luck importing data into Excel that way.
See better answers below
So I would recommend printing the data in csv format using writeDebugStream every n milliseconds. Then copy and paste the entire stream into a text file with a .csv extension. Excel can then open the file correctly.
Example text
1,2,3
2,3,4
6,4,8
^ Just make sure that after opening the csv you save as in xlsx format or you might be really sad later on. I’ve made that mistake way too many times.
If you just have one data point, it might be easier to print to debug stream, select all, copy, and paste in Excel. That does work. For multiple datapoints you can also use Data>Text to Columns in Excel.
I only have two variables of data, so should I save as .csv then .xlsx or should I use Data>Text to Colunms in Excel? Which way would be faster or easier or both?
TBH, there’s no big difference. Do whatever you want, and if you have difficulties there’s still a backup plan.
In order to use in Excel properly, you want to make sure you log the time of each output. nSysTime does that nicely. Once you use it, you will notice Robot C is not always good about being consistent in sending the data across. A USB A-A cable connection seems to have the most reliable data stream.
Once you save the data to a file and place in Excel, please use a scatter plot, not a line plot. A line plot wants everything defined at equal intervals, a scatter plot does the X vs Y plot correctly.
This code logged all PID components in the loop to show the effects of how each was doing each go around. Not necessary, but useful for investigating what is going on inside the PID. You want to find the time at each peak (or valley) to get the period of oscillation in milliseconds. Then you can use Ziegler Nichols formulas quite easily.
Taken from a PID routine that managed the lift (hence the L hard coded). Had a few of these lying about.
writeDebugStreamLine("L|%d|%d|%d|%d|%d|%d|%d",nSysTime, current_pot, arm_speed, motor[Left_Lift_Inside], Arm_Error, Integral_Arm, Derrivitive_Arm);
Comment out this when done as the writeDebugStreamLine code is more intensive than your regular robot code. It’s really the printing to a string that takes the compute cycles and robot C managing the debug stream buffer.
For those without the Microsoft licenses and money for them, Open Office works just as well. And it is free.