Spatial 3/3/3 data in an array

Supporting 4.1 and up
Post Reply
brunoramos96
Phidgetsian
Posts: 10
Joined: Wed Sep 26, 2018 2:14 pm
Contact:

Spatial 3/3/3 data in an array

Post 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
User avatar
Patrick
Lead Developer
Posts: 3399
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

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

Post 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
brunoramos96
Phidgetsian
Posts: 10
Joined: Wed Sep 26, 2018 2:14 pm
Contact:

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

Post 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
jdecoux
Labview Developer
Posts: 161
Joined: Mon Nov 13, 2017 10:20 am
Contact:

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

Post 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;

		}
	}

}
brunoramos96
Phidgetsian
Posts: 10
Joined: Wed Sep 26, 2018 2:14 pm
Contact:

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

Post 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.
jdecoux
Labview Developer
Posts: 161
Joined: Mon Nov 13, 2017 10:20 am
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests