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:35:14 2016 +0000
Revision:
1:5acd27cb1857
Initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Thomas_H 1:5acd27cb1857 1 #include "utils.h"
Thomas_H 1:5acd27cb1857 2
Thomas_H 1:5acd27cb1857 3 /*****************************************************************************
Thomas_H 1:5acd27cb1857 4 * name: crc16_ansi
Thomas_H 1:5acd27cb1857 5
Thomas_H 1:5acd27cb1857 6 * parameters: - message length in byte
Thomas_H 1:5acd27cb1857 7 * - pointer to message start
Thomas_H 1:5acd27cb1857 8 * - crc preload value (start value = 0xFFFF, for the jacksum CRC16 implementation start=0)
Thomas_H 1:5acd27cb1857 9 * return: - crc value
Thomas_H 1:5acd27cb1857 10 * description: calculates the CRC16 ANSI checksum of a buffer.
Thomas_H 1:5acd27cb1857 11 * Implemented as a reverse calculation (Bitorder). So 0xA001 used as
Thomas_H 1:5acd27cb1857 12 * polynom which is the reversed 0x8005 ANSI polynom, g(x) = x^15 + x^2 + 1
Thomas_H 1:5acd27cb1857 13 *****************************************************************************/
Thomas_H 1:5acd27cb1857 14 uint16_t crc16_ansi_rev(uint32_t pa_nLen, const uint8_t* pa_pnData, uint16_t pa_nStart)
Thomas_H 1:5acd27cb1857 15 {
Thomas_H 1:5acd27cb1857 16 #define CRC16_ANSI_REVERSED_POL 0xA001
Thomas_H 1:5acd27cb1857 17
Thomas_H 1:5acd27cb1857 18 uint8_t i;
Thomas_H 1:5acd27cb1857 19 uint32_t k;
Thomas_H 1:5acd27cb1857 20
Thomas_H 1:5acd27cb1857 21 for(k=0; k<pa_nLen; k++) {
Thomas_H 1:5acd27cb1857 22 pa_nStart ^= pa_pnData[k];
Thomas_H 1:5acd27cb1857 23 for (i = 0; i < 8; ++i) {
Thomas_H 1:5acd27cb1857 24 if (pa_nStart & 1) {
Thomas_H 1:5acd27cb1857 25 pa_nStart = (pa_nStart >> 1) ^ CRC16_ANSI_REVERSED_POL;
Thomas_H 1:5acd27cb1857 26 } else {
Thomas_H 1:5acd27cb1857 27 pa_nStart = (pa_nStart >> 1);
Thomas_H 1:5acd27cb1857 28 }
Thomas_H 1:5acd27cb1857 29 }
Thomas_H 1:5acd27cb1857 30 }
Thomas_H 1:5acd27cb1857 31 return pa_nStart;
Thomas_H 1:5acd27cb1857 32 }