My favorites | Sign in
Project Logo
                
Search
for
Updated Oct 09, 2008 by peli0101
SensorSimulator  
Sensor Simulator for simulating sensor data in real time.

Sensor Simulator

(scroll down for detailed description)

We have the SensorSimulator to drive your Android application in real time.

About the SensorSimulator

The OpenIntents SensorSimulator lets you simulate sensor data with the mouse in real time. It currently supports accelerometer, compass, orientation, and temperature sensors, where the behavior can be customized through various settings. TRY IT OUT NOW

Connecting the SensorSimulator with the Android emulator

  • Download the latest openintents-binary-x.x.x.zip.
  • Start tools/SensorSimulator.jar (Java standalone application).
  • Install the latest OpenIntents.apk and samples/OpenGLSensors.apk on your Android emulator.
  • Launch OpenIntents on the emulator / select SensorSimulator.
  • Enter IP address and socket (port) number into the emulator as shown by the SensorSimulator (see below).

  • Press "Connect" on the emulator.
    • Note: The first time you connect to the SensorSimulator, all sensors are DISABLED automatically. This is, because it is the Android application's responsibility to enable the sensors before reading values.
  • Press "Enable sensors".
    • Now you should see the sensor data (see below). With a small delay, they are in sync with the SensorSimulator numbers.
    • Try moving the SensorSimulator phone around with the mouse: The numbers will change in the SensorSimulator and on the Android phone.
    • Note: Only these numbers are transfered between the SensorSimulator and the Android phone. These numbers are the same that you would read out in your application.

Additional settings

Scroll down the settings pane to access the following settings:

How to use the SensorSimulator in your application

  • If you don't have it already, install the latest version of OpenIntents.apk on your mobile phone.
  • Add the external JAR openintents-lib-n.n.n.jar into your project.
  • Replace the following code in onCreate():
  • mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
  • by this code
  • // Before calling any of the Simulator data, 
    // the Content resolver has to be set !! 
    Hardware.mContentResolver = getContentResolver(); 
     
    // Link sensor manager to OpenIntents Sensor simulator 
    mSensorManager = (SensorManager) new SensorManagerSimulator((SensorManager) 
                                  getSystemService(SENSOR_SERVICE)); 
  • By default this still passes the original sensor values, so to activate sensors you have to first call (to set the sensor settings):
  • Intent intent = new Intent(Intent.ACTION_VIEW, 
    Hardware.Preferences.CONTENT_URI); 
    startActivity(intent);
  • and then
  • // first disable the current sensor 
    mSensorManager.unregisterListener(mGraphView); 
     
    // now connect to simulator 
    SensorManagerSimulator.connectSimulator(); 
     
    // now enable the new sensors 
    mSensorManager.registerListener(this, 
               SensorManager.SENSOR_ACCELEROMETER | 
               SensorManager.SENSOR_MAGNETIC_FIELD | 
               SensorManager.SENSOR_ORIENTATION, 
               SensorManager.SENSOR_DELAY_FASTEST); 
  • All other code stays untouched. You can find reference code for how to implement sensors in the API demos / OS / Sensors.java.
  • Usually one would (un)register the sensors in onResume() and onStop():
  •     @Override
        protected void onResume() {
            super.onResume();
            mSensorManager.registerListener(this, 
                    SensorManager.SENSOR_ACCELEROMETER | 
                    SensorManager.SENSOR_MAGNETIC_FIELD | 
                    SensorManager.SENSOR_ORIENTATION,
                    SensorManager.SENSOR_DELAY_FASTEST);
        }
        
        @Override
        protected void onStop() {
            mSensorManager.unregisterListener(mGraphView);
            super.onStop();
        }
  • Then just implement the standard Android SensorListener (there is no OI counterpart necessary).
  • class MySensorActivity extends Activity implements SensorListener {
        public void onSensorChanged(int sensor, float[] values) {
            // do something with the sensor values.
        }
    }
  • Note 1: The OpenIntents class SensorManagerSimulator is derived from the Android class SensorManager and implements exactly the same functions (see Android SensorManager). For the callback, the standard Android SensorListener is used. The only new functions are connectSimulator() and disconnectSimulator().
  • Note 2: Whenever you are not connected to the simulator, you will get real device sensor data: the org.openintents.hardware.SensorManagerSimulator class transparently calls the SensorManager returned by the system service in this case.

