# Switch between two flanges while using the MultiBody library in SM?

GROUPS:
 I am currently working with multibody mechanical systems using the MultiBody library in SystemModeler.Trying to implement a switch between flanges but can't seem to make it work: model FlangeSwitch "Switch between flanges" input Modelica.Mechanics.Translational.Interfaces.Flange_a flanges_a[2]; input Modelica.Mechanics.Translational.Interfaces.Flange_b flanges_b[2]; output Modelica.Mechanics.Translational.Interfaces.Flange_a flange_a_exit; output Modelica.Mechanics.Translational.Interfaces.Flange_b flange_b_exit; input Modelica.Blocks.Interfaces.BooleanInput u; Integer k; initial equation k = 1; equation flange_a_exit = flanges_a[k]; flange_b_exit = flanges_b[k]; when u then k = 1; elsewhen not u then k = 2; end when; end FlangeSwitch; The model cannot pass verification check. The following error comes up: [:0:0-0:0] Error: Model is using the variable flanges_b which does not have a declaration. [:0:0-0:0] Error: Model is using the variable flanges_a which does not have a declaration. Any clue on what's going on?
26 days ago
12 Replies
 What I am trying to achieve is the following:In a multibody system, there is a prismatic joint that I want to control in two different ways. The first part is to move the joint from the current position to an exact position, using the Modelica.Mechanics.Translational.Sources.Position component. Once this is done, I would like to switch the attached flange to connect a Modelica.Mechanics.Translational.Sources.Force component to apply a force to this joint. In a nutshell, I would like to force a displacement on the joint and then leave the joint without restriction for a free movement under external forces (gravity and other applied forces).Is this possible to do in Modelica?
25 days ago
 A simpler approach was also tested: model FlangeSwitch "Switch between flanges" Modelica.Mechanics.Translational.Interfaces.Flange_a flange_a_1; Modelica.Mechanics.Translational.Interfaces.Flange_b flange_b_1; Modelica.Mechanics.Translational.Interfaces.Flange_a flange_a_2; Modelica.Mechanics.Translational.Interfaces.Flange_b flange_b_2; Modelica.Mechanics.Translational.Interfaces.Flange_a flange_a_exit; Modelica.Mechanics.Translational.Interfaces.Flange_b flange_b_exit; Modelica.Blocks.Interfaces.BooleanInput u; equation if u then flange_a_exit = flange_a_2; flange_b_exit = flange_b_2; else flange_a_exit = flange_a_1; flange_b_exit = flange_b_1; end if; end FlangeSwitch; This way the system is not balanced: 10 equations and 12 variables.
25 days ago
 Jose,This should be possible. When you say that you want position enforced followed by a force constraint, is your position constraint a limit? For example, you can easily model a chair on the floor. The floor limits position but forces and gravity can cause it to leave the floor. Is this the type of constraint you want? If so, I can show you an example. If not, Please give a bit more detail for me.Regards
