-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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() |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
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!