mirror of
https://github.com/EFeru/hoverboard-sideboard-hack-GD.git
synced 2025-07-27 09:39:33 +00:00
Improved UART Timeout
Major: - Improved UART Timeout: Apparently, the UART data Rx/Tx is quite unreliable (especially under motor load) leading to very often out-of-sync issues. This change allows to reset the DMA more often, leading to a faster re-sync of the UART transmission and thus avoiding UART timeout Minor: - added #define MPU_SENSOR_ENABLE to allow to enable/disable the MPU6050 sensor and save code size if the sensors is not needed - fixed the orientation in the Processing sketch - updated ReadMe
This commit is contained in:
parent
c703b30930
commit
e9d74bea29
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* ==================================== SETTINGS MPU-6050 ==================================== */
|
/* ==================================== SETTINGS MPU-6050 ==================================== */
|
||||||
|
#define MPU_SENSOR_ENABLE // [-] Enable flag for MPU-6050 sensor. Comment-out this flag to Disable the MPU sensor and reduce code size.
|
||||||
#define MPU_DMP_ENABLE // [-] Enable flag for MPU-6050 DMP (Digital Motion Processing) functionality.
|
#define MPU_DMP_ENABLE // [-] Enable flag for MPU-6050 DMP (Digital Motion Processing) functionality.
|
||||||
#define MPU_DEFAULT_HZ 20 // [Hz] Default MPU frequecy: must be between 1Hz and 200Hz.
|
#define MPU_DEFAULT_HZ 20 // [Hz] Default MPU frequecy: must be between 1Hz and 200Hz.
|
||||||
#define TEMP_READ_MS 500 // [ms] Temperature read time interval
|
#define TEMP_READ_MS 500 // [ms] Temperature read time interval
|
||||||
@ -68,7 +69,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#define USART_MAIN_BAUD 38400 // [bit/s] MAIN Serial Tx/Rx baud rate
|
#define USART_MAIN_BAUD 38400 // [bit/s] MAIN Serial Tx/Rx baud rate
|
||||||
#define SERIAL_START_FRAME 0xABCD // [-] Start frame definition for reliable serial communication
|
#define SERIAL_START_FRAME 0xABCD // [-] Start frame definition for reliable serial communication
|
||||||
#define SERIAL_TIMEOUT 500 // [-] Numer of wrong received data for Serial timeout detection
|
#define SERIAL_TIMEOUT 800 // [-] Numer of wrong received data for Serial timeout detection
|
||||||
|
|
||||||
|
|
||||||
/* ==================================== SETTINGS AUX ==================================== */
|
/* ==================================== SETTINGS AUX ==================================== */
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
// Define to prevent recursive inclusion
|
// Define to prevent recursive inclusion
|
||||||
#ifndef MPU6050_H
|
#ifndef MPU6050_H
|
||||||
#define MPU6050_H
|
#define MPU6050_H
|
||||||
|
#ifdef MPU_SENSOR_ENABLE
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
@ -142,5 +143,5 @@ void mpu_android_orient_func(unsigned char orientation);
|
|||||||
void mpu_handle_input(char c);
|
void mpu_handle_input(char c);
|
||||||
void mpu_print_to_console(void);
|
void mpu_print_to_console(void);
|
||||||
|
|
||||||
|
#endif // MPU_SENSOR_ENABLE
|
||||||
#endif
|
#endif // MPU6050_H
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
// Define to prevent recursive inclusion
|
// Define to prevent recursive inclusion
|
||||||
#ifndef MPU6050_DMP_H
|
#ifndef MPU6050_DMP_H
|
||||||
#define MPU6050_DMP_H
|
#define MPU6050_DMP_H
|
||||||
|
#ifdef MPU_SENSOR_ENABLE
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -102,6 +103,6 @@ int dmp_enable_gyro_cal(unsigned char enable);
|
|||||||
int dmp_read_fifo(short *gyro, short *accel, long *quat,
|
int dmp_read_fifo(short *gyro, short *accel, long *quat,
|
||||||
unsigned long *timestamp, short *sensors, unsigned char *more);
|
unsigned long *timestamp, short *sensors, unsigned char *more);
|
||||||
|
|
||||||
|
#endif // MPU_SENSOR_ENABLE
|
||||||
#endif
|
#endif // MPU6050_DMP_H
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef DMPKEY_H__
|
#ifndef DMPKEY_H__
|
||||||
#define DMPKEY_H__
|
#define DMPKEY_H__
|
||||||
|
#ifdef MPU_SENSOR_ENABLE
|
||||||
|
|
||||||
|
|
||||||
#define KEY_CFG_25 (0)
|
#define KEY_CFG_25 (0)
|
||||||
@ -491,5 +492,5 @@ typedef struct {
|
|||||||
#define DINBC6 0xc6
|
#define DINBC6 0xc6
|
||||||
|
|
||||||
|
|
||||||
|
#endif // MPU_SENSOR_ENABLE
|
||||||
#endif // DMPKEY_H__
|
#endif // DMPKEY_H__
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef DMPMAP_H
|
#ifndef DMPMAP_H
|
||||||
#define DMPMAP_H
|
#define DMPMAP_H
|
||||||
|
#ifdef MPU_SENSOR_ENABLE
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -261,4 +262,6 @@ extern "C"
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif // MPU_SENSOR_ENABLE
|
||||||
#endif // DMPMAP_H
|
#endif // DMPMAP_H
|
||||||
|
11
README.md
11
README.md
@ -43,7 +43,7 @@ If you have never flashed your sideboard before, the MCU is probably locked. To
|
|||||||
|
|
||||||
To build and flash choose one of the following methods:
|
To build and flash choose one of the following methods:
|
||||||
|
|
||||||
### Method 1: Using PlatformIO
|
### Method 1: Using Platformio IDE
|
||||||
|
|
||||||
Because the [GD32F130C6T6](/docs/GD32F130xx-Datasheet_Rev3.3.pdf) is not yet supported by [PlatformIO](https://platformio.org/), we have to make two extra steps. These steps can be skipped once the board is supported (see [this thread](https://community.platformio.org/t/build-gd32-project-with-platformio/11944)).
|
Because the [GD32F130C6T6](/docs/GD32F130xx-Datasheet_Rev3.3.pdf) is not yet supported by [PlatformIO](https://platformio.org/), we have to make two extra steps. These steps can be skipped once the board is supported (see [this thread](https://community.platformio.org/t/build-gd32-project-with-platformio/11944)).
|
||||||
|
|
||||||
@ -70,14 +70,17 @@ packages/
|
|||||||
- click Build Target (or press F7) to build the firmware
|
- click Build Target (or press F7) to build the firmware
|
||||||
- click Load Code (or press F8) to flash the firmware.
|
- click Load Code (or press F8) to flash the firmware.
|
||||||
|
|
||||||
### Method 3: Using Ubuntu
|
### Method 3: Using Linux CLI
|
||||||
|
|
||||||
- prerequisites: install [ST-Flash utility](https://github.com/texane/stlink).
|
- prerequisites: install [ST-Flash utility](https://github.com/texane/stlink).
|
||||||
|
- open a terminal in the repo check-out folder and if you have definded the variant in [config.h](/Inc/config.h) type:
|
||||||
- open a terminal in the repo check-out folder and type:
|
|
||||||
```
|
```
|
||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
or you can set the variant like this
|
||||||
|
```
|
||||||
|
make -e VARIANT=VARIANT_####
|
||||||
|
```
|
||||||
- flash the firmware by typing:
|
- flash the firmware by typing:
|
||||||
```
|
```
|
||||||
make flash
|
make flash
|
||||||
|
13
Src/main.c
13
Src/main.c
@ -86,6 +86,8 @@ int main(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
intro_demo_led(100); // Short LEDs intro demo with 100 ms delay. This also gives some time for the MPU-6050 to power-up.
|
intro_demo_led(100); // Short LEDs intro demo with 100 ms delay. This also gives some time for the MPU-6050 to power-up.
|
||||||
|
|
||||||
|
#ifdef MPU_SENSOR_ENABLE
|
||||||
if(mpu_config()) { // IMU MPU-6050 config
|
if(mpu_config()) { // IMU MPU-6050 config
|
||||||
mpuStatus = ERROR;
|
mpuStatus = ERROR;
|
||||||
gpio_bit_set(LED1_GPIO_Port, LED1_Pin); // Turn on RED LED
|
gpio_bit_set(LED1_GPIO_Port, LED1_Pin); // Turn on RED LED
|
||||||
@ -95,6 +97,9 @@ int main(void)
|
|||||||
gpio_bit_set(LED2_GPIO_Port, LED2_Pin); // Turn on GREEN LED
|
gpio_bit_set(LED2_GPIO_Port, LED2_Pin); // Turn on GREEN LED
|
||||||
}
|
}
|
||||||
mpu_handle_input('h'); // Print the User Help commands to serial
|
mpu_handle_input('h'); // Print the User Help commands to serial
|
||||||
|
#else
|
||||||
|
gpio_bit_set(LED2_GPIO_Port, LED2_Pin); // Turn on GREEN LED
|
||||||
|
#endif
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
||||||
@ -115,7 +120,7 @@ int main(void)
|
|||||||
|
|
||||||
|
|
||||||
// ==================================== USER Handling ====================================
|
// ==================================== USER Handling ====================================
|
||||||
#ifdef SERIAL_DEBUG
|
#if defined(MPU_SENSOR_ENABLE) && defined(SERIAL_DEBUG)
|
||||||
// Get the user Input as one character from Serial
|
// Get the user Input as one character from Serial
|
||||||
if(SET == usart_flag_get(USART_MAIN, USART_FLAG_RBNE)) { // Check if Read Buffer Not Empty meanind Serial data is available
|
if(SET == usart_flag_get(USART_MAIN, USART_FLAG_RBNE)) { // Check if Read Buffer Not Empty meanind Serial data is available
|
||||||
userCommand = usart_data_receive(USART_MAIN);
|
userCommand = usart_data_receive(USART_MAIN);
|
||||||
@ -128,6 +133,7 @@ int main(void)
|
|||||||
|
|
||||||
|
|
||||||
// ==================================== MPU-6050 Handling ====================================
|
// ==================================== MPU-6050 Handling ====================================
|
||||||
|
#ifdef MPU_SENSOR_ENABLE
|
||||||
// Get MPU data. Because the MPU-6050 interrupt pin is not wired we have to check DMP data by pooling periodically
|
// Get MPU data. Because the MPU-6050 interrupt pin is not wired we have to check DMP data by pooling periodically
|
||||||
if (SUCCESS == mpuStatus) {
|
if (SUCCESS == mpuStatus) {
|
||||||
mpu_get_data();
|
mpu_get_data();
|
||||||
@ -138,7 +144,7 @@ int main(void)
|
|||||||
if (main_loop_counter % 50 == 0) {
|
if (main_loop_counter % 50 == 0) {
|
||||||
mpu_print_to_console();
|
mpu_print_to_console();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// ==================================== SENSORS Handling ====================================
|
// ==================================== SENSORS Handling ====================================
|
||||||
sensor1_read = gpio_input_bit_get(SENSOR1_GPIO_Port, SENSOR1_Pin);
|
sensor1_read = gpio_input_bit_get(SENSOR1_GPIO_Port, SENSOR1_Pin);
|
||||||
@ -175,7 +181,6 @@ int main(void)
|
|||||||
// Sensor ACTIVE: Do something here (continuous task)
|
// Sensor ACTIVE: Do something here (continuous task)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================================== SERIAL Tx/Rx Handling ====================================
|
// ==================================== SERIAL Tx/Rx Handling ====================================
|
||||||
#ifdef SERIAL_CONTROL
|
#ifdef SERIAL_CONTROL
|
||||||
// To transmit on USART
|
// To transmit on USART
|
||||||
@ -213,7 +218,7 @@ int main(void)
|
|||||||
timeoutCntSerial = SERIAL_TIMEOUT; // Limit timout counter value
|
timeoutCntSerial = SERIAL_TIMEOUT; // Limit timout counter value
|
||||||
}
|
}
|
||||||
// Most probably we are out-of-sync. Try to re-sync by reseting the DMA
|
// Most probably we are out-of-sync. Try to re-sync by reseting the DMA
|
||||||
if (main_loop_counter % 150 == 0) {
|
if (NewFeedback.start != SERIAL_START_FRAME && NewFeedback.start != 0xFFFF && main_loop_counter % 5 == 0) {
|
||||||
dma_channel_disable(DMA_CH4);
|
dma_channel_disable(DMA_CH4);
|
||||||
usart_Rx_DMA_config(USART_MAIN, (uint8_t *)&NewFeedback, sizeof(NewFeedback));
|
usart_Rx_DMA_config(USART_MAIN, (uint8_t *)&NewFeedback, sizeof(NewFeedback));
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,9 @@
|
|||||||
* min(int a, int b)
|
* min(int a, int b)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
MPU_Data mpu; // holds the MPU-6050 data
|
||||||
|
|
||||||
|
#ifdef MPU_SENSOR_ENABLE
|
||||||
|
|
||||||
static signed char MPU_ORIENTATION[9] = {1, 0, 0, // [-] MPU Sensor orientation matrix: set this according to the sensor installation
|
static signed char MPU_ORIENTATION[9] = {1, 0, 0, // [-] MPU Sensor orientation matrix: set this according to the sensor installation
|
||||||
0, 1, 0,
|
0, 1, 0,
|
||||||
@ -3470,8 +3473,6 @@ int mpu_config(void)
|
|||||||
|
|
||||||
/* =========================== MPU-6050 Get Packet Data =========================== */
|
/* =========================== MPU-6050 Get Packet Data =========================== */
|
||||||
|
|
||||||
MPU_Data mpu;
|
|
||||||
|
|
||||||
void mpu_get_data(void)
|
void mpu_get_data(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -3953,5 +3954,5 @@ void mpu_print_to_console(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // MPU_SENSOR_ENABLE
|
||||||
|
|
||||||
|
@ -23,11 +23,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "systick.h"
|
#include "systick.h"
|
||||||
|
#include "config.h"
|
||||||
#include "mpu6050.h"
|
#include "mpu6050.h"
|
||||||
#include "mpu6050_dmp.h"
|
#include "mpu6050_dmp.h"
|
||||||
#include "mpu6050_dmpKey.h"
|
#include "mpu6050_dmpKey.h"
|
||||||
#include "mpu6050_dmpmap.h"
|
#include "mpu6050_dmpmap.h"
|
||||||
|
|
||||||
|
#ifdef MPU_SENSOR_ENABLE
|
||||||
|
|
||||||
/* The following functions must be defined for this platform:
|
/* The following functions must be defined for this platform:
|
||||||
* i2c_write(unsigned char slave_addr, unsigned char reg_addr,
|
* i2c_write(unsigned char slave_addr, unsigned char reg_addr,
|
||||||
@ -1329,6 +1331,8 @@ int dmp_register_android_orient_cb(void (*func)(unsigned char))
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // MPU_SENSOR_ENABLE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
@ -40,8 +40,8 @@ void draw() {
|
|||||||
text("Roll: " + roll + " Pitch: " + pitch + " Yaw: " + yaw, -200, 300);
|
text("Roll: " + roll + " Pitch: " + pitch + " Yaw: " + yaw, -200, 300);
|
||||||
|
|
||||||
// Rotate the object
|
// Rotate the object
|
||||||
rotateX(radians(roll));
|
rotateZ(radians(roll));
|
||||||
rotateZ(radians(-pitch));
|
rotateX(radians(pitch));
|
||||||
rotateY(radians(yaw));
|
rotateY(radians(yaw));
|
||||||
|
|
||||||
// 3D 0bject
|
// 3D 0bject
|
||||||
|
Loading…
x
Reference in New Issue
Block a user