我正在研究Raspberry Pi 3上的自动无人机程序,我遇到了一个奇怪的问题。我有点像菜鸟,所以请耐心等待。到目前为止,这是我的代码:
class P_2(object):
def __init__(self):
self.init = True
def computation(self, phi_de, theta_de, psi_de):
self.phi_de = phi_de
self.theta_de = phi_de
self.psi_de = phi_de
phi = phi_de*math.pi/180
theta = theta_de*math.pi/180
psi = psi_de*math.pi/180
#some more math stuff
class ESCs(object):
def __init__(self):
self.init = True
def motors(self):
if self.init:
self.init = False
phi_d, theta_d, psi_d = raw_input('Enter the desired
roll, pitch, and yaw in degrees: ').split()
phi_d,theta_d,psi_d=[float(phi_d),
float(theta_d),float(psi_d)]
oop = P_2()
oop.computation(self, phi_d, theta_d, psi_d)
return 0
else:
ich = P_2()
g = ich.computation(self, phi_d, theta_d, psi_d)
for j in range(len(ich)):
g[j] *= 180/math.pi
#some more math stuff
while True:
begin = ESCs()
begin.motors()
如果有帮助的话,我在Raspberry Pi Jessie-Lite图像上运行我的代码。在终端中运行我的代码之后,它不断抛出如下所示的错误:
Enter the desired roll, pitch, and yaw in degrees: 0 0 0
Traceback (most recent call last):
File "Quadcopter_main.py", line 10, in <module>
begin.motors()
File "Quadcopter_main.py", line 28, in motors
oop.computation(self, phi_d, theta_d, psi_d)
File "Quadcopter_main.py", line 41, in computation
phi = phi_de*math.pi/180
TypeError: unsupported operand type(s) for *: 'ESCs' and 'float'
我知道TypeError:不支持的操作数类型是指尝试连接两种类型的不同变量(例如字符串和int)的错误,但是通过使用类来获取此类错误,我有点失望,而且我不确定问题可能在哪里。