From 9fdb6d75f5a5ec0cd0f3c31bd5fd77b2135b4b54 Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Sun, 1 Dec 2019 17:38:36 +0100 Subject: [PATCH 1/3] Fixed checksum Fixed a bug when requesting negative speed in the checksum calculation due to data type. --- Src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/main.c b/Src/main.c index 8c3b85a..368b7d5 100644 --- a/Src/main.c +++ b/Src/main.c @@ -322,7 +322,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 == (uint16_t)(command.start ^ command.steer ^ command.speed)) { if (timeoutFlag) { // Check for previous timeout flag if (timeoutCnt-- <= 0) // Timeout de-qualification timeoutFlag = 0; // Timeout flag cleared From 249d93932e3e23e8f08adef1d7fd471a383fe8d0 Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Sun, 1 Dec 2019 17:46:48 +0100 Subject: [PATCH 2/3] Fixed checksum Fixed a bug when requesting negative speed in the checksum calculation due to data type. --- 02_Arduino/hoverserial/hoverserial.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) { From 6e4405c19cbe3da2c742a3700b45e39ae6e9455e Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Sun, 1 Dec 2019 18:19:59 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) 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