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

Implement hardstops for spinningBodiesOneDOF #646

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ascended121
Copy link
Contributor

@ascended121 ascended121 commented Mar 15, 2024

Description

It is not uncommon for realistic actuators have a non-finite range of motion (ie, if they don't use slip-rings and have cable bundles running through them which cannot rotate, or if there would be mechanical interferences with other parts of the structure at certain angles). Modeling these limits can be important to the practical use of these actuators and associated bodies.

To increase the fidelity of the spinningBodyOneDOF, this PR adds (optional) angular limits to the model. Once theta reaches these locations, the spinningBodyOneDOF will not move further than the boundary.

These limits are set to +/-Inf by default, so that they have no effect unless the caller explicitly sets them to a smaller range.

Verification

Added unit tests verifying that the model respects various configurations of the limits. Existing tests verify that not specifying the limits does not impact default behavior of model.

Documentation

Updated rst file associated with model to document the existence/example usage of these limits.

Future work

Its not of interest for my work, but for high fidelity dynamics simulation it would be possible to model the interaction of the spinningBody with the hardstop (by specifying the mechanical stiffness/damping of the angular limit).

Also, it seems that raising an exception (to stop the program) is the proper response for an invalid configuration (rather than just logging an exception, which the user might ignore (either intentionally or accidentally) and get invalid results). I implemented the ability to propagate a C++ exception to python in the SWIG wrapper for this function. Perhaps it would make sense to generalize this exception handling to make it more widely available to other basilisk modules.

@schaubh schaubh requested a review from joaogvcarneiro March 19, 2024 19:24
@schaubh
Copy link
Contributor

schaubh commented Mar 19, 2024

@joaogvcarneiro , could you please take a look at this PR to your module? Thanks.

@schaubh schaubh self-assigned this Apr 17, 2024
@schaubh schaubh added the enhancement New feature or request label Apr 17, 2024
@schaubh
Copy link
Contributor

schaubh commented May 7, 2024

@joaogvcarneiro , could you please take a look at this PR to your module? Thanks.

@joaogvcarneiro , final finals over now, have you had a chance to look at this PR? Thanks for your review.

Copy link
Contributor

@schaubh schaubh left a comment

Choose a reason for hiding this comment

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

Finally got to look at this full branch. Sorry for the delay, this PR definitely got lost in the cracks this summer.

I like your contribution and added some comments. Overall clean work, but one unit test doesn't appear to be working yet. Also, if something is off I'd like to use the BSK_ERROR message that the BSK software can control. If you have feedback on this last request, glad to chat more :-)

Please rebase your branch on the latest develop as well. I just rebased my copy and didn't have any issues.

Thanks again for supporting the BSK framework. I appreciate this contribution and think these limits will be of interest to the community.

spinningBody.theta_min = np.deg2rad(min_lim)

with pytest.raises(ValueError):
spinningBody.Reset(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

This test doesn't have an assert statement? It passes regardless of what values I put in it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Squash this with the prior commits to clean up the commit history.

torque = torque_log.motorTorque[:, 0]
thetaDot = spinning_body_log.thetaDot
omega = sc_log.omega_BN_B

Copy link
Contributor

Choose a reason for hiding this comment

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

please close all prior plots before making new plots. This is helpful when running lots of tests at once.

@@ -310,8 +310,8 @@ def test_spinning_body_enforces_limits(max_lim, min_lim):
spinningBody.theta_max = np.deg2rad(max_lim)
spinningBody.theta_min = np.deg2rad(min_lim)

with pytest.raises(ValueError):
spinningBody.Reset(0)
# with pytest.raises(ValueError) as exc:
Copy link
Contributor

Choose a reason for hiding this comment

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

please split and squash these commits to the final version to clean up the commit history.

@@ -70,13 +70,14 @@ void SpinningBodyOneDOFStateEffector::Reset(uint64_t CurrentClock)
}
// Ensure user specified valid angular limits
if (this->theta_max < this->theta_min) {
bskLogger.bskLog(
BSK_ERROR, "theta_max (%f) must be greater than theta_min (%f).", this->theta_max, this->theta_min);
throw std::invalid_argument("theta_max (" + std::to_string(this->theta_max)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to keep the BSK_ERROR message as well, as this is expected behavior of a BSK module across the framework. I don't mind if you also include the throw argument as well.


#include <stdexcept>

%exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not following what this swig code is doing? Could you please add some comments on what is being done here?

@schaubh
Copy link
Contributor

schaubh commented Sep 11, 2024

Howdy @ascended121 , just checking that you are still actively pursuing this PR? Thanks for the quick feedback. The requested edits are fairly minor.

@schaubh
Copy link
Contributor

schaubh commented Sep 21, 2024

Howdy @ascended121 , just a quick ping to see if you are still active on this branch? If not, I can try to pull this branch and make the required fixes before pushing? Thanks for the quick feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

2 participants