Some questions about MocoOutputConstraint

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Matthew Lee
Posts: 52
Joined: Sat Jun 20, 2020 7:46 pm

Some questions about MocoOutputConstraint

Post by Matthew Lee » Mon Mar 06, 2023 2:28 pm

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

User avatar
Nicholas Bianco
Posts: 1028
Joined: Thu Oct 04, 2012 8:09 pm

Re: Some questions about MocoOutputConstraint

Post by Nicholas Bianco » Thu Mar 09, 2023 6:00 pm

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

User avatar
Matthew Lee
Posts: 52
Joined: Sat Jun 20, 2020 7:46 pm

Re: Some questions about MocoOutputConstraint

Post by Matthew Lee » Fri Mar 10, 2023 4:10 am

Hi Nick,

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

Best Wishes,
Matthew

POST REPLY