Sensor data definition

The coordinate system with XYZ directions is defined as described in the Android SensorManager reference

Accelerometer

The accelerometer values are defined in the accelerometer reference

"Sensor values are acceleration in the X, Y and Z axis, where the X axis has positive direction toward the right side of the device, the Y axis has positive direction toward the top of the device and the Z axis has positive direction toward the front of the device. The direction of the force of gravity is indicated by acceleration values in the X, Y and Z axes. The typical case where the device is flat relative to the surface of the Earth appears as -STANDARD_GRAVITY in the Z axis and X and Z values close to zero. Acceleration values are given in SI units (m/s^2)."

Magnetic field (compass)

The magnetic field sensor values are defined in the magnetic field sensor reference

"Sensor values are the magnetic vector in the X, Y and Z axis, where the X axis has positive direction toward the right side of the device, the Y axis has positive direction toward the top of the device and the Z axis has positive direction toward the front of the device. Magnetic values are given in micro-Tesla (uT)".

  • NOTE: You can obtain the magnetic field values for your current location from the National Geophysical Data Center in nano Tesla (1000 nano Tesla = 1 micro Tesla).

Orientation

The magnetic field sensor values are defined in the orientation sensor reference

"Sensor values are yaw, pitch and roll Yaw is the compass heading in degrees, range [0, 360[ 0 = North, 90 = East, 180 = South, 270 = West Pitch indicates the tilt of the top of the device, with range -90 to 90. Positive values indicate that the bottom of the device is tilted up and negative values indicate the top of the device is tilted up. Roll indicates the side to side tilt of the device, with range -180 to 180. Positive values indicate that the left side of the device is tilted up and negative values indicate the right side of the device is tilted up."


Comment by kdavis95139, Feb 25, 2008

First, this is an excellent simulator. My only comment (and admittedly it is a weak complaint) is that it assumes that the accelerometer is dead center in the device (variations of Yaw have no affect on the accelerometer where pitch and roll remain constant). Of course, it may (albeit I would think somewhat unlikely) be that the device manufacturer will place the sensor dead center in the device. However, I would think it would be more useful to simulate it as if the sensor were placed in the front of the device. This way we could simulate a swinging motion common in alot of games. However, I realize this might be far more difficult to simulate:)

Thanks again for the sensor simulator. Great Job!

Comment by seeingwithsound, Sep 10, 2008

Excellent indeed. Proved very useful to check if my talking compass code worked as intended in the Android SDK 0.9 beta emulator. Thanks Peli!

Comment by Guardianangel071, Dec 08, 2008

I cannot get past the Connection Intent for the Emulator. Once finished and connected, I try to go back to my main activity, but it always takes me back to the Menu, can anyone help?

Comment by william.caineiii, Jan 12, 2009

I am having the same problem. I added the following code and now instead of going to my app, it takes me to the Sesnsor Simlulator configuration screen. when I hit back, it takes me back to the menu. can anyone help?

Comment by william.caineiii, Jan 12, 2009

nm, i looked at the source code and figured it out. you may want to note that Intent intent = new Intent(Intent.ACTION_VIEW, Hardware.Preferences.CONTENT_URI); startActivity(intent);

# and then

// first disable the current sensor mSensorManager.unregisterListener(mGraphView); // now connect to simulator SensorManagerSimulator?.connectSimulator(); // now enable the new sensors mSensorManager.registerListener(this,

