9

का उपयोग करके अभिविन्यास ढूंढना मैं चुंबकीय उत्तर के संबंध में कैमरे से बाहर निकलने वाले वेक्टर की दिशा प्राप्त करने का प्रयास कर रहा हूं। मैं इस धारणा के तहत हूं कि मुझे getOrientation() से लौटाए गए मानों का उपयोग करने की आवश्यकता है, लेकिन मुझे यकीन नहीं है कि वे क्या प्रतिनिधित्व करते हैं। जब मैं फोन के अभिविन्यास को बदलता हूं (90 डिग्री घूर्णन 90 डिग्री सेल्स नहीं बदलता) तो getOrientation() से प्राप्त मूल्यों को पूर्वानुमानित रूप से परिवर्तित नहीं किया जाता है। मुझे यह जानने की ज़रूरत है कि GetOrientation() का मतलब क्या है। क्या मैं अब तक नीचे लिखा है है:getRotationMatrix() और getOrientation()

package com.example.orientation; 

import android.app.Activity; 
import android.content.Context; 
import android.hardware.Sensor; 
import android.hardware.SensorEvent; 
import android.hardware.SensorEventListener; 
import android.hardware.SensorManager; 
import android.os.Bundle; 
import android.widget.Toast; 

public class Orientation extends Activity{ 

private SensorManager mSM; 
private mSensorEventListener mSEL; 

    float[] inR = new float[16]; 
    float[] outR= new float[16]; 
    float[] I = new float[16]; 
    float[] gravity = new float[3]; 
    float[] geomag = new float[3]; 
    float[] orientVals = new float[3]; 

    final float pi = (float) Math.PI; 
    final float rad2deg = 180/pi;  

/** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mSM = (SensorManager) getSystemService(Context.SENSOR_SERVICE); 
     mSEL = new mSensorEventListener(); 

     mSM.registerListener(mSEL, 
     mSM.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), 
     SensorManager.SENSOR_DELAY_NORMAL); 

    mSM.registerListener(mSEL, 
     mSM.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), 
     SensorManager.SENSOR_DELAY_NORMAL); 

} 



private class mSensorEventListener implements SensorEventListener{ 

    @Override 
    public void onAccuracyChanged(Sensor arg0, int arg1) {} 

    @Override 
    public void onSensorChanged(SensorEvent event) { 

    // If the sensor data is unreliable return 
    if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) 
    return; 

    // Gets the value of the sensor that has been changed 
    switch (event.sensor.getType()){ 
    case Sensor.TYPE_ACCELEROMETER: 
    gravity = event.values.clone(); 
    break; 
    case Sensor.TYPE_MAGNETIC_FIELD: 
    geomag = event.values.clone(); 
    break; 
    } 

    // If gravity and geomag have values then find rotation matrix 
    if (gravity != null && geomag != null){ 

    // checks that the rotation matrix is found 
    boolean success = SensorManager.getRotationMatrix(inR, I, gravity, geomag); 
    if (success){ 

    // Re-map coordinates so y-axis comes out of camera 
    SensorManager.remapCoordinateSystem(inR, SensorManager.AXIS_X, 
     SensorManager.AXIS_Z, outR); 

    // Finds the Azimuth and Pitch angles of the y-axis with 
    // magnetic north and the horizon respectively 
    SensorManager.getOrientation(outR, orientVals); 
    float azimuth = orientVals[0]*rad2deg; 
    float pitch = orientVals[1]*rad2deg; 
    float roll = orientVals[2]*rad2deg; 

    // Displays a pop up message with the azimuth and inclination angles 
    String endl = System.getProperty("line.separator"); 
    Toast.makeText(getBaseContext(), 
     "Rotation:" + 
     outR[0] + " " + outR[1] + " " + outR[2] + endl + 
     outR[4] + " " + outR[5] + " " + outR[6] + endl + 
     outR[8] + " " + outR[9] + " " + outR[10] + endl +endl + 
     "Azimuth: " + azimuth + " degrees" + endl + 
     "Pitch: " + pitch + " degrees" + endl + 
     "Roll: " + roll + " degrees", 
     Toast.LENGTH_LONG).show(); 
    } /*else 
    Toast.makeText(getBaseContext(), 
     "Get Rotation Matrix Failed", Toast.LENGTH_LONG).show();*/ 
    } 
    } 

    } 

} 

मैं sensorManager वर्ग पर दस्तावेज़ीकरण को देखा है, लेकिन यह इस का समाधान नहीं मदद की है। अगर कोई मुझे इससे बाहर निकलने में मदद कर सकता है तो मैं वास्तव में इसकी सराहना करता हूं। मैं एक एंड्रॉइड वन पर परीक्षण कर रहा हूं एंड्रॉइड 2.1

उत्तर

4

क्योंकि मैं एंड्रॉइड के लिए नया था, मैं स्क्रीन पर जानकारी प्रदर्शित करने के लिए टोस्ट का उपयोग कर रहा था। मैंने इसे एक दृश्य पर पाठ को अपडेट करने के लिए बदल दिया और यह ठीक करने लग रहा था। मैंने यह भी पता लगाया कि जो मैंने वास्तव में उन्मुख वैल्यू माना था वह सही था। मुझे रोल की आवश्यकता के लिए उपयोग नहीं किया जाता है। यह भी नहीं पता था कि रेड से डीजी में परिवर्तित करने का एक तरीका था इसलिए मैंने इसका इस्तेमाल किया।

1

मुझे लगता है कि आपको अभिविन्यास प्राप्त करने के बजाय दिशा प्राप्त करने के लिए getInclination का उपयोग करना होगा। getRotationMatrix दोनों गुरुत्वाकर्षण और भू-चुंबकीय feild के आधार पर गणना कर रहा है और आप चुंबकीय क्षेत्र से सीधे इनलाइन प्राप्त करेंगे।

3

आप logger application देख सकते हैं जो स्क्रीन पर कच्चे मूल्य प्रदर्शित करता है। इसके विवरण में आपको स्रोत कोड का एक लिंक मिलेगा ताकि आप सीख सकें कि यह सेंसर तक कैसे पहुंचता है।

HTH, डेनियल

3

आप अपने डिवाइस (लैंडस्केप/पोर्ट्रेट) के उन्मुखीकरण हो और कुछ मुआवजा बनाने की जरूरत है।

SensorManager.getOrientation(R, values); 
mHeading = (int) Math.toDegrees(values[0]); 
Display display = 
((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
int compensation = display.getRotation() * 90;       
mHeading = mHeading+compensation; 
1

मैं लगता है कि तुम लाइन में INR को outR बदलना चाहिए getOrientation

boolean success = SensorManager.getRotationMatrix(inR, I, gravity, geomag); 
if (success){ 
// Re-map coordinates so y-axis comes out of camera 
SensorManager.remapCoordinateSystem(inR, SensorManager.AXIS_X, 
    SensorManager.AXIS_Z, outR); 

// Finds the Azimuth and Pitch angles of the y-axis with 
// magnetic north and the horizon respectively 
**SensorManager.getOrientation(inR, orientVals);**