-
Notifications
You must be signed in to change notification settings - Fork 45
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
SegmentCharacteristics class? #245
Comments
Dear @yugiero This snippet should help : import biorbd # or biorbd_casadi if you are interested in casadi backend
import numpy as np
# Load a bioMod file
m = biorbd.Model("path_to_model.bioMod")
# Printing the current center of mass of the first segment
print(m.segment(0).characteristics().CoM().to_array())
# Change the CoM position to [1, 2, 3]
new_com = np.array([1, 2, 3])
m.segment(0).characteristics().setCoM(new_com)
# Print the new position
print(m.segment(0).characteristics().CoM().to_array()) In the code you pasted, you don't seem to have a model loaded prior, while it is not entirely impossible, I'd strongly suggest to have a bioMod constructed before Hope this helps! |
Thank you, but your answer doesn't explain why the class is missing. |
Hi again! That said, the matrix of intertia (inside a segment characteristics) just like the CoM can be changed. I actually simply forgot to add a set method to modify it. I made a PR #246 to fix this. If you compiled biorbd yourself, this will be shortly available. If you used conda to install, I will make a release shortly and let you know when you can update. That said, the bioMod file can (and should) be used to define the CoM, inertia matrix and the mass. Unless you want to dynamically change these values (for instance optimizing them), you should define them in the bioMod file and not in the actual code. For example the following line could be copy-pasted in pendulum.bioMod and loaded using The following file describe a pendulum that translate and rotate in 2d, with mass 1kg, com -0.0005 0.0688 -0.9542 and an inertia matrix version 4 // This should always be 4
segment Seg1
translations y
rotations x
mass 1
inertia
0.0391 0.0000 0.0000
0.0000 0.0335 -0.0032
0.0000 -0.0032 0.0090
com -0.0005 0.0688 -0.9542
endsegment Does this answer your questions? |
I see! import biorbd
characteristics = biorbd.SegmentCharacteristics(1, biorbd.Vector3d(1, 2, 3), biorbd.Matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9)) |
it seems that it is what you were asking in the first post... What is your version of biorbd and how did you installed it? |
The snippet doesn't work, unfortunately. I've installed it through conda, following the instructions on the github main page of biorbd. My version is 1.1.2 |
Yep, that is why, biorbd is now on 1.8.2.. |
Ohh! That is weird, I installed it a week ago, and never thought about updating, thanks! |
That is probably because the environment you used to install biorbd was not clean (new) as anaconda tries to find the best version that minimize the changes of version (or even prevents incompatibilities). Doing so, it may fall back to old version, if for instance, you already installed a specific version of Python, but the current required version for biorbd is newer. For myself, I use one simple rule : one virtual environment by project. Like that I make sure previous installation does not pollute the future ones :) |
Cleaning is a good idea, otherwise, you may want to specify the biorbd version: |
But this is dangerous as it won't be updated in the future (because you specified that you want this specific version and nothing else) |
Okay I created a new env for this project and got 1.8.2. Now the SegmentCharacteristics constructor is available, thank you so much! |
Hi again :) Since I've never created a Segment in Python (because of this interface method), I never noticed that I've left the RBDL SpatialTransform there (which is equivalent to the 4d matrix).
|
The problem are the Ranges, they should be a list of ranges (one by dof, you declared 6 dof (xyz translations, xyz rotations), so it expects : The following snippets adds two segments and export them to a bioMod: import biorbd
import numpy as np
# Defining two identical segments for testing
name_first = "First_segment"
name_second = "Second_segment"
parent_first = "ROOT"
parent_second = "Pelvis"
translations = "xyz"
rotations = "xyz"
ranges = []
roto_trans = biorbd.RotoTrans(np.array([1, 2, 3]), np.array([4, 5, 6]), "xyz")
mass = 10
com = biorbd.Vector3d(1, 2, 3)
inertia = biorbd.Matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9)
char = biorbd.SegmentCharacteristics(mass, com, inertia)
# Create an empty model and add the two segments
lukas = biorbd.Model()
lukas.AddSegment(name_first, parent_first, translations, rotations, ranges, ranges, ranges, char, roto_trans)
lukas.AddSegment(name_second, parent_second, translations, rotations, ranges, ranges, ranges, char, roto_trans)
# Write the model and read back
biorbd.Writer().writeModel(lukas, "coucou.bioMod")
lukas_coucou = biorbd.Model("coucou.bioMod") |
Ohhh no. Thank you! |
Although the "SegmentCharacteristics" class is listed in the documentation, it is missing for me. I want to SET the characteristics of a segment using python by segment.SegmentCharacteristics(mass, inertia, com), not RETURN them, which I can do by segm.characteristics().
Is this method deprecated?
Here is the doc link:
https://pyomeca.github.io/Documentation/biorbd/classbiorbd_1_1rigidbody_1_1SegmentCharacteristics.html
The text was updated successfully, but these errors were encountered: