Skip to content

Commit

Permalink
Merge branch 'master' into fix-friction
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kormann authored Nov 14, 2023
2 parents 3abe014 + 402662a commit 8952f8c
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 34 deletions.
20 changes: 11 additions & 9 deletions Modelica/Blocks/Math.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2335,29 +2335,31 @@ Note: The output is updated after each period defined by 1/f.
block ContinuousMean
"Calculates the empirical expectation (mean) value of its input signal"
extends Modelica.Blocks.Icons.Block;
parameter SI.Time t_eps(min= 100*Modelica.Constants.eps)=1e-7
parameter SI.Time t_eps(min= 0)=1e-7
"Mean value calculation starts at startTime + t_eps"
annotation(Dialog(group="Advanced"));

Modelica.Blocks.Interfaces.RealInput u "Noisy input signal" annotation (Placement(transformation(extent={{-140,-20},{-100,20}})));
Modelica.Blocks.Interfaces.RealOutput y
"Expectation (mean) value of the input signal"
annotation (Placement(transformation(extent={{100,-10},{120,10}})));

parameter Real startTime=-Modelica.Constants.inf "Starting point for mean if after simulation start-point";
protected
Real mu "Internal integrator variable";
Real mu(start=0, fixed=true) "Internal integrator variable";
parameter Real t_0(fixed=false) "Start time";
parameter Real actualStartTime=max(t_0, startTime);
initial equation
t_0 = time;
mu = u;
equation
der(mu) = noEvent(if time >= t_0 + t_eps then (u-mu)/(time-t_0) else 0);
y = noEvent(if time >= t_0 + t_eps then mu else u);
der(mu) = if time >= actualStartTime then u else 0;
y = noEvent(if time > actualStartTime+t_eps then mu/(time-actualStartTime) else u);

