Skip to content

Commit

Permalink
Fixed index bug in the new external force
Browse files Browse the repository at this point in the history
  • Loading branch information
pariterre committed Nov 13, 2023
1 parent c7c6da4 commit a40ca3d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/ModelReader.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef BIORBD_UTILS_READ_H
#define BIORBD_UTILS_READ_H

#include <stddef.h>
#include <vector>
#include <map>
#include "biorbdConfig.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ModelReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ rigidbody::Mesh Reader::readMeshFileStl(
char dummy[2];
file.readFromBinary(headerChar, 80); // Skip header
file.readFromBinary(nbTrianglesChar, 4);
size_t nbTriangles = *((size_t*) nbTrianglesChar);
size_t nbTriangles = static_cast<size_t>(*((unsigned int*) nbTrianglesChar));

mesh.setPath(path);
utils::Vector3d normal;
Expand Down
9 changes: 5 additions & 4 deletions src/RigidBody/ExternalForceSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ void rigidbody::ExternalForceSet::add(
const utils::SpatialVector& vector
)
{
size_t dofIndex = m_model.segment(segmentName).getLastDofIndexInGeneralizedCoordinates(m_model);
m_externalForces[dofIndex] += vector; // Do not subtract 1 since 0 is used for the base ground
// Add 1 since 0 is used for the base ground
size_t dofIndex = m_model.segment(segmentName).getLastDofIndexInGeneralizedCoordinates(m_model) + 1;
m_externalForces[dofIndex] += vector;
}

void rigidbody::ExternalForceSet::add(
Expand Down Expand Up @@ -273,7 +274,7 @@ void rigidbody::ExternalForceSet::combineTranslationalForces(

for (size_t i = 0; i <m_model.nbSegment(); ++i) {
const rigidbody::Segment& segment(m_model.segment(i));
// (Add 1 to account for the undeclared root
// Add 1 to account for the undeclared root
size_t dofIndex = segment.getLastDofIndexInGeneralizedCoordinates(m_model) + 1;

for (auto& e : m_translationalForces) {
Expand Down Expand Up @@ -319,7 +320,7 @@ void rigidbody::ExternalForceSet::combineSoftContactForces(

for (size_t i = 0; i < m_model.nbSegment(); ++i) {
const rigidbody::Segment& segment(m_model.segment(i));
// Add 1 to account for the undeclared root
// Add 1 to account for the undeclared root
size_t dofIndex = segment.getLastDofIndexInGeneralizedCoordinates(m_model) + 1;

for (size_t j = 0; j < m_model.nbSoftContacts(); j++) {
Expand Down

0 comments on commit a40ca3d

Please sign in to comment.