TypeError: cannot unpack non-iterable Particle object

37 views
Skip to first unread message

n doherty

unread,
Apr 4, 2022, 7:00:52 AM4/4/22
to sympy
Hi,
Looking for some help if possible.  I was recently trying to get the equations of motion of a double pendulum via SymPy.  When I used "kanes_equations" to obtain Fr and Fr* I got the above TypeError message.

I have the loads and the bodies contained in lists which are input into the kanes_equation method, which I think is causing the problem here?  If I apply the method for a single pendulum with a single body (not contained in a list or array) kanes_equations works fine.

I suspect it's a newer version of sympy or python which is causing the issue.  If I try to perform the same method on the human standing tutorial I get the same error but for the bodies being RigidBody instead of Particle.  I've run this tutorial and numerous other examples in the past without this error occurring.

Is there a known workaround to this issue?

Thanks,
Nick

Peter Stahlecker

unread,
Apr 4, 2022, 7:12:29 AM4/4/22
to sy...@googlegroups.com
I have done all sorts of pendulae, single, double, triple.....
If you could send your code, maybe I could find a mistake.
Peter

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/0a4cea0a-8050-4765-873f-7a0a0857b606n%40googlegroups.com.
--
Best regards,

Peter Stahlecker

n doherty

unread,
Apr 4, 2022, 8:57:13 AM4/4/22
to sympy
Thanks very much Peter. 

I hope I'm not making an error but would welcome you finding one if I am.  I'm getting the same error in tutorial examples so suspect it's an error with a new version of sympy or python, or something specific to my setup.  I'm using python 3.8 and sympy 1.8.  I get the same error on 2 different machines although the same versions of sympy/python.

Code is below.  It's when executing the final line that the error comes up - everything else is fine.  Thanks again.
_____________________________________
import sympy as sm
import sympy.physics.mechanics as me

## REFERENCE FRAMES

A = me.ReferenceFrame("A")      # earth reference frame
P1 = me.ReferenceFrame("P1")    # 1st pendulum arm reference frame
P2 = me.ReferenceFrame("P2")    # 2nd pendulum arm reference frame

## ORIENTATION

theta1, theta2 = me.dynamicsymbols("theta1 theta2")   # generalised coordinates

P1.orient(A, "Axis", (theta1, A.z))
P2.orient(P1, "Axis", (theta2, P1.z))

## KINEMATICS
### Points and Locations

m1, m2, L1, L2 = sm.symbols("m1 m2 L1 L2")

O = me.Point("O")
p1 = me.Point("p1")
p2 = me.Point("p2")

p1.set_pos(O, L1 * P1.x)
p2.set_pos(p1, L2 * P2.x)


### Kinematical Differential Equations

omega1, omega2 = me.dynamicsymbols("omega1 omega2")

kinematical_differential_equations = [omega1 - theta1.diff(),
                                      omega2 - theta2.diff()]


### Angular Velocities

P1.set_ang_vel(A, omega1 * A.z)
P2.set_ang_vel(P1, omega1 * P1.z)



### Linear Velocities

O.set_vel(A, 0)     # point O has zero velocity

p1.v2pt_theory(O, A, P1)
p2.v2pt_theory(p1, A, P2)


## KINETICS

g = sm.symbols("g")

F_grav_1 = m1 * g * A.x
F_grav_2 = m2 * g * A.x

B1 = me.Particle("B1", p1, m1)
B2 = me.Particle("B2", p2, m2)


## EQUATIONS OF MOTION

coordinates = [theta1, theta2]
speeds = [omega1, omega2]
loads = [F_grav_1, F_grav_2]
bodies = [B1, B2]


### Kane's Method

kane = me.KanesMethod(A, coordinates, speeds, kinematical_differential_equations)

fr, frstar = kane.kanes_equations(loads, bodies)

_________________________________________

Peter Stahlecker

unread,
Apr 4, 2022, 9:25:38 AM4/4/22
to sy...@googlegroups.com
Your loads were incorrect:

Try this:

loads = [ (p1, F_grav_1), (p2, F_grav_2) ]

When I changed this in your program, it worked, or at least there was no error.

You have to give the points where the forces ‚attack‘, as tuples. Otherwise, hwo would sympy.physics.mechanics ‚know‘, where the forces act?

Peter

Peter Stahlecker

unread,
Apr 4, 2022, 9:33:22 AM4/4/22
to sy...@googlegroups.com
In addition, you probably have a typo in this:

P1.set_ang_vel(A, omega1 * A.z)
P2.set_ang_vel(P1, omega1 * P1.z)

It should probably be

P2.set_ang_vel(P1, omega2 * P1.z)

With this change, it would calculate some rhs, like:

rhs = kanes.rhs()

Peter

n doherty

unread,
Apr 4, 2022, 9:45:53 AM4/4/22
to sympy
Thanks very much Peter - that worked

Peter Stahlecker

unread,
Apr 4, 2022, 9:47:07 AM4/4/22
to sy...@googlegroups.com
Most welcome!

Reply all
Reply to author
Forward
0 new messages