Skip to content

Commit 5cb8205

Browse files
authored
Merge pull request #151 from pariterre/Quaternion
Added Qranges for quaternions
2 parents 76cf8e4 + 9e73af9 commit 5cb8205

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

examples/forwardDynamicsExample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
int main()
1616
{
1717
// Load a predefined model
18-
biorbd::Model model("pyomecaman.bioMod");
18+
biorbd::Model model("/home/pariterre/Programmation/sandbox/biorbd-dev/ModeleBaton_1bras_EpaulesQuat.bioMod");
1919

2020
// Choose a position/velocity/torque to compute dynamics from
2121
biorbd::rigidbody::GeneralizedCoordinates Q(model);

src/ModelReader.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ void biorbd::Reader::readModelFile(
148148
if (rot.compare("q")){
149149
// If not a quaternion
150150
rotLength = rot.length();
151+
} else {
152+
rotLength = 4;
151153
}
152154
for (size_t i=0; i<trans.length() + rotLength; ++i){
153155
file.read(min);
@@ -163,6 +165,8 @@ void biorbd::Reader::readModelFile(
163165
if (rot.compare("q")){
164166
// If not a quaternion
165167
rotLength = rot.length();
168+
} else {
169+
rotLength = 3;
166170
}
167171
for (size_t i=0; i<trans.length() + rotLength; ++i){
168172
file.read(min);
@@ -178,6 +182,8 @@ void biorbd::Reader::readModelFile(
178182
if (rot.compare("q")){
179183
// If not a quaternion
180184
rotLength = rot.length();
185+
} else {
186+
rotLength = 3;
181187
}
182188
for (size_t i=0; i<trans.length() + rotLength; ++i){
183189
file.read(min);
@@ -285,17 +291,26 @@ void biorbd::Reader::readModelFile(
285291
if (rot.compare("q")){
286292
// If not a quaternion
287293
rotLength = rot.length();
294+
} else {
295+
rotLength = 4;
288296
}
289297
for (size_t i=0; i<trans.length() + rotLength; ++i){
290-
QRanges.push_back(
291-
biorbd::utils::Range ());
298+
if (!rot.compare("q") && i>=trans.length()){
299+
QRanges.push_back(
300+
biorbd::utils::Range (-1, 1));
301+
} else {
302+
QRanges.push_back(
303+
biorbd::utils::Range ());
304+
}
292305
}
293306
}
294307
if (!isRangeQDotSet){
295308
size_t rotLength(0);
296309
if (rot.compare("q")){
297310
// If not a quaternion
298311
rotLength = rot.length();
312+
} else {
313+
rotLength = 3;
299314
}
300315
for (size_t i=0; i<trans.length() + rotLength; ++i){
301316
QDotRanges.push_back(
@@ -307,6 +322,8 @@ void biorbd::Reader::readModelFile(
307322
if (rot.compare("q")){
308323
// If not a quaternion
309324
rotLength = rot.length();
325+
} else {
326+
rotLength = 3;
310327
}
311328
for (size_t i=0; i<trans.length() + rotLength; ++i){
312329
QDDotRanges.push_back(

src/RigidBody/Segment.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,22 @@ void biorbd::rigidbody::Segment::setDofs(
283283
}
284284
biorbd::utils::Error::check(
285285
QRanges.size() == 0 ||
286-
QRanges.size() == seqT.length() + nRot,
286+
QRanges.size() == seqT.length() + nRot ||
287+
(QRanges.size() == 4 && m_isQuaternion),
287288
"QRanges and number of dof must be equal");
288289
*m_QRanges = QRanges;
289290

290291
biorbd::utils::Error::check(
291292
QDotRanges.size() == 0 ||
292-
QDotRanges.size() == seqT.length() + nRot,
293+
QDotRanges.size() == seqT.length() + nRot ||
294+
(QDotRanges.size() == 3 && m_isQuaternion),
293295
"QDotRanges and number of dof must be equal");
294296
*m_QDotRanges = QDotRanges;
295297

296298
biorbd::utils::Error::check(
297299
QDDotRanges.size() == 0 ||
298-
QDDotRanges.size() == seqT.length() + nRot,
300+
QDDotRanges.size() == seqT.length() + nRot ||
301+
(QDDotRanges.size() == 3 && m_isQuaternion),
299302
"QDDotRanges and number of dof must be equal");
300303
*m_QDDotRanges = QDDotRanges;
301304
setJoints(model);

0 commit comments

Comments
 (0)