ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

'Path' object has no attribute 'currentPosition'

asked 2017-06-06 10:32:14 -0500

zeinab gravatar image

updated 2017-06-06 11:59:19 -0500

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

edit retag flag offensive close merge delete

Comments

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?

Humpelstilzchen gravatar image Humpelstilzchen  ( 2017-06-06 11:11:51 -0500 )edit

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.

zeinab gravatar image zeinab  ( 2017-06-06 11:44:21 -0500 )edit

Please let me know what you would like to see more.

zeinab gravatar image zeinab  ( 2017-06-06 11:45:04 -0500 )edit

Maybe attach a complete script that can reproduce the problem

Humpelstilzchen gravatar image Humpelstilzchen  ( 2017-06-06 15:25:10 -0500 )edit

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 ..

gvdhoorn gravatar image gvdhoorn  ( 2017-06-07 00:42:43 -0500 )edit

.. to post these kind of programming / Python questions.

Please post similar question to such places in the future.

Thank you.

gvdhoorn gravatar image gvdhoorn  ( 2017-06-07 00:43:22 -0500 )edit

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.

zeinab gravatar image zeinab  ( 2017-07-21 07:32:41 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-06-06 18:15:35 -0500

ufr3c_tjc gravatar image

The class Path is ill-formed. All class variables should be instantiated in the __init__ constructor. It looks like you have variables defined in between the class Path: line and the __init__ constructor. Take these out: nothing inside a class should ever be defined outside functions. Class-wide variables are defined in the __init__ constructor. The variables inside the __init__ look correct, including the prepended self. which people often forget.

Just to be sure, is path a member of another class, which has the function computePathWithoutWaypoints? Also, the line for waypoint in path seems odd to me, as you're iterating over a class?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-06 10:32:14 -0500

Seen: 351 times

Last updated: Jun 06 '17