Skip to content
LIBRARY
Examples.CompareBrakingTorque.md

Examples.CompareBrakingTorque

Compare different braking torques.

Matches MSL Modelica.Mechanics.Rotational.Examples.CompareBrakingTorque.

Four inertias (J=1) start at w=100 rad/s and are braked by different speed-dependent torque sources, all with TorqueDirection=false (torque direction depends on speed direction):

  1. SignTorque (Linear regularization): constant magnitude braking, smooth near zero

  2. LinearSpeedDependentTorque: tau ∝ w → exponential decay w(t) = 100·exp(-t)

  3. QuadraticSpeedDependentTorque: tau ∝ w|w| → w(t) = 100/(1+t)

  4. InverseSpeedDependentTorque: tau ∝ 1/w → rapid braking, w hits 0 at t=0.5

Usage

RotationalComponents.Examples.CompareBrakingTorque()

Behavior

[connect(signtorque+spline,inertia1+splinea)connect(signtorque+support,fixed+spline)connect(linearspeed+spline,inertia2+splinea)connect(linearspeed+support,fixed+spline)connect(quadraticspeed+spline,inertia3+splinea)connect(quadraticspeed+support,fixed+spline)connect(inversespeed+spline,inertia4+splinea)connect(inversespeed+support,fixed+spline)fixed.spline.phi(t)=fixed.phi0inertia1.phi(t)=inertia1.splinea.phi(t)inertia1.phi(t)=inertia1.splineb.phi(t)dinertia1.phi(t)dt=inertia1.w(t)dinertia1.w(t)dt=inertia1.a(t)inertia1.Jinertia1.a(t)=inertia1.splinea.tau(t)+inertia1.splineb.tau(t)signtorque.support.phi(t)=signtorque.phi_support(t)signtorque.support.tau(t)=signtorque.spline.tau(t)signtorque.phi(t)=signtorque.spline.phi(t)signtorque.phi_support(t)signtorque.w(t)=dsigntorque.phi(t)dtsigntorque.tau(t)=signtorque.spline.tau(t)signtorque.tau(t)=signtorque.tau_nominalifelse(|signtorque.w(t)|signtorque.w0,sign(signtorque.w(t)),signtorque.w(t)signtorque.w0)inertia2.phi(t)=inertia2.splinea.phi(t)inertia2.phi(t)=inertia2.splineb.phi(t)dinertia2.phi(t)dt=inertia2.w(t)dinertia2.w(t)dt=inertia2.a(t)inertia2.Jinertia2.a(t)=inertia2.splinea.tau(t)+inertia2.splineb.tau(t)linearspeed.support.phi(t)=linearspeed.phi_support(t)linearspeed.support.tau(t)=linearspeed.spline.tau(t)linearspeed.phi(t)=linearspeed.phi_support(t)+linearspeed.spline.phi(t)linearspeed.w(t)=dlinearspeed.phi(t)dtlinearspeed.tau(t)=linearspeed.spline.tau(t)linearspeed.tau(t)=linearspeed.tau_nominallinearspeed.w(t)linearspeed.w_nominalinertia3.phi(t)=inertia3.splinea.phi(t)inertia3.phi(t)=inertia3.splineb.phi(t)dinertia3.phi(t)dt=inertia3.w(t)dinertia3.w(t)dt=inertia3.a(t)inertia3.Jinertia3.a(t)=inertia3.splinea.tau(t)+inertia3.splineb.tau(t)quadraticspeed.support.phi(t)=quadraticspeed.phi_support(t)quadraticspeed.support.tau(t)=quadraticspeed.spline.tau(t)quadraticspeed.phi(t)=quadraticspeed.spline.phi(t)quadraticspeed.phi_support(t)quadraticspeed.w(t)=dquadraticspeed.phi(t)dtquadraticspeed.tau(t)=quadraticspeed.spline.tau(t)quadraticspeed.tau(t)=quadraticspeed.tau_nominal|quadraticspeed.w(t)|quadraticspeed.w(t)quadraticspeed.w_nominal2inertia4.phi(t)=inertia4.splinea.phi(t)inertia4.phi(t)=inertia4.splineb.phi(t)dinertia4.phi(t)dt=inertia4.w(t)dinertia4.w(t)dt=inertia4.a(t)inertia4.Jinertia4.a(t)=inertia4.splineb.tau(t)+inertia4.splinea.tau(t)inversespeed.support.phi(t)=inversespeed.phi_support(t)inversespeed.support.tau(t)=inversespeed.spline.tau(t)inversespeed.phi(t)=inversespeed.spline.phi(t)inversespeed.phi_support(t)inversespeed.w(t)=dinversespeed.phi(t)dtinversespeed.tau(t)=inversespeed.spline.tau(t)inversespeed.tau(t)=ifelse(|inversespeed.w(t)|<inversespeed.w0,inversespeed.tau_nominalinversespeed.w(t)inversespeed.w0,inversespeed.tau_nominalinversespeed.w_nominalinversespeed.w(t))]

