Code Monkey home page Code Monkey logo

headtracker's Introduction

Head tracking with esp8266/esp8265 and MPU6050 or MPU9250

Installation

Install platform IO

# Build char* array for web
./generateHtmlArray.sh
platformio run --target upload -e wemos
platformio device monitor --baud 115200

How to use

The device will create a new network so for a once time setup you need to have your computer or mobile phone connect to this network and congirue the wifi.

Wifi Config Menu

If you did monitor your device it will show you the IP address of the access point.

While you are at it go to the setup page to tell setup the location and protocol to send data to. You can also calibrate the MPU (Motion Processing Unit). Read the instructions carefully!

Calibration menu

  • FreePie protocol sends Yaw Pitch and Roll using the FreePie format. This has been tested with OpenTrack
  • OpenTrackUDP sends Yaw Pitch and Roll using a simple floar array. This has been tested with OpenTrack.

Where to put the MPU

I have designed a little box that can be printed using a 3D printer. It´s a bit tricky to print but it will work out if you put up some support material. The STL file (mpu6050_holder.stl) is included. Then I have sewed it on a baseball cap. I´s very light and you will hardly fill it.

Holder for MPU6050 menu

The ESP8266 can be put in a other box and you can connect the MPU6050 and ESP8266 using a 5 wire shielded cable. Make sure it´s not longer than 1.5 to 2 meter (I have tested 1.5m) otherwhise I2C communication mght fail.

calibration and zero

Within the setup page there is a tool to setup calibration and setting 'zero' orientation. Calibration of the mpu9250 is unfortunatly more than tricky, but if you have questions please ask.

TODO

  • guide trought calibration for imu's
  • show calibration values on UI + quality of qualibration (mpu 9250)
  • add more IMU's like the ICM-20948
  • code cleanup, this was somewhat hacked together to create a MVP
  • add more output protocols.

headtracker's People

Contributors

jancis avatar rvt avatar vmasdani avatar zhaosn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

headtracker's Issues

Failed compiling due to fatal error in jscript.generated.h

Hello, I'm still new to VSC and platformIO environment. I was trying to compile this code, but it seems I have hit a roadblock here.
Before this, I got an error due to https://github.com/tzapu/WiFiManager#development but this problem is fixed by changing the URL. However, for this case I don't know what to do. Help will be appreciated :)

`> Executing task: C:\Users\skyguardian.platformio\penv\Scripts\platformio.exe run <

Processing wemos (platform: espressif8266; framework: arduino; board: esp01_1m)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/esp01_1m.html
PLATFORM: Espressif 8266 (3.2.0) > Espressif Generic ESP8266 ESP-01 1M
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
PACKAGES:

  • framework-arduinoespressif8266 3.30002.0 (3.0.2)
  • tool-esptool 1.413.0 (4.13)
  • tool-esptoolpy 1.30000.201119 (3.0.0)
  • toolchain-xtensa 2.100300.210717 (10.3.0)
    LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 43 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- 0.0.0-alpha+sha.fbde122cc5
    | |-- 0.0.0-alpha+sha.460d810002
    | | |-- 1.0
    |-- 1.3.2
    |-- 2.0.5-beta+sha.8452df7
    | |-- 1.1.1
    | | |-- 1.0
    | |-- 1.2
    | | |-- 1.0
    | |-- 1.0
    | | |-- 1.0
    | |-- 1.0
    |-- 6.18.5
    |--
    | |-- 6.18.5
    |--
    | |-- 6.18.5
    | |--
    | | |-- 6.18.5
    |--
    | |-- 1.0
    | |-- 6.18.5
    | |--
    | | |-- 6.18.5
    |-- 1.0
    Building in release mode
    Compiling .pio\build\wemos\src\main.cpp.o
    Compiling .pio\build\wemos\liba83\ESP8266WiFi\ESP8266WiFiSTA-WPS.cpp.o
    Compiling .pio\build\wemos\liba83\ESP8266WiFi\ESP8266WiFiSTA.cpp.o
    Compiling .pio\build\wemos\liba83\ESP8266WiFi\ESP8266WiFiScan.cpp.o
    Compiling .pio\build\wemos\liba83\ESP8266WiFi\WiFiClient.cpp.o
    Compiling .pio\build\wemos\liba83\ESP8266WiFi\WiFiClientSecureBearSSL.cpp.o
    Compiling .pio\build\wemos\liba83\ESP8266WiFi\WiFiServer.cpp.o
    Compiling .pio\build\wemos\liba83\ESP8266WiFi\WiFiServerSecureBearSSL.cpp.o
    src\main.cpp:25:10: fatal error: jscript.generated.h: No such file or directory


25 | #include "jscript.generated.h"
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\wemos\src\main.cpp.o] Error 1
=========================================================================== [FAILED] Took 6.52 seconds ===========================================================================
The terminal process "C:\Users\skyguardian.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.
`