25 days ago
 Hi Neil,In a simplified way, this is what I am trying to achieve:I have body connected to the ground with a prismatic joint (with the axis flange enabled) and I would like to control the movement of that joint.At first, I would like to force the movement of the joint (connecting Modelica.Mechanics.Translational.Sources.Position to the joint's axis flange) to move from X1 to X2. Once this is done, I would like to free the body from this position constraint and move it around using a force (using Modelica.Mechanics.Translational.Sources.Force).
24 days ago
 Jose,Is the move from X1 to X2 based on time -- for example for the first 5 seconds you use position control moving form X1 to X2 and hold it there and then the object is free to move after 5 seconds in either direction (away from X1 and/or towards X1)?I can show you how to write a custom constraint to add onto the prismatic joint for this case .However you can use the built in elastigap if the movement is more like this:You want more of a cam-like motion -- it moves from X1 to X2 but at any point in time a force can pull it away from the position constraint (moves from X2 in a direction which is away from X1)? This is more like a hard, moving stop but the object is free to move away from the hard stop if the forces dictate that motion. This can be done entirely with built-in components.The problem with your Flange switch approach is that you must put constraints on the unused flanges otherwise you get a mismatch between equations and variables. Even though you use flange a1 and b1, you must do something with a2 and b2. You can cut them into a separate, meaningless systems I think I could get this to work with some experimentation but I think there are easier and more general approaches to do what you want.Based on your answer above, I can suggest an approach. Regards
24 days ago
 Also note in my second example that if you use the elastogap to do the moving stop, you can move it from X1 to X2, hold it there and then quickly move it out of the way at a given time. This is another way to implement what you want. Would this behavior work? (so there are 3 approaches!)
24 days ago
 Neil Singer 1 Vote Jose,To out line the various approaches mentioned above, look at this post: dropping a bar onto a surface. Here I used elastogap to simulate the surface. You can move the surface as your position constraint and let the forces act on the body. The key to this is turning on the useAxisFlange in the prismatic constraint. This allows you to connect a constraint to the prismatic joint. In the case referenced I used elastogap but you could use a spring or write a custom constraint that changes based on an external input. If you do the custom constraint you may have a numerical instability problem when you suddenly switch behaviors in the middle of the simulation. This discontinuity (depending on what you are doing) could cause the integration to slow down to a crawl or fail completely. To get around this you will likely have to add some very stiff flexibility to your position constraint. Elastogap code is a good example of this -- you can examine it and see that they needed to add a very stiff spring so that impacts against the hard stop would not destabilize the integration.I hope this gets you started.Regards,Neil
24 days ago
 Is the move from X1 to X2 based on time -- for example for the first 5 seconds you use position control moving form X1 to X2 and hold it there and then the object is free to move after 5 seconds in either direction (away from X1 and/or towards X1)? This is exactly the motion that is expected from the model. The first few seconds of the movement correspond to a forced controlled movement, its a kind of "move to initial position" motion. Once this position is reached, the object is "free to move" and actually it is a dynamic control which kicks in in order to maintain equilibrium (the model is similar to an inverted pendulum). I don't really see how the elastigap approach could help me.Thanks,William**(I am using Jose's account, but I am not him).
20 days ago
 Neil Singer 3 Votes William (the Engineer formerly known as Jose),The elastogap is a useful component because it lets you model a fixed or moving wall with intermittent contact.I took the standard pendulum example from SystemModeler and added a moving wall. The combiTimeTable lets me input a time varying position of the wall. In this example, it moves to the right pushing the pendulum up for the first 3 seconds and then holds the position until 5 seconds, then it releases the pendulum by suddenly moving out of the way. I animated the prismatic movement of the wall with a big green arrow so you can see it move. This simulation uses all built-in components -- no need to write any custom code.The model looks like this at 3 seconds: before the pendulum is released.Here is the animation:The model looks like this:To run this model you must disable "dynamic state selection" because we have closed loops in the model (because of our "moving wall")Go into preferences:Why does this work?:The CombiTimeTable outputs your position constraint over time to a translational position block. The position is attached to a prismatic joint so it moves the prismatic joint over time. The prismatic joint is attached to a planar constraint because the pendulum moves up and down so we must allow up/down sliding (y direction). The planar constraint attaches to another prismatic joint connected to an elastogap. This prismatic joint is constrained to allow discontinuous contact. you can set the spring rate and damping to get various behaviors from the elastogap -- i.e. super damped or very bouncy. Lastly, I added a Universal joint. This is more subtle but the prismatic joint ONLY allows X motion, The Planar joint gives you Y motion. However, you also need two rotations because as the pendulum swings, its angle changes so you must allow the angle of connection between the prismatic joint and the pendulum bob to rotate. (Remember -- our goal is to only constrain this bob in the x direction even though it can move up and down and rotate.The model is attached.I hope this helps.Regards,Neil**(Actually Neil was abducted by aliens so I am his evil twin...) Attachments: