Skip to content
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

feat: compute total mass in constructor #73

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/tinyfk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class KinematicModel {

RelevancePredicateTable rptable_;
int num_dof_;
double total_mass_;

mutable SizedStack<LinkIdAndTransform> transform_stack_;
mutable SizedCache<Transform> transform_cache_;
Expand Down
9 changes: 9 additions & 0 deletions src/tinyfk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ KinematicModel::KinematicModel(const std::string &xml_string) {
}
size_t N_link = lid; // starting from 0 and finally ++ increment, so it'S ok

// compute total mass
double total_mass = 0.0;
for (const auto &link : links) {
if (link->inertial != nullptr) {
total_mass += link->inertial->mass;
}
}

// construct joints and joint_ids, and numbering joint id
std::vector<urdf::JointSharedPtr> joints;
std::unordered_map<std::string, int> joint_ids;
Expand Down Expand Up @@ -74,6 +82,7 @@ KinematicModel::KinematicModel(const std::string &xml_string) {
joints_ = joints;
joint_ids_ = joint_ids;
num_dof_ = num_dof;
total_mass_ = total_mass;
joint_angles_ = joint_angles;

// add COM of each link as new link
Expand Down
Loading