Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Compass event.magneticHeading — Gideros Forum

Compass event.magneticHeading

olegoleg Member
edited November 2019 in General questions
How do i determine the direction of rotation of the compass? strilka:setRotation(-mn) or strilka:setRotation(+mn)
It seems to me that the direction is chosen at random when the program starts..
local background = Bitmap.new(Texture.new("compass-background.png"))
 strilka = Bitmap.new(Texture.new("compass-pointer.png", true))
strilka:setAnchorPoint(0.5, 0.5)
 
stage:addChild(background)
stage:addChild(strilka)
 
background:setPosition(10, 40)
strilka:setPosition(160, 210)
 
geolocation = Geolocation.new()
local filter =0.03
magnetic=0
local function onHeadingUpdate(event)
	 magnetic=event.magneticHeading
 
	mn=magnetic*filter+mn * (1-filter)
-- An error occurs here  !!!!!!!!!!!!!!
--Each time you restart, the direction of the scale changes randomly (by time - versus time)
 
	strilka:setRotation(-mn)
	--strilka:setRotation(mn)
end
geolocation:addEventListener(Event.HEADING_UPDATE, onHeadingUpdate)
geolocation:start()
my games:
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!

Comments

  • on android, sometimes the compass needs to be calibrated.
    To calibrate the compass we turn the phone to form a 8 shape.
    I don't know if it's related to your question. :|
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLux said:

    on android, sometimes the compass needs to be calibrated.
    To calibrate the compass we turn the phone to form a 8 shape.
    I don't know if it's related to your question. :|

    Must be rotated to correctly determine the azimuth.
    I have another problem - the compass is confusing west and east

    Think this is a error in gideros
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • hgy29hgy29 Maintainer
    oleg said:


    I have another problem - the compass is confusing west and east

    Think this is a error in gideros

    It gives expected results in my apps (gps navigation)
  • hgy29 said:

    oleg said:


    I have another problem - the compass is confusing west and east

    Think this is a error in gideros

    It gives expected results in my apps (gps navigation)
    I don't use GPS
    I only use a magnetic sensor

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • olegoleg Member
    edited November 2019
    I found the code, is it possible in gideros to get sensor data x, y, z?

    float x = event.values[0];
    float y = event.values[1];
    float z = event.values[2];

    I want to use another formula instead:
    double magneticHeading = (Math.atan2(x, -y) + Math.PI) * (180 / Math.PI);
    public void startUpdatingHeading()
    	{
    		WeakActivityHolder.get().runOnUiThread(new Runnable()
    		{
    			<a href="https://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    			public void run()
    			{
    				if (magneticSensor == null)
    					return;
     
    				if (magneticListener_ != null)
    					return;
     
    				magneticListener_ = new SensorEventListener() {
    					<a href="https://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    					public void onAccuracyChanged(Sensor sensor, int accuracy) { }
     
    					<a href="https://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    					public void onSensorChanged(SensorEvent event)
    					{
    				        float x = event.values[0];
    				        float y = event.values[1];
    				        float z = event.values[2];
     
    				        double magneticHeading = (Math.atan2(x, -y) + Math.PI) * (180 / Math.PI);
     
    						onHeadingChanged(magneticHeading, magneticHeading);
    					}			
    				};
     
    				sensorManager.registerListener(magneticListener_, magneticSensor, SensorManager.SENSOR_DELAY_NORMAL);
    			}
    		});		
    	}
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • hgy29hgy29 Maintainer
    oleg said:

    hgy29 said:


    It gives expected results in my apps (gps navigation)

    I don't use GPS
    I only use a magnetic sensor
    I use both, and magnetic sensor reporting is correct, I use it to rotate the on screen map when the user turns. If you change the formula, my apps won’t work anymore.
  • hgy29 said:

    oleg said:

    hgy29 said:


    It gives expected results in my apps (gps navigation)

    I don't use GPS
    I only use a magnetic sensor
    I use both, and magnetic sensor reporting is correct, I use it to rotate the on screen map when the user turns. If you change the formula, my apps won’t work anymore.
    You do not need to change the formula, you need to add the event x, y, z
    And with additional data I can directly process the sensor data
    Now a number sign is confused on one axis.And in the accelerometer, too, along one axis, the number sign is tangled,

    Don't change anything in Gsderos but just add to event event.magneticHeading events on axes event.X, event.Y event.Z
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • hgy29hgy29 Maintainer
    Accepted Answer
    oleg said:


    Don't change anything in Gsderos but just add to event event.magneticHeading events on axes event.X, event.Y event.Z

    Good idea, might be useful for other things too.

    Likes: oleg

    +1 -1 (+1 / -0 )Share on Facebook
  • One thing about the compass... EVERY one I download has no f**king ability to tell if it is in the southern hemisphere... hence they all point the wrong way!!! Even the Gideros example does this heheh :D

    Likes: oleg

    +1 -1 (+1 / -0 )Share on Facebook
  • antix said:

    One thing about the compass... EVERY one I download has no f**king ability to tell if it is in the southern hemisphere... hence they all point the wrong way!!! Even the Gideros example does this heheh :D

    Thanks, i will consider this when i make my compass

    Likes: antix

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.