Author Topic: Phone sensor fusion demo  (Read 1723 times)

Offline haversin

  • High Voltage Experimenter
  • **
  • Posts: 64
  • Karma: +5/-0
    • View Profile
Phone sensor fusion demo
« on: September 21, 2023, 09:22:14 PM »
Phyphox app was used to send accelerometer, magnetometer and gyro data over wi-fi using Http requests to a Python script running on a pc. The phone orientation in space was calculated two ways: 1) using accelerometer and magnetometer data only and 2) using a Complementary filter on the accelerometer, magnetometer and gyro data. The results are shown in this video.


Offline Fumeaux

  • High Voltage Experimenter
  • **
  • Posts: 82
  • Karma: +7/-0
    • View Profile
Re: Phone sensor fusion demo
« Reply #1 on: January 02, 2024, 06:23:09 PM »
That looks quite cool. Would you mind sharing your code? I'm interested in it.
« Last Edit: January 02, 2024, 09:24:27 PM by Fumeaux »

Offline haversin

  • High Voltage Experimenter
  • **
  • Posts: 64
  • Karma: +5/-0
    • View Profile
Re: Phone sensor fusion demo
« Reply #2 on: January 03, 2024, 05:13:54 PM »
Here is the Python code. you need the Phyphox app on the phone.  I have an android not sure about iphone. I wrote my own quaternion module let me know if you need that.

Code: [Select]
import sys
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
from math import *
import numpy as np
import requests
import quaternions as qu

x,y,z = 1.25,2.5,.25
vertices = (
    (x, -y, -z),
    (x, y, -z),
    (-x, y, -z),
    (-x, -y, -z),
    (x, -y, z),
    (x, y, z),
    (-x,-y, z),
    (-x, y, z)
    )

faces = (
    (0,1,2,3),
    (3,2,7,6),
    (6,7,5,4),
    (4,5,1,0),
    (1,5,7,2),
    (4,0,3,6)
    )

colors = (
    (0.,1.,0.),
    (1.,0.,0.),
    (0.,0.,1.),
    (1.,1.,0.),
    (1.,0.,1.),
    (0.,1.,1.)
    )

def quads():
    cindx = 0
    glBegin(GL_QUADS)
    for face in faces:
        glColor3fv(colors[cindx])
        for vertex in face:
            glVertex3fv(vertices[vertex])
        cindx += 1
    glEnd()       
           
# phyphox comm settings
PP_ADDRESS = "http://192.168.1.3:8080"
PP_CHANNELS = ["accX", "accY", "accZ","gyr_time","gyrX", "gyrY", "gyrZ",
            "magX", "magY", "magZ"]
#PP_CHANNELS = ["acc_time","accX", "accY", "accZ"]# accelerometer data names
#PP_CHANNELS = ["gyr_time","gyrX", "gyrY", "gyrZ"] # gyro data names
#PP_CHANNELS = ["magX", "magY", "magZ"] # magnetometer data names
start = PP_ADDRESS +"/control?cmd=start"
stop = PP_ADDRESS +"/control?cmd=stop"
clear = PP_ADDRESS +"/control?cmd=clear"
url = PP_ADDRESS + "/get?" + ("&".join(PP_CHANNELS))
ax,ay = 0.,0.


def main():
    m, e, u, qf = np.zeros((3,3)),np.zeros(3),np.zeros(3),np.zeros(4)
    b, n, q, dqg = np.zeros(3),np.zeros(3),np.zeros(4),np.zeros(4)
    wu = np.zeros(3)
    wtl = 0.
    crd, twopi = 180./pi, 2*pi
    fac = .9  #  filter parameter
    pygame.init()
    display = (1333,1000)
#    aspr = float(display[0])/display[1]
    aspr = 1.5
    pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
    glEnable(GL_CULL_FACE)
    glFrontFace(GL_CW) # face vertex winding order is CW
#    gluPerspective(45, (display[0]/display[1]), .1, 50.)
    s = 7.
    glOrtho(-s*aspr,s*aspr,-s,s,0.1,50.)
    glTranslatef(0,0,-5)
    glRotated(-90.,1,0,0)
    glRotated(-90.,0,0,1)

   
    data = requests.get(start).json() # start comm with phyphox
   
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                data = requests.get(stop).json() # stop comm with phyphox
                quit()

        data = requests.get(url=url).json()
        ax = data["buffer"][PP_CHANNELS[0]]["buffer"][0]
        ay = data["buffer"][PP_CHANNELS[1]]["buffer"][0]
        az = data["buffer"][PP_CHANNELS[2]]["buffer"][0]
        wt = data["buffer"][PP_CHANNELS[3]]["buffer"][0]
        wx = data["buffer"][PP_CHANNELS[4]]["buffer"][0]
        wy = data["buffer"][PP_CHANNELS[5]]["buffer"][0]
        wz = data["buffer"][PP_CHANNELS[6]]["buffer"][0]
        bx = data["buffer"][PP_CHANNELS[7]]["buffer"][0]
        by = data["buffer"][PP_CHANNELS[8]]["buffer"][0]
        bz = data["buffer"][PP_CHANNELS[9]]["buffer"][0]

        if str(ax) != 'None' and str(wt) != 'None' and str(bx) != 'None' :

