Hello everybody,
I’ve built a simple GUI in processing (P3) to show some sensor data in near real-time and have hit a bit of a snag with Grafica.
I’m plotting three values over a 25 point span and it quickly (20s) uses up all of my available memory and becomes very laggy.
The data is polled live and saved in a FIFO like this:
// located in setup we import grafica, declare our linkedLists, variables, etc.
#import grafica.*;
LinkedList<Integer> E1c = new LinkedList<Integer>();
LinkedList<Integer> E3c = new LinkedList<Integer>();
LinkedList<Integer> E4c = new LinkedList<Integer>();
int nPoints = 25;
float E1, E2, E3, E4;
void Convert2uStrain() {
//Convert to strain
//not shown....gathering data...converting data => E1, E2, E3 are floats
//Array containing the last nPoints
if (running == true) {
if (len < nPoints){
E1c.push(int(E1 * 1000000));
E3c.push(int(E3 * 1000000));
E4c.push(int(E4 * 1000000));
len++;
}
else {
E1c.removeLast();
E3c.removeLast();
E4c.removeLast();
E1c.push(int(E1 * 1000000));
E3c.push(int(E3 * 1000000));
E4c.push(int(E4 * 1000000));
}
}
}
Then we’re graphing the data in another function called in draw() like this:
void PlotValues() {
// are we running and is the graphing mode selected?
if (running == true && graph == true) {
//setup legend
String[] legends = new String[]{"11\"", "Torsional", "27\""};
float[] leg1 = new float[]{0.07, 0.22, 0.42};
float[] leg2 = new float[]{0.92, 0.92, 0.92};
//Set up Arrays for each strain stream and initiate plot
GPointsArray points = new GPointsArray(nPoints);
GPointsArray points3 = new GPointsArray(nPoints);
GPointsArray points4 = new GPointsArray(nPoints);
GPlot plot = new GPlot(this);
//Set up plot properties
plot.setDim(450, 300);
plot.setPos(-512, 0);
plot.setXLim(0, nPoints);
plot.getXAxis().setNTicks(0);
plot.setYLim(-4000, 4000);
plot.getYAxis().setNTicks(9);
plot.getYAxis().setAxisLabelText("MicroStrain");
plot.setPointColor(color(0,200,0));
// If we are running... add the last nPoints to the graphing arrays
if (running == true && len >= nPoints) {
for (int i = 0; i < nPoints; i++) {
points.add(i, E1c.get(i));
points3.add(i, E3c.get(i));
points4.add(i, E4c.get(i));
}
//Set which points to plot and their colors
plot.setPoints(points);
plot.setLineColor(color(0, 10, 255));
plot.addLayer("E3", points3);
plot.getLayer("E3").setLineColor(color(255, 0, 10));
plot.addLayer("E4", points4);
plot.getLayer("E4").setLineColor(color(0, 255, 10));
//Draw the plot its self
plot.beginDraw();
//plot.drawBox();
plot.drawXAxis();
plot.drawYAxis();
plot.drawLines();
plot.drawGridLines(GPlot.HORIZONTAL);
plot.drawLegend(legends, leg1, leg2);
plot.endDraw();
}
}
}
Any tips on how I can reduce this memory hogging?
Thanks,
Twain