diff --git a/02_Arduino/hoverserial/hoverserial.ino b/02_Arduino/hoverserial/hoverserial.ino index ba63ad9..d6908c3 100644 --- a/02_Arduino/hoverserial/hoverserial.ino +++ b/02_Arduino/hoverserial/hoverserial.ino @@ -91,8 +91,8 @@ void Receive() { // Check for new data availability in the Serial buffer if (HoverSerial.available()) { - incomingByte = HoverSerial.read(); // Read the incoming byte - bufStartFrame = ((uint16_t)(incomingBytePrev) << 8) + incomingByte; // Construct the start marker + incomingByte = HoverSerial.read(); // Read the incoming byte + bufStartFrame = ((uint16_t)(incomingBytePrev) << 8) + incomingByte; // Construct the start frame } else { return; @@ -118,8 +118,8 @@ void Receive() // Check if we reached the end of the package if (idx == sizeof(SerialFeedback)) { uint16_t checksum; - checksum = NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR ^ NewFeedback.speedL - ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp; + checksum = (uint16_t)(NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR ^ NewFeedback.speedL + ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp); // Check validity of the new data if (NewFeedback.start == START_FRAME && checksum == NewFeedback.checksum) { diff --git a/README.md b/README.md index 70f0dd4..519c8e2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # hoverboard-firmware-hack-FOC ## with Field Oriented Control (FOC) [![Build Status](https://travis-ci.com/EmanuelFeru/hoverboard-firmware-hack-FOC.svg?branch=master)](https://travis-ci.com/EmanuelFeru/hoverboard-firmware-hack-FOC) +[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=feru_emanuel%40yahoo.com¤cy_code=EUR&source=url) +***If you like this project, you can give me a cup of coffee. Thanks!*** This repository implements Field Oriented Control (FOC) for stock hoverboards. Compared to the commutation method, this new FOC control method offers superior performance featuring: - reduced noise and vibrations diff --git a/Src/main.c b/Src/main.c index 3f3b601..983888c 100644 --- a/Src/main.c +++ b/Src/main.c @@ -330,8 +330,7 @@ int main(void) { #if defined CONTROL_SERIAL_USART2 || defined CONTROL_SERIAL_USART3 // Handle received data validity, timeout and fix out-of-sync if necessary - //if (command.start == START_FRAME && command.checksum == (command.start ^ command.steer ^ command.speed)) { - if (command.start == START_FRAME && command.checksum == (command.start ^ command.speedLeft ^ command.speedRight)) { + if (command.start == START_FRAME && command.checksum == (uint16_t)(command.start ^ command.speedLeft ^ command.speedRight)) { if (timeoutFlag) { // Check for previous timeout flag if (timeoutCnt-- <= 0) // Timeout de-qualification timeoutFlag = 0; // Timeout flag cleared @@ -353,7 +352,7 @@ int main(void) { enable = 1; // enable motors consoleLog("-- Motors enabled --\r\n"); } - + } else { if (timeoutCnt++ >= SERIAL_TIMEOUT) { // Timeout qualification timeoutFlag = 1; // Timeout detected