SensorManager?.SENSOR_ACCELEROMETER | SensorManager?.SENSOR_MAGNETIC_FIELD | SensorManager?.SENSOR_ORIENTATION, SensorManager?.SENSOR_DELAY_FASTEST);

gets called not on create but when a button gets clicked.

Comment by i...@webworkz.nl, Jan 13, 2009

As some users described above i have the same problem when starting my own app. It just takes me back to the simulator screen. It happens at connectSimulator() Anybody know what im doing wrong or what causes this?

regards, Martijn

Comment by avi153, Jan 19, 2009

The problem can be that you are putting in the wrong IP address in the emulator. turn on sensorsimulator.jar & take your IP address from there. It might work. But I`m facing a different problem. When I click on connect, after a couple of minutes it gives an error message "activity sensor simulator (in application open intents ) not responding", anyone knows how to overcome this problem??

Cheers, Avinash Parnandi

Comment by dataforger, Jan 20, 2009

I solved it by not starting the intent in my application. Just connect to the simulator using the OpenIntent? application via the Testing tab. Click the Connect button and data from the simulator should be coming in. Then close the application and start your own application.

Comment by martijnschouwe, Jan 22, 2009

My problem is solved and my app is working with the sensor simulator now and works great. The problem is that i didnt had the permission INTERNET in the configuration XML. The rest of the example given above works but just loose the Intent.

Comment by swapna.cse51, Jan 28, 2009

we are doing a project on all the sensors in android operating system.so we need some help from you about designing(usecase diagrams,sequence diagram..........) and the documentation of it.

Comment by patrickneese, Feb 03, 2009

If your program is closing without an error try placing

<uses-permission android:name="android.permission.INTERNET"/>

in your AndroidManifest?.xml directly after the <manifest> tag

:)

I was the preference/config screen then when I hit the back button it would close without a warning. When I finish a little app I will post.

Comment by craig.de...@motorola.com, Feb 06, 2009
/
  • Initialization of the Activity after it is first created. Must at least
  • call {@link android.app.Activity#setContentView setContentView()} to
  • describe what is to be displayed in the screen.
@Override
protected void onCreate(Bundle savedInstanceState) {
// Be sure to call the super class. super.onCreate(savedInstanceState);
// commented out to enable SensorSimulator class
//mSensorManager = (SensorManager?) getSystemService(SENSOR_SERVICE);

mGraphView = new GraphView?(this); setContentView(mGraphView);
// start of INSERTION FOR SensorSimulator
// Before calling any of the Simulator data, // the Content resolver has to be set !! Hardware.mContentResolver = getContentResolver();
// Link sensor manager to OpenIntents Sensor simulator mSensorManager = (SensorManager?) new SensorManagerSimulator?((SensorManager?)
getSystemService(SENSOR_SERVICE));
Intent intent = new Intent(Intent.ACTION_VIEW,
Hardware.Preferences.CONTENT_URI); startActivity(intent);
// first disable the current sensor mSensorManager.unregisterListener(mGraphView);
// now connect to simulator SensorManagerSimulator?.connectSimulator();
// now enable the new sensors mSensorManager.registerListener(this,
SensorManager?.SENSOR_ACCELEROMETER | SensorManager?.SENSOR_MAGNETIC_FIELD | SensorManager?.SENSOR_ORIENTATION, SensorManager?.SENSOR_DELAY_FASTEST);
// end of INSERTION FOR SensorSimulator
}

@Override
protected void onResume() {
super.onResume();

// below commented out for SensorSimulator

//mSensorManager.registerListener(mGraphView,

// start of INSERTION FOR SensorSimulator

SensorManagerSimulator?.connectSimulator();
mSensorManager.registerListener(this,

// end of INSERTION FOR SensorSimulator
SensorManager?.SENSOR_ACCELEROMETER | SensorManager?.SENSOR_MAGNETIC_FIELD | SensorManager?.SENSOR_ORIENTATION, SensorManager?.SENSOR_DELAY_FASTEST);
}
@Override

protected void onStop() {
// below commented out for SensorSimulator
//mSensorManager.unregisterListener(mGraphView);

// start of INSERTION FOR SensorSimulator

mSensorManager.unregisterListener(this);
// end of INSERTION FOR SensorSimulator

super.onStop();
}

Comment by vimarsh.puneet, Feb 09, 2009

I tried running the java application. I get the following error

Exception in thread "AWT-EventQueue?-0" java.lang.ClassCastException?: org.openintents.tools.sensorsimulator.MobilePanel?$2

at java.awt.AWTEventMulticaster.add(AWTEventMulticaster.java:528) at java.awt.Component.addMouseMotionListener(Component.java:4896) at org.openintents.tools.sensorsimulator.MobilePanel?.<init>(MobilePanel?.java:369) at org.openintents.tools.sensorsimulator.SensorSimulator.<init>(SensorSimulator.java:267) at org.openintents.tools.sensorsimulator.SensorSimulator.createAndShowGUI(SensorSimulator.java:1842) at org.openintents.tools.sensorsimulator.SensorSimulator.access$000(SensorSimulator.java:79) at org.openintents.tools.sensorsimulator.SensorSimulator$1.run(SensorSimulator.java:1887) at java.awt.event.InvocationEvent?.dispatch(InvocationEvent?.java:209) at java.awt.EventQueue?.dispatchEvent(EventQueue?.java:461) at java.awt.EventDispatchThread?.pumpOneEventForHierarchy(EventDispatchThread?.java:269) at java.awt.EventDispatchThread?.pumpEventsForHierarchy(EventDispatchThread?.java:190) at java.awt.EventDispatchThread?.pumpEvents(EventDispatchThread?.java:184) at java.awt.EventDispatchThread?.pumpEvents(EventDispatchThread?.java:176) at java.awt.EventDispatchThread?.run(EventDispatchThread?.java:110)

Comment by kimle123, Feb 10, 2009

Check your java version. Make sure it's 1.6

Comment by stalam, Feb 13, 2009

I am not getting a possible IP address from the Java app

Comment by vannaroja, Feb 17, 2009

hi, i have the same problem, it is going to directly my ip address again i click the back menu, it is going to main menu, can anyone help?

Comment by zenon.hakier, Feb 27, 2009

Hi,

I can add myself to the group of the people who are having the problem with the senson application showing up and then returning to main menu.

I noticed also the following things:

- when I enter the IP and click on connect in Emulator, the Simulator on my computer can change the values of sensors; - when I hit "back" on Emulator, the Simulator shows that all sensors are disconnected.

So from my point of view hitting "back" on Emulator closes the application wheres I would guess what is needed is keeping the application alive and only switching back to my application. How can this be done? Can I somehow do it programmatically in my code?
Can anyone from the ones who got this thing to work publish the code of their application? I guess the devil sits in the details here too and I must be missing something important :-(

Best regards

huckey

Comment by ilovesinai, Mar 04, 2009

oh man yes... because i also look for two days how to solve.. i will AGAIN tell the solution of many probs here

add this in the androidmanifest.xml

<uses-permission android:name="android.permission.INTERNET"/>

Comment by swapna.cse51, Mar 05, 2009

we are doing a project work on sensors in android operating system.so i have a problem with my Accelerometer that is ,it is not displaying the speed just it is displaying the values in the co-ordinate position.By using the Cordinate values we have to calculate the speed. so,it is making a disadvantage in my project, so suggest me to overcome this problem.

Comment by sahilz750, Apr 27, 2009

Hi,

I tried to port the openintents.apk on the Texas Instrument "Zoom" board. The board was uploaded with Kernel 2.6.27.10 & Android file system version 1.5.

Due to some reasons the openintents apk is not appearing on the device. However, the same apk is working fine on the emulator (with SDK 1.1 r1). Using ls command (to view the apks installed on the device) on PC connected to device, I do see the openintents apk, yet, its not visible on Zoom.

CAn you please help me with this??

Thanks.

Best Regards, Zhubham.

Comment by antiraum, May 17, 2009

Hi,

I cannot access the Sensor Simulator settings in the Open Intents app on the emulator. When I select it, I get only a black screen. This is the logcat output:

I/ActivityManager?( 567): Starting activity: Intent { action=android.intent.action.MAIN comp={org.openintents/org.openintents.hardware.SensorSimulatorSettingsActivity?} } D/qemud ( 546): fdhandler_accept_event: accepting on fd 10 D/qemud ( 546): created client 0xc088 listening on fd 14 D/qemud ( 546): client_fd_receive: attempting registration for service 'sensors' D/qemud ( 546): client_fd_receive: -> received channel id 7 D/qemud ( 546): multiplexer_handle_control: unknown control message (26 bytes): 'ko:connect:07:service busy' W/ActivityManager?( 567): Launch timeout has expired, giving up wake lock! W/ActivityManager?( 567): Activity idle timeout for HistoryRecord?{436b1840 {org.openintents/org.openintents.hardware.SensorSimulatorSettingsActivity?}}

The versions I use: Android emulator version 1.9 (build_id CUPCAKE-147336) AVD Target: Google APIs (Google Inc.) Based on Android 1.5 (API level 3) OpenIntents 0.9.0

Any help would be greatly appreciated.

Thomas

Comment by antiraum, May 17, 2009

When I use Android 1.1 (API level 2) as the target of my avd it works.

Comment by sahilz750, May 29, 2009

I get the following error on SDK 1.5 emulator (and OMAP 3430 as well). Can anyone tell how to come out of this??

D:\android-sdk-windows-1.5_r1\tools>adb install D:\openintents-binary-01?.9.0\openintents-binary-0.9.0\OpenIntents.apk 549 KB/s (1196340 bytes in 2.124s) DDM dispatch reg wait timeout Can't dispatch DDM chunk 52454151: no handler defined Can't dispatch DDM chunk 48454c4f: no handler defined

pkg: /data/local/tmp/OpenIntents.apk
Failure INSTALL_FAILED_MISSING_SHARED_LIBRARY?

D:\android-sdk-windows-1.5_r1\tools>

Comment by ronansandford, Jun 03, 2009

I get teh same error on the emulator: adb install OpenIntents.apk 295 KB/s (1196340 bytes in 3.954s)

pkg: /data/local/tmp/OpenIntents.apk
Failure INSTALL_FAILED_MISSING_SHARED_LIBRARY?

I use the SDK 1.5 r1 as well

Are there any solution?

Comment by olibirdie, Jun 05, 2009

If you're getting the MISSING_SHARED_LIBRARY problems, you need to use the 'Google APIs' target for your avd - this includes the Location libraries that are no longer built into the default.

Comment by Paco.Benitez.Chico, Jun 07, 2009

What is the problem when I run SensorSimulator into my Android simulator? When I pulse on OpenIntents --> Settings --> Sensor Simulator, It doesn't work and screen changes a black color (as like as the application doesn't run well).

And the screen of your example (IP & port configuration), I haven't found.

Thanks a lot.

Comment by Paco.Benitez.Chico, Jun 09, 2009

Hi again,

I forgot the next:

I'm using GoogleMaps? + Android Simulator 1.5.

Thanks!

Comment by epmanko, Jun 10, 2009

Wonderful work!

Comment by HastCiberneo, Jun 11, 2009

Please someone can update this document with this two instructions:

First, the Target MUST be the Google APIs (Using 1.5 standard will cause instalation of OpenIntents.apk to fail).

Second, add this in the androidmanifest.xml

<uses-permission android:name="android.permission.INTERNET"/>

To add use tag "Permissions" -> Add -> android.permission.INTERNET o just copy paste it before closing the manifest tag:

<manifest> .... <uses-permission android:name="android.permission.INTERNET"></uses-permission> </manifest>

Cheers.

Comment by finlaysoni, Jun 15, 2009

I'm having the same problem as Paco. Where can I enter the IP and port???

Comment by sahilz750, Jun 15, 2009

When I pulse on OpenIntents --> Settings --> Sensor Simulator, the screen changes to black color and the emulator freezes.

(i) Can anyone please let me know the remedy of this??

(ii) Has it got something to do with the fact that Sensor and Compass APIDemo are failing on SDK 1.5 r1 emulator : refer http://groups.google.com/group/android-developers/browse_thread/thread/9f6c794b17eea701#

Thanks in advance.

Comment by slim.benhammouda, Jun 19, 2009

Hi all, I have the same problem as sahilz750, Paco and finlaysoni, Is there any solution for that problem. For those that SensorSimulator works, which version of sdk and openintents do you use

I use Android SDK 1.5r2 with google apis and openintents 0.9.0 thank you for your Help

Comment by dmeenagh, Jun 26, 2009

Hi guys, I'm using the latest version of the sensor somulator, and Android SDK 1.5r2. When I try to put in the IP address all I get is a blank screen. What can I do to fix this? Do I need a different version of teh SDK?

Comment by cupid953312, Jun 29, 2009

Hi all, I have executed on Android SDK 1.1. If you use Android SDK 1.5, Use Emulator on AVD for Android SDK 1.1 refer : http://developer.android.com/guide/developing/tools/avd.html

Comment by lischke, Jun 30, 2009

Works like charm, thanks for that great piece of software!will mention OpenIntents in my Software.

Comment by preetam.palwe, Sep 10, 2009

I have successfully used it for the android sample Compass.java ! But now I am using it with "SensorEventListener?" and i guess its not supported in "SensorManagerSimulator?"!

Comment by pramodforum, Sep 13, 2009

Will this simulator work with Android 1.5 (Cupcake) release. If not where can get some gaming application to test my accelerometer on cupcake.

Comment by chinabryan, Sep 16, 2009

Could you tell me how to save the data that I collected into a file? Thanks. ---- A new Androider

Comment by renijoym, Sep 20, 2009

while i'm installing OpenIntent?.apk..its not getting loaded into emulator.. error message is shown in command prompt pkg: /data/local/tmp/OpenIntents.apk Failure INSTALL_FAILED_MANIFEST_MALFORMED D:\android-sdk-windows-1.5_r3\tool plz help.... thanks in advance

Comment by dan...@tele2.it, Sep 26, 2009

First of all, thank you for this simulator! But I have to ask you a question. I've upgraded my Android SDK to 1.6 version, and I've realized that the Sensor constant changed if I use the new Interface SensorEventListener? ('cause the old one says it's deprecated!). So, anyone knows if I could use the sensorsimulator with the new Interface or I have to use the deprecated one?? Thank you guys!!

Comment by Nicholaus.Shupe, Oct 31, 2009

I'd like to second the request to update the sensor simulator to new Android SDK 1.6/2.0 APIs. Thanks!

Comment by jkidsimon, Nov 11, 2009

if I want to use my HTC magic to control the SensorSimulator on computer,can i?

Comment by huttarl, Nov 25, 2009

+1 for updating the sensor simulator to the new Android platform and SensorEventListener?. (I just updated some other code for this change, so maybe I could do the same for SensorSimulator and submit a patch.)

Question: The instructions above say "download the latest openintents-binary-x.x.x.zip". I don't see any such thing on the openintents download list. Does sensorsimulator-1.0.0-beta1.zip replace that file?

Thanks, Lars

Comment by huttarl, Nov 25, 2009

P.S. Thanks HastCibernio? for the tip about requiring the Google APIs as a target!

Comment by adammachowy, Dec 07, 2009

As Nicholaus said it would be great to have version for 1.6/2.0/2.1. Thanks

Comment by wilfried.lg, Dec 07, 2009

Is there any version to test applications with android 2.0 and SensorEventListener? ?


Sign in to add a comment
Hosted by Google Code