Angulation capture

Asked

Viewed 32 times

0

I’m doing a project that consists of capturing the angulation of movement using the cell phone. The angles 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 the movement of the arm and want to start the angulation of any angle at 0 from a click of a button.

  • how could I modify my code to obey this rule?

Example: the sensor is at 270 degrees and, when the patient raises the arm, the marking will be at 0 degrees. That is, it made a 90 degree movement. However, when pressing the button at the angle 270 degrees, 0 degrees up to 90 degrees shall be measured when lifting the arm.

Data should always be shown on screen, so it is not possible to 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);
}
  • The angulo2 already stores the starting point not? If yes you just need to take the calculated value of the current angle and do a simple subtraction + 360 angle = ((angle + 360 - angulo2) % 360);

  • Thank you very much. I think I’ve thought of so many complicated things that I’ve escaped from the basics.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.