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

FW[157] Generate State Machine from ADJ #33

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

jdmarmen
Copy link
Contributor

@jdmarmen jdmarmen commented Jan 5, 2025

Added:

  • state_machine.json : where the structure of the state machines, its transitions and actions will be written
  • state_machine_gen.py : a python script that reads the json and generates a file with all the c++ code
  • template_state_machine.hpp : a template hpp file with a primitive structure of the GeneratedStateMachine class
  • state_machine.hpp : this file will be created or rewritten once the user executes the python script

The json follows a structure with:

1. States

  • An array with the name of each general state.
  • If we want to add a nested state machine with its own states, we replace the name with a dictionary and two fields: the name of the nested state machine and an array with its substates.

2. Transitions

  • An array of dictionaries that include the old state name, the new state name and the transition name.
  • If we want to add a description, just add the "description field" in the dictionary.
  • If the old state, the newer one, or both of them aren't general states, we transform that state name into a dictionary with: the name of the nested state machine and the substate name

3. Actions

  • Enter: an array of actions that contain the state name and an array with the action names if there is more than one action to add. If the state is not a general state, it follows the same structure as the transitions, rewrite it as a dictionary with the nested state machine name and the substate name. If you want to add a description to a specific action, instead of only writing the name of the action, include a dictionary with two fields, the name and the description.

  • Cyclic (low/mid/high precision): an array of actions that contain an array of states to apply the cyclic actions (if a state is not a general state, it follows the same structure described above) and an array of state actions which are dictionaries with the action name and the desired period (f.e. 30ms), if you want to add a description just add a third field for that description. Each state action in the array is added to each state in the states array, low/mid/high precision work exactly the same way.

  • Exit: work exactly as enter actions

state_machine.json includes an example of almost every case, visual representation down below

Captura desde 2025-01-05 23-55-33

g0nz4I0
g0nz4I0 previously approved these changes Jan 6, 2025
Copy link
Member

@g0nz4I0 g0nz4I0 left a comment

Choose a reason for hiding this comment

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

Just one nitpick:

Nitpick:

could you change the name of the GeneratedStateMachine class to include information about the board, maybe add some info in the json and then just use that? Same goes for the nested state machine, or just GeneralStateMachine and something descriptive for the nested one.

I assume you have tested and it works fine, so I approve, next time it would be great if you added the generated example.

Great work on the PR description! 🎁

@jdmarmen
Copy link
Contributor Author

jdmarmen commented Jan 7, 2025

Just one nitpick:

Nitpick:

could you change the name of the GeneratedStateMachine class to include information about the board, maybe add some info in the json and then just use that? Same goes for the nested state machine, or just GeneralStateMachine and something descriptive for the nested one.

I assume you have tested and it works fine, so I approve, next time it would be great if you added the generated example.

Great work on the PR description! 🎁

You mean changing the standard name with something like LCUStateMachine()?? If so, it's the same that i do with the nested state machines, ask for a name and then for an array with its states. I also uploaded the generated file for you to check.

state_machine.json Outdated Show resolved Hide resolved
state_machine_gen.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@jdmarmen jdmarmen left a comment

Choose a reason for hiding this comment

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

Added state_machine_object_descriptions.py with the structure of each object and the functions to parse the info from the json. Adapted all the code generation to follow the new logic and also removed the template.hpp file, as it wasn't necessary for the new approach.

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