forked from EFeru/hoverboard-firmware-hack-FOC
UART with sideboards works + major refactoring
► the mainboard can now send and receive Serial data from the sideboards ► heavy refactored the `main.c`. It was becoming too large to manage... Therefore, `util.c` and `util.h` was created ► added new functionality for `VARIANT_HOVERCAR` and variants with `CONTROL_ADC` in general: - ADC limits auto-calibration mode (long press of the power button) - calibration will not be lost at power-off - Max Current and Max Speed adjustment mode (long press followed by a short press of the power button) - calibration will not be lost at power-off - added one sideboard functionality: - LEDs are used to display battery level, Motor Enable, Errors, Reverse driving, Braking. - Photo sensors are used as push buttons: One for changing Control Mode, One for Activating/Deactivating the Field Weakening on the fly
This commit is contained in:
96
Inc/util.h
Normal file
96
Inc/util.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* This file is part of the hoverboard-firmware-hack project.
|
||||
*
|
||||
* Copyright (C) 2020-2021 Emanuel FERU <aerdronix@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Define to prevent recursive inclusion
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(CONTROL_SERIAL_USART2) || defined(CONTROL_SERIAL_USART3)
|
||||
#ifdef CONTROL_IBUS
|
||||
typedef struct{
|
||||
uint8_t start;
|
||||
uint8_t type;
|
||||
uint8_t channels[IBUS_NUM_CHANNELS*2];
|
||||
uint8_t checksuml;
|
||||
uint8_t checksumh;
|
||||
} Serialcommand;
|
||||
#else
|
||||
typedef struct{
|
||||
uint16_t start;
|
||||
int16_t steer;
|
||||
int16_t speed;
|
||||
uint16_t checksum;
|
||||
} Serialcommand;
|
||||
#endif
|
||||
#endif
|
||||
#if defined(SIDEBOARD_SERIAL_USART2) || defined(SIDEBOARD_SERIAL_USART3)
|
||||
typedef struct{
|
||||
uint16_t start;
|
||||
int16_t roll;
|
||||
int16_t pitch;
|
||||
int16_t yaw;
|
||||
uint16_t sensors;
|
||||
uint16_t checksum;
|
||||
} SerialSideboard;
|
||||
#endif
|
||||
|
||||
// Initialization Functions
|
||||
void BLDC_Init(void);
|
||||
void Input_Lim_Init(void);
|
||||
void Input_Init(void);
|
||||
|
||||
// General Functions
|
||||
void poweronMelody(void);
|
||||
void shortBeep(uint8_t freq);
|
||||
void shortBeepMany(uint8_t cnt);
|
||||
void longBeep(uint8_t freq);
|
||||
void calcAvgSpeed(void);
|
||||
void adcCalibLim(void);
|
||||
void updateCurSpdLim(void);
|
||||
void saveConfig(void);
|
||||
|
||||
// Poweroff Functions
|
||||
void poweroff(void);
|
||||
void poweroffPressCheck(void);
|
||||
|
||||
// Read Command Function
|
||||
void readCommand(void);
|
||||
|
||||
// Sideboard functions
|
||||
void sideboardLeds(uint8_t *leds);
|
||||
void sideboardSensors(uint8_t sensors);
|
||||
|
||||
// Filtering Functions
|
||||
void filtLowPass32(int32_t u, uint16_t coef, int32_t *y);
|
||||
void rateLimiter16(int16_t u, int16_t rate, int16_t *y);
|
||||
void mixerFcn(int16_t rtu_speed, int16_t rtu_steer, int16_t *rty_speedR, int16_t *rty_speedL);
|
||||
|
||||
// Multiple Tap Function
|
||||
typedef struct {
|
||||
uint32_t t_timePrev;
|
||||
uint8_t z_pulseCntPrev;
|
||||
uint8_t b_hysteresis;
|
||||
uint8_t b_multipleTap;
|
||||
} MultipleTap;
|
||||
void multipleTapDet(int16_t u, uint32_t timeNow, MultipleTap *x);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user