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.
Revision 2:6e0dfe2caf48, committed 2016-10-23
- Comitter:
- Thomas_H
- Date:
- Sun Oct 23 19:38:35 2016 +0000
- Parent:
- 1:5acd27cb1857
- Commit message:
- removed unused files
Changed in this revision
utils.cpp | Show diff for this revision Revisions of this file |
utils.h | Show diff for this revision Revisions of this file |
--- a/utils.cpp Sun Oct 23 19:35:14 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -#include "utils.h" - -/***************************************************************************** -* name: crc16_ansi - -* parameters: - message length in byte -* - pointer to message start -* - crc preload value (start value = 0xFFFF, for the jacksum CRC16 implementation start=0) -* return: - crc value -* description: calculates the CRC16 ANSI checksum of a buffer. -* Implemented as a reverse calculation (Bitorder). So 0xA001 used as -* polynom which is the reversed 0x8005 ANSI polynom, g(x) = x^15 + x^2 + 1 -*****************************************************************************/ -uint16_t crc16_ansi_rev(uint32_t pa_nLen, const uint8_t* pa_pnData, uint16_t pa_nStart) -{ - #define CRC16_ANSI_REVERSED_POL 0xA001 - - uint8_t i; - uint32_t k; - - for(k=0; k<pa_nLen; k++) { - pa_nStart ^= pa_pnData[k]; - for (i = 0; i < 8; ++i) { - if (pa_nStart & 1) { - pa_nStart = (pa_nStart >> 1) ^ CRC16_ANSI_REVERSED_POL; - } else { - pa_nStart = (pa_nStart >> 1); - } - } - } - return pa_nStart; -} \ No newline at end of file
--- a/utils.h Sun Oct 23 19:35:14 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef UTILS_H -#define UTILS_H - -#include "mbed.h" -uint16_t crc16_ansi_rev(uint32_t pa_nLen, const uint8_t* pa_pnData, uint16_t pa_nStart); - -#endif \ No newline at end of file