Simple piece of code for simulation sensor inputs of a hoverboard to do basic control of wheels.

Dependencies:   WiiNunchuck mbed-dev

This program is inspired by this site:

http://drewspewsmuse.blogspot.co.at/2016/06/how-i-hacked-self-balancing-scooter.html

Here you can get more information of the protocol revervse engineering.

This program uses a Wii nunchuk connected over I2C to controll the speed. Speed is controlled by a closed loop P controller. Feedback is done by counting HALL events from the brushless motor. Some more pictures are available here:

https://github.com/tyler123durden/hoverboard-hardware

Basically you need a serial TX and 3 HALL IRQs per motor side.

Wiring of the board. Gyro boards are not used, input is generated from nucleo board. Motor board has still the HALL connections. Nucleo board just also reads HALL inputs to get speed information for closed loop controll.

/media/uploads/Thomas_H/wiring.jpg

Revision:
0:fe156910301e
Child:
1:5acd27cb1857
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HallDecoder.cpp	Thu Oct 13 08:57:49 2016 +0000
@@ -0,0 +1,65 @@
+#include "HallDecoder.h"
+
+
+HallDecoder::HallDecoder(PinName pin1, PinName pin2, PinName pin3) : _int1(pin1), _int2(pin2), _int3(pin3)
+{
+    _lastint = 0;
+    _ticks = 0;
+    _int1.rise(this, &HallDecoder::hall1_handler);
+    _int1.fall(this, &HallDecoder::hall1_handler);
+    _int2.rise(this, &HallDecoder::hall2_handler);
+    _int2.fall(this, &HallDecoder::hall2_handler);
+    _int3.rise(this, &HallDecoder::hall3_handler);
+    _int3.fall(this, &HallDecoder::hall3_handler);
+}
+
+
+void HallDecoder::hall1_handler()
+{
+    if(_lastint == 2) {
+        _ticks++;
+    } else if(_lastint == 3) {
+        _ticks--;
+    }
+    _lastint = 1;
+}
+
+void HallDecoder::hall2_handler()
+{
+    if(_lastint == 3) {
+        _ticks++;
+    } else if(_lastint == 1) {
+        _ticks--;
+    }
+    _lastint = 2;
+}
+
+void HallDecoder::hall3_handler()
+{
+    if(_lastint == 1) {
+        _ticks++;
+    } else if(_lastint == 2) {
+        _ticks--;
+    }
+    _lastint = 3;
+}
+
+HallDecoder::~HallDecoder()
+{
+
+}
+
+int32_t HallDecoder::getticks()
+{
+    return _ticks;
+}
+void HallDecoder::resetticks()
+{
+    _int1.disable_irq();
+    _int2.disable_irq();
+    _int3.disable_irq();
+    _ticks = 0;
+    _int1.enable_irq();
+    _int2.enable_irq();
+    _int3.enable_irq();
+}