ArduinoJson Ver>6.20 causes compilation issues

main.cpp:112 result in

cannot bind non-const lvalue reference of type 'string&' to an rvalue of type 'string'

reference: https://arduinojson.org/v6/api/jsonvariant/as/

I tried for hours before I realized I should look here😂
Snipaste_2024-01-28_00-09-58

When I changed this line to "const char* tmp = json["tracker_server"].as<const char*>();" the problem was solved

I've made a similar headtracker before and found this much superior project only after doing so. I learned platformIO through this project while adapting my nodemcuv2, thanks to this project.
Also, generating html or js looks like it requires linux, which I found can now be generated and downloaded from Codespaces.

I'm using a translation program, so I apologize for the reading inconvenience!

how to build?

PS C:\Users\user\Desktop\headtracker-master> .\generateHtmlArray.sh
PS C:\Users\user\Desktop\headtracker-master> platformio run --target upload -e wemos
platformio : The term 'platformio' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • platformio run --target upload -e wemos
  •   + CategoryInfo          : ObjectNotFound: (platformio:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

PS C:\Users\user\Desktop\headtracker-master>
PS C:\Users\user\Desktop\headtracker-master> platformio run --target upload -e wemos
platformio : The term 'platformio' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • platformio run --target upload -e wemos
  •   + CategoryInfo          : ObjectNotFound: (platformio:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    

shows MPU-9250 connected.. but no YPR info showing

I have uploaded the sketch, and connected to wifi, accessing the setup pages. Under tracker yaw , pitch and roll all show 0degrees. When I click calibrate the webpage says "Unknown error" but the Serial Monitor goes through the calibration, leaving on flat surface then waving in figure 8.
I am using a Wemos d1 r1 mini https://miro.medium.com/max/2576/1*YKc8KpAfMrlhrOLmNjdRwQ.png and mpu 9250
pins are wired as such
wemos ----- mpu9250
GND ---- GND
3.3v --- VCC
D1 ---- SCL
D2 --- SDA

I wasnt sure if the INT pin was needed but doesnt look like it. I also tried opening up opentrack but still there no data looks like it was being sent as it stayed at 0 for all YPR. I couldnt find a good place to try and debug and possible Serial print the data from the mpu.

Appreciate any help, this project is exactly what i started to try and do myself, but came across this and was way more put together than what I had.
here are a few pictures of the webpage
https://i.imgur.com/QK052Dx.png
https://i.imgur.com/8nK548w.png
here is the serial monitor output.

*WM: [2] Connection result: WL_CONNECTED

*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] AutoConnect: SUCCESS
*WM: [1] STA IP Address: 10.10.11.234
connected...yeey :)
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 
*WM: [2] HTTP server started
*WM: [2] WiFi Scan completed in 2194 ms
mounted file system
reading config file
opened config file
{
  "tracker_server": "10.10.10.165",
  "tracker_port": "5555",
  "tracker_protocol": "freepie",
  "mpu9250": {
    "AB0": -0.112976,
    "AB1": -0.224731,
    "AB2": -0.070923,
    "GB0": -1.427481,
    "GB1": 1.961832,
    "GB2": 2.908397,
    "MB0": -257.3269,
    "MB1": 143.7481,
    "MB2": 187.0547,
    "MS0": 1.001961,
    "MS1": 0.887153,
    "MS2": 1.143177
  },
  "zero": {
    "yaw": 0,
    "pitch": 0,
    "roll": 0,
    "x": 0,
    "y": 0,
    "z": 0
  }
}has tracker location
Initializing MPU9250...
Scanning...
I2C device found at address 0x68  !
done

