Comments (19)
Okay I created a new env for this project and got 1.8.2. Now the SegmentCharacteristics constructor is available, thank you so much!
from biorbd.
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 :
qrange = [biorbd.Range(-np.pi/", np.pi/2)] * 6
But in the process of using writing, I forgot to add the export of ranges which was added later, so it is ignored anyway, so you can pass an empty list. The ranges are only for the user actually, it is never used as a constraints while performing any task. It is merely used by bioviz to set the limits of the sliders. I should add them to the writer anyway at some point.
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")
from biorbd.
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!
from biorbd.
Thank you, but your answer doesn't explain why the class is missing.
I already have the kinematics available (as spatial transform matrices of all joint frames over time). What I want to do now is set the inertia properties for each of the segments (mass, com, inertia matrix). Even for "characteristics()" there is no set function for the inertia matrix..
from biorbd.
Hi again!
I see what you mean... This can be a bit tricky. For most of the rigidbody calculation, biorbd relies on RBDL. Therefore some things in the dynamics cannot be changed once the model is constructed. The SegmentCharacteristics is one of them. It appears in the documentation as the automatically generated documentation from the C++ code, and not the Python doc per se. Since one cannot completely change a segment characteristics, it was not interface for Python.
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 biorbd.Model("pendulum.py")
:
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?
from biorbd.
Hi,
Thanks a lot! I want to create the segments from my data, merge them to a model and then write it to a file with writeModel for later use. A segment.characteristics().setMass method would also be helpful, because then I can just use the RBDL Segment constructor (if it is available in python for biorbd) and specify the segment characteristics here
from biorbd.
I see!
If you want to create a segment characterics, you can directly call the constructor then :
import biorbd
characteristics = biorbd.SegmentCharacteristics(1, biorbd.Vector3d(1, 2, 3), biorbd.Matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9))
from biorbd.
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?
Because the snippet I just posted should work, but I am not sure I see the difference with what you have wrote :S
from biorbd.
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
from biorbd.
Yep, that is why, biorbd is now on 1.8.2..
from biorbd.
Ohh! That is weird, I installed it a week ago, and never thought about updating, thanks!
from biorbd.
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 :)
from biorbd.
Ok yeah, maybe I have to clean up my virtual environment first, because when I try to update with "conda update biorbd" I get some error..
If I try it out, SegmentCharacteristics is still missing, so probably my env is the problem..
from biorbd.
Cleaning is a good idea, otherwise, you may want to specify the biorbd version:
conda install biorbd=1.8.2 -cconda-forge
from biorbd.
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)
from biorbd.
Sorry, for reopening again but I got one more question on the Segment constructor. I specified each argument but the spatial transform "cor". What to do about it? Should I use biorbd.Matrix(4,4), but how to populate the matrix then? Or biorbd.RotoTrans? The "AddSegment" method also has this "cor" argument.
My simple question is therefore just how I can add a segment to my model, without manually editing the file.
Hi, Thanks a lot! I want to create the segments from my data, merge them to a model and then write it to a file with writeModel for later use. A segment.characteristics().setMass method would also be helpful, because then I can just use the RBDL Segment constructor (if it is available in python for biorbd) and specify the segment characteristics here
from biorbd.
Hi again :)
I do not think you actually need to create a segment to add it to the model. There is a method called AddSegment
which properly prepare the Segment itself and updates other variables in the process. This interface method actually expects a 4x4 homogenous matrix, called RotoTrans (that is the rotation matrix concatenated with the translation matrix with a 0 0 0 1 line at the bottom)
[R3x3 T3x1 ]
[ 0 0 0 1 ]
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).
Please note that there are constructor of that 4d matrix that are very useful, especially this one :
RotoTrans(
const Vector& rotation,
const Vector3d& translation,
const String &rotationSequence);
from biorbd.
Ok, I tried to use AddSegment, but it still doesn't work. Maybe I specified something else wrong.
Here is my code:
from biorbd.
Ohhh no. Thank you!
from biorbd.
Related Issues (20)
- anticlockwise rotation in .bioMod HOT 1
- Printing matrices in casadi HOT 2
- getting COM for the whole model HOT 6
- Add ligaments HOT 2
- Choose the muscle characteristic curves instead of a muscle type
- missing euler-cardan sequence yxy HOT 2
- Degree to radian
- Conda install PackagesNotFoundError HOT 3
- Possible to use coordinates of pose estimation with pyomeca? HOT 1
- Issues with the biorbd.model_creation HOT 5
- Create a flag to consider of not the mesh form the model HOT 2
- Declaration LoopConstraint HOT 2
- Constrained EKF HOT 1
- Angular momentum around contact points HOT 4
- Correct presentation of joint angles from biorbd? HOT 16
- Perform inverse dynamics with IMUs and forces from pressure insoles
- Bug in ID with ExternalForceSet ? HOT 6
- SetLocalJCS crash in biorbd_casadi
- Set Symbolic markers HOT 4
- Bug on musculotendon length HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from biorbd.