Page 1 of 1

Some questions about MocoOutputConstraint

Posted: Mon Mar 06, 2023 2:28 pm
by luckyme
Dear Moco development team and Moco users,

Thank you all for your contributions to the biomechanics community! I have some questions about how to use MocoOutputConstraint, I would appreciate it if anyone could give me some advice.

1.I try to use the following codes in Visual Studio C++ to customize bounds for MocoOutputConstraint

Code: Select all

auto* Con= problem.addPathConstraint<MocoOutputConstraint>();
Con ->setOutputPath("/user/defined|path");
Con ->setOutputIndex(0);
Con ->setExponent(1);
auto Coninfo= Con ->updConstraintInfo();
Coninfo.setBounds({-6,6});
After running the codes,the console and opensim.log both show that the bounds of this MocoOutputConstraint is still 0, indicating that the bounds I want to custom have not taken effect.
What should I do to custom bounds for MocoOutputConstraint?

2.From the links below, I can see that the functions setEndpointConstraintBounds() and getEndpointConstraintBounds() have been added to the class MocoGoal to support MocoConstraintInfo::get/setBounds() in bindings for Matlab/Python. After Moco is updated, can these two methods be called through Matlab/Python API to custom bounds for MocoOutputConstraint?

https://github.com/opensim-org/opensim- ... OG_MOCO.md
https://github.com/opensim-org/opensim-core/issues/3322

Thanks again for your patience and time and I am looking forward to hearing from you!

Best Wishes,
Matthew

Re: Some questions about MocoOutputConstraint

Posted: Thu Mar 09, 2023 6:00 pm
by nbianco
Hi Matthew,

You might be accidentally making a copy of the constraint info, which isn't getting propagated to the problem. Also, setBounds() takes a std::vector<MocoBounds>. Try this:

Code: Select all

MocoConstraintInfo& info = Con->updConstraintInfo();
std::vector<MocoBounds> bounds;
bounds.push_back({-6, 6});
info.setBounds(bounds);
You could also try constructing a new constraint info to see if that works:

Code: Select all

MocoConstraintInfo info;
std::vector<MocoBounds> bounds;
bounds.push_back({-6, 6});
info.setBounds(bounds);
Con->setConstraintInfo(info);
Best,
Nick

Re: Some questions about MocoOutputConstraint

Posted: Fri Mar 10, 2023 4:10 am
by luckyme
Hi Nick,

Thanks for your guidance, your method works well, thank you!

Best Wishes,
Matthew