annotation (Documentation(revisions="<html>
<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">
<tr><th>Date</th> <th align=\"left\">Description</th></tr>
<tr><td> June 13, 2023</td>
<td>Hans Olsson. Avoid almost singularity for integrators.</td>
</tr>
<tr><td> June 22, 2015 </td>
<td>
Expand All @@ -2380,8 +2382,8 @@ y = ------------------------
time - startTime
</pre></blockquote>
<p>This can be used to determine the empirical expectation value of a random signal, such as generated by the <a href=\"modelica://Modelica.Blocks.Noise\">Noise</a> blocks.</p>
<p>The parameter t_eps is used to guard against division by zero (the mean value computation
starts at &lt;<em>simulation start time</em>&gt; + t_eps and before that time instant y = u).</p>
<p>The parameter t_eps is used to avoid large fluctuations but can be set to zero (the mean value computation
starts at &lt;<em>simulation start time</em>&gt; but is only returned after an additional t_eps and before that time instant y = u).</p>
<p>See also the <a href=\"modelica://Modelica.Blocks.Math.Mean\">Mean</a> block for a sampled implementation.</p>
<p>
Expand Down
37 changes: 29 additions & 8 deletions Modelica/Blocks/Sources.mo
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ variable <strong>y</strong> is both a variable and a connector.
extends Interfaces.SignalSource;

equation
y = offset + (if time < startTime then 0 else time - startTime);
y = offset + smooth(0, (if time < startTime then 0 else time - startTime));
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
Expand Down Expand Up @@ -294,10 +294,17 @@ If parameter duration is set to 0.0, the limiting case of a Step signal is achie
annotation(Dialog(groupImage="modelica://Modelica/Resources/Images/Blocks/Sources/Sine.png"));
parameter SI.Frequency f(start=1) "Frequency of sine wave";
parameter SI.Angle phase=0 "Phase of sine wave";
parameter Boolean continuous = false "Make output continuous by starting at offset + amplitude*sin(phase)"
annotation(Evaluate=true);
extends Interfaces.SignalSource;
equation
y = offset + (if time < startTime then 0 else amplitude*Modelica.Math.sin(2
*pi*f*(time - startTime) + phase));
if continuous then
y = offset + amplitude*smooth(0, (if time < startTime then Modelica.Math.sin(phase)
else Modelica.Math.sin(2*pi*f*(time - startTime) + phase)));
else
y = offset + (if time < startTime then 0 else amplitude*Modelica.Math.sin(2
*pi*f*(time - startTime) + phase));
end if;
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
Expand Down Expand Up @@ -340,10 +347,17 @@ The Real output y is a sine signal:
annotation(Dialog(groupImage="modelica://Modelica/Resources/Images/Blocks/Sources/Cosine.png"));
parameter SI.Frequency f(start=1) "Frequency of cosine wave";
parameter SI.Angle phase=0 "Phase of cosine wave";
parameter Boolean continuous = false "Make output continuous by starting at offset + amplitude*cos(phase)"
annotation(Evaluate=true);
extends Interfaces.SignalSource;
equation
y = offset + (if time < startTime then 0 else amplitude*Modelica.Math.cos(2
*pi*f*(time - startTime) + phase));
if continuous then
y = offset + smooth(0, amplitude*(if time < startTime then Modelica.Math.cos(phase)
else Modelica.Math.cos(2*pi*f*(time - startTime) + phase)));
else
y = offset + (if time < startTime then 0 else amplitude*Modelica.Math.cos(2
*pi*f*(time - startTime) + phase));
end if;
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
Expand Down Expand Up @@ -593,12 +607,19 @@ and that the parameter <code>startTime</code> is omitted since the voltage can b
parameter Real amplitude=1 "Amplitude of sine wave"
annotation(Dialog(groupImage="modelica://Modelica/Resources/Images/Blocks/Sources/Sinc.png"));
parameter SI.Frequency f(start=1) "Frequency of sine wave";
parameter Boolean continuous = false "Make output (continuously) differentiable by starting at offset + amplitude rather than just offset"
annotation(Evaluate=true);
extends Interfaces.SignalSource;
protected
SI.Angle x=2*pi*f*(time - startTime);
equation
y = offset + (if time < startTime then 0 else amplitude*
(if noEvent(time - startTime < eps) then 1 else (sin(x))/x));
if continuous then
y = offset + amplitude*smooth(1, (if time < startTime then 1 else
(if noEvent(time - startTime < eps) then 1 else (sin(x))/x)));
else
y = offset + (if time < startTime then 0 else amplitude*
(if noEvent(time - startTime < eps) then 1 else (sin(x))/x));
end if;
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
Expand Down Expand Up @@ -1443,7 +1464,7 @@ a flange according to a given acceleration.
b := b - a*shiftTimeScaled;
end getInterpolationCoefficients;
algorithm
if noEvent(size(table, 1) > 1) then
if size(table, 1) > 1 then
assert(not (table[1, 1] > 0.0 or table[1, 1] < 0.0), "The first point in time has to be set to 0, but is table[1,1] = " + String(table[1, 1]));
end if;
when {time >= pre(nextEvent),initial()} then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ model BatteryDischargeCharge "Discharge and charge idealized battery"
Tp=60,
startTime=60)
annotation (Placement(transformation(extent={{-80,-10},{-60,10}})));
parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
parameter Modelica.Electrical.Batteries.ParameterRecords.CellData cellData1(
Qnom=18000,
OCVmax=4.2,
OCVmin=2.5,
Ri=cellData1.OCVmax/1200)
Ri=cellData1.OCVmax/Isc)
annotation (Placement(transformation(extent={{60,20},{80,40}})));
Modelica.Electrical.Batteries.BatteryStacks.CellStack battery1(
Ns=10,
Expand All @@ -38,7 +39,7 @@ model BatteryDischargeCharge "Discharge and charge idealized battery"
parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellData2(
Qnom=18000,
useLinearSOCDependency=false,
Ri=cellData2.OCVmax/1200,
Ri=cellData2.OCVmax/Isc,
Idis=0.1,
nRC=2,
rcData={Modelica.Electrical.Batteries.ParameterRecords.TransientData.RCData(
Expand Down
3 changes: 2 additions & 1 deletion Modelica/Electrical/Batteries/Examples/CCCV_Cell.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ within Modelica.Electrical.Batteries.Examples;
model CCCV_Cell
"Charge a cell with constant current - constant voltage characteristic"
extends Modelica.Icons.Example;
parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
parameter Modelica.Electrical.Batteries.ParameterRecords.ExampleData cellData(
Qnom=18000,
useLinearSOCDependency=false,
Ri=4.2/1200,
Ri=cellData.OCVmax/Isc,
Idis=0.001) "Cell data"
annotation (Placement(transformation(extent={{-10,-60},{10,-40}})));
Modelica.Electrical.Batteries.Utilities.CCCVcharger cccvCharger(I=25, Vend=4.2) annotation (Placement(
Expand Down
3 changes: 2 additions & 1 deletion Modelica/Electrical/Batteries/Examples/CCCV_CellRC.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ within Modelica.Electrical.Batteries.Examples;
model CCCV_CellRC
"Charge a transient cell with constant current - constant voltage characteristic"
extends Modelica.Icons.Example;
parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellData(
Qnom=18000,
useLinearSOCDependency=false,
Ri=4.2/1200,
Ri=cellData.OCVmax/Isc,
Idis=0.001) "Cell data"
annotation (Placement(transformation(extent={{-10,-60},{10,-40}})));
Modelica.Electrical.Batteries.Utilities.CCCVcharger cccvCharger(I=25, Vend=4.2) annotation (Placement(
Expand Down
5 changes: 3 additions & 2 deletions Modelica/Electrical/Batteries/Examples/CCCV_Stack.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ within Modelica.Electrical.Batteries.Examples;
model CCCV_Stack
"Charge a stack with constant current - constant voltage characteristic"
extends Modelica.Icons.Example;
parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
parameter Modelica.Electrical.Batteries.ParameterRecords.ExampleData cellDataOriginal(
Qnom=18000,
useLinearSOCDependency=false,
Ri=4.2/1200,
Ri=cellDataOriginal.OCVmax/Isc,
Idis=0.001) "Original cell data"
annotation (Placement(transformation(extent={{-40,-60},{-20,-40}})));
parameter Modelica.Electrical.Batteries.ParameterRecords.ExampleData cellDataDegraded(
Qnom=18000,
useLinearSOCDependency=false,
Ri=2*4.2/1200,
Ri=2*cellDataDegraded.OCVmax/Isc,
Idis=0.001) "Degraded cell data"
annotation (Placement(transformation(extent={{20,-60},{40,-40}})));
parameter Modelica.Electrical.Batteries.ParameterRecords.StackData
Expand Down
5 changes: 3 additions & 2 deletions Modelica/Electrical/Batteries/Examples/CCCV_StackRC.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ within Modelica.Electrical.Batteries.Examples;
model CCCV_StackRC
"Charge a transient stack with constant current - constant voltage characteristic"
extends Modelica.Icons.Example;
parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellDataOriginal(
Qnom=18000,
useLinearSOCDependency=false,
Ri=4.2/1200,
Ri=cellDataOriginal.OCVmax/Isc,
Idis=0.001) "Original cell data"
annotation (Placement(transformation(extent={{-40,-60},{-20,-40}})));
parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellDataDegraded(
Qnom=18000,
useLinearSOCDependency=false,
Ri=2*4.2/1200,
Ri=2*cellDataDegraded.OCVmax/Isc,
Idis=0.001) "Degraded cell data"
annotation (Placement(transformation(extent={{20,-60},{40,-40}})));
parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.StackData
Expand Down
3 changes: 2 additions & 1 deletion Modelica/Electrical/Batteries/Examples/CCCVcharging.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ within Modelica.Electrical.Batteries.Examples;
model CCCVcharging
"Charge a battery with constant current - constant voltage characteristic"
extends Modelica.Icons.Example;
parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellData(
Qnom=18000,
useLinearSOCDependency=false,
Ri=cellData.OCVmax/1200,
Ri=cellData.OCVmax/Isc,
Idis=0.001)
annotation (Placement(transformation(extent={{20,-20},{40,0}})));
Modelica.Electrical.Batteries.BatteryStacks.CellRCStack battery(
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Math/package.mo
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ v = {2, -4, -2, -1};
input Real v[:] "Real vector";
input Real eps(min=0.0)=100*Modelica.Constants.eps
"if |v| < eps then result = v/eps";
output Real result[size(v, 1)] "Input vector v normalized to length=1";
output Real result[size(v, 1)](each final unit="1") "Input vector v normalized to length=1";

algorithm
/* This function has the inline annotation. If the function is inlined:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ model OneAxis

extends Modelica.Icons.Example;
parameter SI.Mass mLoad(min=0)=15 "Mass of load";
parameter SI.Radius rg = 1.14 "Radius of gyration of load";
parameter Real kp=5 "Gain of position controller of axis";
parameter Real ks=0.5 "Gain of speed controller of axis";
parameter SI.Time Ts=0.05
Expand All @@ -27,7 +28,7 @@ model OneAxis
kp=kp,
ks=ks,
Ts=Ts) annotation (Placement(transformation(extent={{20,0},{40,20}})));
Modelica.Mechanics.Rotational.Components.Inertia load(J=1.3*mLoad)
Modelica.Mechanics.Rotational.Components.Inertia load(J=rg^2*mLoad)
annotation (Placement(transformation(extent={{60,0},{80,20}})));
Utilities.PathPlanning1 pathPlanning(
swingTime=swingTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ function from_nxy "Return orientation object from n_x and n_y vectors"
import Modelica.Math.Vectors.length;
import Modelica.Math.Vectors.normalize;

input Real n_x[3](each final unit="1")
input Real n_x[3]
"Vector in direction of x-axis of frame 2, resolved in frame 1";
input Real n_y[3](each final unit="1")
input Real n_y[3]
"Vector in direction of y-axis of frame 2, resolved in frame 1";
output TransformationMatrices.Orientation T
"Orientation object to rotate frame 1 into frame 2";
Expand Down
4 changes: 2 additions & 2 deletions Modelica/Mechanics/MultiBody/Frames/from_nxy.mo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
within Modelica.Mechanics.MultiBody.Frames;
function from_nxy "Return fixed orientation object from n_x and n_y vectors"
extends Modelica.Icons.Function;
input Real n_x[3](each final unit="1")
input Real n_x[3]
"Vector in direction of x-axis of frame 2, resolved in frame 1";
input Real n_y[3](each final unit="1")
input Real n_y[3]
"Vector in direction of y-axis of frame 2, resolved in frame 1";
output Orientation R "Orientation object to rotate frame 1 into frame 2";
algorithm
Expand Down
4 changes: 2 additions & 2 deletions Modelica/Utilities/Internal.mo
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package PartialModelicaServices
"Position vector from origin of world frame to origin of object frame, resolved in world frame" annotation(Dialog);
input SI.Position r_shape[3]={0,0,0}
"Position vector from origin of object frame to shape origin, resolved in object frame" annotation(Dialog);
input Real lengthDirection[3](each final unit="1")={1,0,0}
input Real lengthDirection[3]={1,0,0}
"Vector in length direction, resolved in object frame" annotation(Dialog);
input Real widthDirection[3](each final unit="1")={0,1,0}
input Real widthDirection[3]={0,1,0}
"Vector in width direction, resolved in object frame" annotation(Dialog);
input SI.Length length=0 "Length of visual object" annotation(Dialog);
input SI.Length width=0 "Width of visual object" annotation(Dialog);
Expand Down

0 comments on commit 8952f8c

Please sign in to comment.