Skip to content

Change thrusterData to a pointer#967

Merged
schaubh merged 2 commits into
developfrom
feature/952-avoid-duplication-of-thruster-config-messages
Apr 20, 2025
Merged

Change thrusterData to a pointer#967
schaubh merged 2 commits into
developfrom
feature/952-avoid-duplication-of-thruster-config-messages

Conversation

@Yume27
Copy link
Copy Markdown
Contributor

@Yume27 Yume27 commented Mar 31, 2025

  • Tickets addressed: bsk-952
  • Review: By commit
  • Merge strategy: Merge (no squash)

Description

Changed the thruster config message in thrusterDynamicEffector to a pointer, duplication of thruster config messages is avoided, and parameters can be easily modified during simulation.

Verification

Unit test was done with test_ThrusterDynamicsUnit.py

Documentation

N/A

Future work

N/A

@Yume27 Yume27 added the enhancement New feature or request label Mar 31, 2025
@Yume27 Yume27 self-assigned this Mar 31, 2025
@Yume27 Yume27 requested a review from a team as a code owner March 31, 2025 15:09
@Yume27 Yume27 linked an issue Mar 31, 2025 that may be closed by this pull request
@Yume27 Yume27 added this to Basilisk Mar 31, 2025
@Yume27 Yume27 force-pushed the feature/952-avoid-duplication-of-thruster-config-messages branch from 6b7dfe1 to 3984f1a Compare March 31, 2025 16:53
@schaubh schaubh moved this to 👀 In review in Basilisk Mar 31, 2025
@schaubh schaubh self-requested a review March 31, 2025 17:06
@juan-g-bonilla
Copy link
Copy Markdown
Contributor

Have you thought about using std::shared_ptr instead of a raw pointer? It'd allow you to share the thrusterData between different models and with Python, and it'll get automatically cleared once no one is using it. By creating these objects in Python and passing them as raw pointers to C++, you risk use-after-free (segfault if you're lucky!). If the Python objects go out of scope, they will get garbage collected (so the C++ object will be cleared from memory), but your models will still have pointers to them! We've had this problem in the past for standalone messages created in Python functions that never get returned.

Take a look at how gravityModel gets handled in gravityEffector. It's all very transparent to users, and you don't have to worry about handling its memory. You only need to add:

%include <std_shared_ptr.i>
%shared_ptr(THRSimConfig)

to the SWIG interface file before you %include "simulation/dynamics/_GeneralModuleFiles/THRSimConfig.h". A better approach would be to create a THRSimConfig.i file an %import -ing that instead of %include.

@schaubh
Copy link
Copy Markdown
Contributor

schaubh commented Apr 1, 2025

Howdy @juan-g-bonilla, thanks for the suggestion. I think I'd like to try this, but in a separate branch. We did the RW configuration messages as raw pointers as well. If we change this, I'd like to change both RW and thrusters at once. I like the benefits you list for having better memory management if something is connected to these configuration message objects.

@schaubh
Copy link
Copy Markdown
Contributor

schaubh commented Apr 1, 2025

Mm, looking at the unit tests, we are getting a lot of segfault errors. I'm assuming we have several scenarios where the thruster info is copied to the BSK effector and then not retained. With the raw pointers this leads to seg faults.

@Yume27 , could you please try out @juan-g-bonilla's suggestion above for this branch? Right now the tests are not passing. Please be sure to test all BSK tests on your computer as well before pushing a PR.

Copy link
Copy Markdown
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.

The BSK tests are not all passing. See Juan's suggestion on using smart pointers.

Also, be sure to document these changes by updating the Release Notes, and update the thruster RST documentation.

@Yume27
Copy link
Copy Markdown
Contributor Author

Yume27 commented Apr 1, 2025

Mm, looking at the unit tests, we are getting a lot of segfault errors. I'm assuming we have several scenarios where the thruster info is copied to the BSK effector and then not retained. With the raw pointers this leads to seg faults.

@Yume27 , could you please try out @juan-g-bonilla's suggestion above for this branch? Right now the tests are not passing. Please be sure to test all BSK tests on your computer as well before pushing a PR.

Do you recommend trying what @juan-g-bonilla suggested rather than adapting each example script that was affected by the change?

@schaubh
Copy link
Copy Markdown
Contributor

schaubh commented Apr 1, 2025

Let's try @juan-g-bonilla's suggestion to see if this helps here.

@Yume27 Yume27 moved this from 👀 In review to 🏗 In progress in Basilisk Apr 14, 2025
@Yume27 Yume27 force-pushed the feature/952-avoid-duplication-of-thruster-config-messages branch 3 times, most recently from 815d618 to 0dfd611 Compare April 19, 2025 00:14
@schaubh schaubh moved this from 🏗 In progress to 👀 In review in Basilisk Apr 19, 2025
@schaubh schaubh force-pushed the feature/952-avoid-duplication-of-thruster-config-messages branch from 0dfd611 to d586a07 Compare April 19, 2025 14:08
@schaubh schaubh force-pushed the feature/952-avoid-duplication-of-thruster-config-messages branch from d586a07 to 90e9dbd Compare April 19, 2025 23:35
@schaubh schaubh merged commit 92a7d8c into develop Apr 20, 2025
11 checks passed
@schaubh schaubh deleted the feature/952-avoid-duplication-of-thruster-config-messages branch April 20, 2025 13:56
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in Basilisk Apr 20, 2025
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: ✅ Done

Development

Successfully merging this pull request may close these issues.

Avoid duplication of thruster config messages

3 participants