Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

position, velocity, acceleration, torque signal to rotational flange

position, velocity, acceleration, torque signal to rotational flange

I have this working for position, velocity, acceleration, but when I add the signal to torque condition, the class no longer works.

My goal is to have my model compiled and ready to drive a joint by position, velocity, acceleration, or torque by changeable parameters.

For example, a model can be compiled with a ramp function that can be set by parameters to provide a signal to my "signalToFlange" class. In addition, the signalToFlange takes an integer signal "inputType" which can have values 1=position, 2=velocity, 3=acceleration, 4=torque. This needs to be an interface to allow it to be set externally it seems. If I make "inputType" a parameter in signalToFlange, the compilation will bake the value in and the parameter cannot be overridden during execution.

This works fine for position, velocity, acceleration. When I uncomment the "else" below, the signalToFlange with inputType=1 no longer imposes position (angle) on phi. I'm fairly new at Modelica, so I imagine I'm missing something.

Maybe this approach is all wrong, but it works for the p,v,a cases, allowing me to "drive" a joint by these sources without recompiling the simulation executable/fmu.

Note that the code for the inputType cases was taken from existing standard Modelica Rotational Source classes.

model SignalToFlange
  import SI = Modelica.SIunits;
  extends Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2;
  parameter Boolean exact = false "true/false exact treatment/filtering the input signal";
  parameter SI.Frequency f_crit = 50 "if exact=false, critical frequency of filter to filter input signal" annotation(Dialog(enable = not exact));
  SI.Angle phi "Rotation angle of flange with respect to support";
  SI.AngularVelocity w "If exact=false, Angular velocity of flange with respect to support else dummy";
  SI.AngularAcceleration a "If exact=false, Angular acceleration of flange with respect to support else dummy";
  Modelica.Blocks.Interfaces.RealInput signal "Reference angle of flange with respect to support as input signal" annotation(Placement(visible = true, transformation(extent = {{-140, -20}, {-100, 20}}, rotation = 0), iconTransformation(extent = {{-140, -20}, {-100, 20}}, rotation = 0)));
  Modelica.Blocks.Interfaces.IntegerInput inputType annotation(Placement(visible = true, transformation(origin = {0, 120}, extent = {{-20, -20}, {20, 20}}, rotation = -90), iconTransformation(origin = {0, 120}, extent = {{-20, -20}, {20, 20}}, rotation = -90)));
protected
  parameter Modelica.SIunits.AngularFrequency w_crit = 2 * Modelica.Constants.pi * f_crit "Critical frequency";
  constant Real af = 1.3617 "s coefficient of Bessel filter";
  constant Real bf = 0.6180 "s*s coefficient of Bessel filter";
initial equation
  if not exact then
    if inputType == 1 then
      phi = signal;
    elseif inputType == 2 then
      w = signal;
    end if;
  end if;
equation
  if inputType == 1 then
    phi = flange.phi - phi_support;
    if exact then
      phi = signal;
      w = 0;
      a = 0;
    else
      // Filter: a = phi_ref*s^2/(1 + (af/w_crit)*s + (bf/w_crit^2)*s^2)
      w = der(phi);
      a = der(w);
      a = ((signal - phi) * w_crit - af * w) * (w_crit / bf);
    end if;
  elseif inputType == 2 then
    phi = flange.phi - phi_support;
    w = der(phi);
    if exact then
      w = signal;
      a = 0;
    else
      // Filter: a = w_ref/(1 + (1/w_crit)*s)
      a = der(w);
      a = (signal - w) * w_crit;
    end if;
  else //if inputType == 3 then
    phi = flange.phi - phi_support;
    w = der(phi);
    a = der(w);
    a = signal;
/*
  else
    phi = 0;
    w = 0;
    a = 0;
    signal = -flange.tau;
*/
  end if;

  annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Text(origin = {-4, 81}, lineColor = {0, 85, 255}, extent = {{-96, 19}, {104, -21}}, textString = "%name"), Rectangle(origin = {17, 35}, lineColor = {115, 115, 115}, fillColor = {255, 255, 255}, fillPattern = FillPattern.HorizontalCylinder, extent = {{-87, 15}, {53, -15}}), Line(origin = {3.03, -24.19}, points = {{-69.0275, -35.8114}, {-57.0275, 6.1886}, {-3.02752, 24.1886}, {50.9725, 10.1886}, {66.9725, -35.8114}}, thickness = 2, arrow = {Arrow.None, Arrow.Filled}, arrowSize = 20, smooth = Smooth.Bezier), Line(origin = {-2.97, -48.19}, points = {{52.9725, -11.8114}, {42.9725, 16.1886}, {2.97248, 28.1886}, {-33.0275, 14.1886}, {-41.0275, -11.8114}}, thickness = 2, arrow = {Arrow.None, Arrow.Filled}, arrowSize = 20, smooth = Smooth.Bezier), Text(origin = {0, 35}, extent = {{-70, 15}, {70, -15}}, textString = "A, V, W")}));
end SignalToFlange;

There are 0 guests and 0 other users also viewing this topic
You are here: