Page 1 of 1

[SOLVED] Callbacks added in cfheadless.py not getting called

Posted: Fri Nov 21, 2014 5:30 am
by chad
Hi all,

I've been banging my head against the wall for the greater part of yesterday and this evening trying to understand this.

In cfheadless.py (line 92) there's a parameter update callback being added but I don't see that the callback function itself ever gets called.

Code: Select all

    
def connect_crazyflie(self, link_uri):
        """Connect to a Crazyflie on the given link uri"""
        self._cf.connection_failed.add_callback(self._connection_failed)
        self._cf.param.add_update_callback(group="imu_sensors", name="HMC5883L",
                cb=(lambda name, found:
                    self._jr.setAltHoldAvailable(eval(found))))
I added a print statement in the add_update_callback() function (line 157) of cflib/crazyflie/param.py and I can verify that function gets called during startup of cfheadless. So the callback is added.

Code: Select all

    def add_update_callback(self, group, name=None, cb=None):
        """
        Add a callback for a specific parameter name. This callback will be
        executed when a new value is read from the Crazyflie.
        """
        print "*** add_update_callback() name: {}".format(name)
I added another print statement to the setAltHoldAvailable() function (line 148) in cfclient/utils/input.py and have confirmed that this function (the callback routine) never gets called during a cfheadless run... It never executes.

Code: Select all

    def setAltHoldAvailable(self, available):
        print "*** setAltHoldAvailable() available: {}".format(available)
        self._has_pressure_sensor = available
What I haven't figured out yet is why it's not getting called. With these same print statements in, the python GUI client executes the callback just fine. The cfheadless.py implementation does not. I thought it might just be a timing issue (TOC hasn't filled out yet) but judicious use of time.sleep() has proven that theory incorrect. :-(

Are there any CF junkies out there that have a deeper understanding of the cfheadless and python client architecture that can point me in the right direction to figure out what's going on here?

Re: Callbacks added in cfheadless.py not getting called...?

Posted: Sat Nov 22, 2014 6:20 am
by whoenig
I believe that this happens because cfheadless client does not request parameter updates (and the callback is only called if this parameter was requested and received from the crazyflie). The only place where parameters are requested seems to be ParamTab.py, line 124.

Re: Callbacks added in cfheadless.py not getting called...?

Posted: Sat Nov 22, 2014 8:08 am
by chad
Indeed that's it!! Thanks!

If I force a call to self._cf.param.request_param_update("imu_sensors.HMC5883L") (ensuring it happens after param TOC finishes updating), it works. When I've got an elegant solution I'll post it back here and possibly open a pull request... Unless you've already done that.

Thanks whoenig. You're a gentleman and a scholar (and a prolific forum contributor). :-)

[SOLVED] Callbacks added in cfheadless.py not getting called

Posted: Wed Nov 26, 2014 7:01 am
by chad
Cool. Thanks again whoenig! I think I found an acceptable solution to this and made the change on a branch in my fork. The pull request is #132 in the bitcraze/crazyflie-client-python Git repo.

Regards!

Re: [SOLVED] Callbacks added in cfheadless.py not getting ca

Posted: Thu Nov 27, 2014 5:42 am
by whoenig
Well done! Thanks chad!