Implement PID/Position/Orientation controllers#3730
Conversation
2c3294e to
29c478b
Compare
00a0b9c to
77bdcee
Compare
StarrryNight
left a comment
There was a problem hiding this comment.
lgtm left some comments
Andrewyx
left a comment
There was a problem hiding this comment.
Looks good, left some comments. Make sure to link TODO involving writing future test.
| double k_p; | ||
| double k_i; | ||
| double k_d; | ||
| double max_integral; | ||
|
|
There was a problem hiding this comment.
These variables were public in the original implementation. But now that you bring it up, I do think that they shouldn't be publicly accessible
There was a problem hiding this comment.
I guess if we want to change the pid constants at runtime, for example to tune them programmatically? What do you think ?
There was a problem hiding this comment.
If we do that, it will probably be through a public function in this class. So these variables should be kept private anyway.
There was a problem hiding this comment.
Actually that does make sense, especially with the max_integral variable we would want a setter function that checks for the invariant. I'll make them all private for now
| { | ||
| if (max_integral < 0.0) | ||
| { | ||
| throw std::invalid_argument("PidController max_integral must be >= 0.0"); |
There was a problem hiding this comment.
Not sure if we should continue inserting exceptions into our code (despite it being used in many locations) . See https://google.github.io/styleguide/cppguide.html#Exceptions and make the design decision call. Personally, I would lean towards alternatives since it is unlikely that this exception will be caught at a higher level.
There was a problem hiding this comment.
Hmm I actually didn't know that google's c++ style guide disallows exceptions. I personally think exceptions are good, especially in this context of enforcing correct arguments in a constructor, where we would want the program to explicitly crash. If we consider that the max_integral constant would be provided by the developer, this could be changed to an assert statement?
There was a problem hiding this comment.
I agree with the alternative choice of an assertion
Andrewyx
left a comment
There was a problem hiding this comment.
This is a really clever design and a fantastic execution. Really nice work here 💯
Description
Creates an abstraction around the following code from #3716:
In the new
software/embedded/motion_controlpackage, creates three classes:PidControllerPositionControllerOrientationControllerThe step() methods in PositionController and OrientationController encapsulate the logic that was originally in PrimitiveExecutor. This makes PrimitiveExecutor take on less responsibility as now the calculations for getting the corrected target linear and angular velocities are in these new classes.
Testing Done
Unit tests were written for PidController. @williamckha told me not to write tests for PositionController and OrientationController since they might change in implementation and constants will need to be tuned.
Resolved Issues
resolves #3726
Length Justification and Key Files to Review
N/A
Review Checklist
It is the reviewers responsibility to also make sure every item here has been covered
.hfile) should have a javadoc style comment at the start of them. For examples, see the functions defined inthunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.TODO(or similar) statements should either be completed or associated with a github issue