-
Notifications
You must be signed in to change notification settings - Fork 7
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
hugo/feature/Update MotionKit to Fusion #1292
Conversation
🔖 Version comparison
|
File comparision analysis report🔖 Info
Click to show memory sections
📝 SummaryClick to show summary
🗺️ Map files diff outputClick to show diff list
|
File comparision analysis report🔖 Info
Click to show memory sections
📝 SummaryClick to show summary
🗺️ Map files diff outputClick to show diff list
|
Codecov Report
@@ Coverage Diff @@
## develop #1292 +/- ##
===========================================
+ Coverage 98.73% 98.75% +0.01%
===========================================
Files 145 147 +2
Lines 3729 3765 +36
===========================================
+ Hits 3682 3718 +36
Misses 47 47
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
e94e355
to
b789b93
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.
first review, thanks for the refactor. 👍
I still have a lot of questions and I'm not sure the system is error proof.
MotionKit tests must not rely on LSM6DSOX but must use an IMUKit mock
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.
Much better, thanks!
Added a few suggestions.
We'll discuss tests tomorrow :)
643434f
to
4d298f3
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.
Great changes, code is much clearer 👍
I've made a few suggestions + I still have some questions
libs/MotionKit/include/PID.hpp
Outdated
float _error_position_total = 0.F; | ||
float _error_position_last = 0.F; | ||
float _proportional = 0.F; | ||
float _integral = 0.F; | ||
float _derivative = 0.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.
could be made a struct as they are all related, at least the last 3
64e7a48
to
970fdb2
Compare
970fdb2
to
d6e7b3a
Compare
📈 Changes Impact Analysis Report📌 Info
🤖 Firmware impact analysis
Click to show memory sections
🔬 Detailed impact analysisClick to show detailed analysis for all targets
🗺️ Map files diff output
|
📈 Changes Impact Analysis Report📌 Info
🤖 Firmware impact analysis
Click to show memory sections
🔬 Detailed impact analysisClick to show detailed analysis for all targets
🗺️ Map files diff output
|
0ebd679
to
9f109ee
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.
thanks for the refactor 👍
I think we're good for the time being.
I've made some suggestions/refactors for 1.5.0 to allow us to do what we talked about in our weekly #1308 and provide a lot of different controls
MotionKit won't need to depend on IMUKit and Motors, only the controls will depend on those
RotationControl _rotation_control; | ||
StabilizationControl _stabilization_control; |
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.
for now, we'll say this is okay.
for 1.5.0, it must be refactored to instanciate control classes outside and register/start them when needed.
on the same model as CommandKit
This will allow us to add more controls without the need to recompile MotionKit
libs/MotionKit/include/MotionKit.hpp
Outdated
void calculateTotalYawRotation(float yaw); | ||
void setMotorsSpeedAndDirection(float speed, Rotation direction); |
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.
do both controls need those?
if not, they could be move to the control class that needs them.
void processAngleForRotation(const EulerAngles &angles, Rotation direction); | ||
void processAngleForStabilization(const EulerAngles &angles); |
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.
in a future PR, this should replaced by start(control_name)
_imukit(imu_kit), | ||
_event_loop(event_loop), | ||
_timeout(timeout) | ||
MotionKit(interface::Motor &motor_left, interface::Motor &motor_right, interface::IMUKit &imu_kit, |
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.
in a futur PR/refactor, I think MotionKit will not depend on IMUKit but instead, each control class that needs it will depend on what is needed.
just like CommandKit
same for the motors, etc.
MotionKit will just need to start and stop the control without knowing what the control actually does.
9f109ee
to
0f61fec
Compare
0f61fec
to
280f03a
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.
Seems like a few things have changed between yesterday and now, I've made new change requests.
to me, too much "rotation" logic is still present in MotionKit whereas it should be moved to RotationControl.
auto RotationControl::calculateYawRotation(float previous_yaw, float yaw) -> float | ||
{ | ||
auto abs_yaw_delta = std::abs(previous_yaw - yaw); | ||
if (abs_yaw_delta >= 300.F) { | ||
return 360.F - abs_yaw_delta; | ||
} | ||
return abs_yaw_delta; |
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.
auto RotationControl::calculateYawRotation(float previous_yaw, float yaw) -> float | |
{ | |
auto abs_yaw_delta = std::abs(previous_yaw - yaw); | |
if (abs_yaw_delta >= 300.F) { | |
return 360.F - abs_yaw_delta; | |
} | |
return abs_yaw_delta; | |
auto RotationControl::calculateYawRotation(float previous, float current) -> float | |
{ | |
auto abs_delta = std::abs(previous - current); | |
if (abs_delta >= 300.F) { | |
return 360.F - abs_delta; | |
} | |
return abs_delta; |
libs/MotionKit/source/MotionKit.cpp
Outdated
_angle_rotation_sum += _rotation_control.calculateYawRotation(_euler_angles_previous.yaw, angles.yaw); | ||
|
||
while (_stabilisation_requested || _target_not_reached) { | ||
auto [pitch, roll, yaw] = _imukit.getEulerAngles(); | ||
auto [speed, rotation] = _pid.processPID(pitch, roll, yaw); | ||
if (_rotate_x_turns_requested && _target_not_reached) { | ||
auto speed = _rotation_control.processRotationAngle(_angle_rotation_target, _angle_rotation_sum); |
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.
why do you need this to be here?
the RotationControl should handle this logic, not MotionKit
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.
the whole function should be in RotationControl
you push the raw yaw value as input and get speed + direction as output
(before we move all that to the control class completely)
libs/MotionKit/source/MotionKit.cpp
Outdated
_euler_angles_previous = _imukit.getEulerAngles(); | ||
|
||
_target_not_reached = true; | ||
_stabilisation_requested = false; | ||
_rotate_x_turns_requested = true; | ||
|
||
_rotations_to_execute = number_of_rotations; | ||
|
||
_motor_left.spin(direction, kPwmMaxValue); | ||
_motor_right.spin(direction, kPwmMaxValue); | ||
_angle_rotation_sum = 0; | ||
_angle_rotation_target = number_of_rotations * 360.F; | ||
|
||
auto on_timeout = [this] { stop(); }; | ||
|
||
_timeout.onTimeout(on_timeout); | ||
_timeout.start(10s); | ||
|
||
_event_loop.start(); | ||
auto on_euler_angles_rdy_callback = [this, direction](const EulerAngles &euler_angles) { | ||
processAngleForRotation(euler_angles, direction); | ||
}; | ||
|
||
_imukit.onEulerAnglesReady(on_euler_angles_rdy_callback); | ||
|
||
_on_rotation_ended_callback = on_rotation_ended_callback; |
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.
All of this should be part of RotationControl
SonarCloud Quality Gate failed. |
PR split into:
|
MotionKit refactor following the previous IMUKit refactor with the Fusion algorithm and an asynchronous behavior.