Skip to content
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

Add example for a multiphase problem. #333

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

moorepants
Copy link
Member

I realized that we can probably do multiphase problems with something like this. But I am currently limited to the duration of each phase having to be equal. @Peter230655 any ideas on how to let this block collide with the wall at any time? My intuition is that I need to move the collision equation from the instance constraints into the DAE somehow.

@Peter230655
Copy link
Contributor

I realized that we can probably do multiphase problems with something like this. But I am currently limited to the duration of each phase having to be equal. @Peter230655 any ideas on how to let this block collide with the wall at any time? My intuition is that I need to move the collision equation from the instance constraints into the DAE somehow.

Let me think about it. :-)
(As I understand, you want it with Newtonian collission, so we have different eoms before and after the impact?)

@moorepants
Copy link
Member Author

There is essentially just 1 eom in this case because the block is always sliding:

$$ m\dot{v} = -\textrm{sgn}({v})\mu m g + F $$

but at $x=1$ the impact occurs and you apply a mometum balance for before and after impact:

$$ v_\textrm{after} = e v_\textrm{before} $$

If you break the EoM into the moving right and moving left portions, then you can remove the dicontinuity in the EoM. So then you do have 2 EoMs, one for before and one after.

@Peter230655
Copy link
Contributor

There is essentially just 1 eom in this case because the block is always sliding:

m v ˙ = − s g n ( v ) μ m g + F

As I understood the equations in your code, F = 0 after the impact, the equation above seems to imply F is present always?

but at x = 1 the impact occurs and you apply a mometum balance for before and after impact:

v a f t e r = e v b e f o r e

If you break the EoM into the moving right and moving left portions, then you can remove the dicontinuity in the EoM. So then you do have 2 EoMs, one for before and one after.

I guess with Newtonian impact, by definition the speed will change discontinuously - something opty does not like.
So, two eoms are likely necessary.
Is Newtonian collision important, or would Hunt-Crossley also be o.k.?

I am asking, so I know in which direction to think.

@moorepants
Copy link
Member Author

As I understood the equations in your code, F = 0 after the impact, the equation above seems to imply F is present always?

I wrote one equation in this comment, but I split it into two in the opty formulation.

@moorepants
Copy link
Member Author

moorepants commented Feb 8, 2025

Is Newtonian collision important, or would Hunt-Crossley also be o.k.?

The point of this example is to avoid discontinuities when transitioning between phases of a problem. I can solve this with an impact force, but that's not the purpose. Sometimes you want to model transitions from one eom to another, e.g. standing on the ground, jumping off, and landing but not have to model the contact forces with things such as Hunt-Crossely. Newton's momentum exchange is a perfectly good model for impact also.

@Peter230655
Copy link
Contributor

Is Newtonian collision important, or would Hunt-Crossley also be o.k.?

The point of this example is to avoid discontinuities when transitioning between phases of a problem. I can solve this with an impact force, but that's not the purpose. Sometimes you want to model transitions from one eom to another, e.g. standing on the ground, jumping off, and landing but not have to model the contact forces with things such as Hunt-Crossely. Newton's momentum exchange is a perfectly good model for impact also.

All clear now to me, I think.

@Peter230655
Copy link
Contributor

Peter230655 commented Feb 8, 2025

Could this be done as a two stage problem, similar to PR #262 ?

In your example, splitting it up will simply result in using maximum force until impact, and in the second phase there is no control left for opty to do anything with. It will just slide.

In PR #262 the second phase is depending on the first one, through the amount of fuel left. (the third phase is like your second phase: nothing left to be controlled)
When I did it, I had to optimize the the first and second phases separately - and surely this must be worse (maximally equal) to optimizing them combined. I do not know, how Betts optimized them, but the results of PR #262 and of Betts are quite close.

So, I guess the goal must be to do it in one stage (splitting it up is 'primitive') - let me think along these lines.

@moorepants
Copy link
Member Author

When I did it, I had to optimize the the first and second phases separately - and surely this must be worse (maximally equal) to optimizing them combined.

Yes, I want to solve these kinds of problems where all phases are solve simultaneously. My example here may be able to be solved by separating into multiple optimal control problems but, in general, we'd like to solve problems this way that cannot be solved separately. That's what I'm trying to do, but there may not be a "hack" to get opty to do this. It may be something we have to build into opty more carefully.

@Peter230655
Copy link
Contributor

Peter230655 commented Feb 8, 2025

When I did it, I had to optimize the the first and second phases separately - and surely this must be worse (maximally equal) to optimizing them combined.

Yes, I want to solve these kinds of problems where all phases are solve simultaneously. My example here may be able to be solved by separating into multiple optimal control problems but, in general, we'd like to solve problems this way that cannot be solved separately. That's what I'm trying to do, but there may not be a "hack" to get opty to do this. It may be something we have to build into opty more carefully.

I do not know, but I am getting clearer in the direction of thinking.
Would it be of any help to ask John Betts whether he solved #262 simultaneously or one after another?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants