Linear Velocity Constraint or Goal
- cedric attias
- Posts: 11
- Joined: Tue Jan 10, 2023 8:22 am
Linear Velocity Constraint or Goal
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!
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!
- Nicholas Bianco
- Posts: 1045
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Linear Velocity Constraint or Goal
Hi Cedric,
You can use MocoFinalOutputGoal in endpoint constraint mode to achieve what you're looking for:
Best,
Nick
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);
Nick
- cedric attias
- Posts: 11
- Joined: Tue Jan 10, 2023 8:22 am
Re: Linear Velocity Constraint or Goal
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.
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.
- Nicholas Bianco
- Posts: 1045
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Linear Velocity Constraint or Goal
Ah yes, apologies.
Here is the correct snippet:
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);
- cedric attias
- Posts: 11
- Joined: Tue Jan 10, 2023 8:22 am
Re: Linear Velocity Constraint or Goal
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
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
Last edited by cedric attias on Fri Aug 23, 2024 9:16 am, edited 1 time in total.
- Nicholas Bianco
- Posts: 1045
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Linear Velocity Constraint or Goal
Try ".add()" instead.
(Appending to a std::vector in Matlab and Python works differently and I can never remember which one to use.)
(Appending to a std::vector in Matlab and Python works differently and I can never remember which one to use.)
- cedric attias
- Posts: 11
- Joined: Tue Jan 10, 2023 8:22 am
Re: Linear Velocity Constraint or Goal
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
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
- Nicholas Bianco
- Posts: 1045
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Linear Velocity Constraint or Goal
Hi Cedric,
You can use "setOutputIndex" to specific the component to minimize or constraint:
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);
- cedric attias
- Posts: 11
- Joined: Tue Jan 10, 2023 8:22 am
Re: Linear Velocity Constraint or Goal
Sorry to resurface an old post, but I cannot seem to identify the units for speed in Moco.
- Nicholas Bianco
- Posts: 1045
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Linear Velocity Constraint or Goal
Hi Cedric,
OpenSim (and Moco) uses SI units: meters, radians, Newtons, etc. Speed is measured in meters per second (m/s).
Best,
Nick
OpenSim (and Moco) uses SI units: meters, radians, Newtons, etc. Speed is measured in meters per second (m/s).
Best,
Nick