Skip to content

Main refactor#189

Open
ericv555 wants to merge 21 commits into
mainfrom
feature-main-refactor
Open

Main refactor#189
ericv555 wants to merge 21 commits into
mainfrom
feature-main-refactor

Conversation

@ericv555
Copy link
Copy Markdown
Collaborator

Just a little main refactor to keep things interesting. Moved all Main functionality to member functions of a (hypervisor?) class called HelloRobot. This breaks up what was previously main.cpp into 5 primary functions, which can be individually run and tested. This reduces our main script to simply initializing the robot and running its main loop. The loop itself is now also broken up into the division I suggested above. The HelloRobot class owns all of the managers and hardware interfaces, except for ref and the comms_layer, which have been globalized. The purpose of this architectural change is to allow for unit tests of all main file functionality.

@ericv555 ericv555 requested a review from roccoagain April 14, 2026 23:35
@ericv555 ericv555 self-assigned this Apr 14, 2026
@github-actions
Copy link
Copy Markdown

Doxygen warnings output: (if empty, there are no warnings). Please correct any warnings before merging.

  

return (primary_val != 0) ? primary_val : secondary_val;
};

pos_x = merge_input(mouse_x,ref.ref_data.kbm_interaction.mouse_speed_x) * 0.05 * delta;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe this breaks mouse aiming. The old code accumulated mouse movement with +=. Aiming now only reflects the mouse's tiny delta each loop.


pos_x = merge_input(mouse_x,ref.ref_data.kbm_interaction.mouse_speed_x) * 0.05 * delta;
pos_y = merge_input(mouse_y,ref.ref_data.kbm_interaction.mouse_speed_y) * 0.05 * delta;
l_mouse_button = merge_input(l_mouse_button,ref.ref_data.kbm_interaction.button_left);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This writes the merged value, which is based on l_mouse_button, back into l_mouse_button. merge_input(l_mouse_button, ...) can keep selecting that previous true value even after the button is released, causing it to latch.

Comment thread src/hello_robot.hpp
#define LOOP_FREQ 1000
#define HEARTBEAT_FREQ 2
#ifdef PROFILER
Profiler prof;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Linker error when profiling is enabled through the flag in Profiler.hpp:

./build/./src/main.cpp.o:/Users/ranto/robotics/firmware/src/hello_robot.hpp:42: multiple definition of `prof'; ./build/./src/hello_robot.cpp.o:/Users/ranto/robotics/firmware/src/hello_robot.hpp:42: first defined here

This header is included in multiple source files, so we have to move this definition to a source file and access it through the extern in profiler.hpp.

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.

2 participants