Attempting to read airspeed sensor with modified tutorial app

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…

I am still unsure about this…

  • indicated_airspeed_m_s isn’t an array, drop the square brackets.
  • PX4_INFO is like printf, and the way you’ve specified the print format it’s expecting 3 floating point arguments

Thank you! I also had to the move the airspeed-reporting bit inside of the first fds[0].revents section:

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


                                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",
                                         (double)raw2.indicated_airspeed_m_s);

but it is working and reporting “air speed”.

NuttShell (NSH)
nsh>
nsh> px4_simple_app
INFO [px4_simple_app] Hello Sky!
INFO [px4_simple_app] Accelerometer: 0.1535 -0.0821 -10.7183
INFO [px4_simple_app] Airspeed: 14.8150
INFO [px4_simple_app] Accelerometer: 0.1587 -0.2423 -10.7200
INFO [px4_simple_app] Airspeed: 14.6874
INFO [px4_simple_app] Accelerometer: 0.1233 -0.1961 -10.6557
INFO [px4_simple_app] Airspeed: 14.6234
INFO [px4_simple_app] Accelerometer: 0.1516 -0.1895 -10.6267
INFO [px4_simple_app] Airspeed: 14.6348
INFO [px4_simple_app] Accelerometer: 0.1116 -0.1261 -10.6858
INFO [px4_simple_app] Airspeed: 14.7283
INFO [px4_simple_app] exiting
nsh> px4_simple_app
INFO [px4_simple_app] Hello Sky!
INFO [px4_simple_app] Accelerometer: 7.0488 -2.6423 -7.2635
INFO [px4_simple_app] Airspeed: 36.3059
INFO [px4_simple_app] Accelerometer: 7.0571 -2.6490 -7.2125
INFO [px4_simple_app] Airspeed: 39.2983
INFO [px4_simple_app] Accelerometer: 7.0323 -2.6571 -7.2453
INFO [px4_simple_app] Airspeed: 45.1343
INFO [px4_simple_app] Accelerometer: 7.0617 -2.6681 -7.2447
INFO [px4_simple_app] Airspeed: 48.6648
INFO [px4_simple_app] Accelerometer: 7.0481 -2.6933 -7.2209
INFO [px4_simple_app] Airspeed: 50.2937
INFO [px4_simple_app] exiting

Thanks again!

Is this application executable while connecting via Telemetry. I’ve try to do same as your code but it only visible when i try to connect with USB instead of Telemetry.

Hello there …sorry to bumb but I just want to have a little information on something.

@vance86 : Which airspeed sensor you were using ? And How did you integrate/config with pixhawk.

Regards
Abin Ephrem