# use acceleromter and magnetometer data to construct rotation matrix
            u[:] = ax, ay, az
            umag = sqrt(u.dot(u))
            u /= umag
            b[:] = bx, by, bz
            e = np.cross(b,u)
            emag = sqrt(e.dot(e))
            e /= emag
            n = np.cross(u,e)
            m[0] = e
            m[1] = n
            m[2] = u
# convert rotation matrix to quaternion qam
            qam = qu.mat2q(m)
            if wtl == 0.:
              qf, wtl = qam, wt
# compute delta rotation quaternion from gyro data
            dwt = wt - wtl
            if dwt > .2:
              dwt = .2
            print(wx, wy, wz, wt, wtl, dwt)
            wtl = wt
            wu[:] = wx, wy, wz
            wmag = sqrt(wu.dot(wu))
            wu /= wmag
            thao2 = wmag*dwt/2.
            sthao2 = sin(thao2)
            dqg[:] = cos(thao2), wu[0]*sthao2, wu[1]*sthao2, wu[2]*sthao2
            qg = qu.q_mult(dqg,qf)
            qf = qu.Slerp(qam,qg,fac)

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
# draw object with it's own screen positon           
        glPushMatrix()
        glTranslatef(0,-4.25,0)
        tha = 2*acos(qam[0])
        glRotated(tha*crd,qam[1],qam[2],qam[3])
        quads()
        glPopMatrix()


# draw object with it's own screen positon           
        glPushMatrix()
        glTranslatef(0,4.25,0)
        tha = 2*acos(qf[0])
        glRotated(tha*crd,qf[1],qf[2],qf[3])
        quads()
        glPopMatrix()

        pygame.display.flip()
        pygame.time.wait(1)   
main()

High Voltage Forum

Re: Phone sensor fusion demo
« Reply #2 on: January 03, 2024, 05:13:54 PM »

 


* Recent Topics and Posts

