Add Xbox controller support
I recently started building a balancing bot of my own when I came across your project. You are clearly farther along than I am - I'm still tuning the parameters to my Kalman filter to get it to balance properly. I like your idea to use a web interface to tune those in real time and am adding that to my project now. Thank you for the great idea.
In the attached file, I have added code to your balancing robot that supports using an Xbox controller to drive the robot. Note, while this code compiles, I haven't built your physical robot so can't ensure it actually works correctly. I believe I have mapped the Ps3 buttons to the similarly located Xbox buttons based on images from the web. I have used very similar code in my own balancing robot, just not with yours. Sorry for the gitdiff - I'm unfamiliar with gitlab (I use github) and haven't been able to figure out how to submit a merge request.
I submit it for consideration in case there are others who have an Xbox controller instead of a PS3 controller. While, like the Ps3 controller, it adds to the image size significantly (I suspect most of that is the BLE stack) it is about 400K less than the PS3 controller (see below for details) so may fit better in your project and free up space for more features (like restoring the OTA capability).
Have you considered using a variable trigger button on the controller to control the speed? It seems to me that would be a much smoother and easier way to drive the bot. It's pretty trivial to calculate the percentage the trigger is pressed and use that to control the speed. I also intend (but have yet to implement) using an analog joystick to drive the bot. Seems like it would make for an easier driving experience - just push the stick in the direction you want to go.
Thanks and good luck!
Ben Peart
p.s. platform.ini needs to have the xbox controller library added:
platform.ini
asukiaaa/XboxSeriesXControllerESP32_asukiaaa@^1.0.9
WO/PS3 controller
Calculating size .pio\build\esp32doit-devkit-v1\firmware.elf
text data bss dec hex filesize filename
697378 238808 30128 966314 ebeaa 13304384 .pio\build\esp32doit-devkit-v1\firmware.elf
W/PS3 controller
Calculating size .pio\build\esp32doit-devkit-v1\firmware.elf
text data bss dec hex filesize filename
1259510 284520 41232 1585262 18306e 17643508 .pio\build\esp32doit-devkit-v1\firmware.elf
W/Xbox controller
text data bss dec hex filesize filename
903310 281556 37880 1222746 12a85a 17244856 .pio\build\esp32doit-devkit-v1\firmware.elf
=================================================================
PS3 Difference
==================================================================================
text data bss dec hex filesize
562132 45712 11104 618948 971c4 4339124
==================================================================================
Xbox Difference
==================================================================================
text data bss dec hex filesize
205932 42748 7752 256432 3beb8 3940472
==================================================================================
PS3 Vs Xbox Difference
==================================================================================
text data bss dec hex filesize
356200 2964 3352 362516 58814 398652