Hi everyone,

I have started my journey into using ModelingToolkit. So far it has been working quite well and I am very impressed.

I am going down the component-based path. I have a somewhat complex system in mind but I have started implementing a few components and testing them individually. I have hit an issue with some multi-body dynamics, I have a mass-less rigid Link, which when combined with a Mass component to create a pendulum has issues when crossing vertical. I have attached two files:

- A single component pendulum which seems to work as expected.
- A two component pendulum which appears to explode/become unstable when the pendulum crosses vertical (θ = -90). QNDF-solver does seem to stabilize the model but it seems to do so at the cost of dissipating a lot of energy from the system. Also, if gravity is applied in horizontal direction it does become stable as long as the pendulum does not cross vertical.

To the best of my knowledge the two systems should be equivalent.

ModelingToolkit does not generate the same set of equations for both systems but I am not sure that is to be expected. Output of full_equations() below:

Single component system:

```
Differential(t)(θ(t)) ~ θ̇(t)
Differential(t)(θ̇(t)) ~ θˍtt(t)
0 ~ (-cos(θ(t))*f(t)) / m + l*sin(θ(t))*θˍtt(t) + l*(θ̇(t)^2)*cos(θ(t))
0 ~ (-g*m - sin(θ(t))*f(t)) / m - l*θˍtt(t)*cos(θ(t)) + l*sin(θ(t))*(θ̇(t)^2)
```

Two component system:

```
Differential(t)(link₊pY₊u(t)) ~ link₊pY₊uˍt(t)
Differential(t)(link₊pY₊uˍt(t)) ~ link₊l*cos(link₊θ(t))*link₊θˍtt(t) - link₊l*sin(link₊θ(t))*(link₊θˍt(t)^2)
0 ~ -link₊pY₊u(t) + link₊l*sin(link₊θ(t))
0 ~ mass₊g*mass₊m + link₊f(t)*sin(link₊θ(t)) + (link₊l*cos(link₊θ(t))*link₊θˍtt(t) - link₊l*sin(link₊θ(t))*(link₊θˍt(t)^2))*mass₊m
0 ~ -link₊pY₊uˍt(t) + link₊l*cos(link₊θ(t))*link₊θˍt(t)
0 ~ (cos(link₊θ(t))*link₊f(t)) / mass₊m - link₊l*sin(link₊θ(t))*link₊θˍtt(t) - link₊l*cos(link₊θ(t))*(link₊θˍt(t)^2)
```

I wonder what I am missing here? Any ideas/inputs on how to stabilize the model would be much appreciated.

pendulum.jl (1.2 KB)

pendulum_split.jl (2.0 KB)