Skip to content

Commit

Permalink
add LUT zeroing to factory res
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrbroz committed Jan 31, 2022
1 parent d1b0265 commit 8657e6e
Show file tree
Hide file tree
Showing 20 changed files with 29,390 additions and 28,998 deletions.
3 changes: 2 additions & 1 deletion Core/Inc/calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

#define V_CAL 1.0f // Calibration voltage
//#define I_CAL 5.0f
#define W_CAL 10.0f // Calibration speed in rad/s
//#define W_CAL 10.0f // Calibration speed in rad/s
#define W_CAL 2.0f
#define T1 1.0f // Cal settling period
#define PPAIRS_MAX 64
#define SAMPLES_PER_PPAIR N_LUT
Expand Down
1 change: 1 addition & 0 deletions Core/Inc/fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern "C" {
#define SETUP_CMD 's'
#define ZERO_CMD 'z'
#define FRESET_CMD 'f'
#define FDUMP_CMD 'd'
#define ENTER_CMD 13


Expand Down
9 changes: 1 addition & 8 deletions Core/Src/calibration.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ void order_phases(EncoderStruct *encoder, ControllerStruct *controller, CalStruc

int debug_sine = 0;
if(debug_sine){

#define sampleCount 200
#define sampleRate 100
static float valsA[sampleCount];
static float valsB[sampleCount];
static float valsC[sampleCount];
static float times[sampleCount];


if(debugCounter%sampleRate==0){
//printf("DC %u k, time = %f\n\r", debugCounter/1000, cal->time);
//printf("%f %f %f \r\n", controller->i_a, controller->i_b, controller->i_c);
Expand All @@ -62,14 +59,10 @@ void order_phases(EncoderStruct *encoder, ControllerStruct *controller, CalStruc
for(int i=0;i<sampleCount;i++){
printf("%f %f %f %f \r\n", times[i], valsA[i], valsB[i], valsC[i]);
}

}
}
}


debugCounter++;

//blindly rotate motor instead of callibration
float A = 0.04;
float f = 10;
Expand All @@ -80,7 +73,7 @@ void order_phases(EncoderStruct *encoder, ControllerStruct *controller, CalStruc
controller->dtc_w = 0.5 + A*sin_lut(2*3.14*(f*cal->time)+2*6.28/3.0);
set_dtc(controller);
return;

//debug sine end
}

if(cal->time < T1){
Expand Down
4 changes: 3 additions & 1 deletion Core/Src/flash_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Maybe replace with EEPROM emulation or implement wear-leveling in the future. (1
#define BANK1_START 0x08000000
#define RESERVED_PAGE 123 //max prog. upload reduced by 10k in platformio.ini, reserving pages 123 to 127 of bank 2
#define RESERVED_ADDR BANK2_START + PAGELEN*RESERVED_PAGE
#define RESERVED_AREA_LEN 5 //number of reserved pages


#define FLOATSCOUNT 64
#define INTSCOUNT 256
Expand Down Expand Up @@ -73,7 +75,7 @@ int erase_reserved_flash(){
eraseStruct.TypeErase = FLASH_TYPEERASE_PAGES;
eraseStruct.Banks = FLASH_BANK_2;
eraseStruct.Page = RESERVED_PAGE;
eraseStruct.NbPages = 5;
eraseStruct.NbPages = RESERVED_AREA_LEN;
uint32_t error;
HAL_FLASHEx_Erase(&eraseStruct, &error);
printf("Leaving erase flash.");
Expand Down
54 changes: 53 additions & 1 deletion Core/Src/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
//spi.SetMechOffset(M_OFFSET);
save_to_flash();
load_from_flash();
printf("\n\r Saved new zero position: %.4f\n\r\n\r", M_ZERO);
printf("\n\r Saved new zero position: %.4d \n\r\n\r", M_ZERO);
break;
case FRESET_CMD:
E_ZERO = 0;
Expand All @@ -235,9 +235,60 @@
P_MIN = -12.5f;
V_MAX = 65.0f;
V_MIN = -65.0f;
//zero encoder LUT
int *lut = &ENCODER_LUT;
for(int i = 0; i < 128; i++){
lut[i] = 0;
}
save_to_flash();
load_from_flash();
printf("\n\r FLASH variables reset. \n\r Please cycle power. \n\r\n\r");
break;
case FDUMP_CMD:
printf("Variable dump:\n\r");

printf("---Enc. LUT:---\n\r");
int *encLut = &ENCODER_LUT;
for(int i = 0; i < 128;){
printf("%d ", encLut[i]);
i++;
if(i%8==0){
printf("\n\r");
}
}

printf("---Int regs:---\n\r");
printf("PHASE_ORDER %d \n\r", PHASE_ORDER);
printf("CAN_ID %d \n\r", CAN_ID);
printf("CAN_MASTER %d \n\r", CAN_MASTER);
printf("CAN_TIMEOUT %d \n\r", CAN_TIMEOUT);
printf("M_ZERO %d \n\r", M_ZERO);
printf("E_ZERO %d \n\r", E_ZERO);

printf("--Float regs:--\n\r");
printf("I_BW %f \n\r", I_BW);
printf("I_MAX %f \n\r", I_MAX);
printf("THETA_MIN %f \n\r", THETA_MIN);
printf("THETA_MAX %f \n\r", THETA_MAX);
printf("I_FW_MAX %f \n\r", I_FW_MAX);
printf("R_NOMINAL %f \n\r", R_NOMINAL);
printf("TEMP_MAX %f \n\r", TEMP_MAX);
printf("I_MAX_CONT %f \n\r", I_MAX_CONT);
printf("PPAIRS %f \n\r", PPAIRS);
printf("R_PHASE %f \n\r", R_PHASE);
printf("KT %f \n\r", KT);
printf("C_TH %f \n\r", C_TH);
printf("GR %f \n\r", GR);
printf("I_CAL %f \n\r", I_CAL);
printf("P_MIN %f \n\r", P_MIN);
printf("P_MAX %f \n\r", P_MAX);
printf("V_MIN %f \n\r", V_MIN);
printf("V_MAX %f \n\r", V_MAX);
printf("KP_MAX %f \n\r", KP_MAX);
printf("KD_MAX %f \n\r", KD_MAX);

printf("----------------\n\r");
break;
}
break;
case SETUP_MODE:
Expand Down Expand Up @@ -276,6 +327,7 @@
printf(" e - Display Encoder\n\r");
printf(" z - Set Zero Position\n\r");
printf(" f - Factory reset flash vars\n\r");
printf(" d - Variable dump\n\r");
printf(" esc - Exit to Menu\n\r");

//gpio.led->write(0);
Expand Down
2 changes: 2 additions & 0 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ int main(void)

}

printf("erase %d ", erase_reserved_flash());

init_controller_params(&controller);

/* calibration "encoder" zeroing */
Expand Down
Binary file modified Debug/Core/Src/calibration.o
Binary file not shown.
4 changes: 2 additions & 2 deletions Debug/Core/Src/calibration.su
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
calibration.c:17:6:order_phases 96 static
calibration.c:126:6:calibrate_encoder 96 static
calibration.c:227:6:measure_lr 24 static
calibration.c:119:6:calibrate_encoder 96 static
calibration.c:220:6:measure_lr 24 static
Binary file modified Debug/Core/Src/flash_access.o
Binary file not shown.
6 changes: 3 additions & 3 deletions Debug/Core/Src/flash_access.su
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flash_access.c:36:6:load_from_flash 80 static
flash_access.c:71:5:erase_reserved_flash 32 static
flash_access.c:90:5:save_to_flash 40 static
flash_access.c:38:6:load_from_flash 80 static
flash_access.c:73:5:erase_reserved_flash 32 static
flash_access.c:92:5:save_to_flash 40 static
Binary file modified Debug/Core/Src/fsm.o
Binary file not shown.
10 changes: 5 additions & 5 deletions Debug/Core/Src/fsm.su
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fsm.c:22:7:run_fsm 24 static
fsm.c:95:7:fsm_enter_state 16 static
fsm.c:134:7:fsm_exit_state 16 static
fsm.c:174:7:update_fsm 16 static
fsm.c:267:7:enter_menu_state 8 static
fsm.c:284:7:enter_setup_state 24 static
fsm.c:309:7:process_user_input 16 static
fsm.c:398:7:enter_motor_mode 4 static
fsm.c:174:7:update_fsm 32 static
fsm.c:318:7:enter_menu_state 8 static
fsm.c:336:7:enter_setup_state 24 static
fsm.c:361:7:process_user_input 16 static
fsm.c:450:7:enter_motor_mode 4 static
Binary file modified Debug/Core/Src/main.o
Binary file not shown.
4 changes: 2 additions & 2 deletions Debug/Core/Src/main.su
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
core_cm4.h:1809:22:__NVIC_SetPriority 16 static
main.c:122:5:main 40 static
main.c:344:6:SystemClock_Config 168 static
main.c:404:6:Error_Handler 4 static
main.c:346:6:SystemClock_Config 168 static
main.c:406:6:Error_Handler 4 static
Binary file modified Debug/Core/Src/stm32g4xx_it.o
Binary file not shown.
Binary file modified Debug/motorcontrol_stm32g474re.bin
Binary file not shown.
Binary file modified Debug/motorcontrol_stm32g474re.elf
Binary file not shown.
Loading

0 comments on commit 8657e6e

Please sign in to comment.