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);
}
}
}