-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
Rover Sailboat: refactor the mainsail/wingmast/mast_rotation logic #26152
Rover Sailboat: refactor the mainsail/wingmast/mast_rotation logic #26152
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.
Nice improvement! Looks like there should not be any change in behavior?
Rover/sailboat.cpp
Outdated
mast_rotation_out = 0.0f; | ||
return; | ||
relax_sails(); | ||
}else{ |
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.
}else{ | |
} else { |
Rover/sailboat.cpp
Outdated
// | ||
|
||
// mainsail_out represents a range from 0 to 100 | ||
float mainsail_out = 100.f; |
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.
I find the .
harder to read than .0
, we don't really need the f
either. (I know there all over already)
Rover/sailboat.cpp
Outdated
|
||
if (motor_state == UseMotor::USE_MOTOR_ALWAYS) { | ||
relax_sails(); | ||
}else{ |
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.
}else{ | |
} else { |
There is a change in behaviour from https://github.com/ArduPilot/ardupilot/blob/master/Rover/mode_manual.cpp#L38 , which I think was a bug? So I changed behaviour to as if NOTE In practise this bug had no effect so no actual change in behaviour since both |
EDIT: Fixed I hope. |
83375be
to
1e6d6e7
Compare
Reset to head at original PR prior to rebase |
1e6d6e7
to
e3feab2
Compare
e3feab2
to
4618e17
Compare
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.
Looking good, just that friend stuff and I think we can merge.
Rover/sailboat.h
Outdated
friend class Rover; | ||
friend class Mode; | ||
friend class ModeManual; | ||
friend class ModeHold; | ||
friend class ModeLoiter; | ||
friend class ModeAcro; | ||
friend class RC_Channel_Rover; |
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.
I don't think these are needed for this PR? There are no changes to most of those classes.
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.
I modified Sailboat class member function access to make all the non const Sailboat member functions private and so those classes calling private Sailboat functions ( ie Sailboat state modifying functions) require friend access to Sailboat. The overall idea is limit who can change the state as much as possible. If non const member functions are public, anyone can change state thus making debugging harder. The precedent is similar use of friends in Rover class https://github.com/ArduPilot/ardupilot/blob/master/Rover/Rover.h#L77
Shall I revert it to those non const member functions of Sailboat being public?
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.
Ah, I see. I had not appreciated the change in scope of those functions. I think my preference would be to keep the current structure.
They key difference is that all of the params and internal state variables are currently private. So cannot be changed externally. It we add friends then they can all reach in any change things they probably shouldn't. EG you should call set_motor_state
not just change motor_state
. That is currently enforced.
If there are things that should defiantly not be able to change anything (those class which you did not have to add as friends) then we could go via a const reference to the class. But i'm not really sure there are any that would need this?
…d make non const sailboat functions private to the sailboat class. Saves around 128 bytes of text image size (in SITL anyway)
4618e17
to
dba1f19
Compare
dba1f19
to
2e9f0c5
Compare
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.
Looks good, Thanks, I have just added Rover: Sailboat
to start of the last commit message.
Rover Sailboat: refactor the mainsail/wingmast/mast_rotation logic and make non const sailboat functions private to the sailboat class. Refactor saves around 128 bytes of text image size (in SITL anyway) and easier to read the source code