Skip to content

Most efficient way to code multiple similar state machines in one project #22

@ICPete

Description

@ICPete

I'm looking for advice on whether there is an available notation in the Arduino IDE that would save me a bunch of copy-paste-modify effort. Here is a summary of what my code needs to do:

  • Software Overview:
  • The architecture of this code project is a Finite State Machine, and we make use of Jose Rullan's StateMachine library:
  • https://github.com/jrullan/StateMachine
  • Note that this library, in turn, makes use of Ivan Seidel's LinkedList library:
  • https://github.com/ivanseidel/LinkedList
  • We'll need seven state machines, one for each inverter.
  • Each FSM has four states and eight transitions, as shown in the diagram, "BPCC State Diagram R2.pdf".
  • The state machines and their states are created during Initialization, and the transitions are added within the setup routine.
  • Functions define what happens within each state, and the conditions that trigger transitions; these functions are
  • duplicated for the seven state machines.

BPCC State Diagram R2.pdf

I tried using array notation (e.g., "machine[0]" for the name of the StateMachine instance), and it actually compiled, but didn't appear to be running successfully. This was using the code example provided, which otherwise worked fine with simple names for the multiple machines.

It may be that I need to learn more about using pointers in Arduino code??

Otherwise I guess I will need to write and debug the code for ONE inverter's state machine, then copy and paste the many lines that create and define states and transitions for that machine, then edit the names of the machines and transitions to reflect the six additional inverters.

Just as an example of what I'd like to be able to do, I'm already using array variables for the seven I/O pins and related parameters (e.g., voltages), so that I can create a "for" loop with an index that steps from 0 to 6, that can perform the transition testing within a Switch-Case code structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions