Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Candas1 committed Jun 7, 2024
1 parent efb438b commit f291812
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
10 changes: 5 additions & 5 deletions Inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
#define BAT_CALIB_ADC 1492 // adc-value measured by mainboard (value nr 5 on UART debug output)
#define BAT_CELLS 10 // battery number of cells. Normal Hoverboard battery: 10s
#define BAT_LVL2_ENABLE 0 // to beep or not to beep, 1 or 0
#define BAT_LVL1_ENABLE 1 // to beep or not to beep, 1 or 0
#define BAT_DEAD_ENABLE 1 // to poweroff or not to poweroff, 1 or 0
#define BAT_LVL1_ENABLE 0 // to beep or not to beep, 1 or 0
#define BAT_DEAD_ENABLE 0 // to poweroff or not to poweroff, 1 or 0
#define BAT_BLINK_INTERVAL 80 // battery led blink interval (80 loops * 5ms ~= 400ms)
#define BAT_LVL5 (390 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE // Green blink: no beep
#define BAT_LVL4 (380 * BAT_CELLS * BAT_CALIB_ADC) / BAT_CALIB_REAL_VOLTAGE // Yellow: no beep
Expand Down Expand Up @@ -148,7 +148,7 @@

// Control selections
#define CTRL_TYP_SEL FOC_CTRL // [-] Control type selection: COM_CTRL, SIN_CTRL, FOC_CTRL (default)
#define CTRL_MOD_REQ VLT_MODE // [-] Control mode request: OPEN_MODE, VLT_MODE (default), SPD_MODE, TRQ_MODE. Note: SPD_MODE and TRQ_MODE are only available for CTRL_FOC!
#define CTRL_MOD_REQ SPD_MODE // [-] Control mode request: OPEN_MODE, VLT_MODE (default), SPD_MODE, TRQ_MODE. Note: SPD_MODE and TRQ_MODE are only available for CTRL_FOC!
#define DIAG_ENA 1 // [-] Motor Diagnostics enable flag: 0 = Disabled, 1 = Enabled (default)

// Limitation settings
Expand All @@ -174,8 +174,8 @@

// ############################## DEFAULT SETTINGS ############################
// Default settings will be applied at the end of this config file if not set before
#define INACTIVITY_TIMEOUT 8 // Minutes of not driving until poweroff. it is not very precise.
#define BEEPS_BACKWARD 1 // 0 or 1
#define INACTIVITY_TIMEOUT 0 // Minutes of not driving until poweroff. it is not very precise.
#define BEEPS_BACKWARD 0 // 0 or 1
#define ADC_MARGIN 100 // ADC input margin applied on the raw ADC min and max to make sure the MIN and MAX values are reached even in the presence of noise
#define ADC_PROTECT_TIMEOUT 100 // ADC Protection: number of wrong / missing input commands before safety state is taken
#define ADC_PROTECT_THRESH 200 // ADC Protection threshold below/above the MIN/MAX ADC values
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ This repository implements Field Oriented Control (FOC) for stock hoverboards. C
- smooth torque output and improved motor efficiency. Thus, lower energy consumption
- field weakening to increase maximum speed range

This branch is for combat robot drive:
- battery level alert and turn off are disabled
- no inactivity check
- no turn off functionality
- no backwards beep
- SPD_MODE is used to both wheels turn at the same speed (be careful with the phase/hall combination or it will go to max speed)

This firmare will be used on a robot with the TIP127 removed and Drain/Source shorted so that the robot cannot turn off, the only way to turn it off is to disconnect the battery.
This also means the capacitors will be always discharged when the battery is removed.

To be checked:
- if the MCU resets while wheels are spinning, the offset calibration will be wrong. When the input is close to zero, motor will enable and things can go horribly wrong. Check if it's worth saving the offsets.

Table of Contents
=======================

Expand Down
14 changes: 8 additions & 6 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,14 @@ int main(void) {
}
#endif

if (inactivity_timeout_counter > (INACTIVITY_TIMEOUT * 60 * 1000) / (DELAY_IN_MAIN_LOOP + 1)) { // rest of main loop needs maybe 1ms
#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3)
printf("Powering off, wheels were inactive for too long\r\n");
#endif
poweroff();
}
#if (INACTIVITY_TIMEOUT > 0)
if (inactivity_timeout_counter > (INACTIVITY_TIMEOUT * 60 * 1000) / (DELAY_IN_MAIN_LOOP + 1)) { // rest of main loop needs maybe 1ms
#if defined(DEBUG_SERIAL_USART2) || defined(DEBUG_SERIAL_USART3)
printf("Powering off, wheels were inactive for too long\r\n");
#endif
poweroff();
}
#endif


// HAL_GPIO_TogglePin(LED_PORT, LED_PIN); // This is to measure the main() loop duration with an oscilloscope connected to LED_PIN
Expand Down
4 changes: 2 additions & 2 deletions Src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1550,8 +1550,8 @@ void poweroff(void) {
HAL_Delay(100);
}
saveConfig();
HAL_GPIO_WritePin(OFF_PORT, OFF_PIN, GPIO_PIN_RESET);
while(1) {}
//HAL_GPIO_WritePin(OFF_PORT, OFF_PIN, GPIO_PIN_RESET);
//while(1) {}
}


Expand Down

0 comments on commit f291812

Please sign in to comment.