Source

dyad
"""
Compare different braking torques.

Matches MSL Modelica.Mechanics.Rotational.Examples.CompareBrakingTorque.

Four inertias (J=1) start at w=100 rad/s and are braked by different
speed-dependent torque sources, all with TorqueDirection=false (torque
direction depends on speed direction):

1. SignTorque (Linear regularization): constant magnitude braking, smooth near zero
2. LinearSpeedDependentTorque: tau ∝ w → exponential decay w(t) = 100·exp(-t)
3. QuadraticSpeedDependentTorque: tau ∝ w|w| → w(t) = 100/(1+t)
4. InverseSpeedDependentTorque: tau ∝ 1/w → rapid braking, w hits 0 at t=0.5
"""
example component CompareBrakingTorque
  "Fixed ground for all source supports"
  fixed = RotationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -240, "y1": 400, "x2": -140, "y2": 500, "rot": 90}
      },
      "tags": []
    }
  }
  "Inertia 1 for sign torque braking"
  inertia1 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 430, "y1": 20, "x2": 530, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sign torque with Linear regularization (tau_nominal=-100, w0=1)"
  sign_torque = RotationalComponents.Sources.SignTorque(tau_nominal = -100, reg = RotationalComponents.Sources.Regularization.Linear(), w0 = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 2 for linear speed dependent braking"
  inertia2 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 420, "y1": 250, "x2": 520, "y2": 350, "rot": 0}
      },
      "tags": []
    }
  }
  "Linear speed dependent torque (TorqueDirection=false)"
  linear_speed = RotationalComponents.Sources.LinearSpeedDependentTorque(tau_nominal = -100, TorqueDirection = false, w_nominal = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 150, "y1": 250, "x2": 250, "y2": 350, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 3 for quadratic speed dependent braking"
  inertia3 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 420, "y1": 470, "x2": 520, "y2": 570, "rot": 0}
      },
      "tags": []
    }
  }
  "Quadratic speed dependent torque (TorqueDirection=false)"
  quadratic_speed = RotationalComponents.Sources.QuadraticSpeedDependentTorque(tau_nominal = -100, TorqueDirection = false, w_nominal = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 150, "y1": 470, "x2": 250, "y2": 570, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 4 for inverse speed dependent braking"
  inertia4 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 420, "y1": 710, "x2": 520, "y2": 810, "rot": 0}
      },
      "tags": []
    }
  }
  "Inverse speed dependent torque (TorqueDirection=false)"
  inverse_speed = RotationalComponents.Sources.InverseSpeedDependentTorque(tau_nominal = -100, TorqueDirection = false, w_nominal = 100, w0 = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 710, "x2": 260, "y2": 810, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial inertia1.phi = 0
  initial inertia1.w = 100
  initial inertia2.phi = 0
  initial inertia2.w = 100
  initial inertia3.phi = 0
  initial inertia3.w = 100
  initial inertia4.phi = 0
  initial inertia4.w = 100
  connect(sign_torque.spline, inertia1.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sign_torque.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 210, "y": 160}, {"x": 0, "y": 160}, {"x": 0, "y": 450}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(linear_speed.spline, inertia2.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(linear_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 200, "y": 450}], "E": -1},
        {"S": -1, "M": [], "E": -2},
        {"S": -2, "M": [], "E": 2}
      ],
      "junctions": [{"x": -140, "y": 450}, {"x": -140, "y": 450}],
      "renderStyle": "standard"
    }
  }
  connect(quadratic_speed.spline, inertia3.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(quadratic_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 200, "y": 700}, {"x": 0, "y": 700}, {"x": 0, "y": 450}],
          "E": -1
        },
        {"S": -1, "M": [], "E": 2}
      ],
      "junctions": [{"x": -140, "y": 450}],
      "renderStyle": "standard"
    }
  }
  connect(inverse_speed.spline, inertia4.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(inverse_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 210, "y": 905}, {"x": 0, "y": 905}, {"x": 0, "y": 450}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://RotationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 5,
        "atol": {
          "inertia1.w": 0.001,
          "inertia2.w": 0.001,
          "inertia3.w": 0.001,
          "inertia4.w": 0.001
        },
        "expect": {
          "initial": {"inertia1.w": 100, "inertia2.w": 100, "inertia3.w": 100, "inertia4.w": 100},
          "signals": ["inertia1.w", "inertia2.w", "inertia3.w", "inertia4.w"]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Compare different braking torques.

Matches MSL Modelica.Mechanics.Rotational.Examples.CompareBrakingTorque.

Four inertias (J=1) start at w=100 rad/s and are braked by different
speed-dependent torque sources, all with TorqueDirection=false (torque
direction depends on speed direction):

1. SignTorque (Linear regularization): constant magnitude braking, smooth near zero
2. LinearSpeedDependentTorque: tau ∝ w → exponential decay w(t) = 100·exp(-t)
3. QuadraticSpeedDependentTorque: tau ∝ w|w| → w(t) = 100/(1+t)
4. InverseSpeedDependentTorque: tau ∝ 1/w → rapid braking, w hits 0 at t=0.5
"""
example component CompareBrakingTorque
  "Fixed ground for all source supports"
  fixed = RotationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -240, "y1": 400, "x2": -140, "y2": 500, "rot": 90}
      },
      "tags": []
    }
  }
  "Inertia 1 for sign torque braking"
  inertia1 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 430, "y1": 20, "x2": 530, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sign torque with Linear regularization (tau_nominal=-100, w0=1)"
  sign_torque = RotationalComponents.Sources.SignTorque(tau_nominal = -100, reg = RotationalComponents.Sources.Regularization.Linear(), w0 = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 2 for linear speed dependent braking"
  inertia2 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 420, "y1": 250, "x2": 520, "y2": 350, "rot": 0}
      },
      "tags": []
    }
  }
  "Linear speed dependent torque (TorqueDirection=false)"
  linear_speed = RotationalComponents.Sources.LinearSpeedDependentTorque(tau_nominal = -100, TorqueDirection = false, w_nominal = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 150, "y1": 250, "x2": 250, "y2": 350, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 3 for quadratic speed dependent braking"
  inertia3 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 420, "y1": 470, "x2": 520, "y2": 570, "rot": 0}
      },
      "tags": []
    }
  }
  "Quadratic speed dependent torque (TorqueDirection=false)"
  quadratic_speed = RotationalComponents.Sources.QuadraticSpeedDependentTorque(tau_nominal = -100, TorqueDirection = false, w_nominal = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 150, "y1": 470, "x2": 250, "y2": 570, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 4 for inverse speed dependent braking"
  inertia4 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 420, "y1": 710, "x2": 520, "y2": 810, "rot": 0}
      },
      "tags": []
    }
  }
  "Inverse speed dependent torque (TorqueDirection=false)"
  inverse_speed = RotationalComponents.Sources.InverseSpeedDependentTorque(tau_nominal = -100, TorqueDirection = false, w_nominal = 100, w0 = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 710, "x2": 260, "y2": 810, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial inertia1.phi = 0
  initial inertia1.w = 100
  initial inertia2.phi = 0
  initial inertia2.w = 100
  initial inertia3.phi = 0
  initial inertia3.w = 100
  initial inertia4.phi = 0
  initial inertia4.w = 100
  connect(sign_torque.spline, inertia1.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sign_torque.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 210, "y": 160}, {"x": 0, "y": 160}, {"x": 0, "y": 450}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(linear_speed.spline, inertia2.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(linear_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 200, "y": 450}], "E": -1},
        {"S": -1, "M": [], "E": -2},
        {"S": -2, "M": [], "E": 2}
      ],
      "junctions": [{"x": -140, "y": 450}, {"x": -140, "y": 450}],
      "renderStyle": "standard"
    }
  }
  connect(quadratic_speed.spline, inertia3.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(quadratic_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 200, "y": 700}, {"x": 0, "y": 700}, {"x": 0, "y": 450}],
          "E": -1
        },
        {"S": -1, "M": [], "E": 2}
      ],
      "junctions": [{"x": -140, "y": 450}],
      "renderStyle": "standard"
    }
  }
  connect(inverse_speed.spline, inertia4.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(inverse_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 210, "y": 905}, {"x": 0, "y": 905}, {"x": 0, "y": 450}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://RotationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 5,
        "atol": {
          "inertia1.w": 0.001,
          "inertia2.w": 0.001,
          "inertia3.w": 0.001,
          "inertia4.w": 0.001
        },
        "expect": {
          "initial": {"inertia1.w": 100, "inertia2.w": 100, "inertia3.w": 100, "inertia4.w": 100},
          "signals": ["inertia1.w", "inertia2.w", "inertia3.w", "inertia4.w"]
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt

  • Examples

  • Experiments

  • Analyses