Can't subscribe to uORB topics in mixer_multirotor.cpp

Working off of PX4 v1.10.2, I attempted to subscribe to a uORB topic from mixer_multirotor.cpp by including the uORB::Subscription class in mixer.h, but I got an “undefined reference to function” when trying to create a Subscription object.

My Changes
I added these headers to mixer.h:

#include <uORB/Subscription.hpp>
#include <uORB/topics/topic_name.h>

…and added this private field to the MultirotorMixer class description in mixer.h:

uORB::Subscription _topic_name_sub{ORB_ID(topic_name)};

This is the same way CollisionPrevention.hpp retrieves various uORB topic data.

Expected behaviour
I expected the code to compile with these additions so I could then use Subscription::updated() and Subscription::copy() to retrieve the data. This works in CollisionPrevention.cpp.

Compile Error

/…/src/modules/uORB/Subscription.hpp:66: undefined reference to `uORB::Subscription::subscribe()’

/…/src/modules/uORB/Subscription.hpp:71: undefined reference to `uORB::Subscription::unsubscribe()’

Any help would be great. Also, if you know a more elegant way to add this uORB data, feel free to let me know in detail.

Thanks!

Can you paste the full build output? I’m wondering if maybe the mixer.h file is compiled using C (not C++) somewhere and then the linking fails.

Yes- my bad. Here’s the full output without first running make clean:

Ok I see. You added a uORB subscription in mixer itself. The problem is that mixer is also compiled for PX4IO which does not come with uORB due to flash space limits and because it’s not needed. I think this means that you can’t use a new subscription in the mixer (unless you disable PX4IO somehow if you don’t need it). The right approach would be to add whatever data you need to the mixer interface and then pass that data in.

1 Like

Ok, that makes sense. Thanks. I’m currently searching through the files to find which is responsible for creating a MultirotorMixer class object and using it to generate motor outputs for flight. Then I could update the uORB data in the MultirotorMixer object from that file. Would you happen to know which file this is?

Hi, look in the module pwm_out. It is one of the output modules that use the mixer library. pwm_out writes on the MAIN pins on autopilots without IO, and on AUX pins otherwise.

Cool, I checked it out. My mods are currently on v1.10.1 so I’d have to refactor to use the version with pwm_out. Even so, you’re saying that this would only work on boards without px4IO? This may not be possible for me (I’m using a Pixhawk Cube, by the way).

I just checked the master branch, and I see there was major refactoring in the mixer lib files. I haven’t reviewed the changes thoroughly, but it looks like MultirotorMixer no longer #includes a mixer.h, but Mixer.hpp instead. @dagar, off the top of your head, do you know if it would help my issue (see below) to port my mods to the most recent code? I’ve been on v1.10.2.

(To recap, my goal was to add a uORB topic subscription in mixer_multirotor.cpp, and use this modified firmware with PX4IO PWM outputs. This wasn’t working because the files are also compiled on PX4IO, which doesn’t have uORB)

@JulianOes I just happened to stumble upon this and can’t really make any sense of it. What does this mean:

If I go to src/drivers/px4io/px4io.cpp it is full of uORB subscriptions and publications. Is this not what you mean by PX4IO? What am I missunderstanding here?

Please, did you solve this problem, I have the same problem