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

Offline haversin

  • High Voltage Experimenter
  • **
  • Posts: 73
  • 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: 73
  • 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 Powering fluorescent lamps with Tesla coils
[Spark Gap Tesla Coils (SGTC)]
MechatEng2023
Today at 07:11:14 AM
post Re: High pressure sodium lamp phosphorescence
[Light, Lasers and Optics]
MechatEng2023
Today at 07:05:14 AM
post Re: Universal Driver 1.3b doesn't oscillate
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
Today at 04:24:59 AM
post Re: Universal Driver 1.3b doesn't oscillate
[Dual Resonant Solid State Tesla coils (DRSSTC)]
PATWORK007
Today at 03:39:31 AM
post Re: Big Coil Build Log
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
Today at 02:24:08 AM
post Re: Universal Driver 1.3b doesn't oscillate
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
Today at 01:20:15 AM
post Re: My first QCW
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
Today at 01:14:27 AM
post Re: Big Coil Build Log
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
October 13, 2024, 11:21:59 PM
post Re: Big Coil Build Log
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
October 13, 2024, 10:41:48 PM
post Re: My first QCW
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mathieu thm
October 13, 2024, 08:54:14 PM
post FEEDBACK IH WORKING GREAT- HIGH POWER TEST RUN
[Induction Launchers, Coil Guns and Rails guns]
radbloke
October 13, 2024, 08:14:41 PM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
betalab99
October 13, 2024, 07:03:05 PM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
Bert911
October 13, 2024, 02:29:31 PM
post Re: Benjamin's DRSSTC3
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
October 13, 2024, 04:17:58 AM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
October 13, 2024, 01:40:19 AM
post Re: Benjamin's DRSSTC3
[Dual Resonant Solid State Tesla coils (DRSSTC)]
buchtawill
October 12, 2024, 07:04:03 PM
post Universal Driver 1.3b doesn't oscillate
[Dual Resonant Solid State Tesla coils (DRSSTC)]
PATWORK007
October 12, 2024, 10:09:14 AM
post Re: Tested and working feedback induction heater driver with current limiter
[Induction Launchers, Coil Guns and Rails guns]
radbloke
October 12, 2024, 05:45:55 AM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
betalab99
October 11, 2024, 06:37:44 PM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
petespaco
October 11, 2024, 05:13:41 PM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
betalab99
October 11, 2024, 04:50:45 PM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
petespaco
October 11, 2024, 04:43:06 PM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
October 11, 2024, 03:06:59 PM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
betalab99
October 11, 2024, 10:56:03 AM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
petespaco
October 11, 2024, 05:54:38 AM
post Re: Benjamin's DRSSTC3
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
October 10, 2024, 08:46:26 PM
post Re: Coupling coefficient and some more Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 10, 2024, 07:19:54 PM
post Re: Help for people buying the "12-48 Volt 1800/2500 Watt ZVS induction Heater"
[Electronic Circuits]
betalab99
October 10, 2024, 03:29:45 PM
post Re: Benjamin's DRSSTC3
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
October 10, 2024, 11:27:43 AM
post Re: Benjamin's DRSSTC3
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
October 10, 2024, 11:09:29 AM
post Re: Coupling coefficient and some more Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
October 10, 2024, 11:01:26 AM
post Re: Coupling coefficient and some more Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 10, 2024, 05:55:50 AM
post Re: Coupling coefficient and some more Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
October 09, 2024, 10:32:30 AM
post Re: Benjamin's DRSSTC3
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 09, 2024, 05:44:25 AM
post Re: Coupling coefficient and some more Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
October 08, 2024, 09:35:59 PM
post Re: Coupling coefficient and some more Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
October 08, 2024, 09:33:40 PM
post Re: Coupling coefficient and some more Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
October 08, 2024, 09:10:38 PM
post Re: Benjamin's DRSSTC3
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
October 08, 2024, 08:48:43 PM
post Re: Coupling coefficient and some more Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
October 08, 2024, 08:22:07 PM
post Re: Last cap in CW always blowing up
[Voltage Multipliers]
JoeBusic
October 08, 2024, 02:36:07 PM
post Coupling coefficient and some more Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Admiral Aaron Ravensdale
October 08, 2024, 07:46:14 AM
post Re: [WTS] Yard Sale (IGBT's/Wires/Cooling/wire/induction/BusCaps/Coils/Magnetrons)
[Sell / Buy / Trade]
dbach
October 08, 2024, 02:46:32 AM
post Re: MIDI Music Note Control for DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
October 07, 2024, 07:13:58 PM
post Re: Shock box
[Electronic Circuits]
haversin
October 07, 2024, 05:45:41 PM
post Re: MIDI Music Note Control for DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Alex_1996
October 07, 2024, 05:32:31 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Late
October 07, 2024, 04:01:51 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Late
October 07, 2024, 03:59:27 PM
post Re: [WTS] Yard Sale (IGBT's/Wires/Cooling/wire/induction/BusCaps/Coils/Magnetrons)
[Sell / Buy / Trade]
Late
October 07, 2024, 03:56:11 PM
post Re: On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
October 07, 2024, 02:58:03 PM
post Re: [WTS] Yard Sale (IGBT's/Wires/Cooling/wire/induction/BusCaps/Coils/Magnetrons)
[Sell / Buy / Trade]
dbach
October 07, 2024, 02:09:29 PM
post Re: [WTS] Yard Sale (IGBT's/Wires/Cooling/wire/induction/BusCaps/Coils/Magnetrons)
[Sell / Buy / Trade]
dbach
October 07, 2024, 02:05:07 PM
post Re: On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Uspring
October 07, 2024, 01:51:38 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
futurist
October 07, 2024, 11:39:50 AM
post Re: Building my first DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
October 07, 2024, 09:20:11 AM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
October 07, 2024, 09:03:59 AM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
October 07, 2024, 08:52:23 AM
post Re: On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 06, 2024, 07:26:46 PM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
October 06, 2024, 07:17:56 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 06, 2024, 07:04:24 PM
post Re: On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
October 06, 2024, 06:56:45 PM
post Has anyone done a teardown of one of these "Induction Heaters for Auto Use"?
[Electronic Circuits]
petespaco
October 06, 2024, 04:53:46 PM
post Re: [WTS] Yard Sale (IGBT's/Wires/Cooling/wire/induction/BusCaps/Coils/Magnetrons)
[Sell / Buy / Trade]
Late
October 06, 2024, 04:23:47 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Late
October 06, 2024, 04:17:48 PM
post Re: My first QCW
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mathieu thm
October 06, 2024, 02:59:35 PM
post Re: On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Uspring
October 06, 2024, 01:18:16 PM
post Re: Last cap in CW always blowing up
[Voltage Multipliers]
JoeBusic
October 05, 2024, 10:56:17 PM
post Re: current transformers
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 05, 2024, 09:42:27 PM
post Re: MIDI Music Note Control for DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
October 05, 2024, 09:35:43 PM
post Re: current transformers
[Dual Resonant Solid State Tesla coils (DRSSTC)]
thedoc298
October 05, 2024, 08:50:55 PM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 05, 2024, 07:59:15 PM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
October 05, 2024, 05:35:00 PM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
October 05, 2024, 05:24:59 PM
post Crystal HFSSTC
[Solid State Tesla Coils (SSTC)]
Perolodzilla
October 05, 2024, 01:16:19 PM
post Re: current transformers
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
October 05, 2024, 09:14:48 AM
post Re: On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 05, 2024, 06:45:42 AM
post Re: current transformers
[Dual Resonant Solid State Tesla coils (DRSSTC)]
thedoc298
October 05, 2024, 06:20:55 AM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 05, 2024, 06:13:35 AM
post Re: Building my first DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
October 05, 2024, 05:53:22 AM
post Re: The evolution of a solid state Tesla coil
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
October 05, 2024, 04:19:17 AM
post Re: current transformers
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
October 05, 2024, 12:15:59 AM
post Re: On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Continuum
October 04, 2024, 11:12:20 PM
post current transformers
[Dual Resonant Solid State Tesla coils (DRSSTC)]
thedoc298
October 04, 2024, 10:25:43 PM
post Re: On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
October 04, 2024, 07:15:58 PM
post Re: Shock box
[Electronic Circuits]
alan sailer
October 04, 2024, 02:58:01 AM
post Re: On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Continuum
October 04, 2024, 01:27:07 AM
post Re: Shock box
[Electronic Circuits]
haversin
October 04, 2024, 01:03:02 AM
post Re: Shock box
[Electronic Circuits]
alan sailer
October 04, 2024, 12:44:17 AM
post Shock box
[Electronic Circuits]
haversin
October 04, 2024, 12:21:09 AM
post Re: Bertran Model 205A-03R High Voltage Power Supply
[General Chat]
klugesmith
October 03, 2024, 07:38:36 AM
post Re: An unexpected autotransformer
[Transformer (Ferrite Core)]
haversin
October 03, 2024, 12:45:51 AM
post Re: An unexpected autotransformer
[Transformer (Ferrite Core)]
klugesmith
October 03, 2024, 12:15:29 AM
post Re: An unexpected autotransformer
[Transformer (Ferrite Core)]
haversin
October 02, 2024, 10:49:03 PM
post Re: An unexpected autotransformer
[Transformer (Ferrite Core)]
klugesmith
October 02, 2024, 06:27:22 PM
post On poles and detuning in QCW coils
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Anders Mikkelsen
October 02, 2024, 05:41:09 PM
post Re: MIDI Music Note Control for DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Alex_1996
October 02, 2024, 05:23:18 PM
post Re: Tested and working feedback induction heater driver with current limiter
[Induction Launchers, Coil Guns and Rails guns]
radbloke
October 02, 2024, 05:57:37 AM
post Re: Tested and working feedback induction heater driver with current limiter
[Induction Launchers, Coil Guns and Rails guns]
davekni
October 02, 2024, 05:00:12 AM
post Re: MIDI Music Note Control for DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
October 02, 2024, 03:01:15 AM
post MIDI Music Note Control for DRSSTC
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Alex_1996
October 01, 2024, 10:22:59 PM
post Re: An unexpected autotransformer
[Transformer (Ferrite Core)]
haversin
October 01, 2024, 06:04:57 PM

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