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

Stm outline #54

Closed
wants to merge 24 commits into from
Closed

Stm outline #54

wants to merge 24 commits into from

Conversation

DylanCavers
Copy link
Contributor

Start of the outline of the state machine code, is very far from done. This will be the basic structure of the state machine instances with appropriate states and transitions.

@kshxtij kshxtij mentioned this pull request Nov 17, 2022
update data
should check if a transition is needed with current data
then run transition to move to next state
return (None || transition_message)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an std::optional return type then

Copy link
Member

@maxguy2001 maxguy2001 left a comment

Choose a reason for hiding this comment

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

A few structural changes.

}

// Transition to next state
void StateMachine::transition(Message message)
Copy link
Member

Choose a reason for hiding this comment

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

const


void StateMachine::reset()
{
current_state = states[0];
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the point of having an enum class so that you can just set current_state = State::kInitialState? Idk if I'm missing something here but why are we instantiating a local object that is kind of similar to the enum class we already defined?

void reset();

// TODOLater change states to actual states
State states[5]
Copy link
Member

Choose a reason for hiding this comment

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

Why do we do this?

= {State::kInitialState, State::state1, State::state2, State::state3, State::state4};

// TODOLater change transitions to actual transitions
Transition transitions[5] = {
Copy link
Member

Choose a reason for hiding this comment

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

You've implicitly used the number of states a few times now without stating where the number 5 comes from. Better design would be to create a variable somewhere (e.g. kNumStates = 5) and refer to that?

Transition(State::state3, State::state4, Message::message1),
};

State current_state = states[0];
Copy link
Member

Choose a reason for hiding this comment

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

Would this not be initialized in constructor?

// transition.
class Transition {
public:
Transition(State from_state, State to_state, Message transition_message)
Copy link
Member

Choose a reason for hiding this comment

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

Should this not be a separate function within this class? Also why are we storing all of this as class members?

@@ -0,0 +1,24 @@
#pragma once

#include "message.cpp"
Copy link
Member

Choose a reason for hiding this comment

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

Don't include a cpp file. Always include headers (all functions, classes, etc. should be defined there anyways).


std::optional<Message> checkTransition();

void reset();
Copy link
Member

Choose a reason for hiding this comment

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

This is not defined in your set of transitions so how do you define this behavior?

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.

5 participants