Differences between SimScape model and Sympy model

8 vues (au cours des 30 derniers jours)
Ondrej Zoufaly
Ondrej Zoufaly le 13 Déc 2023
I have a SimScape model of a 3D pendulum hanging by one of its corner. I derived equations of motion for the same model using Sympy.mechanics and there are differences while simulating. Spherical joint is represented by gimbal joint and these are the result of simulation using ode45. X,Y,Z represents rotation around these axes.
The results are the same for the first 10s, then the results started to be different. I tried different options(reltol,abstol, step sizes etc.) for matlab solver and for simulink solver but the results doesn't change much. Do you have any idea why this may happen ? Is this because of some Simscape linearization ?
The model I used is this one:
Thank you for the answers.
Edit 1:
I tried to make it a 2D pendulum by letting it rotate only around X axis and changed the hanging point to the middle of the upper side. Output time from simulink from Simscape was then used as an input to ODE solver in MATLAB so the time and steps are the same. When I simulate it then the result looks like this[angle around X axis on the vertical axis]:
So I suppose that the sympy derivation might be incorrect ? Or may this happen due to ODE solver ?
Edit2:
I tried to import the model to Simulink using MATLAB Function. The equations of motion are large and compiling takes roughly 2 hours, but finally I was able to simulate in Simulink so it is solved by one solver only. The equations of motion are probably correct as the difference is very tiny but still using only one solver there is difference between SimScape model and model derived using sympy.
In the pictures below there is simulation of 3D double pendulum with some external forces and also a contact force. "q1..q6" are the coordinates calculated in MATLAB using ode45, the "q1sim..q6sim" are the coordinates calculated by SimScape and "q1sim symp..q6sim symp" are the coordinates calculated in Simulink with Sympy equations of motion imported to MATLAB Function. It is not clear from the picture, but the results using derived EoMs from sympy are equivalent in MATLAB and Simulink, so the ODE configuration doesn't actually matter here.
So is there actually something that Simulink does differetnly than just deriving equations of motion like I did in Sympy ? Thank you everybody.

Réponses (1)

UDAYA PEDDIRAJU
UDAYA PEDDIRAJU le 19 Déc 2023
Hi Ondrej,
I understand the discrepancies you're facing with the 3D pendulum simulations in Simscape and Sympy. To resolve this issue, you can try the following steps:
  1. Numerical Solver Consistency: Ensure you're using the same numerical solver and settings in both Simscape and MATLAB's ODE solver. Different solvers can yield varied results, especially in sensitive systems like a 3D pendulum.
  2. Equations of Motion Verification: Double-check that the equations of motion derived in Sympy match those used by Simscape. Any discrepancy here could lead to divergent simulation behaviors.
  3. Physical Parameters Alignment: Confirm that all physical parameters such as mass, dimensions, and initial conditions are identical across both models.
  4. Joint Representation Accuracy: Make sure the spherical joint is represented consistently in both models, as differences in constraints and degrees of freedom can cause variations in the results.
  5. Linearization Check: If Simscape uses linearization, ensure that the Sympy model is not using the full nonlinear equations, as this could lead to differences in the behavior of the pendulum.
  6. Symbolic vs. Numeric Differences: Be aware that symbolic computation in Sympy may not translate directly to numeric simulation, potentially introducing errors. Check for any approximations or assumptions in the symbolic derivation.
  7. Solver Diagnostics: Use MATLAB's solver diagnostics to identify any numerical issues during the simulation that could be causing the observed discrepancies.
I hope this helps!
  1 commentaire
Ondrej Zoufaly
Ondrej Zoufaly le 3 Jan 2024
I tried to play with it for a moment and added some springs and damping and for low range of angles the results are identical, so the equations of motions are probably correct. If I simulate it for let's say 100s or if the movement is more chaotic there are slight differences in the results even though the solver options are exactly the same.
So my question is if SimScape(Simulink) is doing something else in the blackbox during the simulation I'm not aware of ?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Variable Initialization dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by