modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
472 stars 168 forks source link

Modelica.Mechanics.MultiBody.Frames.from_nxz calculation of w #2776

Open GarronFish opened 5 years ago

GarronFish commented 5 years ago

Modelica.Mechanics.MultiBody.Frames.from_nxz sets R.w={0,0,0} this seems incorrect. Shouldn't R.w be calculated?

R.w can be calculated with der(T) and T.

beutlich commented 5 years ago

I believe the assumption is/was that n_x and n_y are constant w.r.t. time, since it says fixed orientation in the description.

See also from_nxy.

GarronFish commented 5 years ago

Thanks, for pointing that out.

A non-fixed version would be helpful.

beutlich commented 5 years ago

A non-fixed version would be helpful.

Yes, can even be done in a backward-compatible way.

beutlich commented 5 years ago

Reading section 3.10.6 of the Dymola 2020 Release Notes, I see that you meanwhile worked on this issue.

Added function from_nxy_movingAxes for calculating the orientation R based on moving axes.

@GarronFish @mdempse1 @Claytex Do you think you could contribute to the MSL this time and provide this enhanced function implementation (either as PR or as code snippet)? Thank you.

GarronFish commented 5 years ago

Happy to. I'm not sure how this function would be backwards compatible as the derivatives of the n_x and n_y are required in the calculation. I was thinking that the user would supply the derivatives n_x_der, and n_y_der (what is the MSL convention for the naming the derivatives of signals?).

When would you like the update by?

beutlich commented 5 years ago

I thought it would be possible like

function from_nxz "Return fixed orientation object from n_x and n_z vectors"
  extends Modelica.Icons.Function;
  input Real n_x[3](each final unit="1") "Vector in direction of x-axis of frame 2, resolved in frame 1";
  input Real n_z[3](each final unit="1") "Vector in direction of z-axis of frame 2, resolved in frame 1";
  input Boolean movingAxis = false "= true, if moving axis are to be considered, otherwise fixed axis";
  output Orientation R "Orientation object to rotate frame 1 into frame 2";
algorithm
  if movingAxis then
    R := TODO;
  else
    R := Orientation(T=TransformationMatrices.from_nxz(n_x,n_z),w= zeros(3));
  end if;
end from_nxz;

Don't you think so?

When would you like the update by?

Anytime soon. 😄

GarronFish commented 5 years ago

Unfortunately the derivatives of the axes have to be calculated to determine R.w, this requires derivative information.

I'm unfamiliar with Git which would be a slowing factor. I could send the function by Wednesday, not sure how long it would take for me to put it into the MSL Git repository, probably by next Monday. I'd be interested to learn this though.

beutlich commented 5 years ago

Hm, can't the derivatives be calculated within the function or provided as optional arguments, too?

Regarding git we collected some information in our wiki:

GarronFish commented 5 years ago

It is not legal to use der() inside a function.

Thanks I'll have a look at those links.

GarronFish commented 5 years ago

Sorry I'm going to be quite a while, work has just got hectic. I can provide you with the models soon, if you want to put them into push these onto the Modelica Library. Otherwise it could be a few weeks before it gets loaded up.

tobolar commented 3 years ago

@GarronFish Any update on this issue?

GarronFish commented 3 years ago

Sorry I've just been too busy, here are the functions please incorporate these in Modelica Standard Library Claytex.Mechanics.MultiBody.Frames.TransformationMatrices.from_nxy_movingAxes:

function from_nxy_movingAxes
  "Return orientation object from n_x and n_y vectors that are moving"

  input Real n_x[3](each final unit="1")
    "Vector in direction of x-axis of frame 2, resolved in frame 1";
  input Real n_y[3](each final unit="1")
    "Vector in direction of y-axis of frame 2, resolved in frame 1";
  input Real der_n_x[3](each final unit="1/s") = {0,0,0}
    "Velocity of of x-axis of frame 2, resolved in frame 1";
  input Real der_n_y[3](each final unit="1/s") = {0,0,0}
    "Velocity of y-axis of frame 2, resolved in frame 1";

  output MB.Frames.TransformationMatrices.Orientation T
    "Orientation object to rotate frame 1 into frame 2";
  output SI.AngularVelocity w[3]
    "Absolute angular velocity of local frame, resolved in local frame";

