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

Committer:
Thomas_H
Date:
Sun Oct 23 19:38:35 2016 +0000
Revision:
2:6e0dfe2caf48
Parent:
1:5acd27cb1857
removed unused files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Thomas_H 0:fe156910301e 1 #include "HallDecoder.h"
Thomas_H 0:fe156910301e 2
Thomas_H 0:fe156910301e 3
Thomas_H 0:fe156910301e 4 HallDecoder::HallDecoder(PinName pin1, PinName pin2, PinName pin3) : _int1(pin1), _int2(pin2), _int3(pin3)
Thomas_H 0:fe156910301e 5 {
Thomas_H 0:fe156910301e 6 _lastint = 0;
Thomas_H 0:fe156910301e 7 _ticks = 0;
Thomas_H 0:fe156910301e 8 _int1.rise(this, &HallDecoder::hall1_handler);
Thomas_H 0:fe156910301e 9 _int1.fall(this, &HallDecoder::hall1_handler);
Thomas_H 0:fe156910301e 10 _int2.rise(this, &HallDecoder::hall2_handler);
Thomas_H 0:fe156910301e 11 _int2.fall(this, &HallDecoder::hall2_handler);
Thomas_H 0:fe156910301e 12 _int3.rise(this, &HallDecoder::hall3_handler);
Thomas_H 0:fe156910301e 13 _int3.fall(this, &HallDecoder::hall3_handler);
Thomas_H 0:fe156910301e 14 }
Thomas_H 0:fe156910301e 15
Thomas_H 0:fe156910301e 16
Thomas_H 0:fe156910301e 17 void HallDecoder::hall1_handler()
Thomas_H 0:fe156910301e 18 {
Thomas_H 0:fe156910301e 19 if(_lastint == 2) {
Thomas_H 0:fe156910301e 20 _ticks++;
Thomas_H 0:fe156910301e 21 } else if(_lastint == 3) {
Thomas_H 0:fe156910301e 22 _ticks--;
Thomas_H 0:fe156910301e 23 }
Thomas_H 0:fe156910301e 24 _lastint = 1;
Thomas_H 0:fe156910301e 25 }
Thomas_H 0:fe156910301e 26
Thomas_H 0:fe156910301e 27 void HallDecoder::hall2_handler()
Thomas_H 0:fe156910301e 28 {
Thomas_H 0:fe156910301e 29 if(_lastint == 3) {
Thomas_H 0:fe156910301e 30 _ticks++;
Thomas_H 0:fe156910301e 31 } else if(_lastint == 1) {
Thomas_H 0:fe156910301e 32 _ticks--;
Thomas_H 0:fe156910301e 33 }
Thomas_H 0:fe156910301e 34 _lastint = 2;
Thomas_H 0:fe156910301e 35 }
Thomas_H 0:fe156910301e 36
Thomas_H 0:fe156910301e 37 void HallDecoder::hall3_handler()
Thomas_H 0:fe156910301e 38 {
Thomas_H 0:fe156910301e 39 if(_lastint == 1) {
Thomas_H 0:fe156910301e 40 _ticks++;
Thomas_H 0:fe156910301e 41 } else if(_lastint == 2) {
Thomas_H 0:fe156910301e 42 _ticks--;
Thomas_H 0:fe156910301e 43 }
Thomas_H 0:fe156910301e 44 _lastint = 3;
Thomas_H 0:fe156910301e 45 }
Thomas_H 0:fe156910301e 46
Thomas_H 0:fe156910301e 47
Thomas_H 0:fe156910301e 48 int32_t HallDecoder::getticks()
Thomas_H 0:fe156910301e 49 {
Thomas_H 0:fe156910301e 50 return _ticks;
Thomas_H 0:fe156910301e 51 }
Thomas_H 0:fe156910301e 52 void HallDecoder::resetticks()
Thomas_H 0:fe156910301e 53 {
Thomas_H 0:fe156910301e 54 _ticks = 0;
Thomas_H 0:fe156910301e 55 }