You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Modelica模型中圆柱体固定坐标系下的角速度?

获取刚体固连坐标系下的角速度(Modelica多体建模问题)

我编写了如下Modelica脚本,建模了带弹簧质量块的圆柱,用平面约束限制弹簧质量块在平面内运动。想要绘制圆柱在其固连坐标系(rigidBody.frame_a)下的角速度,但绘图面板里只能看到世界坐标系下的角速度,请问怎么获取固连坐标系下的角速度?

model ModelicaCheckCase
    Modelica.Mechanics.MultiBody.Joints.Planar planar(
      n = {1,0,0},
      n_x = {0,1,0}) annotation (Placement(transformation(origin = {6, 54}, extent = {{-10, -10}, {10, 10}})));
      
  Modelica.Mechanics.MultiBody.Parts.BodyCylinder rigidBody(r = {0.5, 0, 0}, r_shape = {-0.5, 0, 0}, r_0(start = {0, 0, 0}, each fixed = true), w_0_start = {0, 0, 0.1}) annotation(
    Placement(transformation(extent = {{40, -10}, {60, 10}})));
    
  inner Modelica.Mechanics.MultiBody.World world(n = {-1, 0, 0}, gravityType = Modelica.Mechanics.MultiBody.Types.GravityTypes.NoGravity) annotation(
    Placement(transformation(origin = {-40, -26}, extent = {{-40, 40}, {-20, 60}})));
    
  Modelica.Mechanics.MultiBody.Parts.Body sloshMass(r_CM = {0, 0, 0}, m = 3, r_0(each fixed = true, start = {0, 0.2, 0}), v_0(each fixed = true, start = {0, 0, 0})) annotation(
    Placement(transformation(extent = {{40, 30}, {60, 50}})));
    
  Modelica.Mechanics.MultiBody.Forces.Spring spring(c = 20, s_unstretched=0) annotation(
    Placement(transformation(origin = {-22, 76}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
    
  Modelica.Mechanics.MultiBody.Parts.FixedTranslation attachmentPoint(r = {0, 0, 0}) annotation(
    Placement(transformation(origin = {-16, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
    
equation
  connect(attachmentPoint.frame_a, rigidBody.frame_a) annotation(
    Line(points = {{-16, 0}, {-16, -3}, {6, -3}, {6, 0}}, color = {95, 95, 95}, thickness = 0.5));
  connect(attachmentPoint.frame_b, planar.frame_a) annotation(
    Line(points = {{-16, 20}, {-19, 20}, {-19, 54}, {-4, 54}}, color = {95, 95, 95}, thickness = 0.5));
  connect(spring.frame_b, sloshMass.frame_a) annotation(
    Line(points = {{-22, 86}, {28, 86}, {28, 40}, {40, 40}}, color = {95, 95, 95}, thickness = 0.5));
  connect(spring.frame_a, attachmentPoint.frame_b) annotation(
    Line(points = {{-22, 66}, {-16, 66}, {-16, 20}}));
  connect(planar.frame_b, sloshMass.frame_a) annotation(
    Line(points = {{16, 54}, {40, 54}, {40, 40}}, color = {95, 95, 95}));
  annotation(
    Icon(coordinateSystem(preserveAspectRatio = false)),
    Diagram(coordinateSystem(preserveAspectRatio = false)),
    uses(Modelica(version = "4.0.0")),
    experiment(StopTime = 10, Interval = 0.01));
end ModelicaCheckCase;

解决方法

方法1:用坐标系转换函数计算

固连坐标系下的角速度可通过世界坐标系角速度与刚体旋转矩阵转换得到,在模型中添加以下代码:

import Modelica.Mechanics.MultiBody.Frames;
Modelica.SIunits.AngularVelocity w_body[3] = Frames.resolve1(rigidBody.R, rigidBody.w);
  • rigidBody.R是刚体固连坐标系相对世界坐标系的旋转矩阵
  • Frames.resolve1函数负责将世界坐标系下的角速度矢量(rigidBody.w)转换到固连坐标系
    仿真完成后,直接绘制w_body的三个分量即可。

方法2:直接访问内置变量(工具依赖)

部分Modelica仿真工具(如Dymola)允许直接读取刚体的内部状态,固连坐标系下的角速度通常存于rigidBody.w_rel变量中。可以在绘图面板的变量搜索框中输入rigidBody.w_rel,若工具支持,直接选择该变量绘制曲线。

方法3:添加角速度传感器组件

使用Modelica.Mechanics.MultiBody.Sensors.AngularVelocitySensor组件,将其与刚体固连帧和世界帧连接,输出即为固连坐标系下的角速度。修改模型如下:

  1. 添加传感器定义:
Modelica.Mechanics.MultiBody.Sensors.AngularVelocitySensor bodyAngVelSensor annotation(
  Placement(transformation(origin = {20, 0}, extent = {{-10, -10}, {10, 10}})));
  1. 在equation段添加连接:
connect(bodyAngVelSensor.frame_a, rigidBody.frame_a);
connect(bodyAngVelSensor.frame_b, world.frame_b);

仿真后绘制bodyAngVelSensor.w的分量即可。

内容的提问来源于stack exchange,提问作者Tombombadilly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 20:22:04