How to check, if one uORB topic is successfully setup

Hi,

i would like to know, how i can check a uORB message/topic is setup all right. I have followed the instruction to create a XXX.msg and add the name in CMakeLists.txt file. In an application, I have used orb_advertise() and orb_publish() functions to public a message all the time. And then I call another application to try to orb_subscribe() the topic. But the result of px4_poll() is zero. It seems, that the application can not get the uORB message. Is there any wrong settings by me? Could someone give me some suggestions? Thanks.

If you share some of your code we could look for the problem. Otherwise go through the uORB messaging section of the dev guide (http://dev.px4.io/advanced-uorb.html) to see if you missed anything. Try using the topic listener in SITL to see if you’re successfully publishing your topic.

Example

listener sensor_accel 5

Thank you for your reply. I’ve tried to list all objs using ls/obj to display all topics. There is my topic after I active my application.

But for the command litener, is it limited by px4fmu-v4 according to the dev guide? My hardware can be applied with v2.

Here are some codes from my program, can you just have a look and help me find some erros? Thanks.

In zigbee_position.h, which is auto-gem through a .msg by Nuttx

struct zigbee_position_s {
uint64_t timestamp; // required for logger
float value;
uint8_t _padding0[4]; // required for logger
};

In zigbee.c, include the zigbee_position.h and use following codes

struct zigbee_position_s zig_s;
memset(&zig_s, 0, sizeof(zig_s));
orb_advert_t zig_pub_fd = orb_advertise(ORB_ID(zigbee_position), &zig_s);

Based on the app demo, I’ve written the publication in a loop:

for (int i = 0; i < 10; i++) {
/* wait for sensor update of 1 file descriptor for 1000 ms (1 second) /
int poll_ret = px4_poll(fds, 1, 1000);
if (poll_ret == 0) {
/
this means none of our providers is giving us data /
printf("[px4_simple_app] Got no data within a second\n");
} else if (poll_ret < 0) {
/
this is seriously bad - should be an emergency /
if (error_counter < 10 || error_counter % 50 == 0) {
/
use a counter to prevent flooding (and slowing us down) /
printf("[px4_simple_app] ERROR return value from poll(): %d\n"
, poll_ret);
}
error_counter++;
} else {
if (fds[0].revents & POLLIN) {
/
obtained data for the first file descriptor /
struct sensor_combined_s raw;
/
copy sensors raw data into local buffer */
orb_copy(ORB_ID(sensor_combined), sensor_sub_fd, &raw);
printf("[px4_simple_app] Accelerometer:\t%8.4f\t%8.4f\t%8.4f\n",
(double)raw.accelerometer_m_s2[0],
(double)raw.accelerometer_m_s2[1],
(double)raw.accelerometer_m_s2[2]);
zig_s.value = 10.0f;
orb_publish(ORB_ID(zigbee_position), zig_pub_fd, &zig_s);
}
}
}

After run the application zigbee, I’ve tried to get the value and print it in px4_simple_app.c by using:

int zigbee_position_fd = orb_subscribe(ORB_ID(zigbee_position));

for (int i = 0; i < 5; i++) {
    /* wait for sensor update of 1 file descriptor for 1000 ms (1 second) */
    int poll_ret = px4_poll(fds, 1, 1000);
   /* handle the poll result */
    if (poll_ret == 0) {
        /* this means none of our providers is giving us data */
        PX4_ERR("[px4_simple_app] Got no data within a second");
    } else if (poll_ret < 0) {
        /* this is seriously bad - should be an emergency */
        if (error_counter < 10 || error_counter % 50 == 0) {
            /* use a counter to prevent flooding (and slowing us down) */
            PX4_ERR("[px4_simple_app] ERROR return value from poll(): %d"
                , poll_ret);
        }
        error_counter++;
    } else {
        if (fds[0].revents & POLLIN) {
            /* obtained data for the first file descriptor */
            struct sensor_combined_s raw;
            /* copy sensors raw data into local buffer */
            orb_copy(ORB_ID(sensor_combined), sensor_sub_fd, &raw);
            PX4_WARN("[px4_simple_app] Accelerometer:\t%8.4f\t%8.4f\t%8.4f",
                 (double)raw.accelerometer_m_s2[0],
                 (double)raw.accelerometer_m_s2[1],
                 (double)raw.accelerometer_m_s2[2]);
            /* set att and publish this information for other apps */
            att.roll = raw.accelerometer_m_s2[0];
            att.pitch = raw.accelerometer_m_s2[1];
            att.yaw = raw.accelerometer_m_s2[2];
            orb_publish(ORB_ID(vehicle_attitude), att_pub, &att);
        }
        if (fds[1].revents & POLLIN) {
            struct zigbee_position_s zig;
            orb_copy(ORB_ID(zigbee_position), zigbee_position_fd, &zig);
            PX4_WARN("[zigbee] value:\t%8.4f",
                 (double)zig.value);
        }
    }
}

In px4_simple_app is fds[1] your zigbee uorb message? The loop is only 5 iterations and if fds[1] isn’t zigbee it isn’t going to wait.

Hello,

thanks for your message. I have figured out the error.

int poll_ret = px4_poll(fds, 1, 1000);

should be

int poll_ret = px4_poll(fds, 2, 1000);