'Path' object has no attribute 'currentPosition'
I have a very strange case here. I have a python node that has a class with several attributes one of which is currentPosition. My code runs without problems for the initial iterations and very often breaks before the last iteration. I have identified the problem segment and where everything goes wrong, it is in the constructor!
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
I will copy the function is which I see the error:
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
Here is my Class (off course parts of it): 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
Now, I've checked all the indentation and made sure there is not a problem there. I can't understand what is happening inside this constructor. I get meaningful and correct values in the first print and upon second one I get:
> print newPath.currentPosition,newPath.speed AttributeError: 'Path' object has no attribute 'currentPosition'
Please let me know what could be the problem.
Thanks, Zeynab
I don't think that this can be answered from the small code given. Also it looks more a python question then ros. Btw calling "Path(path.currentPosition,path.speed)" looks a bit strange. Do you effectively want to copy your object?
Thanks for your reply. Well, its not copying but rather creating a new object with similar fields for the variables of
currentPosition
andspeed
. I agree it's more a python problem and the code is small. But it really looks like the issue happens in this one line of calling the constructor.Please let me know what you would like to see more.
Maybe attach a complete script that can reproduce the problem
I'll leave this open as there are already comments and answers, but it should really have been closed as off-topic.
@zeinab: ROS Answers is for questions on ROS only. We try to keep this forum as on-topic as possible, as we already have almost 35000 questions and there are better places ..
.. to post these kind of programming / Python questions.
Please post similar question to such places in the future.
Thank you.
Sure, but I thought there might be an element of ROS such as threads that could lead to this, since I could not think of anything else.