Skip to content

Conversation

@tobolar
Copy link
Contributor

@tobolar tobolar commented Feb 12, 2020

Close #2556

Summary by CodeRabbit

  • New Features

    • Introduced a new example model showcasing a planar mechanism simulation with enhanced joint initialization options, including configurable angles and velocities.
    • Added improved functionality for computing rotational velocity based on dynamic inputs.
    • Provided demonstration models highlighting various configuration scenarios for free-motion joints.
  • Chores

    • Updated package organization to incorporate the newly added components.

@tobolar tobolar added the L: Mechanics.MultiBody Issue addresses Modelica.Mechanics.MultiBody label Feb 12, 2020
@tobolar tobolar closed this Feb 12, 2020
@tobolar
Copy link
Contributor Author

tobolar commented Feb 12, 2020

Sorry, I shall first resolve the conflicts.

@beutlich beutlich added this to the never milestone Feb 12, 2020
@beutlich beutlich added the invalid Invalid issue label Feb 12, 2020
@tobolar tobolar reopened this Feb 14, 2020
@tobolar
Copy link
Contributor Author

tobolar commented Feb 14, 2020

All conflicts resolved now.

@tobolar tobolar removed the invalid Invalid issue label Feb 14, 2020
Copy link
Member

@dietmarw dietmarw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are no example models testing the newly added models. Could you provide some, either as proper examples in MSL or in ModelicaTest?

Copy link
Contributor

@HansOlsson HansOlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@beutlich beutlich force-pushed the issue2556_FreeMotionScalarInit branch from cc6f953 to 3f0f1fc Compare February 22, 2020 20:05
@beutlich beutlich removed this from the never milestone Feb 22, 2020
@beutlich
Copy link
Member

All conflicts resolved now.

I removed the awkward merge commit by cherry-picking the relevant commits only.

Copy link
Member

@beutlich beutlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Components of Modelica.Mechanics.MultiBody.Joints.FreeMotionScalarInit have been removed and retyped/renamed, which usual requires a conversion. Since removal is not covered by the conversion, it needs to be documented in the edited release notes.

@beutlich beutlich changed the title Redesign FreeMotionScalarInit [Do not merge yet] Redesign FreeMotionScalarInit Feb 23, 2020
@beutlich beutlich changed the title [Do not merge yet] Redesign FreeMotionScalarInit Redesign FreeMotionScalarInit Feb 28, 2020
Copy link
Member

@beutlich beutlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too late for MSL v4.0.0 to get merged. To get not merged by accident I am requesting changes here.

Furthermore, there are conversion issues to be considered.

@beutlich beutlich removed their assignment May 4, 2020
@beutlich beutlich force-pushed the issue2556_FreeMotionScalarInit branch from bf40aed to 2b05105 Compare January 19, 2021 22:06
@beutlich beutlich dismissed their stale review January 19, 2021 22:12

Was only blocked to not get into MSL v4.0.0 by accident.

@tobolar
Copy link
Contributor Author

tobolar commented Jan 29, 2021

Would be nice if @MartinOtter could give feedback as well.

@beutlich beutlich force-pushed the issue2556_FreeMotionScalarInit branch from 32db48a to e241e8d Compare April 9, 2025 17:49
@coderabbitai
Copy link

coderabbitai bot commented Apr 9, 2025

Walkthrough

This pull request introduces several new components and updates within the Modelica MultiBody package. A new example model (InitPlanar.mo) demonstrates the initialization of a planar mechanism with revolute joints, sensor outputs, and a modified initialization joint. A new function (from_anglesd) is added to compute rotational velocity vectors. The FreeMotionScalarInit joint is updated with additional parameters and now utilizes a new internal component (InitAngleAndDerivatives) for handling angle and derivative initialization. Corresponding entries in package order files and test models have also been updated.

Changes