protected 
  Real abs_n_x=sqrt(n_x*n_x);
  Real e_x[3](each final unit="1") = n_x/abs_n_x;
  Real abs_n_y=sqrt(n_y*n_y);
  Real e_y[3](each final unit="1") = n_y/abs_n_y;
  Real e_z[3](each final unit="1") = cross(e_x, e_y);

algorithm 
  T := {e_x,e_y,e_z};
  w[1] := e_z*der_n_y/abs_n_y;
  w[2] := -e_z*der_n_x/abs_n_x;
  w[3] := e_y*der_n_x/abs_n_x;

  annotation (smoothOrder=3, Documentation(info="<html>
<p>Similar to <a href=\"modelica://Modelica.Mechanics.MultiBody.Frames.TransformationMatrices.from_nxy\">from_nxy</a> from the Modelica Standard Library except designed for moving axes, this means that the rotational velocity of the axes (i.e. <b>w</b>) is calculated.</p>
<p>It is assumed that the two input vectors n_x and n_y are resolved in frame 1 and are directed along the x and y axis of frame 2 and that they are orthogonal to each other. </p>
<p><b>NOTE:</b> The axes are assumed to be orthogonal this is different from the Modelica Standard Library version which can tolerate n_x and n_y not being orthogonal.</p>
</html>"
);
end from_nxy_movingAxes;

Claytex.Mechanics.MultiBody.Frames.from_nxy_movingAxes:

function from_nxy_movingAxes
  "Return orientation object from moving n_x and n_y axes"

  input Real n_x[3](each final unit="1")
    "Vector in direction of x-axis of frame 2, resolved in frame 1";
  input Real n_y[3](each final unit="1")
    "Vector in direction of y-axis of frame 2, resolved in frame 1";
  input Real der_n_x[3](each final unit="1/s") = {0,0,0}
    "Velocity of x-axis of frame 2, resolved in frame 1";
  input Real der_n_y[3](each final unit="1/s") = {0,0,0}
    "Velocity of y-axis of frame 2, resolved in frame 1";

  output MB.Frames.Orientation R
    "Orientation object to rotate frame 1 into frame 2";
protected 
  MB.Frames.TransformationMatrices.Orientation T
    "Orientation object to rotate frame 1 into frame 2";
  SI.AngularVelocity w[3]
    "Absolute angular velocity of local frame, resolved in local frame";
algorithm 
  (T,w) :=
    Claytex.Mechanics.MultiBody.Frames.TransformationMatrices.from_nxy_movingAxes(
            n_x=n_x,
            n_y=n_y,
            der_n_x=der_n_x,
            der_n_y=der_n_y);

  R := Modelica.Mechanics.MultiBody.Frames.from_T(T=T, w=w);

  annotation (
    smoothOrder=3,
    Documentation(info="<html>
<p>Similar to <a href=\"modelica://Modelica.Mechanics.MultiBody.Frames.TransformationMatrices.from_nxy\">from_nxy</a> from the Modelica Standard Library except designed for moving axes, this means that the rotational velocity of the axes (i.e. <b>R.w</b>) is calculated.</p>
<p>It is assumed that the two input vectors n_x and n_y are resolved in frame 1 and are directed along the x and y axis of frame 2 and that they are orthogonal to each other. </p>
<p><b>NOTE:</b> The axes are assumed to be orthogonal this is different from the Modelica Standard Library version which can tolerate n_x and n_y not being orthogonal.</p>
</html>"),
    Icon(graphics));
end from_nxy_movingAxes;

Imports used in the Claytex package:

  import Modelica.Units.SI;
  import MB = Modelica.Mechanics.MultiBody;
GarronFish commented 3 years ago

The documentation annotation unfortunately is being modified by the GitHub viewer.

tobolar commented 3 years ago

Sorry I've just been too busy,

No matter, I bet we all are continuously busy - in spite of Corona.. ;-)