Page 1 of 1

Spatial 3/3/3 data in an array

Posted: Wed Dec 05, 2018 2:05 pm
by brunoramos96
Hi there,

Is it possible to save acceleration data from Spatial 3/3/3 in an array, in order to apply the FFT? How can I do that on android studio?

Thanks

Re: Spatial 3/3/3 data in an array

Posted: Fri Dec 07, 2018 9:57 am
by Patrick
Hi,

Dump acceleration data into a queue from the AccelerationChange event, and then operate on that queue as you like. I have done this in C#, not sure what FFT libraries are available on Android, but it should be fairly straightforward.

-Patrick

Re: Spatial 3/3/3 data in an array

Posted: Thu Jan 31, 2019 5:40 pm
by brunoramos96
Patrick wrote:Hi,

Dump acceleration data into a queue from the AccelerationChange event, and then operate on that queue as you like. I have done this in C#, not sure what FFT libraries are available on Android, but it should be fairly straightforward.

-Patrick
Can you explain how to do that? I think that I might misunderstand that.
Anyway, I allready solved the fft problem. There are librarys, but they quite dificult to implement. I ended wrighting the code myself.

Thanks

Re: Spatial 3/3/3 data in an array

Posted: Mon Feb 04, 2019 12:19 pm
by jdecoux
You will need to create an array (and an index variable) in the class containing the event handler, but not within the event handler itself. Then you can put the data from your Acceleration Change event into the array every time it happens.

In Android Java, this could look something like:

Code: Select all

public class AccelerometerExample extends Activity {

	//... Initialization code, etc.

	double[][]  accelerationArray = new double[10][3];
	double[] timestampArray = new double[10];
	int accelerationIndex = 0;

	class AccelerometerAccelerationChangeEventHandler implements Runnable {
		Phidget ch;
		AccelerometerAccelerationChangeEvent accelerationChangeEvent;

		public AccelerometerAccelerationChangeEventHandler(Phidget ch,
		  AccelerometerAccelerationChangeEvent accelerationChangeEvent) {
			this.ch = ch;
			this.accelerationChangeEvent = accelerationChangeEvent;
		}

		public void run() {
			//Adds data to an array
			accelerationArray[accelerationIndex][0] =
				accelerationChangeEvent.getAcceleration()[0];
			accelerationArray[accelerationIndex][1] =
				accelerationChangeEvent.getAcceleration()[1];
			accelerationArray[accelerationIndex][2] =
				accelerationChangeEvent.getAcceleration()[2];
			timestampArray[accelerationIndex] =
				accelerationChangeEvent.getTimestamp();

			accelerationIndex = (accelerationIndex + 1) % 10;

		}
	}

}

Re: Spatial 3/3/3 data in an array

Posted: Wed Feb 06, 2019 4:21 pm
by brunoramos96
Thank you so much for the help. It was very usefull for my problem.

So it means that the void "run" it's like a endless loop that works since the sensor is connected. Is it possible to infer a pause to that loop? For example, when I get 100 values in the array the loop pauses and the user analyse the values collected.

Thank you so much again for the help.

Re: Spatial 3/3/3 data in an array

Posted: Thu Feb 07, 2019 10:39 am
by jdecoux
In this case, "run" is the function that runs one every time the Acceleration Change event happens. Like a function you assign to run every time you press a button on the screen.

It's not really a loop, it happens outside the regular program flow, in another thread. You can't really "pause" the events, they run every time new data comes in from the sensor (e.g. every DataInterval), to ensure your program is always using the most recent data within the event code.

The exception to this is if your event code runs too long, then later events will be queued to happen in order once it completes. We strongly recommend against having your events run longer than your DataInterval time, as this can result in your program reacting to increasingly older data if the problem persists.

You can certainly make something to periodically analyse data in the array, for example using a timer, or within the event code itself (if time constraints permit). If your program needs more time to do the analysis, consider making multiple buffers, so your program can work on one while the other gets filled.