Files
BondGraph/test.mo

132 lines
9.1 KiB
Plaintext

model test
EmbeddedControl.Boundary.DAC dac(stepSize = 0.01, scale = -1) annotation(
Placement(transformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}})));
EmbeddedControl.Boundary.ADC adc(stepSize = 0.01) annotation(
Placement(transformation(origin = {10, 0}, extent = {{-10, -10}, {10, 10}})));
model Controller
extends EmbeddedControl.Bases.ControlBase;
Modelica.Blocks.Interfaces.IntegerInput angle_crad annotation(
Placement(transformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {-122, 120}, extent = {{-20, -20}, {20, 20}})));
Modelica.Blocks.Interfaces.IntegerOutput y annotation(
Placement(transformation(origin = {162, 0}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}})));
Modelica.Blocks.Interfaces.IntegerInput angle_setpoint annotation(
Placement(transformation(origin = {-120, 40}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {-120, 180}, extent = {{-20, -20}, {20, 20}})));
Modelica.Blocks.MathInteger.Sum sum(nu = 2, k = {-1, 1}) annotation(
Placement(transformation(origin = {64, 0}, extent = {{-10, -10}, {10, 10}})));
Modelica.Blocks.Interfaces.IntegerInput position_mm annotation(
Placement(transformation(origin = {-120, 80}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {-120, 0}, extent = {{-20, -20}, {20, 20}})));
EmbeddedControl.Util.PID pida(kP = 200, kI = 50, kD = 10, scale = 100000) annotation(
Placement(transformation(origin = {102, 0}, extent = {{-10, -10}, {10, 10}})));
Modelica.Blocks.Interfaces.IntegerInput position_setpoint annotation(
Placement(transformation(origin = {-120, 120}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {-120, -62}, extent = {{-20, -20}, {20, 20}})));
equation
connect(angle_crad, sum.u[1]) annotation(
Line(points = {{-120, 0}, {54, 0}}, color = {255, 127, 0}));
connect(sum.y, pida.u) annotation(
Line(points = {{75.5, 0}, {90, 0}}, color = {255, 127, 0}));
connect(pida.y, y) annotation(
Line(points = {{113, 0}, {162, 0}}, color = {255, 127, 0}));
connect(angle_setpoint, sum.u[2]) annotation(
Line(points = {{-120, 40}, {-90, 40}, {-90, 0}, {54, 0}}, color = {255, 127, 0}));
annotation(
Diagram(coordinateSystem(extent = {{-140, 140}, {180, -20}})),
experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002),
Icon(graphics = {Rectangle(origin = {-90, 50}, lineColor = {255, 85, 0}, fillColor = {156, 156, 156}, fillPattern = FillPattern.Solid, extent = {{-10, 150}, {10, -150}})}));
end Controller;
Controller controller annotation(
Placement(transformation(origin = {60, 0}, extent = {{-10, -10}, {10, 10}})));
EmbeddedControl.Boundary.tickGenerator tickGenerator(period(displayUnit = "ms") = 0.01) annotation(
Placement(transformation(origin = {-10, -40}, extent = {{-10, -10}, {10, 10}})));
inner Modelica.Mechanics.MultiBody.World world annotation(
Placement(transformation(origin = {-190, -40}, extent = {{-10, -10}, {10, 10}})));
Modelica.Mechanics.MultiBody.Joints.Prismatic prismatic1(animation = false, useAxisFlange = true) annotation(
Placement(transformation(origin = {-146, -40}, extent = {{-10, -10}, {10, 10}})));
Modelica.Mechanics.MultiBody.Joints.Revolute revolute1(useAxisFlange = true, phi(start = 1.5690509975429023)) annotation(
Placement(transformation(origin = {-96, -40}, extent = {{-10, -10}, {10, 10}})));
Modelica.Mechanics.MultiBody.Parts.Body body1(m = 1, r_CM = {0.5, 0, 0}) annotation(
Placement(transformation(origin = {-50, -40}, extent = {{-10, -10}, {10, 10}})));
Modelica.Mechanics.Rotational.Components.IdealRollingWheel idealRollingWheel1(radius = 0.1) annotation(
Placement(transformation(origin = {-138, 0}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
Modelica.Mechanics.Rotational.Sources.Torque torque(useSupport = true) annotation(
Placement(transformation(origin = {-102, 10}, extent = {{10, -10}, {-10, 10}})));
Modelica.Mechanics.Rotational.Components.Damper damper1(d = 1) annotation(
Placement(transformation(origin = {-102, 34}, extent = {{-10, -10}, {10, 10}})));
Modelica.Mechanics.Rotational.Sensors.RelAngleSensor relAngleSensor annotation(
Placement(transformation(origin = {-36, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
Modelica.Mechanics.Translational.Sensors.PositionSensor positionSensor annotation(
Placement(transformation(origin = {-100, -74}, extent = {{-10, -10}, {10, 10}})));
Modelica.Blocks.Sources.Constant const(k = -0.5*Modelica.Constants.pi) annotation(
Placement(transformation(origin = {-30, -90}, extent = {{-10, -10}, {10, 10}})));
EmbeddedControl.Boundary.ADC adc1(stepSize = 0.01) annotation(
Placement(transformation(origin = {10, -90}, extent = {{-10, 10}, {10, -10}}, rotation = -0)));
EmbeddedControl.Boundary.ADC adc11(stepSize = 0.0001) annotation(
Placement(transformation(origin = {10, -130}, extent = {{-10, 10}, {10, -10}})));
EmbeddedControl.Boundary.ADC adc111(stepSize = 0.0001) annotation(
Placement(transformation(origin = {10, -170}, extent = {{-10, 10}, {10, -10}})));
Modelica.Blocks.Sources.Constant const1(k = 0) annotation(
Placement(transformation(origin = {-30, -170}, extent = {{-10, -10}, {10, 10}})));
equation
connect(tickGenerator.y, adc.tickInput) annotation(
Line(points = {{1, -40}, {10, -40}, {10, -12}}, color = {255, 0, 255}));
connect(tickGenerator.y, controller.tickInput) annotation(
Line(points = {{1, -40}, {60, -40}, {60, -12}}, color = {255, 0, 255}));
connect(tickGenerator.y, dac.tickInput) annotation(
Line(points = {{1, -40}, {106, -40}, {106, -12}}, color = {255, 0, 255}));
connect(tickGenerator.tickPeriodUs, controller.tickPeriodIn) annotation(
Line(points = {{1, -48}, {52, -48}, {52, -12}}, color = {0, 0, 127}));
connect(controller.y, dac.u) annotation(
Line(points = {{71, 0}, {94, 0}}, color = {255, 127, 0}));
connect(world.frame_b, prismatic1.frame_a) annotation(
Line(points = {{-180, -40}, {-156, -40}}, color = {95, 95, 95}));
connect(prismatic1.frame_b, revolute1.frame_a) annotation(
Line(points = {{-136, -40}, {-106, -40}}, color = {95, 95, 95}));
connect(revolute1.frame_b, body1.frame_a) annotation(
Line(points = {{-86, -40}, {-60, -40}}, color = {95, 95, 95}));
connect(idealRollingWheel1.flangeT, prismatic1.axis) annotation(
Line(points = {{-138, -10}, {-138, -34}}));
connect(torque.flange, idealRollingWheel1.flangeR) annotation(
Line(points = {{-112, 10}, {-138, 10}}));
connect(torque.support, revolute1.support) annotation(
Line(points = {{-102, 0}, {-102, -30}}));
connect(revolute1.support, damper1.flange_b) annotation(
Line(points = {{-102, -30}, {-102, -12}, {-76, -12}, {-76, 34}, {-92, 34}}));
connect(idealRollingWheel1.flangeR, damper1.flange_a) annotation(
Line(points = {{-138, 10}, {-138, 34}, {-112, 34}}));
connect(revolute1.axis, relAngleSensor.flange_a) annotation(
Line(points = {{-96, -30}, {-96, -24}, {-36, -24}, {-36, -10}}));
connect(relAngleSensor.flange_b, revolute1.support) annotation(
Line(points = {{-36, 10}, {-58, 10}, {-58, -12}, {-102, -12}, {-102, -30}}));
connect(relAngleSensor.phi_rel, adc.u) annotation(
Line(points = {{-24, 0}, {-2, 0}}, color = {0, 0, 127}));
connect(dac.y, torque.tau) annotation(
Line(points = {{117, 0}, {128, 0}, {128, 66}, {-36, 66}, {-36, 22}, {-70, 22}, {-70, 10}, {-90, 10}}, color = {0, 0, 127}));
connect(prismatic1.axis, positionSensor.flange) annotation(
Line(points = {{-138, -34}, {-130, -34}, {-130, -74}, {-110, -74}}, color = {0, 127, 0}));
connect(tickGenerator.y, adc1.tickInput) annotation(
Line(points = {{2, -40}, {10, -40}, {10, -78}}, color = {255, 0, 255}));
connect(const.y, adc1.u) annotation(
Line(points = {{-18, -90}, {-2, -90}}, color = {0, 0, 127}));
connect(tickGenerator.y, adc11.tickInput) annotation(
Line(points = {{2, -40}, {10, -40}, {10, -118}}, color = {255, 0, 255}));
connect(positionSensor.s, adc11.u) annotation(
Line(points = {{-88, -74}, {-60, -74}, {-60, -130}, {-2, -130}}, color = {0, 0, 127}));
connect(const1.y, adc111.u) annotation(
Line(points = {{-18, -170}, {-2, -170}}, color = {0, 0, 127}));
connect(tickGenerator.y, adc111.tickInput) annotation(
Line(points = {{2, -40}, {10, -40}, {10, -158}}, color = {255, 0, 255}));
connect(adc.y, controller.angle_crad) annotation(
Line(points = {{22, 0}, {28, 0}, {28, 12}, {48, 12}}, color = {255, 127, 0}));
connect(adc1.y, controller.angle_setpoint) annotation(
Line(points = {{22, -90}, {34, -90}, {34, 18}, {48, 18}}, color = {255, 127, 0}));
connect(adc11.y, controller.position_mm) annotation(
Line(points = {{22, -130}, {38, -130}, {38, 0}, {48, 0}}, color = {255, 127, 0}));
connect(adc111.y, controller.position_setpoint) annotation(
Line(points = {{22, -170}, {44, -170}, {44, -6}, {48, -6}}, color = {255, 127, 0}));
annotation(
uses(Modelica(version = "4.1.0")),
Diagram(coordinateSystem(extent = {{-220, 80}, {140, -140}})),
version = "",
experiment(StartTime = 0, StopTime = 25, Tolerance = 1e-06, Interval = 0.02));
end test;