Constraints part:2

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Nithin Kurup
Posts: 149
Joined: Sat Jan 18, 2014 5:13 am

Constraints part:2

Post by Nithin Kurup » Thu Jun 25, 2015 1:03 pm

Hi,

I have sort of implemented the member function, constraintfunc() with contents similar to objectivefunc(). Now I really want help with setting this constraint equation,

Equation I need : CoordinateB(finaltime) = CoordinateB (value=360deg)

Objective: The simulation shouldn't end before the set final time of integration, and when coordinate reaches final time the value should be around 360 (deg )in radians or vice versa.

This is how I tried,

LHS: I couldnt find any code which I can relate the coordinate & final time ?
RHS: I plan to set the value to 6 radians but dont know if its the right approach.

Code: Select all

Coordinate& codB = _model.getCoordinateSet().get("coordinateB");
int re = 6; //  360 deg approx radian
int tf = osimState.getTime();
if (tf=finalTime){
constraints[0] = codB.getValue(s) -[codB.setValue( s,re, true)];
OR
constraints[0] = codB.getValue(s) -6;
}
else
{
// Problem if simulation finish before final time if condition doesn't happen
};
This is the first time I am setting up an equation..and I am completely wrong, kindly help.

regards,

Nithin

User avatar
Michael Sherman
Posts: 807
Joined: Fri Apr 01, 2005 6:05 pm

Re: Constraints part:2

Post by Michael Sherman » Thu Jun 25, 2015 3:44 pm

Nithin, it is important to untangle the optimization from the integration! You have some optimization parameters p, some objective function f(p), and some constraints g(p). The optimizer will solve:

Code: Select all

minimize f(p)
subject to g(p)=0
I suggest that you consider carefully:
- what are your optimization parameters p? For example, is final time a parameter?
- what is your function f? Perhaps f is the result of an integration that runs until a particular time is reached, or maybe it is one that runs until a coordinate achieves a particular value. In the latter case the final time would be a *result* of that computation.
- what is your function g? Typically it will be some constraints using the same computation that was performed to evaluate f.

Possibly you are asking a question about how to terminate a simulation when a certain condition is reached. But it would be much easier to discuss if you can clarify p, f, and g.

Sherm

User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Re: Constraints part:2

Post by Jiang Ping » Thu Jun 25, 2015 11:43 pm

Your purpose is unclear.

If you wanted Coordinate B to keep constant all the time during simulation, why not add constraint to B in the model,
and then minimize the constraint force of it?

If you just wanted Coordinate B to be a constant value at the final time of simulation, constraints[0] = codB.getValue(s) -6
were correct i think. In the case that simulation was stopped by a event trigger before final time you have set, the solution should be abandoned (?,i guess)

User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Re: Constraints part:2

Post by Jiang Ping » Thu Jun 25, 2015 11:56 pm

Also some small problems of your code


int re = 6; should be double re=6*SimTK::PI/180
int tf = osimState.getTime(); should be double tf=osimState.getTime();
if (tf=finalTime) should be if(tf==finalTime) or if(fabs(tf-finalTime)<1.0e-6)

POST REPLY