Skip to content

Commit

Permalink
PMW3901: use quality metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico van Duijn authored and dagar committed Sep 4, 2019
1 parent 5fd483d commit b4709d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/drivers/optical_flow/pmw3901/PMW3901.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ PMW3901::Run()

int16_t delta_x_raw = 0;
int16_t delta_y_raw = 0;
uint8_t qual = 0;
float delta_x = 0.0f;
float delta_y = 0.0f;

Expand All @@ -311,7 +312,7 @@ PMW3901::Run()

_flow_dt_sum_usec += dt_flow;

readMotionCount(delta_x_raw, delta_y_raw);
readMotionCount(delta_x_raw, delta_y_raw, qual);

_flow_sum_x += delta_x_raw;
_flow_sum_y += delta_y_raw;
Expand Down Expand Up @@ -346,7 +347,7 @@ PMW3901::Run()
report.quality = 0;

} else {
report.quality = 255;
report.quality = qual;
}

/* No gyro on this board */
Expand All @@ -369,13 +370,13 @@ PMW3901::Run()
}

int
PMW3901::readMotionCount(int16_t &deltaX, int16_t &deltaY)
PMW3901::readMotionCount(int16_t &deltaX, int16_t &deltaY, uint8_t &qual)
{
uint8_t data[10] = { DIR_READ(0x02), 0, DIR_READ(0x03), 0, DIR_READ(0x04), 0,
DIR_READ(0x05), 0, DIR_READ(0x06), 0
uint8_t data[12] = { DIR_READ(0x02), 0, DIR_READ(0x03), 0, DIR_READ(0x04), 0,
DIR_READ(0x05), 0, DIR_READ(0x06), 0, DIR_READ(0x07), 0
};

int ret = transfer(&data[0], &data[0], 10);
int ret = transfer(&data[0], &data[0], 12);

if (OK != ret) {
perf_count(_comms_errors);
Expand All @@ -385,6 +386,7 @@ PMW3901::readMotionCount(int16_t &deltaX, int16_t &deltaY)

deltaX = ((int16_t)data[5] << 8) | data[3];
deltaY = ((int16_t)data[9] << 8) | data[7];
qual = data[11];

ret = OK;

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/optical_flow/pmw3901/PMW3901.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ class PMW3901 : public device::SPI, public px4::ScheduledWorkItem
int writeRegister(unsigned reg, uint8_t data);

int sensorInit();
int readMotionCount(int16_t &deltaX, int16_t &deltaY);
int readMotionCount(int16_t &deltaX, int16_t &deltaY, uint8_t &qual);
};

0 comments on commit b4709d2

Please sign in to comment.