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

Firmware/software/electronics/mechanics
Post Reply
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

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

Post 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?
Last edited by chad on Wed Nov 26, 2014 7:01 am, edited 1 time in total.
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

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

Post 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.
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

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

Post 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). :-)
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

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

Post 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!
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

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

Post by whoenig »

Well done! Thanks chad!
Post Reply