Angle Capture

0

I'm doing a project that involves capturing the angulation of movement using the cell phone. The angulations have already been calculated and are working. The problem I'm having is with the following proposal:

  

Since a patient will take the angulation of arm movement and want to start angulation from any angle to 0 from a click of a button.

  • How could I change my code to comply with this rule?

Example : The sensor is in the 270 degree position and the patient will lift the arm, the marking will be at 0 degrees. That is, he made a 90 degree movement. However, when you push the knob at 270 degrees, you should measure 0 degrees to 90 degrees when lifting your arm.

The data should always be shown on screen, so it is not possible to only apply a subtraction.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ac = (SensorManager) getSystemService(SENSOR_SERVICE);
    accelerometer = ac.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    ac.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
    acceleration = (TextView) findViewById(R.id.acceleration);
    anguloZerado = (TextView) findViewById(R.id.angulozerado);
    zeraAngulo = (Button)findViewById(R.id.zeraAngulacao);
}

 public void onSensorChanged(final SensorEvent sensorEvent) {

    acceleration.setText("X: " + sensorEvent.values[0] +
            "\nY: " + sensorEvent.values[1] +
            "\nZ: " + sensorEvent.values[2]);
    float x = sensorEvent.values[0];
    float y = sensorEvent.values[1];
    angle =  (float)((float) Math.atan2(x, y)/ (Math.PI/180));

    angle = ((angle + 360) % 360) + 90; //resolve o problema de -180 a -1 e conserta a angulação dos quadrantes
    str_angle = Float.toString(angle);
    angulation = (TextView) findViewById(R.id.angulo);
    angulation.setText(str_angle);

    zeraAngulo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            float x = sensorEvent.values[0];
            float y = sensorEvent.values[1];
            angulo2 = (float)((float) Math.atan2(x, y)/ (Math.PI/180));
            angulo2 = (((((angulo2 + 360) % 360) + 90) - angulo2) + 360) %360; //resolve o problema de -180 a -1
            str_zeraAngulo = Float.toString(angle);

            anguloZerado.setText(str_zeraAngulo);


        }
    });
    angulo2 = (((((angulo2 + 360) % 360) + 90) - angulo2) + 360) %360; //erro
    str_zeraAngulo = Float.toString(angulo2);
    anguloZerado = (TextView) findViewById(R.id.angulozerado);
    anguloZerado.setText(str_zeraAngulo);
}
    
asked by anonymous 01.12.2017 / 02:47

0 answers