Skip to content

calibrate.py waiting forever in certain cases (ros ticket #5211) #222

@ahendrix

Description

@ahendrix

pr2_bringup/calibrate.py has a pyhton for loop on a list, but the elements of the list can be removed during the loop.

def calibrate(controllers):
...
# Sets up callbacks for calibration completion
waiting_for = launched[:]
def calibrated(msg, name): # Somewhat not thread-safe
if name in waiting_for:
waiting_for.remove(name)
for name in waiting_for:
rospy.Subscriber("%s/calibrated" % name, Empty, calibrated, name)

    # Waits until all the controllers have calibrated
    while waiting_for and not rospy.is_shutdown():
        print "Waiting for: %s" % ', '.join(waiting_for)
        sleep(0.5)

So if the first controllers in the queue publish something quickly enough, the callback function could be called before the for loop has finished, what results in the last cycle/s not being executed, and thus, the last subscribers not being called. This leads to the subsequent while loop running forever.

I've been using this with custom calibration controllers (not with a pr2 robot but with a Shadow Robot hand). If the calibration controllers take more time to publish on the xxx/calibrated topic, then this problem doesn't happen (in our case it takes a very short time, thus the problem).

trac data:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions