# Sympy -- AttributeError: 'tuple' object has no attribute 'right'

I am trying to build a simple pendulum model in `sympy`.

Does anyone know why I would be getting this error?

The tutorial is here:

http://for.rest/articles/The-Spring-Pendulum-with-Sympy/

Here's the code. Note, I modified my code slightly because the tutorial picked a very unintuitive coordinate system(+y pointing down).

``````import sympy
from sympy import symbols, init_printing
import sympy.physics.mechanics as me
init_printing()
import matplotlib.pyplot as plt
import numpy as np
from pydy.system import System
from numpy import linspace
%matplotlib inline

# Create the variables
L, theta = me.dynamicsymbols('L theta')

# Create the velocities
L_dot, theta_dot = me.dynamicsymbols('L_dot theta_dot')

# Create the constants
m, g, t, L_0 = sympy.symbols('m g t L_0')

# Create the world frame
A = me.ReferenceFrame('A')

# Create the pendulum frame
B = A.orientnew('B', 'axis', [theta, A.z])

# Set the rotation of the pendulum frame
B.set_ang_vel(A, theta_dot * A.z)

# Create the Origin
O = me.Point('O')

# Create the mass point
P = O.locatenew('P', L * -B.y)

# Display the mass point location in the A frame
P.pos_from(O).express(A)

# Set origin velocity to zero
O.set_vel(A, 0)

# Create the velocity of the mass point
P.set_vel(B, L_dot * -B.y)
P.v1pt_theory(O, A, B)

P.vel(A).express(A)
``````

The problem arises in the last line of code there. Note, the object `P.vel(A)` is type `sympy.physics.vector.vector.Vector`, which has `express` as a method.

Here's the error

``````---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
691                 type_pprinters=self.type_printers,
692                 deferred_pprinters=self.deferred_printers)
--> 693             printer.pretty(obj)
694             printer.flush()
695             return stream.getvalue()

C:\ProgramData\Anaconda3\lib\site-packages\IPython\lib\pretty.py in pretty(self, obj)
363                 if cls in self.type_pprinters:
364                     # printer registered in self.type_pprinters
--> 365                     return self.type_pprinters[cls](obj, self, cycle)
366                 else:
367                     # deferred printer

C:\ProgramData\Anaconda3\lib\site-packages\sympy\interactive\printing.py in _print_plain(arg, p, cycle)
66         """caller for pretty, for use in IPython 0.11"""
67         if _can_print_latex(arg):
---> 68             p.text(stringify_func(arg))
69         else:
70             p.text(IPython.lib.pretty.pretty(arg))

C:\ProgramData\Anaconda3\lib\site-packages\sympy\printing\pretty\pretty.py in pretty(expr, **settings)
2162
2163     try:
-> 2164         return pp.doprint(expr)
2165     finally:
2166         pretty_use_unicode(uflag)

C:\ProgramData\Anaconda3\lib\site-packages\sympy\printing\pretty\pretty.py in doprint(self, expr)
60
61     def doprint(self, expr):
---> 62         return self._print(expr).render(**self._settings)
63
64     # empty op so _print(stringPict) returns the same

C:\ProgramData\Anaconda3\lib\site-packages\sympy\physics\vector\vector.py in render(self, *args, **kwargs)
283                                 pform = vp._print(
284                                     ar[i][0][j])
--> 285                             pform = prettyForm(*pform.right(" ",
286                                                 ar[i][1].pretty_vecs[j]))
287                         else:

AttributeError: 'tuple' object has no attribute 'right'
``````

This creates a separate issue because, without expressing this, I can't run a computation later.

``````pendulum = me.Particle('pend', P, m)

gravity = m * g * A.y
forces = gravity

kane = me.KanesMethod(A,
q_ind=[L, theta],
u_ind=[L_dot, theta_dot],
kd_eqs=[L_dot - L.diff(t),
theta_dot - theta.diff(t)])
``````

Which produces this error

``````---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-222-aeb1b3bb40e8> in <module>()
----> 1 fr, frstar = kane.kanes_equations([(P, forces)], [pendulum])

537                     'kinematic differential equations to use this method.')
--> 539         frstar = self._form_frstar(bodies)
540         if self._uaux:
541             if not self._udep:

C:\ProgramData\Anaconda3\lib\site-packages\sympy\physics\mechanics\kane.py in _form_frstar(self, bl)
332             v = [msubs(vel, self._qdot_u_map) for vel in vlist]
333             return partial_velocity(v, self.u, N)
--> 334         partials = [get_partial_velocity(body) for body in bl]
335
336         # Compute fr_star in two components:

C:\ProgramData\Anaconda3\lib\site-packages\sympy\physics\mechanics\kane.py in <listcomp>(.0)
332             v = [msubs(vel, self._qdot_u_map) for vel in vlist]
333             return partial_velocity(v, self.u, N)
--> 334         partials = [get_partial_velocity(body) for body in bl]
335
336         # Compute fr_star in two components:

C:\ProgramData\Anaconda3\lib\site-packages\sympy\physics\mechanics\kane.py in get_partial_velocity(body)
326                 vlist = [body.masscenter.vel(N), body.frame.ang_vel_in(N)]
327             elif isinstance(body, Particle):
--> 328                 vlist = [body.point.vel(N),]
329             else:
330                 raise TypeError('The body list may only contain either '

C:\ProgramData\Anaconda3\lib\site-packages\sympy\physics\vector\point.py in vel(self, frame)
453         if not (frame in self._vel_dict):
454             raise ValueError('Velocity of point ' + self.name + ' has not been'
--> 455                              ' defined in ReferenceFrame ' + frame.name)
456         return self._vel_dict[frame]
457

ValueError: Velocity of point P has not been defined in ReferenceFrame A
``````