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

Feature/improve wrench computation #1343

Open
wants to merge 5 commits into
base: devel
Choose a base branch
from

Conversation

rjgriffin42
Copy link

No description provided.

@hrp2-14

This comment was marked as resolved.

@rjgriffin42 rjgriffin42 force-pushed the feature/improve-wrench-computation branch from ed9ff75 to 80845bd Compare February 11, 2025 20:34
@nim65s nim65s changed the base branch from master to devel February 11, 2025 20:37
Copy link
Member

@cmastalli cmastalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @rjgriffin42!

A few, yet simple, minor requests.

@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

* Updated the rotation transpose in contact wrench cone to re-use the same object to avoid additional transpose operations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indicate the PR as in the examples above. Also, notice that there is a conflict with other changes in the changelog.

*
* @param[in] cost_item Cost item
*/
void addCost(const boost::shared_ptr<CostItem>& cost_item);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We recently moved to std::shared_ptr, as you can see in this {boost -> std}::shared_ptr #1339.
  2. I suggest defining weight (in the code above) as a default argument. This will require to update the Python bindings.
Suggested change
void addCost(const boost::shared_ptr<CostItem>& cost_item);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value should be 1, of course.

Comment on lines +54 to +73
template <typename Scalar>
void CostModelSumTpl<Scalar>::addCost(const boost::shared_ptr<CostItem>& cost_item)
{
if (cost_item->cost->get_nu() != nu_) {
throw_pretty(
cost_item->name
<< " cost item doesn't have the same control dimension (it should be " +
std::to_string(nu_) + ")");
}
costs_.insert(std::make_pair(cost_item->name, cost_item));
if (cost_item->active) {
nr_ += cost_item->cost->get_activation()->get_nr();
nr_total_ += cost_item->cost->get_activation()->get_nr();
active_set_.insert(cost_item->name);
} else {
nr_total_ += cost_item->cost->get_activation()->get_nr();
inactive_set_.insert(cost_item->name);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the previous comment, we need to remove this

Suggested change
template <typename Scalar>
void CostModelSumTpl<Scalar>::addCost(const boost::shared_ptr<CostItem>& cost_item)
{
if (cost_item->cost->get_nu() != nu_) {
throw_pretty(
cost_item->name
<< " cost item doesn't have the same control dimension (it should be " +
std::to_string(nu_) + ")");
}
costs_.insert(std::make_pair(cost_item->name, cost_item));
if (cost_item->active) {
nr_ += cost_item->cost->get_activation()->get_nr();
nr_total_ += cost_item->cost->get_activation()->get_nr();
active_set_.insert(cost_item->name);
} else {
nr_total_ += cost_item->cost->get_activation()->get_nr();
inactive_set_.insert(cost_item->name);
}
}

Comment on lines -159 to +162
A_.row(2 * i).head(3) = (mu_nsurf + tsurf_i).transpose() * R_.transpose();
A_.row(2 * i).head(3) = (mu_nsurf + tsurf_i).transpose() * R_transpose;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made these improvements in private, but I can discard them.

Suggested change
A_.row(2 * i).head(3) = (mu_nsurf + tsurf_i).transpose() * R_.transpose();
A_.row(2 * i).head(3) = (mu_nsurf + tsurf_i).transpose() * R_transpose;
A_.row(2 * i).template head<3>() = (mu_nsurf + tsurf_i).transpose() * R_transpose;

@@ -299,6 +302,7 @@ void WrenchConeTpl<Scalar>::set_box(const Vector2s& box) {

template <typename Scalar>
void WrenchConeTpl<Scalar>::set_mu(const Scalar mu) {
mu_ = mu;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Thanks for fixing this.

This also means we're not properly unit-testing this. I would define a test_setter function in https://github.com/loco-3d/crocoddyl/blob/master/unittest/test_wrench_cone.cpp

}
A_.row(nf_).head(3) = R_.col(2).transpose();
A_.row(nf_).head(3) = R_transpose.row(2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A_.row(nf_).head(3) = R_transpose.row(2);
A_.row(nf_).template head<3>() = R_transpose.row(2);

@@ -156,26 +159,26 @@ void WrenchConeTpl<Scalar>::update() {
Scalar theta_i = theta * static_cast<Scalar>(i);
Vector3s tsurf_i = Vector3s(cos(theta_i), sin(theta_i), Scalar(0.));
Vector3s mu_nsurf = -mu * Vector3s::UnitZ();
A_.row(2 * i).head(3) = (mu_nsurf + tsurf_i).transpose() * R_.transpose();
A_.row(2 * i).head(3) = (mu_nsurf + tsurf_i).transpose() * R_transpose;
A_.row(2 * i + 1).head(3) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A_.row(2 * i + 1).head(3) =
A_.row(2 * i + 1).template head<3>() =

}

// Create a temporary object for computation
Matrix3s R_transpose = R_.transpose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we allocate this data once (i.e., as a member of the structure)? Not sure if it is justified in this case. Any thought?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants