Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
making an android compass
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bob  
View profile  
 More options Sep 27 2012, 11:33 am
From: bob <b...@coolfone.comze.com>
Date: Thu, 27 Sep 2012 08:33:31 -0700 (PDT)
Local: Thurs, Sep 27 2012 11:33 am
Subject: making an android compass

So, I'm trying to learn how to make an android compass.

Naturally, I used a site called google and typed the following in:

"making an android compass"

I found myself at this URL:

http://android-er.blogspot.com/2010/08/simple-compass-sensormanager-a...

After looking thru it, I'm thinking it's incorrect.

There is this suspiciously simple method:

public void onSensorChanged(SensorEvent event) {
 // TODO Auto-generated method stub
 myCompassView.updateDirection((float)event.values[0]);

}

Basically, it seems like they are using the x component of the force vector
as if it were an angle.  Can someone else look at this and let me know what
you think?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Anderson  
View profile  
 More options Sep 27 2012, 2:01 pm
From: Justin Anderson <magouyaw...@gmail.com>
Date: Thu, 27 Sep 2012 11:58:06 -0600
Local: Thurs, Sep 27 2012 1:58 pm
Subject: Re: [android-developers] making an android compass

Why not post a comment on his blog and ask him about it?  That's what
others have done... and he seems to respond to comments/questions
consistently...

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lew  
View profile  
 More options Sep 27 2012, 2:27 pm
From: Lew <lewbl...@gmail.com>
Date: Thu, 27 Sep 2012 11:27:46 -0700 (PDT)
Local: Thurs, Sep 27 2012 2:27 pm
Subject: Re: making an android compass

bob wrote:
> So, I'm trying to learn how to make an android [sic] compass.

> Naturally, I used a site called google and typed the following in:

> "making an android compass"

> I found myself at this URL:

> http://android-er.blogspot.com/2010/08/simple-compass-sensormanager-a...

> After looking thru it, I'm thinking it's incorrect.

You are mistaken.

> There is this suspiciously simple method:

What does "suspiciously simple" even mean?

Why should simplicity engender suspicion?

It's obviously a cover method for one that is less "suspicious".

> public void onSensorChanged(SensorEvent event) {
>  // TODO Auto-generated method stub
>  myCompassView.updateDirection((float)event.values[0]);
> }

> Basically, it seems like they are using the x component of the force
> vector as if it were an angle.  Can someone else look at this and let me
> know what you think?

I think, no, wait, I am certain because I read the code to which you linked
that it uses the x component
to calculate the angle.

It's trigonometry. I know, it must seem like magic.

From the site to which you linked:

 canvas.drawLine(cxCompass, cyCompass,
   (float)(cxCompass + radiusCompass * Math.sin((double)(-direction) * 3.14/180)),
   (float)(cyCompass - radiusCompass * Math.cos((double)(-direction) * 3.14/180)),
   paint);

I think I might've used
http://developer.android.com/reference/java/lang/Math.html#PI
and predefined

private static final double CONVERT = Math.PI / 180.0;

but that's neither here nor there.

--
Lew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bob  
View profile  
 More options Sep 27 2012, 2:30 pm
From: bob <b...@coolfone.comze.com>
Date: Thu, 27 Sep 2012 11:30:57 -0700 (PDT)
Local: Thurs, Sep 27 2012 2:30 pm
Subject: Re: [android-developers] making an android compass

After wrestling with about 10+ CAPTCHA failures…

*Your comment has been saved and will be visible after blog owner approval.*


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lew  
View profile  
 More options Sep 27 2012, 2:32 pm
From: Lew <lewbl...@gmail.com>
Date: Thu, 27 Sep 2012 11:32:57 -0700 (PDT)
Local: Thurs, Sep 27 2012 2:32 pm
Subject: Re: making an android compass

I'm sorry, I made a mistake. I said, "uses the x component to calculate the
angle" and should have
said, "uses the angle to calculate the x component".

See
http://developer.android.com/guide/topics/sensors/sensors_position.html

--
Lew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bob  
View profile  
 More options Sep 27 2012, 2:44 pm
From: bob <b...@coolfone.comze.com>
Date: Thu, 27 Sep 2012 11:44:41 -0700 (PDT)
Local: Thurs, Sep 27 2012 2:44 pm
Subject: Re: making an android compass

Here is the *correct* (until proven otherwise) version of a compass for a
device lying flat on a table:

package com.magnet_test;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;

public class Magnet_Listener implements SensorEventListener {

private float[] magneticFieldValues;

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
magneticFieldValues = sensorEvent.values;
 float x = magneticFieldValues[0];
float y = magneticFieldValues[1];
 float angle = (float) Math.atan2(y, x);
 float angle_in_degrees = (float) Math.toDegrees(angle) + 180;
 System.out.println("angle = " + angle_in_degrees);

}
}

*Inspired by code from Reto Meier.*


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lew  
View profile  
 More options Sep 27 2012, 3:32 pm
From: Lew <lewbl...@gmail.com>
Date: Thu, 27 Sep 2012 12:32:39 -0700 (PDT)
Local: Thurs, Sep 27 2012 3:32 pm
Subject: Re: making an android compass

bob wrote:
> Here is the *correct* (until proven otherwise) version of a compass for a
> device lying flat on a table:

As long as you have the device lying flat, i.e., with no roll, then the
Meier version is fine, if computationally
expensive per the documentation.

> package com.magnet_test;

> Do you own the domain "magnet_test.com"?

You should (roughly) conform to the Java Coding Conventions.

import android.hardware.Sensor;

> import android.hardware.SensorEvent;
> import android.hardware.SensorEventListener;

> public class Magnet_Listener implements SensorEventListener {

The Java Coding Conventions call for underscores only in constant variable
names.
Otherwise, use camel case.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bob  
View profile  
 More options Sep 27 2012, 3:53 pm
From: bob <b...@coolfone.comze.com>
Date: Thu, 27 Sep 2012 12:53:54 -0700 (PDT)
Local: Thurs, Sep 27 2012 3:53 pm
Subject: Re: making an android compass

I see the issue.

He was using:

Sensor.TYPE_ORIENTATION

I was using:

Sensor.TYPE_MAGNETIC_FIELD

I guess TYPE_ORIENTATION returns angles whereas TYPE_MAGNETIC_FIELD returns
a vector.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lew  
View profile  
 More options Sep 27 2012, 5:56 pm
From: Lew <lewbl...@gmail.com>
Date: Thu, 27 Sep 2012 14:56:13 -0700 (PDT)
Local: Thurs, Sep 27 2012 5:56 pm
Subject: Re: making an android compass

bob wrote:
> I see the issue.

> He was using:

> Sensor.TYPE_ORIENTATION

> I was using:

> Sensor.TYPE_MAGNETIC_FIELD

> I guess TYPE_ORIENTATION returns angles whereas TYPE_MAGNETIC_FIELD
> returns a vector.

Why guess? I pointed you to the documentation which removes the guesswork.

RTFM

--
Lew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »