vortexntnu / vortex-auv

Software for guidance, navigation and control for the Vortex AUVs. Purpose built for competing in AUV/ROV competitions.
https://www.vortexntnu.no/
MIT License
91 stars 21 forks source link

[TASK] FSM for docking task using YASMIN #474

Open Andeshog opened 2 months ago

Andeshog commented 2 months ago

Description of task

Continue to explore and learn how the YASMIN library works. Do so by developing a demo for the docking task at TACC. The demo should be similar to how we (auto) will handle the task in a real run, but since we cant yet rely on data from Perception you can use timers in the demo. The flow of the demo can be as follows:

The demo will be tested in the simulator at the office.

Suggested Workflow

Specifications

Specification for the demo

Contacts

@Andeshog

Code Quality

chrstrom commented 1 month ago

Just some food for thought after some of the things we learned when working on Beluga Mk2 and setting up the state machines for robosub:

More states usually lead to more clutter. Finding the "right" amount of states and what these should be is hard, while concluding on "lets just add another state" is easy. As an example, could "moving_to_dock", "returning_home", and "docking" all be captured in the state "moving_to_point"? (I don't know if that's feasible for this specific task, but it's something to think about).

In addition to being critical about what states you add, you might want to think about what events and effects you define. Ideally, all state transitions are triggered by external "events", i.e. the dp controller letting you know you've reached a setpoint. The output for a given state are called "effects", which could f.ex be firing up a dp controller to move to a specific point. If you were to check if you've reached the checkpoint internally, you suddenly need access to odometry, and end up "disconnecting" the fsm from the dp controller.

It is also very common to see an "error" state, but be wary of the implications there. Transitioning to an "error" state is equivalent to panicking / terminating a program and should act as a sink in the fsm, while transitioning to different states if something goes wrong is equivalent to a try-catch, and is a perfectly reasonable thing to have. The effects of the "error" state could be to shut down all non-essential systems and alert the user. The problem occurs when the "error" state is implemented in a way that allows the fsm to transition back out of the error state. In such a state machine, you shouldn't have transitioned into the "error" state to begin with - or maybe you don't need the "error" state at all.

If you model states/effects/events properly, you end up with guarantees like "only 1 controller is running at any given time". You also end up with robustness against errors (i.e. the only failure mode is fall over and die, look into exception handling vs fault tolerant design for more info)