src/drivers/px4flow/px4flow.cpp
/**
 * Perform some basic functional tests on the driver;
 * make sure we can collect data from the sensor in polled
 * and automatic modes.
 */
Perform some basic functional tests on the driver;
make sure we can collect data from the sensor in polled
and automatic modes.
Perform some basic functional tests on the driver ; make sure we can collect data from the sensor in polled and automatic modes .
void
test()
{
	struct optical_flow_s report;
	ssize_t sz;
	int ret;
	int fd = open(PX4FLOW_DEVICE_PATH, O_RDONLY);
	if (fd < 0) {
		err(1, "%s open failed (try 'px4flow start' if the driver is not running", PX4FLOW_DEVICE_PATH);
	}
	sz = read(fd, &report, sizeof(report));
	if (sz != sizeof(report))
	{
		warnx("immediate read failed");
	}
	warnx("single read");
	warnx("pixel_flow_x_integral: %i", f_integral.pixel_flow_x_integral);
	warnx("pixel_flow_y_integral: %i", f_integral.pixel_flow_y_integral);
	warnx("framecount_integral: %u",
	      f_integral.frame_count_since_last_readout);
	if (OK != ioctl(fd, SENSORIOCSPOLLRATE, 10)) {
		errx(1, "failed to set 10Hz poll rate");
	}
	for (unsigned i = 0; i < 10; i++) {
		struct pollfd fds;
		fds.fd = fd;
		fds.events = POLLIN;
		ret = poll(&fds, 1, 2000);
		if (ret != 1) {
			errx(1, "timed out waiting for sensor data");
		}
		sz = read(fd, &report, sizeof(report));
		if (sz != sizeof(report)) {
			err(1, "periodic read failed");
		}
		warnx("periodic read %u", i);
		warnx("framecount_total: %u", f.frame_count);
		warnx("framecount_integral: %u",
		      f_integral.frame_count_since_last_readout);
		warnx("pixel_flow_x_integral: %i", f_integral.pixel_flow_x_integral);
		warnx("pixel_flow_y_integral: %i", f_integral.pixel_flow_y_integral);
		warnx("gyro_x_rate_integral: %i", f_integral.gyro_x_rate_integral);
		warnx("gyro_y_rate_integral: %i", f_integral.gyro_y_rate_integral);
		warnx("gyro_z_rate_integral: %i", f_integral.gyro_z_rate_integral);
		warnx("integration_timespan [us]: %u", f_integral.integration_timespan);
		warnx("ground_distance: %0.2f m",
		      (double) f_integral.ground_distance / 1000);
		warnx("time since last sonar update [us]: %i",
		      f_integral.time_since_last_sonar_update);
		warnx("quality integration average : %i", f_integral.qual);
		warnx("quality : %i", f.qual);
	}
	errx(0, "PASS");
}
void test ( ) { struct optical_flow_s report ; ssize_t sz ; int ret ; int fd = open ( PX4FLOW_DEVICE_PATH , O_RDONLY ) ; if ( fd < 0 ) { err ( 1 , " " , PX4FLOW_DEVICE_PATH ) ; } sz = read ( fd , & report , sizeof ( report ) ) ; if ( sz != sizeof ( report ) ) { warnx ( " " ) ; } warnx ( " " ) ; warnx ( " " , f_integral . pixel_flow_x_integral ) ; warnx ( " " , f_integral . pixel_flow_y_integral ) ; warnx ( " " , f_integral . frame_count_since_last_readout ) ; if ( OK != ioctl ( fd , SENSORIOCSPOLLRATE , 10 ) ) { errx ( 1 , " " ) ; } for ( unsigned i = 0 ; i < 10 ; i ++ ) { struct pollfd fds ; fds . fd = fd ; fds . events = POLLIN ; ret = poll ( & fds , 1 , 2000 ) ; if ( ret != 1 ) { errx ( 1 , " " ) ; } sz = read ( fd , & report , sizeof ( report ) ) ; if ( sz != sizeof ( report ) ) { err ( 1 , " " ) ; } warnx ( " " , i ) ; warnx ( " " , f . frame_count ) ; warnx ( " " , f_integral . frame_count_since_last_readout ) ; warnx ( " " , f_integral . pixel_flow_x_integral ) ; warnx ( " " , f_integral . pixel_flow_y_integral ) ; warnx ( " " , f_integral . gyro_x_rate_integral ) ; warnx ( " " , f_integral . gyro_y_rate_integral ) ; warnx ( " " , f_integral . gyro_z_rate_integral ) ; warnx ( " " , f_integral . integration_timespan ) ; warnx ( " " , ( double ) f_integral . ground_distance / 1000 ) ; warnx ( " " , f_integral . time_since_last_sonar_update ) ; warnx ( " " , f_integral . qual ) ; warnx ( " " , f . qual ) ; } errx ( 0 , " " ) ; }
Perform some basic functional tests on the driver;
 make sure we can collect data from the sensor in polled
 and automatic modes.
Perform some basic functional tests on the driver ; make sure we can collect data from the sensor in polled and automatic modes .
/* do a simple demand read */ /* start the sensor polling at 10Hz */ /* read the sensor 5x and report each value */ /* wait for data to be ready */ /* now go get it */