File(s) Change Summary
Modelica/…/Examples/Elementary/InitPlanar.mo
Modelica/…/Examples/Elementary/package.order
Added new InitPlanar model demonstrating a planar mechanism with revolute joints, a FreeMotionScalarInit joint, and sensor connections; added entry in package order.
Modelica/…/Frames/Internal/from_anglesd.mo
Modelica/…/Frames/Internal/package.order
Introduced function from_anglesd to compute the rotational velocity vector from derivative inputs; added to package order.
Modelica/…/Joints/FreeMotionScalarInit.mo
Modelica/…/Joints/Internal/InitAngleAndDerivatives.mo
Modelica/…/Joints/Internal/package.order
Modified FreeMotionScalarInit by adding final parameters enforceStates and enforceStatesDer, replacing InitAngle with InitAngleAndDerivatives for comprehensive initialization; updated package order.
ModelicaTest/MultiBody.mo Added a new test model showcasing various configurations of the FreeMotionScalarInit joint with different state selections and sensor setups.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FSM as FreeMotionScalarInit
    participant IAD as InitAngleAndDerivatives
    participant Sensor as RelativeSensor
    User->>FSM: Set initial angles and state flags
    FSM->>IAD: Compute angle and derivative initialization
    IAD-->>FSM: Return computed angles and angular velocities
    FSM->>Sensor: Provide sensor outputs for verification
Loading
sequenceDiagram
    participant Model as InitPlanar
    participant Joint1 as Revolute Joint (r12)
    participant Joint2 as Revolute Joint (r23)
    participant FSM as FreeMotionScalarInit
    participant Sensor as RelativeSensor
    Model->>Joint1: Initialize angle and velocity
    Model->>Joint2: Initialize angle and velocity
    Model->>FSM: Configure joint parameters
    FSM->>Sensor: Emit relative motion data
Loading

Assessment against linked issues

