merge with checksum fix
This commit is contained in:
commit
61b40e9526
|
@ -91,8 +91,8 @@ void Receive()
|
||||||
{
|
{
|
||||||
// Check for new data availability in the Serial buffer
|
// Check for new data availability in the Serial buffer
|
||||||
if (HoverSerial.available()) {
|
if (HoverSerial.available()) {
|
||||||
incomingByte = HoverSerial.read(); // Read the incoming byte
|
incomingByte = HoverSerial.read(); // Read the incoming byte
|
||||||
bufStartFrame = ((uint16_t)(incomingBytePrev) << 8) + incomingByte; // Construct the start marker
|
bufStartFrame = ((uint16_t)(incomingBytePrev) << 8) + incomingByte; // Construct the start frame
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
|
@ -118,8 +118,8 @@ void Receive()
|
||||||
// Check if we reached the end of the package
|
// Check if we reached the end of the package
|
||||||
if (idx == sizeof(SerialFeedback)) {
|
if (idx == sizeof(SerialFeedback)) {
|
||||||
uint16_t checksum;
|
uint16_t checksum;
|
||||||
checksum = NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR ^ NewFeedback.speedL
|
checksum = (uint16_t)(NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR ^ NewFeedback.speedL
|
||||||
^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp;
|
^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp);
|
||||||
|
|
||||||
// Check validity of the new data
|
// Check validity of the new data
|
||||||
if (NewFeedback.start == START_FRAME && checksum == NewFeedback.checksum) {
|
if (NewFeedback.start == START_FRAME && checksum == NewFeedback.checksum) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# hoverboard-firmware-hack-FOC
|
# hoverboard-firmware-hack-FOC
|
||||||
## with Field Oriented Control (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)
|
[![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:
|
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
|
- reduced noise and vibrations
|
||||||
|
|
|
@ -330,8 +330,7 @@ int main(void) {
|
||||||
#if defined CONTROL_SERIAL_USART2 || defined CONTROL_SERIAL_USART3
|
#if defined CONTROL_SERIAL_USART2 || defined CONTROL_SERIAL_USART3
|
||||||
|
|
||||||
// Handle received data validity, timeout and fix out-of-sync if necessary
|
// 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.speedLeft ^ command.speedRight)) {
|
||||||
if (command.start == START_FRAME && command.checksum == (command.start ^ command.speedLeft ^ command.speedRight)) {
|
|
||||||
if (timeoutFlag) { // Check for previous timeout flag
|
if (timeoutFlag) { // Check for previous timeout flag
|
||||||
if (timeoutCnt-- <= 0) // Timeout de-qualification
|
if (timeoutCnt-- <= 0) // Timeout de-qualification
|
||||||
timeoutFlag = 0; // Timeout flag cleared
|
timeoutFlag = 0; // Timeout flag cleared
|
||||||
|
@ -353,7 +352,7 @@ int main(void) {
|
||||||
enable = 1; // enable motors
|
enable = 1; // enable motors
|
||||||
consoleLog("-- Motors enabled --\r\n");
|
consoleLog("-- Motors enabled --\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (timeoutCnt++ >= SERIAL_TIMEOUT) { // Timeout qualification
|
if (timeoutCnt++ >= SERIAL_TIMEOUT) { // Timeout qualification
|
||||||
timeoutFlag = 1; // Timeout detected
|
timeoutFlag = 1; // Timeout detected
|
||||||
|
|
Loading…
Reference in New Issue