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

Offline haversin

  • High Voltage Experimenter
  • **
  • Posts: 63
  • 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: 63
  • 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: Pulse Power High Current Discharges from 3 Phase PFC Capacitors
[Capacitor Banks]
MRMILSTAR
Today at 05:22:43 AM
post Re: Want to build HV HF oscilloscope probe.
[Electronic Circuits]
Twospoons
Today at 05:08:46 AM
post Re: Pulse Power High Current Discharges from 3 Phase PFC Capacitors
[Capacitor Banks]
davekni
Today at 04:49:16 AM
post Re: Ring Launcher AC vs DC?
[Induction Launchers, Coil Guns and Rails guns]
FPS
Today at 03:55:37 AM
post Re: Want to build HV HF oscilloscope probe.
[Electronic Circuits]
klugesmith
Today at 02:48:22 AM
post Re: Want to build HV HF oscilloscope probe.
[Electronic Circuits]
Domo
Today at 02:05:05 AM
post Re: Plasma Torid - Class E Self Resonant Dual/Stereo - Plasma Torid Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
alan sailer
Today at 01:43:10 AM
post Re: Want to build HV HF oscilloscope probe.
[Electronic Circuits]
Twospoons
May 18, 2024, 11:30:11 PM
post Re: Pulse Power High Current Discharges from 3 Phase PFC Capacitors
[Capacitor Banks]
MRMILSTAR
May 18, 2024, 10:10:56 PM
post Want to build HV HF oscilloscope probe.
[Electronic Circuits]
Domo
May 18, 2024, 09:46:17 PM
post Re: Pulse Power High Current Discharges from 3 Phase PFC Capacitors
[Capacitor Banks]
davekni
May 18, 2024, 08:05:36 PM
post Re: Help an EE student
[General Chat]
Twospoons
May 18, 2024, 05:59:21 AM
post Re: What capacitor configuration to explode foil?
[Capacitor Banks]
MRMILSTAR
May 18, 2024, 05:44:41 AM
post Re: RDRSSTC - Project Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
ZakW
May 18, 2024, 01:55:42 AM
post Re: What capacitor configuration to explode foil?
[Capacitor Banks]
klugesmith
May 17, 2024, 11:49:33 PM
post Re: Pulse Power High Current Discharges from 3 Phase PFC Capacitors
[Capacitor Banks]
MRMILSTAR
May 17, 2024, 10:18:46 PM
post Pulse Power High Current Discharges from 3 Phase PFC Capacitors
[Capacitor Banks]
Mads Barnkob
May 17, 2024, 07:24:22 PM
post Re: What capacitor configuration to explode foil?
[Capacitor Banks]
Mads Barnkob
May 17, 2024, 07:14:35 PM
post Re: Help an EE student
[General Chat]
Mads Barnkob
May 17, 2024, 08:35:38 AM
post Re: Help an EE student
[General Chat]
MRMILSTAR
May 17, 2024, 05:34:10 AM
post Re: colored 50 Ohm coax
[General Chat]
Da_Stier
May 16, 2024, 10:53:53 PM
post Re: Help an EE student
[General Chat]
Michelle_
May 16, 2024, 10:37:50 PM
post Re: Help an EE student
[General Chat]
davekni
May 16, 2024, 10:29:30 PM
post Re: Help an EE student
[General Chat]
klugesmith
May 16, 2024, 08:26:41 PM
post Re: Aluminum electrolytic capacitor ripple current issue
[Beginners]
davekni
May 16, 2024, 06:54:05 PM
post Re: Aluminum electrolytic capacitor ripple current issue
[Beginners]
NyaaX_X
May 16, 2024, 05:04:41 PM
post Re: Tesla Synth Player for Syntherrupter
[Computers, Microcontrollers, Programmable Logic, Interfaces and Displays]
AntoineRcbs
May 16, 2024, 12:13:47 PM
post Re: Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
Domo
May 16, 2024, 06:58:12 AM
post Re: New EE student asks about Cutting-Edge fields
[General Chat]
davekni
May 16, 2024, 06:47:09 AM
post Re: Aluminum electrolytic capacitor ripple current issue
[Beginners]
NyaaX_X
May 16, 2024, 06:00:49 AM
post Re: New EE student asks about Cutting-Edge fields
[General Chat]
Twospoons
May 16, 2024, 05:45:08 AM
post Re: New EE student asks about Cutting-Edge fields
[General Chat]
davekni
May 16, 2024, 05:03:41 AM
post Re: DRSSTC grounding issues
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
May 16, 2024, 04:58:40 AM
post Re: Aluminum electrolytic capacitor ripple current issue
[Beginners]
davekni
May 16, 2024, 04:36:40 AM
post Re: colored 50 Ohm coax
[General Chat]
klugesmith
May 16, 2024, 12:28:27 AM
post Re: Watercooling
[Dual Resonant Solid State Tesla coils (DRSSTC)]
acobaugh
May 15, 2024, 11:13:48 PM
post Re: Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
klugesmith
May 15, 2024, 10:58:05 PM
post colored 50 Ohm coax
[General Chat]
Da_Stier
May 15, 2024, 08:31:48 PM
post Re: DRSSTC grounding issues
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
May 15, 2024, 07:56:38 PM
post Re: DRSSTC grounding issues
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
May 15, 2024, 06:29:59 PM
post Re: Watercooling
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Felix B.
May 15, 2024, 04:04:14 PM
post Re: Schmitt trigger schematic question
[Electronic Circuits]
Michelle_
May 15, 2024, 03:32:57 PM
post DRSSTC grounding issues
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Felix B.
May 15, 2024, 03:07:39 PM
post New EE student asks about Cutting-Edge fields
[General Chat]
samsonwilliams
May 15, 2024, 05:50:59 AM
post Re: Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
Domo
May 15, 2024, 05:38:14 AM
post Re: Schmitt trigger schematic question
[Electronic Circuits]
Benjamin Lockhart
May 15, 2024, 04:58:02 AM
post Re: Big Coil Build Log
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
May 15, 2024, 04:34:49 AM
post Re: Watercooling
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
May 15, 2024, 04:30:18 AM
post Re: Watercooling
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
May 15, 2024, 04:00:55 AM
post Re: Watercooling
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
May 15, 2024, 03:21:51 AM
post Re: Schmitt trigger schematic question
[Electronic Circuits]
Michelle_
May 14, 2024, 11:12:22 PM
post Re: Schmitt trigger schematic question
[Electronic Circuits]
Benjamin Lockhart
May 14, 2024, 11:00:00 PM
post Schmitt trigger schematic question
[Electronic Circuits]
Michelle_
May 14, 2024, 09:45:38 PM
post Re: Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
klugesmith
May 14, 2024, 09:02:28 PM
post Re: Small-ish 3D printed SGTC via cheap ZVS flyback build, humbly asking a couple ?s
[Spark Gap Tesla Coils (SGTC)]
Michelle_
May 14, 2024, 05:55:24 AM
post Re: Weird AC/DC mini SSTC build review
[Solid State Tesla Coils (SSTC)]
Michelle_
May 14, 2024, 05:44:12 AM
post Re: Small-ish 3D printed SGTC via cheap ZVS flyback build, humbly asking a couple ?s
[Spark Gap Tesla Coils (SGTC)]
MRMILSTAR
May 14, 2024, 05:11:54 AM
post Re: Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
alan sailer
May 13, 2024, 11:44:56 PM
post Re: Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
Domo
May 13, 2024, 10:28:34 PM
post Re: Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
alan sailer
May 13, 2024, 10:20:19 PM
post Re: Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
Domo
May 13, 2024, 09:27:58 PM
post Re: Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
alan sailer
May 13, 2024, 09:06:59 PM
post Help with primary voltages of unknown transformer
[Transformer (Ferrite Core)]
Domo
May 13, 2024, 08:43:49 PM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
May 13, 2024, 07:25:29 PM
post Re: Plasma Torid - Class E Self Resonant Dual/Stereo - Plasma Torid Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
OmGigaTron
May 13, 2024, 06:50:59 PM
post Re: Weird AC/DC mini SSTC build review
[Solid State Tesla Coils (SSTC)]
Michelle_
May 13, 2024, 03:47:08 PM
post Re: Small-ish 3D printed SGTC via cheap ZVS flyback build, humbly asking a couple ?s
[Spark Gap Tesla Coils (SGTC)]
Michelle_
May 13, 2024, 03:42:58 PM
post Re: Aluminum electrolytic capacitor ripple current issue
[Beginners]
NyaaX_X
May 13, 2024, 07:09:16 AM
post Re: Aluminum electrolytic capacitor ripple current issue
[Beginners]
davekni
May 13, 2024, 05:02:46 AM
post Re: Aluminum electrolytic capacitor ripple current issue
[Beginners]
NyaaX_X
May 13, 2024, 02:25:25 AM
post Re: Plasma Torid - Class E Self Resonant Dual/Stereo - Plasma Torid Build
[Dual Resonant Solid State Tesla coils (DRSSTC)]
alan sailer
May 13, 2024, 01:39:11 AM
post Re: Plasma Toroid
[Solid State Tesla Coils (SSTC)]
alan sailer
May 13, 2024, 01:33:21 AM
post Re: Aluminum electrolytic capacitor ripple current issue
[Beginners]
davekni
May 12, 2024, 10:56:53 PM
post Re: Quick question about steve ward mini SST5 resonant frequency
[Solid State Tesla Coils (SSTC)]
NyaaX_X
May 12, 2024, 05:10:40 PM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
Michelle_
May 12, 2024, 04:24:44 PM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
alan sailer
May 12, 2024, 04:10:54 PM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
Michelle_
May 12, 2024, 04:04:11 PM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
hal7rr
May 12, 2024, 03:56:57 PM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
Michelle_
May 12, 2024, 03:46:45 PM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
hal7rr
May 12, 2024, 02:59:16 PM
post Re: Quick question about steve ward mini SST5 resonant frequency
[Solid State Tesla Coils (SSTC)]
Michelle_
May 12, 2024, 02:51:27 PM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
Michelle_
May 12, 2024, 02:49:42 PM
post Re: Quick question about steve ward mini SST5 resonant frequency
[Solid State Tesla Coils (SSTC)]
ZakW
May 12, 2024, 08:34:39 AM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
ZakW
May 12, 2024, 08:30:29 AM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
Michelle_
May 12, 2024, 02:35:17 AM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
alan sailer
May 12, 2024, 02:07:32 AM
post Re: Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
Michelle_
May 11, 2024, 09:55:59 PM
post Re: Help with LabCoatz's Staccato QCW DRSSTC
[Beginners]
NyaaX_X
May 11, 2024, 06:16:22 PM
post Help with LabCoatz's Staccato QCW DRSSTC Tesla Coil
[Beginners]
hal7rr
May 11, 2024, 05:24:34 PM
post Re: Type 77 Metglas Laced Ferrite Core
[General Chat]
NyaaX_X
May 11, 2024, 10:39:24 AM
post Re: Type 77 Metglas Laced Ferrite Core
[General Chat]
Mads Barnkob
May 11, 2024, 07:02:20 AM
post Re: Aluminum electrolytic capacitor ripple current issue
[Beginners]
NyaaX_X
May 11, 2024, 06:40:50 AM
post Type 77 Metglas Laced Ferrite Core
[General Chat]
paulp1776
May 11, 2024, 06:23:59 AM
post Re: Weird AC/DC mini SSTC build review
[Solid State Tesla Coils (SSTC)]
Michelle_
May 11, 2024, 05:27:22 AM
post Re: Quick question about steve ward mini SST5 resonant frequency
[Solid State Tesla Coils (SSTC)]
alan sailer
May 11, 2024, 01:37:37 AM
post Re: designing and building electron gun help!
[General Chat]
Twospoons
May 11, 2024, 12:10:44 AM
post designing and building electron gun help!
[General Chat]
Luca c.
May 10, 2024, 09:38:05 PM
post Re: Quick question about steve ward mini SST5 resonant frequency
[Solid State Tesla Coils (SSTC)]
Michelle_
May 10, 2024, 09:24:21 PM
post Re: Quick question about steve ward mini SST5 resonant frequency
[Solid State Tesla Coils (SSTC)]
alan sailer
May 10, 2024, 08:43:11 PM
post Quick question about steve ward mini SST5 resonant frequency
[Solid State Tesla Coils (SSTC)]
Michelle_
May 10, 2024, 08:33:47 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