Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace intermediate states with conditional transitions #689

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

andchiind
Copy link
Contributor

@andchiind andchiind commented Jan 3, 2025

Closes #687

Ready for review checklist:

  • A self-review has been performed
  • All commits run individually
  • Temporary changes have been removed, like logging, TODO, etc.
  • The PR has been tested locally
  • A test has been written
    • This change doesn't need a new test
  • Relevant issues are linked
  • Remaining work is documented in issues
    • There is no remaining work from this PR that requires new issues
  • The changes do not introduce dead code as unused imports, functions etc.

@andchiind andchiind added refactor Refactoring of old functionality improvement Improvement to existing functionality labels Jan 3, 2025
@andchiind andchiind self-assigned this Jan 3, 2025
"dest": self.monitor_state,
"conditions": self._start_task,
},
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This transition is basically the "else" which is run if the conditional above returns false. In this case, if it fails to continue the mission (for instance if there are no more tasks) it will go to the idle state and run the "_full_mission_finished" cleanup function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same is true for the transition from idle to idle. This is for when we fail to start a mission.

@andchiind andchiind force-pushed the remove-old-states branch 8 times, most recently from d804d72 to e2c9adb Compare January 3, 2025 15:25
@andchiind andchiind marked this pull request as ready for review January 3, 2025 15:25
@andchiind andchiind requested review from oysand and tsundvoll January 6, 2025 08:12
@andchiind andchiind marked this pull request as draft January 8, 2025 09:00
@andchiind andchiind force-pushed the remove-old-states branch 10 times, most recently from efd4cfc to fbd7b14 Compare January 15, 2025 09:37
self.start_mission_thread.start_thread(
start_mission_or_task, name="Robot start mission thread"
)
# TODO: consider what happens when we get another start_mission while the start_mission_thread is running.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove todo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be removed before moving the PR out of draft

self.current_status = task_status
time.sleep(settings.FSM_SLEEP_TIME)

def stop(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

when is this triggered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not used yet, but I might use it before moving the PR out of draft

self.robot_task_status_thread = ThreadedRequest(
request_func=self.run_robot_task_status_thread
)
self.robot_task_status_thread.start_thread(name="Robot task status thread")
Copy link
Contributor

Choose a reason for hiding this comment

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

how is this stopped when there is no mission active?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thread exits when it transitions out of monitor, and it is then cleaned up when receiving another mission

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will change it so that the thread stays alive, but only sleeps while no mission or task is active. This way we avoid the cost of having to start another thread when a new task starts. Alternatively I might make it start when we detect that we enter monitor, then exit when we leave monitor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement to existing functionality refactor Refactoring of old functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move initiate and initialize state to a transition
2 participants