Page 1 of 1
Linear Velocity Constraint or Goal
Posted: Tue Aug 20, 2024 10:39 am
by cattias
I am attempting to constrain the motion of my model so that the final velocity of the hand is a certain linear speed as such:
problem.setStateInfo('/bodyset/hand/speed', [0,50], 0, 10);
I am realizing that the setStatInfo does not recognize a body, and requires a joint speed to constrain. The problem is that I am interested in segment velocity, not joint velocity.
How can I go about constraining a segment in my model to start and end at a certain linear velocity? Is this better achieved through a cost function? If so, which cost?
Thank you in advance!
Re: Linear Velocity Constraint or Goal
Posted: Wed Aug 21, 2024 3:38 pm
by nbianco
Hi Cedric,
You can use
MocoFinalOutputGoal in endpoint constraint mode to achieve what you're looking for:
Code: Select all
finalHandVelocity = MocoFinalOutputGoal('final_hand_velocity);
finalHandVelocity.setOutputPath('/bodyset/hand|linear_velocity');
finalHandVelocity.setMode('endpoint_constraint');
finalHandVelocity.setEndpointConstraintBounds(MocoBounds(10));
problem.addGoal(finalHandVelocity);
Best,
Nick
Re: Linear Velocity Constraint or Goal
Posted: Fri Aug 23, 2024 8:35 am
by cattias
Thank you Nick!
I am having an issue with the following line:
setEndpointConstraintBounds(MocoBounds(10));
Where it says;
Incorrect number or types of inputs or outputs for function setEndpointConstraintBounds.
From my understanding, setEndpointConstraintBounds requires a vector with the length equal to the number of outputs for this goal. This goal only has one output (linear velocity), so I am unsure why MocoBounds(10) is insufficient.
Re: Linear Velocity Constraint or Goal
Posted: Fri Aug 23, 2024 9:07 am
by nbianco
Ah yes, apologies.
Here is the correct snippet:
Code: Select all
finalHandVelocity = MocoFinalOutputGoal('final_hand_velocity);
finalHandVelocity.setOutputPath('/bodyset/hand|linear_velocity');
finalHandVelocity.setMode('endpoint_constraint');
bounds = StdVectorMocoBounds();
bounds.append(MocoBounds(10));
finalHandVelocity.setEndpointConstraintBounds(bounds);
problem.addGoal(finalHandVelocity);
Re: Linear Velocity Constraint or Goal
Posted: Fri Aug 23, 2024 9:13 am
by cattias
Nick, you are a lifesaver!
But unfortunately, append seems to require a text input. I used add instead of append and that seemed to work, but wanted to check and confirm if that was a viable solution.
Thanks again,
Cedric
Re: Linear Velocity Constraint or Goal
Posted: Fri Aug 23, 2024 9:15 am
by nbianco
Try ".add()" instead.
(Appending to a std::vector in Matlab and Python works differently and I can never remember which one to use.)
Re: Linear Velocity Constraint or Goal
Posted: Mon Aug 26, 2024 9:25 am
by cattias
Thanks for all the help Nick.
I see your responses across a number of forum posts, and the efforts are very much appreciated.
Regarding my question, is there a way to specify a direction for my linear velocity? For example, if I want the hand to reach a final velocity along the positive x-axis?
Thanks
Cedric
Re: Linear Velocity Constraint or Goal
Posted: Tue Aug 27, 2024 3:33 pm
by nbianco
Hi Cedric,
You can use "setOutputIndex" to specific the component to minimize or constraint:
Code: Select all
finalHandVelocity = MocoFinalOutputGoal('final_hand_velocity);
finalHandVelocity.setOutputPath('/bodyset/hand|linear_velocity');
finalHandVelocity.setMode('endpoint_constraint');
// assuming here that the 0th index corresponds to the x-direction
finalHandVelocity.setOutputIndex(0);
// change the sign on the bounds to specific the direction
bounds = StdVectorMocoBounds();
bounds.append(MocoBounds(10));
finalHandVelocity.setEndpointConstraintBounds(bounds);
problem.addGoal(finalHandVelocity);
Re: Linear Velocity Constraint or Goal
Posted: Thu Oct 17, 2024 10:25 am
by cattias
Sorry to resurface an old post, but I cannot seem to identify the units for speed in Moco.
Re: Linear Velocity Constraint or Goal
Posted: Sat Oct 19, 2024 9:42 am
by nbianco
Hi Cedric,
OpenSim (and Moco) uses SI units: meters, radians, Newtons, etc. Speed is measured in meters per second (m/s).
Best,
Nick