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

Feature/state machine #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Feature/state machine #5

wants to merge 5 commits into from

Conversation

Ian-Carroll
Copy link
Contributor

Implemented a basic demo and unit testing for the Node state machine. Additional info is in fsm/README.md. This code needs to be super solid so any grilling is much appreciated!

Copy link
Collaborator

@andrewnash andrewnash left a comment

Choose a reason for hiding this comment

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

Some of my comments are probably invalid because it's been years since I touched C - but take a look, others please swoop in and defend Ian if I'm wrong on stuff


// Unit test asserting correct state transitions
// returns true if pass, false otherwise
void test_fsm()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we put tests in another file?

// returns true if pass, false otherwise
void test_fsm()
{
char input;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you define somewhere what each char corresponds to, I figured it out after staring at the code for a while but a little key comment would be nice


if (curr_state == (int)boot)
{
if (input == 'P' || input == 'p' || input == 'W' || input == 'w')
Copy link
Collaborator

Choose a reason for hiding this comment

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

this if is the same for every state, IMO you should just pull it out to the beginning and break early if called


int curr_state = (int)**state;

if (curr_state == (int)boot)
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing logic to deny state change if health not good

{
State boot = BOOT;
State autonomous = AUTONOMOUS;
State manual = MANUAL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I'm just not used to C code but isn't it redundant to recreate these globals?

State autonomous = AUTONOMOUS;
State manual = MANUAL;

int curr_state = (int)**state;
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a reason to reassign this variable that's passed in? Shouldn't you just name the original variable curr_state

Copy link
Collaborator

Choose a reason for hiding this comment

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

also shouldn't you be using camel case not snake case?


else
{
*state = &autonomous;
Copy link
Collaborator

Choose a reason for hiding this comment

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

am I reading this right as a state change from autonomous to autonomous?

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.

2 participants