How to subscribe vehicle_local_position in mc_att_control.c successfully

Hello, I want to use integrate control of PID when the copter fly away from the ground, thus I need to subscribe vehicle_local_position in mc_att_control.c, I have done it by referencing how mc_pos_control do, but it is confusing because any change of the subscribe code will not report errors, even I delete the header “#include <uORB/topics/vehicle_local_position.h>”. Can anyone tell me how to validate whether I have done the right subscribe?

Thank you! Nice day!

Hi @yun,

can you show me your code? Then I can see what may be wrong.

Best
Nils

The code is a little long, I am considering how to upload it:pensive:

https://coding.net/u/yunzhongjie/p/mc_att_control_main/git/blob/master/mc_att_control_main

You can get the code from the link, and ctrl+f search “local_pos” for what I have done in subscribing vehicle_local_position. Thank you!

Hi @yun,

At a first view your code seems fine. Pls check if data gets published to the topic vehicle_local_position by using

listener vehicle_local_position

Best
Nils

listener vehicle_local_position

How to use this command? In the system console ( nsh ) ?

Thank you!

Hi,

Yes you can run the command in the console after your system is running. Just try to type

listener vehicle_local_position

If nothing happens look which topics are published by typing

list_topics

Best
Nils

Hi,
The development guide says that “The listener command is only available on Pixracer (FMUv4) and Linux / OS X.”

So with my pixhawk, listener command is not available ? For there is always “command not found” in system console.

Best
yun

Hi @yun,

Then try to just add some outputs, just like a in this example code, to see if something gets published:

struct vehicle_local_position_s raw_position;
orb_copy(ORB_ID(att_pos_mocap), position_sub_fd, &raw_position);
            
// printing the position data into the terminal
PX4_INFO("Local Position:\t%8.4f\t%8.4f\t%8.4f",
                 (double)raw_position.x,
                 (double)raw_position.y,
                 (double)raw_position.z);

Best
Nils

Hi,

I just did it as you told me, as follows,

But whether I add headers “#include <uORB/topics/vehicle_local_position.h>” or not, there is no errors when I make, And the console output as follows,

It seems integrate works successfully, But I’m very confusing about whether the header is necessary? Or it has been include by other files?

Thank you!
yun

Hi @yun,

Since it seems to work I am not sure why the header is not necessary in your case. Normally you need to include it that the compiler know the uORB function for the vehicle_local_position topic.

Best
Nils