post Re: Problem with SSTC
[Solid State Tesla Coils (SSTC)]
davekni
Today at 01:33:37 AM
post Re: Problem with SSTC
[Solid State Tesla Coils (SSTC)]
Nunu00
Today at 12:17:32 AM
post Re: Restoring a Rogowski coil calibrator
[Capacitor Banks]
davekni
July 11, 2024, 07:38:26 PM
post Re: Restoring a Rogowski coil calibrator
[Capacitor Banks]
klugesmith
July 11, 2024, 06:30:00 PM
post LOD Non Resonant SSTC?
[Solid State Tesla Coils (SSTC)]
ColinHeath
July 11, 2024, 06:08:30 PM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
July 11, 2024, 12:24:56 PM
post Re: Strange QCW Streamer Behavior
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
July 11, 2024, 06:42:23 AM
post Re: Syntherrupter Lightsaber Sender Programming
[Computers, Microcontrollers, Programmable Logic, Interfaces and Displays]
Cameron Prince
July 11, 2024, 05:46:07 AM
post Syntherrupter Lightsaber Sender Programming
[Computers, Microcontrollers, Programmable Logic, Interfaces and Displays]
Cameron Prince
July 11, 2024, 05:26:51 AM
post Re: Strange QCW Streamer Behavior
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
July 11, 2024, 02:50:54 AM
post Strange QCW Streamer Behavior
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Coupling
July 11, 2024, 12:59:55 AM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
petespaco
July 10, 2024, 07:10:34 PM
post Re: Understanding and tracking upper and lower poles of QCW DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 10, 2024, 06:52:42 PM
post Re: Understanding and tracking upper and lower poles of QCW DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
July 10, 2024, 06:28:19 PM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Alex_1996
July 10, 2024, 01:34:09 PM
post Re: Silicon(e) plasma
[General Chat]
alan sailer
July 10, 2024, 12:09:06 AM
post Re: Problem with SSTC
[Solid State Tesla Coils (SSTC)]
Nunu00
July 09, 2024, 11:52:00 PM
post Understanding and tracking upper and lower poles of QCW DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Simranjit
July 09, 2024, 07:37:22 PM
post Re: Silicon(e) plasma
[General Chat]
MechatEng2023
July 09, 2024, 07:30:05 PM
post Re: UD2.7C outputs very odd single square wave pulses
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 09, 2024, 03:30:49 AM
post Re: UD2.7C outputs very odd single square wave pulses
[Dual Resonant Solid State Tesla coils (DRSSTC)]
verliebt_in_neukölln17
July 09, 2024, 12:51:02 AM
post Re: UD2.7C outputs very odd single square wave pulses
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 08, 2024, 11:30:44 PM
post Re: Why so cheap?
[General Chat]
alan sailer
July 08, 2024, 10:57:10 PM
post UD2.7C outputs very odd single square wave pulses
[Dual Resonant Solid State Tesla coils (DRSSTC)]
verliebt_in_neukölln17
July 08, 2024, 10:21:01 PM
post Why so cheap?
[General Chat]
MRMILSTAR
July 08, 2024, 09:55:24 PM
post Re: Syntherrupter - A Feature-rich, Polyphonic Interrupter
[Computers, Microcontrollers, Programmable Logic, Interfaces and Displays]
Cameron Prince
July 08, 2024, 09:18:21 PM
post Re: Syntherrupter - A Feature-rich, Polyphonic Interrupter
[Computers, Microcontrollers, Programmable Logic, Interfaces and Displays]
Max
July 08, 2024, 05:17:49 PM
post Re: Syntherrupter - A Feature-rich, Polyphonic Interrupter
[Computers, Microcontrollers, Programmable Logic, Interfaces and Displays]
Cameron Prince
July 08, 2024, 04:49:20 PM
post Re: Tesla coil in FEMM
[Beginners]
Simranjit
July 08, 2024, 04:28:43 AM
post Re: Tesla coil in FEMM
[Beginners]
davekni
July 08, 2024, 04:06:53 AM
post Tesla coil in FEMM
[Beginners]
Simranjit
July 08, 2024, 03:46:49 AM
post Re: Best core material for QCW Buck modulator ?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Simranjit
July 08, 2024, 02:42:00 AM
post Re: QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
July 08, 2024, 01:37:55 AM
post Re: First DRSSTC Build- Issues with Fibernet project
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Sebigamer
July 08, 2024, 12:53:08 AM
post Re: QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
July 08, 2024, 12:49:48 AM
post Re: Silicon(e) plasma
[General Chat]
alan sailer
July 07, 2024, 11:15:35 PM
post Silicon(e) plasma
[General Chat]
MechatEng2023
July 07, 2024, 11:04:43 PM
post Re: QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
July 07, 2024, 09:39:07 PM
post Re: First DRSSTC Build- Issues with Fibernet project
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 07, 2024, 05:32:56 PM
post Re: QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
July 07, 2024, 02:52:19 PM
post Re: No change in Phase Lead
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
July 07, 2024, 02:50:04 PM
post Re: Best core material for QCW Buck modulator ?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
July 07, 2024, 02:20:11 PM
post Teardown of a APC SmartUPS VT 40 kVA
[Electronic Circuits]
Mads Barnkob
July 07, 2024, 10:02:22 AM
post First DRSSTC Build- Issues with Fibernet project
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Sebigamer
July 07, 2024, 09:23:58 AM
post Re: QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
July 07, 2024, 12:44:53 AM
post Re: FEMM tesla coil simulation
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Simranjit
July 07, 2024, 12:08:50 AM
post Re: FEMM tesla coil simulation
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
July 06, 2024, 10:35:49 PM
post FEMM tesla coil simulation
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Simranjit
July 06, 2024, 09:42:43 PM
post Re: No change in Phase Lead
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 06, 2024, 06:06:23 PM
post Re: No change in Phase Lead
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
July 06, 2024, 10:21:16 AM
post Re: No change in Phase Lead
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
July 06, 2024, 10:15:42 AM
post Re: QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Simranjit
July 06, 2024, 04:53:56 AM
post Re: No change in Phase Lead
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
July 06, 2024, 04:42:16 AM
post Re: QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
July 06, 2024, 04:09:50 AM
post Re: Best core material for QCW Buck modulator ?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 06, 2024, 03:07:11 AM
post Re: No change in Phase Lead
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 06, 2024, 03:05:18 AM
post Re: QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
July 06, 2024, 02:37:16 AM
post Re: QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Simranjit
July 06, 2024, 02:20:14 AM
post QCWDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
July 06, 2024, 01:55:14 AM
post Re: No change in Phase Lead
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
July 05, 2024, 11:50:37 PM
post Best core material for QCW Buck modulator ?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Simranjit
July 05, 2024, 10:07:04 PM
post 230v Tesla coil and krypton gas
[Spark Gap Tesla Coils (SGTC)]
gravitysrainbow
July 05, 2024, 07:13:25 PM
post Re: No change in Phase Lead
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
July 05, 2024, 06:17:13 PM
post Re: Phase lead inductors
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
July 04, 2024, 11:40:45 PM
post Re: Sling Psychrometer
[Laboratories, Equipment and Tools]
Twospoons
July 04, 2024, 11:02:32 PM
post Phase lead inductors
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 04, 2024, 06:28:08 PM
post Re: Sling Psychrometer
[Laboratories, Equipment and Tools]
klugesmith
July 04, 2024, 12:31:40 AM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Alex_1996
July 04, 2024, 12:07:21 AM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Alex_1996
July 04, 2024, 12:06:17 AM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
July 03, 2024, 10:51:23 PM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
July 03, 2024, 09:44:14 PM
post Re: Coax cable for DRSSTC interrupter?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
July 03, 2024, 08:48:13 PM
post Re: Coax cable for DRSSTC interrupter?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Simranjit
July 03, 2024, 08:24:50 PM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Alex_1996
July 03, 2024, 08:12:55 PM
post Re: Coax cable for DRSSTC interrupter?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
July 03, 2024, 07:29:53 PM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
July 03, 2024, 07:21:38 PM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 03, 2024, 05:05:39 PM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Alex_1996
July 03, 2024, 04:29:53 PM
post Re: FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 03, 2024, 04:09:11 PM
post FIRST DRSSTC SKM400GB128D OCD SETTING
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Alex_1996
July 03, 2024, 02:47:18 PM
post Re: Eliminating discharges from a SSTC
[Solid State Tesla Coils (SSTC)]
Alex_1996
July 03, 2024, 01:35:24 PM
post Re: Coax cable for DRSSTC interrupter?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
July 03, 2024, 02:19:03 AM
post Re: Coax cable for DRSSTC interrupter?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
verliebt_in_neukölln17
July 03, 2024, 01:19:50 AM
post Coax cable for DRSSTC interrupter?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Simranjit
July 02, 2024, 11:29:18 PM
post Re: Is this a good pulse experiment capacitor?
[Capacitor Banks]
Mads Barnkob
July 02, 2024, 09:59:07 PM
post Re: LabCoatz Staccato QCW No straight sparks
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
July 02, 2024, 09:55:53 PM
post Re: Capacitor wiring for single phase 240 to split phase (180 degree) 240v
[Capacitor Banks]
klugesmith
July 02, 2024, 09:44:55 PM
post Re: LabCoatz Staccato QCW No straight sparks
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
July 02, 2024, 07:51:37 PM
post Re: LabCoatz Staccato QCW No straight sparks
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
July 02, 2024, 06:14:07 PM
post Is this a good pulse experiment capacitor?
[Capacitor Banks]
FPS
July 02, 2024, 06:02:38 PM
post Re: LabCoatz Staccato QCW No straight sparks
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
July 02, 2024, 11:37:46 AM
post Re: Building my first DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
July 02, 2024, 05:22:10 AM
post Re: Coulometric hourmeters
[Laboratories, Equipment and Tools]
davekni
July 02, 2024, 05:16:30 AM
post Re: Building my first DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
drobotk
July 01, 2024, 11:50:12 PM
post Re: Restoring a Rogowski coil calibrator
[Capacitor Banks]
klugesmith
July 01, 2024, 08:48:53 PM
post Uses for Weston's Little Bee probe
[Laboratories, Equipment and Tools]
klugesmith
July 01, 2024, 08:40:59 AM
post Re: Coulometric hourmeters
[Laboratories, Equipment and Tools]
klugesmith
July 01, 2024, 08:09:42 AM
post Re: Coulometric hourmeters
[Laboratories, Equipment and Tools]
davekni
June 30, 2024, 06:49:45 AM
post Re: Restoring a Rogowski coil calibrator
[Capacitor Banks]
davekni
June 30, 2024, 03:57:13 AM
post Re: Coulometric hourmeters
[Laboratories, Equipment and Tools]
klugesmith
June 30, 2024, 03:19:40 AM

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 
SimplePortal 2.3.6 © 2008-2014, SimplePortal