Objective Addressed Explanation
Redesign FreeMotionScalarInit to not influence dynamic simulation when no states are selected (#2556)

Poem

I'm a bunny hopping with glee,
New models and functions set us free.
Planar joints and sensors in line,
Angles and vibes now perfectly fine.
With leaps of code and ASCII art so bright,
I celebrate these changes day and night!
🐇💫


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
Modelica/Mechanics/MultiBody/Examples/Elementary/InitPlanar.mo (1)

15-21: Confirm unit consistency for angle vs. angle_d.
angle_3(displayUnit="deg") and angle_d_3(displayUnit="rad/s") are correct in principle, but ensure that calculations elsewhere correctly convert from degrees to radians if any direct relationships are used.

Modelica/Mechanics/MultiBody/Joints/Internal/InitAngleAndDerivatives.mo (1)

2-2: Fix minor spelling in documentation.
The documentation title says "initialize the angels" instead of "initialize the angles".

- model InitAngleAndDerivatives "Internal model to initialize the angels ...
+ model InitAngleAndDerivatives "Internal model to initialize the angles ...
ModelicaTest/MultiBody.mo (3)

5343-5344: Update parameter description.

The description for w_start parameter incorrectly states "Initial angles of free motion joints" when it should be "Initial angular velocities of free motion joints" since it's used for initializing angular velocities.

  parameter SI.Angle angle_start[3] = {0,0,0} "Initial angles of free motion joints";
- parameter SI.AngularVelocity w_start[3] = {0.4,0.5,0.6} "Initial angles of free motion joints";
+ parameter SI.AngularVelocity w_start[3] = {0.4,0.5,0.6} "Initial angular velocities of free motion joints";

5604-5605: Update parameter description.

Similar to the previous model, the description for w_start parameter incorrectly states "Initial angles of free motion joints" when it should be "Initial angular velocities of free motion joints".

  parameter SI.Angle angle_start[3] = {0,0,0} "Initial angles of free motion joints";
- parameter SI.AngularVelocity w_start[3] = {0.4,0.5,0.6} "Initial angles of free motion joints";
+ parameter SI.AngularVelocity w_start[3] = {0.4,0.5,0.6} "Initial angular velocities of free motion joints";

5340-5778: Consider adding model documentation.

While the test models are well-structured, adding documentation comments at the beginning of each model explaining the purpose and what aspect is being tested in each test case would improve readability and maintainability.

Example:

model FreeMotionScalarInitStatesNo
  "Test model for FreeMotionScalarInit without state selection"
  extends Modelica.Icons.Example;
  
  // Test cases:
  // 1. a1_*: Angular velocity initialization (use_angle=true, use_w=true)
  // 2. a2_*: Angle derivatives initialization (use_angle=true, use_angle_d=true)
  // 3. a3_*: No initialization with RelativeSensor for verification
  // 4. a4_*: Angular velocity initialization with non-rooted body A
  // 5. a5_*: Angle derivatives initialization with non-rooted body A
  
  parameter SI.Angle angle_start[3] = {0,0,0} "Initial angles of free motion joints";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be949b2 and e241e8d.

📒 Files selected for processing (8)
  • Modelica/Mechanics/MultiBody/Examples/Elementary/InitPlanar.mo (1 hunks)
  • Modelica/Mechanics/MultiBody/Examples/Elementary/package.order (1 hunks)
  • Modelica/Mechanics/MultiBody/Frames/Internal/from_anglesd.mo (1 hunks)
  • Modelica/Mechanics/MultiBody/Frames/Internal/package.order (1 hunks)
  • Modelica/Mechanics/MultiBody/Joints/FreeMotionScalarInit.mo (3 hunks)
  • Modelica/Mechanics/MultiBody/Joints/Internal/InitAngleAndDerivatives.mo (1 hunks)
  • Modelica/Mechanics/MultiBody/Joints/Internal/package.order (1 hunks)
  • ModelicaTest/MultiBody.mo (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: external_c_checks_cmake_windows-msvc
🔇 Additional comments (15)
Modelica/Mechanics/MultiBody/Frames/Internal/from_anglesd.mo (1)

1-31: Well-implemented function for computing rotational velocity vector

This new function from_anglesd is a valuable addition that calculates the rotational velocity vector from the derivatives of rotation angles. The implementation is mathematically sound, using the appropriate transformations based on the rotation sequence and angles.

The function follows the Modelica Standards Library (MSL) conventions, and the documentation clearly explains its purpose. The algorithm correctly computes the angular velocity as a sum of contributions from each of the three angles in the sequence, with proper transformations to account for the rotation order.

This function will be useful for the redesigned FreeMotionScalarInit joint to handle angular velocity initialization properly.

Modelica/Mechanics/MultiBody/Examples/Elementary/package.order (1)

5-5: Appropriate addition of InitPlanar to package order

The addition of InitPlanar to the package order is correctly placed in alphabetical order between "FreeBody" and "InitSpringConstant". This ensures the new example model for initializing a planar mechanism is properly accessible within the Modelica package hierarchy.

Modelica/Mechanics/MultiBody/Frames/Internal/package.order (1)

3-3: from_anglesd function added to package order

The from_anglesd function has been properly added to the package order file, making it accessible within the Modelica.Mechanics.MultiBody.Frames.Internal package. This is consistent with the addition of the corresponding function file.

Note that the entry is not in alphabetical order, which differs from some other package ordering conventions in the library. However, the placement might be intentional based on functional grouping or other organizational principles used in this specific package.

Modelica/Mechanics/MultiBody/Joints/Internal/package.order (1)

7-7: InitAngleAndDerivatives component added to package order

The addition of InitAngleAndDerivatives is properly placed after related initialization components (InitAngle and InitAngularVelocity), suggesting a logical grouping based on functionality. This new component will enhance the FreeMotionScalarInit joint by supporting initialization of both angles and their derivatives.

Modelica/Mechanics/MultiBody/Examples/Elementary/InitPlanar.mo (4)

2-3: Model structure looks good.
All key components (joints, bodies, and sensor) are well-organized for a clear planar mechanism example.


5-14: Validate revolute joints' initial angles and velocities.
revolute12.w(start=0.7) and revolute23.w(fixed=true) might produce non-intuitive initial conditions if you intended both joints to have a similar or synchronized rotation.

Please confirm whether a non-zero initial angular velocity on one revolute joint while the other is fully fixed is intended for the demonstration.


37-40: Consider verifying Damper placement.
The damper is connected to the revolute12 axis. If you intended partial damping for only one joint, this is fine; otherwise confirm that you do not need a second damper for revolute23.


77-101: Documentation is thorough.
The experiment settings and embedded HTML documentation sufficiently explain the model usage and verification steps.

Modelica/Mechanics/MultiBody/Joints/FreeMotionScalarInit.mo (3)

172-179: Confirm threshold in the state selection logic.

Integer(angle_1_stateSelect) + Integer(angle_2_stateSelect) + Integer(angle_3_stateSelect) > 3

If exactly one or two angles are StateSelect.always, it may not trigger the intended outcome. Verify that > 3 is correct.


184-188: Initialization component reference is clear.
initAngleAndDerivatives neatly consolidates angle-based state initialization. This improves readability and maintainability compared to embedding the logic directly in this file.


251-262: Double-check conditional connections.
connect(initAngleAndDerivatives.angleDer, derdd.u) is unconditional, but if use_angle or use_angle_d is false, these signals may be unused or remain at defaults. Confirm that this won't cause unexpected behavior during simulations.

Modelica/Mechanics/MultiBody/Joints/Internal/InitAngleAndDerivatives.mo (2)

36-38: Coordinate the initialization step with statesAngleDer.
When not statesAngle but statesAngleDer == true, you set angle once in the initial equation block. Confirm that this one-time initialization is valid if the downstream usage expects a fully dynamic relationship.


80-97: Excellent clarity in documentation.
Explaining how angles and angle derivatives are determined based on the presence of states is particularly helpful for new users.

ModelicaTest/MultiBody.mo (2)

5340-5599: Well-structured test model.

This new model FreeMotionScalarInitStatesNo provides comprehensive test coverage for various initialization configurations of the FreeMotionScalarInit joint without enforcing states. It includes:

  • Five different test cases (a1-a5)
  • Various combinations of initialization options (angles, angular velocities, angle derivatives)
  • Different body configurations (rooted vs. non-rooted)
  • Sensor measurements for verification

The model structure is logical and follows a systematic approach to testing.


5601-5778: Well-designed state selection test model.

This new model FreeMotionScalarInitStates effectively demonstrates the enhanced state selection capabilities of the redesigned FreeMotionScalarInit joint. It includes:

  • Four test cases with different state selection strategies
  • Systematic testing of StateSelect.always applied to different variables
  • Proper connection between components

The model provides good coverage of the new state selection features, which aligns with the PR objective of redesigning the FreeMotionScalarInit joint.

Comment on lines +61 to +62
w = Frames.Internal.from_anglesd(sequence_start, angle, angleDer);
w = Modelica.Mechanics.MultiBody.Frames.angularVelocity1(R_rel);
Copy link

@coderabbitai coderabbitai bot Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Overwritten assignment to w.
Line 61 sets w using Frames.Internal.from_anglesd(...), and line 62 immediately overwrites w via Frames.angularVelocity1(R_rel). This renders the first assignment moot. Consider removing it if unused, or combine the logic if needed.

-    w = Frames.Internal.from_anglesd(sequence_start, angle, angleDer);
     w = Modelica.Mechanics.MultiBody.Frames.angularVelocity1(R_rel);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
w = Frames.Internal.from_anglesd(sequence_start, angle, angleDer);
w = Modelica.Mechanics.MultiBody.Frames.angularVelocity1(R_rel);
w = Modelica.Mechanics.MultiBody.Frames.angularVelocity1(R_rel);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG! 😱

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@casella I understand your surprise! This type of bug can be easy to miss during development. The redundant assignment to w is potentially concerning because:

  1. The first calculation using Frames.Internal.from_anglesd() is completely unused
  2. This could indicate a logic error in how the angular velocity is being calculated
  3. The unused calculation adds unnecessary computational overhead

Would you like me to help investigate the original intent of these two calculations? It's possible one of them was meant for a different variable or there's a deeper issue in the implementation logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai, I guess you have no clue what Modelica is all about. It's a declarative modelling language, not a procedural programming language. It's perfectly fine to have two equations each starting with "w = ", as long as the RHS's are different.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@casella You're absolutely right, and I appreciate the correction. I made a fundamental error in my analysis by applying procedural programming concepts to Modelica code.

In Modelica, as a declarative modeling language, these two equations:

w = Frames.Internal.from_anglesd(sequence_start, angle, angleDer);
w = Modelica.Mechanics.MultiBody.Frames.angularVelocity1(R_rel);

Are not sequential assignments but mathematical constraints that must be satisfied simultaneously - essentially declaring that both expressions must yield the same result for w. Thank you for the important clarification on how Modelica equations work.

✏️ Learnings added
Learnt from: casella
PR: modelica/ModelicaStandardLibrary#3406
File: Modelica/Mechanics/MultiBody/Joints/Internal/InitAngleAndDerivatives.mo:61-62
Timestamp: 2025-04-11T13:44:46.464Z
Learning: Modelica is a declarative modeling language, not a procedural programming language. Multiple equations with the same left-hand side (e.g., "w = expr1" and "w = expr2") represent mathematical constraints that must be satisfied simultaneously, not sequential assignments that overwrite each other. This is a fundamental aspect of equation-based modeling in Modelica.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: Mechanics.MultiBody Issue addresses Modelica.Mechanics.MultiBody

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redesign FreeMotionScalarInit to not influence dynamic simulation when no states are selected

5 participants