Best way for sensor Listening

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

Best way for sensor Listening

Postby cosmoken » Thu Aug 07, 2014 3:23 pm

Hi,

Is there a good way to be notified on a value from a sensor when it changes ? (some kind of listener)

Or the only way is to create it with a loop in a thread ?

Thanks,
Ken
cosmoken
New User
 
Posts: 2
Joined: Thu Aug 07, 2014 3:15 pm

Re: Best way for sensor Listening

Postby fuzzycow » Thu Aug 07, 2014 4:38 pm

You may not want to react to each and every sensor value change for many of the sensor types. This will not work for IMU, distance,etc sensors.

The best results I have got so far were running threads (reading from SampleProviders and implementing SampleProvider interface) via scheduled thread pool executor (using single or two threads).
This allows you to filter (e.g.: mean) results polled at high frequency, while actual polling from your main thread is decoupled and can occur on less frequent basis.

NOTE: this is just my own testing, and may be completely of the mark
fuzzycow
Novice
 
Posts: 28
Joined: Sun Sep 08, 2013 4:33 pm

Re: Best way for sensor Listening

Postby cosmoken » Fri Aug 08, 2014 7:42 am

Thanks, this is what I wanted to do, but I needed to be sure
cosmoken
New User
 
Posts: 2
Joined: Thu Aug 07, 2014 3:15 pm

Re: Best way for sensor Listening

Postby Aswin » Sat Aug 16, 2014 5:15 pm

fuzzycow wrote:
The best results I have got so far were running threads (reading from SampleProviders and implementing SampleProvider interface) via scheduled thread pool executor (using single or two threads).
This allows you to filter (e.g.: mean) results polled at high frequency, while actual polling from your main thread is decoupled and can occur on less frequent basis.


You can build this with two of the filters provided, the MeanFilter and the SampleThread filter. You stack the MeanFilter on the sensor and the SampleThread filter on top of that. You can then query the SampleThread filter at large or irregular intervals from the main program.
Code: Select all
SampleProvider mean = new MeanFilter(aSampleProvider, 10);
SampleProvider recentSample = new SampleThread(mean, 10);
// you can now fetch a recent sample mean from recentSample
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 206
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands


Return to EV3 Software

Who is online

Users browsing this forum: esmetaman and 2 guests

more stuff