Skip to content

Feat/acoustics#42

Open
Wiacer wants to merge 126 commits into
mainfrom
feat/acoustics
Open

Feat/acoustics#42
Wiacer wants to merge 126 commits into
mainfrom
feat/acoustics

Conversation

@Wiacer
Copy link
Copy Markdown

@Wiacer Wiacer commented Apr 24, 2026

It works, but needs a bit of polish

1 FDCAN
1 SPI master
3 SPI slaves
1 Usart
allow cli make clean all build project
used to generate compile_json
remove all incompatible *f16.c from CMSIS.DSP
remove all incompatible ARM cortex A (neon) from CMSIS_DSP
remove all source files that include all source files in the same directory
First iteration, made completely by chatgtp
@Wiacer Wiacer self-assigned this Apr 24, 2026
@jorgenfj
Copy link
Copy Markdown

image bruh

@Wiacer
Copy link
Copy Markdown
Author

Wiacer commented Apr 25, 2026

image

bruh

Idk man, cyp ville ha deg med

Copy link
Copy Markdown
Contributor

@forrisdahl forrisdahl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know why, but the GitHub browser is insanely slow and difficult to mark where I want to comment, so I will make one larger comment instead.

My general impression of main is that it is big. It has a lot of functions, and it is not immediately clear which are important/used and which are not. I suggested splitting the debug or printf functions into another file. I understand that this might be challenging due to variable scope. The most important thing to see in the main.c file is the main function. I would like the main function to be as early as possible, with other functions defined below it but declared in the header or before main.

I think the code inside the while loop could also be split into functions. It does not have to be many functions, but as it is now, we end up with a lot of indentation. Function names could also make it easier to understand what each step is trying to achieve.

It is a bit random where there are comments and where there are not. For the most important functions, you should have Doxygen-style comments to explain what they do and what they expect.

Comment thread acoustics/acoustics_firmware2/Core/Src/main.c Outdated
Comment thread acoustics/acoustics_firmware2/Core/Src/main.c Outdated
Comment thread acoustics/acoustics_firmware2/Core/Src/main.c Outdated
Wiacer added 2 commits April 26, 2026 22:47
//NOT TESTED AT TIME OF COMMIT//
cleaned and modularized everything
all that remains should be to implement dumping functionality and test
Features added:
CAN interface
Proper state machine
Stale Data detection
Left to implement:
    Dump commands
    Making it not error due to stale data every 10 seconds
@Wiacer Wiacer closed this Apr 27, 2026
@Wiacer Wiacer reopened this Apr 27, 2026
@Wiacer
Copy link
Copy Markdown
Author

Wiacer commented Apr 27, 2026

Idk what i'm doing.
Anyway I fixed all the issues i think and majorly rebased and reorganized acoustics.
It errors out and resets every 10 seconds but it works (havent properly tested direction but i assume it works)

…SPI interface would fail. Fixed it. Acoustics is now megagood.

Dump still not implemented
@Wiacer
Copy link
Copy Markdown
Author

Wiacer commented Apr 27, 2026

Fixed the erroring out thingy now.
Only optional thing missing is dump functionality but we'll only need it if it doesn't work to begin with

Comment on lines +171 to +191
while(((idxs[0] < dead_space) || (idxs[0] > (WORKSPACE_LEN-(WORKSPACE_OFFSET-1)*BLOCK_LEN))) && max_retries--){
float32_t threshold = dsp_min_max_lerp(processing_workspace[0], WORKSPACE_LEN, linear_threshold, n_upper_average, dead_space);
idxs[0] = dsp_rl_under_threshold_search(processing_workspace[0],WORKSPACE_LEN, threshold , PROCESSING_PATIENCE);
linear_threshold *= 2;
}
times_of_arrival[0] = (float32_t)idxs[0];

for(int i = 1; i < N_HYDROPHONES; i++){
float32_t linear_threshold = lerp_threshold;
uint8_t max_retries = 6;
uint32_t dead_space = n_lower_average;
idxs[i] = 0;
while(((utils_abs_int32(idxs[0] - idxs[i])) > max_idx_difference) && max_retries--){
float32_t threshold = dsp_min_max_lerp(processing_workspace[i], WORKSPACE_LEN, linear_threshold, n_upper_average, dead_space);
idxs[i] = dsp_rl_under_threshold_search(processing_workspace[i],WORKSPACE_LEN, threshold , PROCESSING_PATIENCE);
linear_threshold *= 2;
}
times_of_arrival[i] = (float32_t)idxs[i];
}

valid_buffers = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these conditions are quite cryptic, not immediately obvious what they are checking. You could have a static inline function to have a human readable name for the conditions.

You probably should split the first part of the function, (the searching?) to its own function. Currently function does a lot of things. Could have one function that finds the TDOA and validates the data and one that solves the position

@Wiacer
Copy link
Copy Markdown
Author

Wiacer commented May 15, 2026

Aight now there are surely no other problems left

@forrisdahl
Copy link
Copy Markdown
Contributor

This looks a lot better, much easier to understand the acoustics processing.

What remains now is to clean up your branch. First of all I see that there are telemetry files I accidentally pushed on the branch that needs to be removed.

I think the old version of the firmware can be removed to save space. Both the old version and the new version includes CMSIS library which adds a lot more files to your branch than needs to be. In addition since I do not think we have done any changes cmsis library we should look for a way to avoid having it in our repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants