Hello,
I am new to developing apps with PX4. I have modifed the tutorial app to display airspeed sensor data. I have gleaned as much information as I can can find from the module code and header files. I am not sure how to complete this. Below is the code and error code. I am not sure what else to change? Thank you in advance.
__EXPORT int px4_simple_app_main(int argc, char *argv[]);
int px4_simple_app_main(int argc, char *argv[])
{
PX4_INFO(“Hello Sky!”);
/* subscribe to sensor_combined topic */
int sensor_sub_fd = orb_subscribe(ORB_ID(sensor_combined));
int sensor_sub_as = orb_subscribe(ORB_ID(airspeed));
/* limit the update rate to 5 Hz */
orb_set_interval(sensor_sub_fd, 200);
orb_set_interval(sensor_sub_as, 200);
/* advertise attitude topic */
struct vehicle_attitude_s att;
memset(&att, 0, sizeof(att));
orb_advert_t att_pub = orb_advertise(ORB_ID(vehicle_attitude), &att);
/* one could wait for multiple topics with this technique, just using one here */
px4_pollfd_struct_t fds[] = {
{ .fd = sensor_sub_fd, .events = POLLIN },
{ .fd = sensor_sub_as, .events = POLLIN },
/* there could be more file descriptors here, in the form like:
* { .fd = other_sub_fd, .events = POLLIN },
*/
};
int error_counter = 0;
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("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("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_INFO("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
the following does not have any meaning, it's just an example
*/
att.q[0] = raw.accelerometer_m_s2[0];
att.q[1] = raw.accelerometer_m_s2[1];
att.q[2] = raw.accelerometer_m_s2[2];
orb_publish(ORB_ID(vehicle_attitude), att_pub, &att);
}
/*attempting airspeed check*/
if (fds[1].revents & POLLIN) {
/* obtained data for the first file descriptor */
struct airspeed_s raw2;
/* copy sensors raw data into local buffer */
orb_copy(ORB_ID(airspeed), sensor_sub_as, &raw2);
PX4_INFO("Airspeed:\t%8.4f\t%8.4f\t%8.4f",
(float)raw2.indicated_airspeed_m_s[0]);
}
/* there could be more file descriptors here, in the form like:
* if (fds[1..n].revents & POLLIN) {}
*/
}
}
PX4_INFO("exiting");
return 0;
}
ERROR CODE
/home/vance/src/Firmware/src/examples/px4_simple_app/px4_simple_app.c:130:76: error: subscripted value is neither array nor pointer nor vector
(float)raw2.indicated_airspeed_m_s[0]);
^
/home/vance/src/Firmware/src/platforms/px4_log.h:262:49: note: in definition of macro ‘__px4_log_modulename’
px4_log_modulename(level, MODULE_NAME, fmt, ##VA_ARGS);
^
/home/vance/src/Firmware/src/examples/px4_simple_app/px4_simple_app.c:129:33: note: in expansion of macro ‘PX4_INFO’
PX4_INFO(“Airspeed:\t%8.4f\t%8.4f\t%8.4f”,
^
compilation terminated due to -Wfatal-errors.
src/examples/px4_simple_app/CMakeFiles/examples__px4_simple_app.dir/build.make:62: recipe for target ‘src/examples/px4_simple_app/CMakeFiles/examples__px4_simple_app.dir/px4_simple_app.c.obj’ failed
make[3]: *** [src/examples/px4_simple_app/CMakeFiles/examples__px4_simple_app.dir/px4_simple_app.c.obj] Error 1
CMakeFiles/Makefile2:6292: recipe for target ‘src/examples/px4_simple_app/CMakeFiles/examples__px4_simple_app.dir/all’ failed
make[2]: *** [src/examples/px4_simple_app/CMakeFiles/examples__px4_simple_app.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs…