【发布时间】:2022-01-25 02:05:20
【问题描述】:
我试图让机器人从一个坐标移动到目标坐标以“收集比萨饼”,然后将比萨饼移动到一组新坐标但是出现以下 NonType Eroor 我不知道这是什么方法。这是我的移动代码:
def move(self):
for c in [0,1]:
if (self.coordinates[c] < self.target[c]):
if ((self.target[c] - self.coordinates[c]) < self.max[c]):
self.velocity[c] = (self.target[c] - self.coordinates[c])
else:
self.velocity[c] = self.max[c]
elif (self.coordinates[c] > self.target[c]):
if ((self.coordinates - self.target[c]) < self.max[c]):
self.velocity[c] = -(self.coordinates[c] - self.target[c])
else:
self.velocity[c] = -self.max[c]
else:
self.velocity[c] = 0
self.coordinates[c] += self.velocity[c]
这是错误信息:
TypeError Traceback (most recent call last)
<ipython-input-140-00c07d25f390> in <module>()
33 robot.activity = 'idle'
34
---> 35 robot.move()
36 ecosystem.update()
37 print(ecosystem.hour)
<ipython-input-136-c31d02f30645> in move(self)
36 def move(self):
37 for c in [0,1]:
---> 38 if (self.coordinates[c] < self.target[c]):
39 if ((self.target[c] - self.coordinates[c]) < self.max[c]):
40 self.velocity[c] = (self.target[c] - self.coordinates[c])
TypeError: 'NoneType' object is not subscriptable
这是机器人代码
class Robot:
model = 'robot1'
def __init__(self):
self.coordinates = [1,2,0]
self.kind = 'Robot'
self.max = [1,1,0]
self.velocity = [1,1,0]
self.status = 'on'
self.name = 'robotJL'
self.activity = 'idle'
self.target = None
self.age = 0
self.serviced = 0
self.soc = 600
self.capacity = 600
self.service = 0
self.size = 500
self.damage = 0
self.color = 'green'
self.shape = 'triangle'
self.on_arena = 0
self.service = 0
self.weight = 50
self.payload = 100
self.cargo = None
self.distance = 0
self.energy = 0
【问题讨论】:
-
“self.coordinates”或“self.target”为无。为了获得更好的答案,需要更多的上下文(代码)。
-
“self.target”在“Robot”初始化代码中设置为None。