Skip to content
LIBRARY
PlanarMechanics.BodyShape.md

PlanarMechanics.BodyShape

Body with shape: a rigid rod (FixedTranslation) from frame_a to frame_b with a Body attached at the center of mass via a second FixedTranslation.

This component extends from PartialTwoFrames This component extends from MultibodyComponents.Renderable

Usage

MultibodyComponents.PlanarMechanics.BodyShape(render=true, color=[0.5019608, 0.0, 0.5019608, 1.0], specular_coefficient=0.7, r=[1, 0], r_cm=[0.5, 0], m=1, I=0.1, radius=0.1, z_position=0, l=sqrt(r[1] ^ 2 + r[2] ^ 2))

Parameters:

NameDescriptionUnitsDefault value
rendertrue
color[0.5019608, 0, 0.5019608, 1]
specular_coefficient0.7
rVector from frame_a to frame_b resolved in frame_am[1, 0]
r_cmVector from frame_a to center of mass, resolved in frame_am[0.5, 0]
mMass of the bodykg1
IInertia of the body with respect to the center of masskg.m20.1
radiusRadius of the body in animations0.1
z_positionz-position of the body shape in animations0

Connectors

  • frame_a - Coordinate system (2-dim.) fixed to the component with one cut-force and cut-torque.

All variables are resolved in the planar world frame. (Frame2D)

  • frame_b - Coordinate system (2-dim.) fixed to the component with one cut-force and cut-torque.

All variables are resolved in the planar world frame. (Frame2D)

Behavior

@example
using MultibodyComponents #hide
using ModelingToolkit #hide
@variables render #hide
@variables color #hide
@variables specular_coefficient #hide
@variables r #hide
@variables r_cm #hide
@variables m #hide
@variables I #hide
@variables radius #hide
@variables z_position #hide
@named sys = MultibodyComponents.PlanarMechanics.BodyShape(render=render, color=color, specular_coefficient=specular_coefficient, r=r, r_cm=r_cm, m=m, I=I, radius=radius, z_position=z_position) #hide
full_equations(sys) #hide

Source

dyad
"""
Body with shape: a rigid rod (FixedTranslation) from frame_a to frame_b with a
Body attached at the center of mass via a second FixedTranslation.
"""
component BodyShape
  extends PartialTwoFrames
  extends MultibodyComponents.Renderable(color = [0.5019608, 0.0, 0.5019608, 1.0])
  translation = FixedTranslation(r = r, render = false)
  translation_cm = FixedTranslation(r = r_cm, render = false)
  body = Body(m = m, I = I, render = false)
  "Visualization shape for the rod (cylinder from frame_a to frame_b)"
  rod_shape = MultibodyComponents.CylinderShape(render = render, color = color)
  "Vector from frame_a to frame_b resolved in frame_a"
  parameter r::Length[2] = [1, 0]
  "Vector from frame_a to center of mass, resolved in frame_a"
  parameter r_cm::Length[2] = [0.5, 0]
  "Mass of the body"
  parameter m::Dyad.Mass = 1
  "Inertia of the body with respect to the center of mass"
  parameter I::MomentOfInertia = 0.1
  "Radius of the body in animations"
  parameter radius::Real = 0.1
  "z-position of the body shape in animations"
  parameter z_position::Real = 0
  "Length of rod"
  final parameter l::Length = sqrt(r[1] ^ 2 + r[2] ^ 2)
relations
  connect(frame_a, translation.frame_a, translation_cm.frame_a)
  connect(frame_b, translation.frame_b)
  connect(translation_cm.frame_b, body.frame_a)
  # Rod shape position and orientation (2D lifted to 3D)
  rod_shape.r = [frame_a.x, frame_a.y, z_position]
  rod_shape.R = MultibodyComponents.RR(MultibodyComponents.nullrotation())
  rod_shape.r_shape = [0, 0, 0]
  rod_shape.length_direction = [translation.r0[1] / l, translation.r0[2] / l, 0]
  rod_shape.width_direction = [0, 0, 1]
  rod_shape.length = l
  rod_shape.width = 2 * radius
  rod_shape.height = 2 * radius
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MultibodyComponents/BodyShape.svg"},
    "labels": [
      {
        "label": "$(instance)",
        "x": 500,
        "y": 240,
        "rot": 0,
        "attrs": {"font-size": "160"}
      }
    ]
  }
}
end
Flattened Source
dyad
"""
Body with shape: a rigid rod (FixedTranslation) from frame_a to frame_b with a
Body attached at the center of mass via a second FixedTranslation.
"""
component BodyShape
  frame_a = Frame2D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 50, "y1": 450, "x2": 150, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  frame_b = Frame2D() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 850, "y1": 450, "x2": 950, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  parameter render::Boolean = true
  parameter color::Real[4] = [0.5, 0.5, 0.5, 1.0]
  parameter specular_coefficient::Real = 0.7
  translation = FixedTranslation(r = r, render = false)
  translation_cm = FixedTranslation(r = r_cm, render = false)
  body = Body(m = m, I = I, render = false)
  "Visualization shape for the rod (cylinder from frame_a to frame_b)"
  rod_shape = MultibodyComponents.CylinderShape(render = render, color = color)
  "Vector from frame_a to frame_b resolved in frame_a"
  parameter r::Length[2] = [1, 0]
  "Vector from frame_a to center of mass, resolved in frame_a"
  parameter r_cm::Length[2] = [0.5, 0]
  "Mass of the body"
  parameter m::Dyad.Mass = 1
  "Inertia of the body with respect to the center of mass"
  parameter I::MomentOfInertia = 0.1
  "Radius of the body in animations"
  parameter radius::Real = 0.1
  "z-position of the body shape in animations"
  parameter z_position::Real = 0
  "Length of rod"
  final parameter l::Length = sqrt(r[1] ^ 2 + r[2] ^ 2)
relations
  connect(frame_a, translation.frame_a, translation_cm.frame_a)
  connect(frame_b, translation.frame_b)
  connect(translation_cm.frame_b, body.frame_a)
  # Rod shape position and orientation (2D lifted to 3D)
  rod_shape.r = [frame_a.x, frame_a.y, z_position]
  rod_shape.R = MultibodyComponents.RR(MultibodyComponents.nullrotation())
  rod_shape.r_shape = [0, 0, 0]
  rod_shape.length_direction = [translation.r0[1] / l, translation.r0[2] / l, 0]
  rod_shape.width_direction = [0, 0, 1]
  rod_shape.length = l
  rod_shape.width = 2 * radius
  rod_shape.height = 2 * radius
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MultibodyComponents/BodyShape.svg"},
    "labels": [
      {
        "label": "$(instance)",
        "x": 500,
        "y": 240,
        "rot": 0,
        "attrs": {"font-size": "160"}
      }
    ]
  }
}
end


Test Cases

No test cases defined.