- 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.
- 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.
- Physical Parameters Alignment: Confirm that all physical parameters such as mass, dimensions, and initial conditions are identical across both models.
- 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.
- 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.
- 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.
- Solver Diagnostics: Use MATLAB's solver diagnostics to identify any numerical issues during the simulation that could be causing the observed discrepancies.
Differences between SimScape model and Sympy model
8 views (last 30 days)
Show older comments
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 ?
link to github with matlab files: https://github.com/zoufaond/matlab_sympy_eoms/tree/main/3D_pend
link to google colab with sympy derivation: https://colab.research.google.com/drive/1-0ZGEPLMZBL5atnS8QAy_oActhf1kdL0?usp=sharing
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.
0 Comments
Answers (1)
UDAYA PEDDIRAJU
on 19 Dec 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:
I hope this helps!
See Also
Categories
Find more on Variable Initialization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!