MPU9250 9-axis motion sensor...
MPU9250 is online...
x-axis self test: acceleration trim within : 1.0% of factory value
y-axis self test: acceleration trim within : 1.1% of factory value
z-axis self test: acceleration trim within : 1.6% of factory value
x-axis self test: gyration trim within : 8.7% of factory value
y-axis self test: gyration trim within : 11.1% of factory value
z-axis self test: gyration trim within : 1.0% of factory value
Using saved calibration.
MPU9250 initialized for active data mode....
AK8963 I AM 48 I should be 48
AK8963 initialized for active data mode....
DMP Ready!*WM: [2] <- HTTP Root
*WM: [3] -> 10.10.11.234
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [2] WiFi Scan completed in 2195 ms
*WM: [2] <- HTTP Param 
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [3] Sent param page 
About to start calibrating gyro and accelerator, keep device flat and still!!!
Starting....
Finnished in 0.4 seconds
About to start calibrating magnetic compass, Wave device in a figure eight until done!
Starting....
Mag Calibration: Wave device in a figure eight until done!
Mag Calibration done!
Finnished in 22.5 seconds
saving config

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 3656, room 16 
tail 8
chksum 0x0c
csum 0x0c
v9c56ed1f
~ld

 Starting
*WM: [3] allocating params bytes: 20
*WM: [2] Added Parameter:
*WM: [2] Added Parameter: track_server
*WM: [2] Added Parameter: track_port
*WM: [2] Added Parameter: track_protocol
*WM: [2] Added Parameter:
*WM: [1] <form action='/wifi'    method='get'><button>Configure WiFi</button></form><br/>
<form action='/0wifi'   method='get'><button>Configure WiFi (No Scan)</button></form><br/>
<form action='/info'    method='get'><button>Info</button></form><br/>
<form action='/param'   method='get'><button>Setup</button></form><br/>
<hr><br/><form action='/erase'   method='get'><button class='D'>Erase</button></form><br/>
<form action='/restart' method='get'><button>Restart</button></form><br/>

*WM: [1] AutoConnect
*WM: [2] esp_wifi_set_country: US
*WM: [2] Connecting as wifi client...
*WM: [3] STA static IP:
*WM: [2] setSTAConfig static ip not set, skipping
*WM: [1] Connecting to SAVED AP: OHS_WiFi
*WM: [3] Using Password: 0rangut@n
*WM: [3] WiFi station enable
*WM: [3] enableSTA PERSISTENT ON
*WM: [1] connectTimeout not set, ESP waitForConnectResult...
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] AutoConnect: SUCCESS
*WM: [1] STA IP Address: 10.10.11.234
connected...yeey :)
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 
*WM: [2] HTTP server started
*WM: [2] WiFi Scan completed in 2193 ms
mounted file system
reading config file
opened config file
{
  "tracker_server": "10.10.10.165",
  "tracker_port": "5555",
  "tracker_protocol": "freepie",
  "mpu9250": {
    "AB0": -1.142944,
    "AB1": -0.092163,
    "AB2": -0.892395,
    "GB0": 0.099237,
    "GB1": 0.717557,
    "GB2": 1.229008,
    "MB0": 21.29602,
    "MB1": 944.123,
    "MB2": 125.2752,
    "MS0": 1.102136,
    "MS1": 0.621141,
    "MS2": 2.071553
  },
  "zero": {
    "yaw": 0,
    "pitch": 0,
    "roll": 0,
    "x": 0,
    "y": 0,
    "z": 0
  }
}has tracker location
Initializing MPU9250...
Scanning...
I2C device found at address 0x0C  !
I2C device found at address 0x68  !
done

MPU9250 9-axis motion sensor...
MPU9250 is online...
x-axis self test: acceleration trim within : 1.9% of factory value
y-axis self test: acceleration trim within : 0.3% of factory value
z-axis self test: acceleration trim within : 1.2% of factory value
x-axis self test: gyration trim within : 8.6% of factory value
y-axis self test: gyration trim within : 11.2% of factory value
z-axis self test: gyration trim within : 0.7% of factory value
Using saved calibration.
MPU9250 initialized for active data mode....
AK8963 I AM 48 I should be 48
AK8963 initialized for active data mode....
DMP Ready!

