Skip to content

Refactor Tbots.py a little bit - #3905

Merged
williamckha merged 14 commits into
UBC-Thunderbots:masterfrom
GrayHoang:better_command_names
Aug 31, 2026
Merged

Refactor Tbots.py a little bit#3905
williamckha merged 14 commits into
UBC-Thunderbots:masterfrom
GrayHoang:better_command_names

Conversation

@GrayHoang

@GrayHoang GrayHoang commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Description

I hate tbots.py

This only sort of fixes the problems we are having, it effectively introduces some boilerplate to prevent having to hardcode flags and values into the decision tree for the interactive CLI. It also localizes all the interactive CLI stuff to a class rather than have it distributed across two separate files.

Testing Done

tbots.py runs fine after changes (I think? No new bugs introduced??)

Resolved Issues

Resolves #3876
Resolves #3885
Resolves #3871

Length Justification and Key Files to Review

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

@nycrat

nycrat commented Aug 28, 2026

Copy link
Copy Markdown
Member

@GrayHoang ready for review?

@nycrat nycrat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good so far. I think that tbots.py is now going in the right direction!

Comment thread src/tbots.py Outdated
Comment thread src/tbots.py Outdated
Comment thread src/tbots.py Outdated
Comment thread src/tbots.py Outdated
@GrayHoang

Copy link
Copy Markdown
Contributor Author

Me when I lie

@GrayHoang

Copy link
Copy Markdown
Contributor Author

THere are some improvements that could be made to the history thing, like adding a bit more description but I don't wanna :((((((( (its some very pleasant tuple manipulation :DDDD)

@GrayHoang

Copy link
Copy Markdown
Contributor Author

I made the changes. Please test and give me some feedback, but barring that this is ready to merge @nycrat @StarrryNight

@maggiettu
maggiettu self-requested a review August 28, 2026 19:45
Comment thread src/cli/cli_params.py Outdated
Comment thread src/cli/cli_params.py
description="Flash the powerboard firmware (powerloop_main)",
),
# Maps to the deploy_powerboard.yml playbook but additionally compiles
# powerloop_main with the DEBUG_POWERLOOP flag, swapping in bare setup()/loop()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this is same as the disable services from above? is this two separate paths to the same setup, or just a shortcut so you dont have to select disable each time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no, disable_powerloop prevents the Pi from trying to communicate with the powerboard.
This one flashes dummy code onto the powerboard that pretty much doesn't do anything, so that elec people or testers can flash their own code on.

Comment thread src/cli/cli_params.py

if not past_cmd:
return
print(f"\n{'=' * 33} Running: {'=' * 38}\n\n{past_cmd}\n\n{'=' * 81}\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what do these numbers represent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just some arbitrarily chosen numbers to create nice dividers in the CLI

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yea i agree its kind of weird to have random constants but we got bigger issues to worry about here 💀

Comment thread src/cli/cli_params.py
).unsafe_ask()
cmd_title += launch_label

if launch_mode == InteractiveCli.LaunchMode.SIM:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

a little unclear what this whole if block is doing, maybe some parts can be pulled into its own function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the block is creating a questionary selection prompt and retrieving the results. While it is possible to move this to its own function I don't really think it would be meaningful, and would just mean that a future developer would have to run around looking at a bunch of different functions calling each other to understand the hierarchy.

Comment thread src/cli/cli_params.py
for label in sim_option_labels:
cmd_title += label

for opt in sim_options:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same sentiment here, this could probably be its own named fn

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this code is also just creating a questionary prompt and handling the result, adding labels and arguments and generating the command.

Comment thread src/cli/cli_params.py
choices=InteractiveCli.PLAYBOOK_CHOICES,
style=InteractiveCli.INTERACTIVE_STYLE,
).unsafe_ask()
cmd_title += flash_cmd_label

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i feel like im seeing a lot of these label updates, is it the best way to keep separately updating in each section?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the problem is that questionary doesn't support callbacks afaik, so there's not really any way to enforce behaviour after a question is answered. I'm pretty sure questionary is just a tool to help create those selection prompts and retrieve some values, but doesn't really support implementing behaviour. So unfortunately, these sorts of updates are the best way, I think.

@GrayHoang

Copy link
Copy Markdown
Contributor Author

the bazelrc change might not need to be used? idk I always find myself needing to limit the number of jobs so I don't get screwed over

@adrianchan787 adrianchan787 left a comment

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.

Two small things but looks good, also tested tbots.py a bit and seems to work

Comment thread src/cli/cli_params.py
Comment thread src/cli/cli_params.py Outdated
@williamckha
williamckha merged commit 002169e into UBC-Thunderbots:master Aug 31, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants