'路径'对象没有属性' currentPosition'

时间:2017-06-06 17:15:08

标签: ros

我这里有一个非常奇怪的案例。我有一个python节点,它有一个具有多个属性的类,其中一个属性是currentPosition。我的代码在初始迭代时运行没有问题,并且经常在最后一次迭代之前中断。我已经确定了问题段以及一切出错的地方,它都在构造函数中!

print "path.currentPosition and path.speed",path.currentPosition,path.speed

newPath=Path(path.currentPosition,path.speed)

print "newPath.currentPosition and newPath.speed",newPath.currentPosition,newPath.speed

我将复制我看到错误的函数:

def computePathWithoutWaypoints(self, path, waypointsToExclude):
    '''! Compute the path based on the current path but without considering some tasks

    It have to recompute the path in some cases using the motion_planner so it can be slow.
    Necessary to estimateRobotLossWithoutWaypoints()
    '''

    print "path.currentPosition, path.speed",path.currentPosition, path.speed
    newPath=Path(path.currentPosition, path.speed)
    print "NEW path.currentPosition, path.speed", newPath.currentPosition,newPath.speed

    i=0
    lastAdded=-1
    conflict=False
    for waypoint in path:
        # print waypoint
        if waypoint in waypointsToExclude:
            conflict=True
            i+=1
            continue

        if conflict==False:
            newPath.append(path.waypointsPlanned[i],path.timePlanned[i])
        elif i-lastAdded==1:
            newPath.append(path.waypointsPlanned[i],updateTime=True)
        else:
            pathToWaypoint,timeToWaypoint=self.computePathToWaypoint(waypoint, startingPoint=newPath.lastPlannedPosition(),startingTime=newPath.lastPlannedTime())
            newPath.append(pathToWaypoint,timeToWaypoint)

        i+=1
        lastAdded=i-1

    return newPath

这是我的课程(非课程部分): class Path:

waypointsPlanned=0
timePlanned=0
currentPosition=0
speed=0.3

def __init__(self,currentPosition,speed):

    self.waypointsPlanned=[]
    self.timePlanned=[]
    self.currentPosition=currentPosition
    self.speed=speed

现在,我检查了所有缩进并确保那里没有问题。我无法理解这个构造函数中发生了什么。我在第一个印刷品中获得了有意义且正确的值,在第二个印刷品中,我得到了:

>  print  newPath.currentPosition,newPath.speed    AttributeError: 'Path' object has no attribute 'currentPosition'

请让我知道可能是什么问题。

谢谢, Zeynab

0 个答案:

没有答案