problem compiling

Hello! can you help me compile this? i have instaled and reinstaled vscode & platformio but without any improvements. Can you help me a bit with this?

calibration and zero do not work properly, calibration lead to crash(or wdt?)

calibration and zero do not work properly, the calibration problem can be solved inelegantly by changing the if in line 231 to always true. But "TRACK_PEEK_URI" always 0, so the zero button is useless.

change

if (hwTrack->isReady()) {
            doCalibrate = true;

to

 if (1) {
            doCalibrate = true;

or something seems crash when hit calibrate button in browser.

 Starting
*wm:AutoConnect
*wm:No wifi saved, skipping
*wm:AutoConnect: FAILED for  1 ms
*wm:StartAP with SSID:  WM_AutoConnectAP
*wm:AP IP address: 192.168.4.1
*wm:Starting Web Portal

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (28):
epc1=0x40205493 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffc30 end: 3fffffd0 offset: 0190
3ffffdc0:  4020f301 00000030 00000010 00000000
3ffffdd0:  0023002f 00000000 00000000 000f000f  
3ffffde0:  00000000 00000000 00000000 fffffffe
3ffffdf0:  3fff29c4 3fff2b20 00000000 40212d58
3ffffe00:  3fff0fd8 00000000 00000000 00000000  
3ffffe10:  3fff0fd8 3fff29c4 3fff2adc 40204fe1
3ffffe20:  00000000 3fff29c4 3fff296c 4020ce60
3ffffe30:  00000001 00000000 00000000 0023002f
3ffffe40:  00000000 00000000 3ffea4b4 3fff29a0  
3ffffe50:  00000000 00006e44 00000000 00000001
3ffffe60:  3fff0fd8 3fff29a0 00000000 00000000
3ffffe70:  3fff0fd8 3fff29a0 3fff296c 4020f096  
3ffffe80:  40220c14 00000000 00001388 40207322
3ffffe90:  3fff0fd8 3fff0fd8 3fff32d4 4021dc2b
3ffffea0:  3fff0fd8 00000000 402139be 00000000
3ffffeb0:  3fff0fd8 3fff0fd8 3fff0ed8 4020f301  
3ffffec0:  00303231 3fffff0c 3fffff18 00000000
3ffffed0:  00000000 00000000 3ffea4b4 00000001
3ffffee0:  3fff0fd8 00000000 402139be 00000000  
3ffffef0:  3fff0fd8 00000001 3fff0ed8 4020f721
3fffff00:  00000000 73646e6f 00000000 00000000
3fffff10:  000b000f 00000000 00000000 000b000f
3fffff20:  00000000 00000000 3fff0ed8 3fff0e84  
3fffff30:  3ffea8de 00000000 00000001 4020b920
3fffff40:  00000000 00000000 00000000 3fff0e84
3fffff50:  3fff0e68 3fff133c 3fff0ed8 40204d82  
3fffff60:  40201d54 3ffea6ed 4021fa10 4021fa08
3fffff70:  3ffea703 3ffea707 3ffea70d 3fff259c
3fffff80:  3fff25b8 3fff25b8 feefeffe feefeffe  
3fffff90:  3fff25b8 00000000 feefeffe feefeffe
3fffffa0:  feefeffe feefeffe feefeffe 3fff14c8
3fffffb0:  3fffdad0 00000000 3fff149c 40213b40
3fffffc0:  feefeffe feefeffe 3fffdab0 4010126d  
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3424, room 16
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8
tail 0
chksum 0x2b
csum 0x2b
v00069120
~ld

 Starting
*wm:AutoConnect
*wm:No wifi saved, skipping
*wm:AutoConnect: FAILED for  1 ms
*wm:StartAP with SSID:  WM_AutoConnectAP
*wm:AP IP address: 192.168.4.1
*wm:Starting Web Portal
Snipaste_2024-01-28_22-54-35 The correct setup process is to set the computer's IP address and port in this screen before setting up the AP, is that right? Because I can't get in this setup screen after connecting the ap (browser input 192.168.1.*). I can now get stable output after modifying it according to the above, but this strange crash is confusing me, the problem seems to be in the "hwTrack->isReady()", the doCalibrate and calibrateMpu() functions not causing the problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.