Skip to content

Commit

Permalink
Add some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
supertom01 committed Aug 18, 2023
1 parent 1378a11 commit 1c56aee
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Core/Src/robot.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ void init(void){
LOG("[init:"STRINGIZE(__LINE__)"] Initializing MTi\n");
MTi = NULL;
uint16_t MTi_made_init_attempts = 0;

// Check whether the MTi is already intialized.
// If the 3rd and 4th bit of the statusword are non-zero, then the initializion hasn't completed yet.
while ((MTi == NULL || (MTi->statusword & (0x18)) != 0) && MTi_made_init_attempts < MTi_max_init_attempts) {
MTi = MTi_Init(1, XFP_VRU_general);
IWDG_Refresh(iwdg);
Expand All @@ -425,8 +428,12 @@ void init(void){
}
MTi_made_init_attempts += 1;
LOG_sendAll();

// The MTi is allowed to take 1 second per attempt. Hence we wait a bit more and then check again whether the initialization succeeded.
HAL_Delay(1100);
}

// If after the maximum number of attempts the calibration still failed, play a warning sound... :(
if (MTi == NULL || (MTi->statusword & (0x18)) != 0) {
LOG_printf("[init:"STRINGIZE(__LINE__)"] Failed to initialize MTi after %d out of %d attempts\n", MTi_made_init_attempts, MTi_max_init_attempts);
buzzer_Play_WarningOne();
Expand Down

0 comments on commit 1c56aee

Please sign in to comment.