sabato 28 marzo 2020

QTSensors su Ubuntu Touch (UBPorts) in QML

Visto che sto imparando a programmare UBPorts ho voluto provare a convertire questo progetto Android/Kotlin per QML. In pratica si tratta di leggere i valori dell'accelerometro e, ad intervalli regolari, inviare i dati ad server web con una richiesta GET


Per abilitare l'utilizzo della rete nella app si deve modificare il file apparmor
apparmor
===========================================
{
    "policy_groups": ["networking"],
    "policy_version": 16.04
}

===========================================


Main.qml
===========================================
/*
 * Copyright (C) 2020  Your FullName
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * ubuntu-calculator-app is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.7
import Ubuntu.Components 1.3
//import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Qt.labs.settings 1.0

import QtSensors 5.0



MainView {
    id: root
    objectName: 'mainView'
    applicationName: 'acc2.luca.innocenti'
    automaticOrientation: true
   
    // variabili globali
    readonly property double radians_to_degrees: 180 / Math.PI
    property double pitch: 0.0
    property double roll: 0.0

    width: units.gu(45)
    height: units.gu(75)

    // un evento ogni 5 secondi
    Timer {
          interval: 5000
          running: true
          repeat: true
          onTriggered: {
            console.log("Timer")
            var xmlHttp = new XMLHttpRequest();
            xmlHttp.open("GET", "http://192.168.1.102/index.php?pitch="+pitch.toFixed(3)+"&roll="+roll.toFixed(3), true); // false for synchronous request
            xmlHttp.send();

          }
      }


    Accelerometer {
        id: accel
        dataRate: 100
        active:true

        onReadingChanged: {
            var x = accel.reading.x
            var y = accel.reading.y
            var z = accel.reading.z
            pitch = calcPitch(x,y,z)
            roll = calcRoll (x,y,z)
            //etichetta.text=""+accel.reading.x+"\n"+accel.reading.y+"\n"+accel.reading.z
            etichetta.text = "Pitch : "+pitch.toFixed(1)+"\nRoll : "+roll.toFixed(1)

            function calcPitch(x,y,z) {
                return Math.atan2(y, z)*radians_to_degrees;

                }
            function calcRoll(x,y,z) {
                return Math.atan2(-x, Math.sqrt((y*y)+(z*z)))*radians_to_degrees;
                }

          }


        }



    Page {
        anchors.fill: parent

        header: PageHeader {
            id: header
            title: i18n.tr('acc2')
        }


        Label {
            anchors {
                top: header.bottom
                left: parent.left
                right: parent.right
                bottom: parent.bottom
            }
            id: etichetta
            text: i18n.tr('Luca')

            verticalAlignment: Label.AlignVCenter
            horizontalAlignment: Label.AlignHCenter
        }

    }
}

Nessun commento:

Posta un commento

Physics informed neural network Fukuzono

Visto che puro ML non funziona per le serie tempo di cui mi sto occupando ed le regressioni basate su formule analitiche mostrano dei limiti...