public void OnAccelerometerData(SensorEvent e) { if (transmiting == true) { double x = e.Values[0]; double y = e.Values[1]; double z = e.Values[2]; double roll = Math.Atan(x / Math.Sqrt(Math.Pow(z, 2) + Math.Pow(y, 2))); double pitch = Math.Atan(y / Math.Sqrt(Math.Pow(x, 2) + Math.Pow(z, 2))); roll *= 180.0 / Math.PI; pitch *= 180.0 / Math.PI; tRoll = roll * rollGain; tPitch = pitch * pitchGain; if (parent.parent.mBluetoothConnection != null) { //byte[] msg = CommandProtocol.NewSimple(CommandProtocol.Cmd.setPitch, (float)tPitch); parent.parent.mBluetoothConnection.SendMessage(CommandProtocol.NewSimple(CommandProtocol.Cmd.setPitch, (float)tPitch)); //byte[] msg2 = CommandProtocol.NewSimple(CommandProtocol.Cmd.setRoll, (float)tRoll); parent.parent.mBluetoothConnection.SendMessage(CommandProtocol.NewSimple(CommandProtocol.Cmd.setRoll, (float)tRoll)); } mTextView2.Text = string.Format("Pitch: {0:f}, Roll: {1:f}", tPitch, tRoll); } }
private void OnYaw(object sender, SeekBar.ProgressChangedEventArgs e) { //byte[] msg = CommandProtocol.NewSimple(CommandProtocol.Cmd.setYaw, real_values[5]); if (parent.parent.mBluetoothConnection != null) { parent.parent.mBluetoothConnection.SendMessage(CommandProtocol.NewSimple(CommandProtocol.Cmd.setYaw, real_values[5])); } textViews[5].Text = String.Format("Yaw = {0:0.##} [deg]", real_values[5].ToString()); }
private void OnX(object sender, SeekBar.ProgressChangedEventArgs e) { //byte[] msg = CommandProtocol.NewSimple(CommandProtocol.Cmd.setX, real_values[0]); if (parent.parent.mBluetoothConnection != null) { parent.parent.mBluetoothConnection.SendMessage(CommandProtocol.NewSimple(CommandProtocol.Cmd.setX, real_values[0])); } textViews[0].Text = String.Format("X = {0:0.##} [mm]", real_values[0].ToString()); textViews[0].Text = System.Text.Encoding.ASCII.GetString(CommandProtocol.NewSimple(CommandProtocol.Cmd.setX, real_values[0])); }