-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RTR] contact force at the end of interval for takeoff #891
Conversation
@Ipuch could you review the logic please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise looks good to me
Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @EveCharbie)
bioptim/limits/penalty.py
line 839 at r1 (raw file):
cx = horzcat(*([controller.states.cx_start] + controller.states.cx_intermediates_list)) states_integrated = controller.integrate(
I think end_interval_states
is more accurate
bioptim/limits/penalty.py
line 847 at r1 (raw file):
d=controller.numerical_timeseries.cx, )["xf"] penalty.integrate = True
I'm not sure what it is for.
Code quote:
penalty.integrate = True
tests/shard4/test_penalty.py
line 1172 at r1 (raw file):
contact_index=0, node=Node.PENULTIMATE, )
Just to say something:
if penalty_origin == ObjectiveFcn.Mayer:
penalty_type = ObjectiveFcn.Mayer.MINIMIZE_CONTACT_FORCES_END_OF_INTERVAL
penalty_object = Objective
else:
penalty_type = ConstraintFcn.TRACK_CONTACT_FORCES_END_OF_INTERVAL
penalty = Constraint
penalty = penalty_object(
penalty_type,
contact_index=0,
node=Node.PENULTIMATE,
)
Code quote:
if penalty_origin == ObjectiveFcn.Mayer:
penalty_type = ObjectiveFcn.Mayer.MINIMIZE_CONTACT_FORCES_END_OF_INTERVAL
penalty = Objective(
penalty_type,
contact_index=0,
node=Node.PENULTIMATE,
)
else:
penalty_type = ConstraintFcn.TRACK_CONTACT_FORCES_END_OF_INTERVAL
penalty = Constraint(
penalty_type,
contact_index=0,
node=Node.PENULTIMATE,
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @Ipuch and @pariterre)
bioptim/limits/penalty.py
line 839 at r1 (raw file):
Previously, Ipuch (Pierre Puchaud) wrote…
I think
end_interval_states
is more accurate
Done.
bioptim/limits/penalty.py
line 847 at r1 (raw file):
Previously, Ipuch (Pierre Puchaud) wrote…
I'm not sure what it is for.
I removed it since it is a Mayer term, @pariterre need confirmation.
tests/shard4/test_penalty.py
line 1172 at r1 (raw file):
Previously, Ipuch (Pierre Puchaud) wrote…
Just to say something:
if penalty_origin == ObjectiveFcn.Mayer: penalty_type = ObjectiveFcn.Mayer.MINIMIZE_CONTACT_FORCES_END_OF_INTERVAL penalty_object = Objective else: penalty_type = ConstraintFcn.TRACK_CONTACT_FORCES_END_OF_INTERVAL penalty = Constraint penalty = penalty_object( penalty_type, contact_index=0, node=Node.PENULTIMATE, )
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r2, all commit messages.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @pariterre)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @pariterre)
bioptim/limits/penalty.py
line 847 at r1 (raw file):
Previously, EveCharbie (Eve Charbonneau) wrote…
I removed it since it is a Mayer term, @pariterre need confirmation.
Last comment before @pariterre pops. CodeClimate describe a coginitive complexity of 6 (allowed 5)
Here is my proposition:
if controller.get_nlp.contact_forces_func is None:
raise RuntimeError("minimize_contact_forces requires a contact dynamics")
if controller.control_type != ControlType.CONSTANT:
raise NotImplementedError(
f"This constraint is only useful for ControlType.CONSTANT controls. For any other dynamics, you should constraint the contact at the begining of the interval."
)
if controller.algebraic_states.cx_start.shape[0] != 0:
raise NotImplementedError(
"This constraint is not implemented for problems with algebraic states as you should provide their dynamics to integrate it as well."
)
PenaltyFunctionAbstract.set_axes_rows(penalty, contact_index)
penalty.quadratic = True if penalty.quadratic is None else penalty.quadratic
t_span = controller.t_span.cx
cx = horzcat(*([controller.states.cx_start] + controller.states.cx_intermediates_list)) if controller.get_nlp.ode_solver.is_direct_collocation else controller.states.cx_start
end_of_interval_states = controller.integrate(
t_span=t_span,
x0=cx,
u=controller.controls.cx_start,
p=controller.parameters.cx,
a=controller.algebraic_states.cx_start,
d=controller.numerical_timeseries.cx,
)["xf"]
contact_force = controller.get_nlp.contact_forces_func(
controller.time.cx,
end_of_interval_states,
controller.controls.cx_start,
controller.parameters.cx,
controller.algebraic_states.cx_start,
controller.numerical_timeseries.cx,
)
return contact_force
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @Ipuch and @pariterre)
bioptim/limits/penalty.py
line 847 at r1 (raw file):
Previously, Ipuch (Pierre Puchaud) wrote…
Last comment before @pariterre pops. CodeClimate describe a coginitive complexity of 6 (allowed 5)
Here is my proposition:
if controller.get_nlp.contact_forces_func is None: raise RuntimeError("minimize_contact_forces requires a contact dynamics") if controller.control_type != ControlType.CONSTANT: raise NotImplementedError( f"This constraint is only useful for ControlType.CONSTANT controls. For any other dynamics, you should constraint the contact at the begining of the interval." ) if controller.algebraic_states.cx_start.shape[0] != 0: raise NotImplementedError( "This constraint is not implemented for problems with algebraic states as you should provide their dynamics to integrate it as well." ) PenaltyFunctionAbstract.set_axes_rows(penalty, contact_index) penalty.quadratic = True if penalty.quadratic is None else penalty.quadratic t_span = controller.t_span.cx cx = horzcat(*([controller.states.cx_start] + controller.states.cx_intermediates_list)) if controller.get_nlp.ode_solver.is_direct_collocation else controller.states.cx_start end_of_interval_states = controller.integrate( t_span=t_span, x0=cx, u=controller.controls.cx_start, p=controller.parameters.cx, a=controller.algebraic_states.cx_start, d=controller.numerical_timeseries.cx, )["xf"] contact_force = controller.get_nlp.contact_forces_func( controller.time.cx, end_of_interval_states, controller.controls.cx_start, controller.parameters.cx, controller.algebraic_states.cx_start, controller.numerical_timeseries.cx, ) return contact_force
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @EveCharbie)
All Submissions:
New Feature Submissions:
black . -l120 --exclude "external/*"
)?Changes to Core Features:
This change is