40 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id())),
43 _yaw_rotation(yaw_rotation)
120 c2 = ((
unsigned short)c2 * 45) / 100;
224 SPI::set_lockmode(LOCK_THREADS);
248 if (
data[0] == 0x49) {
263 int ret = transfer(&cmd[0], &cmd[0], count + 1);
271 memcpy(&data[0], &cmd[1], count);
285 ret = transfer(&cmd[0],
nullptr, 2);
303 int16_t delta_x_raw = 0;
304 int16_t delta_y_raw = 0;
306 float delta_x = 0.0f;
307 float delta_y = 0.0f;
311 _previous_collect_timestamp = timestamp;
335 report.pixel_flow_x_integral =
static_cast<float>(delta_x);
336 report.pixel_flow_y_integral =
static_cast<float>(delta_y);
339 float zeroval = 0.0f;
341 rotate_3f(
_yaw_rotation, report.gyro_x_rate_integral, report.gyro_y_rate_integral, report.gyro_z_rate_integral);
346 report.sensor_id = 0;
351 report.gyro_x_rate_integral = NAN;
352 report.gyro_y_rate_integral = NAN;
353 report.gyro_z_rate_integral = NAN;
356 report.max_flow_rate = 5.0f;
357 report.min_ground_distance = 0.1f;
358 report.max_ground_distance = 30.0f;
378 int ret = transfer(&data[0], &data[0], 12);
387 deltaX = ((int16_t)data[5] << 8) | data[3];
388 deltaY = ((int16_t)data[9] << 8) | data[7];
391 if (deltaX > 240 || deltaY > 240 || deltaX < -240 || deltaY < -240) {
#define PARAM_INVALID
Handle returned when a parameter cannot be found.
int readRegister(unsigned reg, uint8_t *data, unsigned count)
measure the time elapsed performing an event
static constexpr uint32_t TIME_us_TSWW
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
uint8_t _flow_sample_counter
__EXPORT void rotate_3f(enum Rotation rot, float &x, float &y, float &z)
rotate a 3 element float vector in-place
int readMotionCount(int16_t &deltaX, int16_t &deltaY, uint8_t &qual)
uint64_t _previous_collect_timestamp
#define PMW3901_SPI_BUS_SPEED
void print_info()
Diagnostics - print some basic information about the driver.
uORB::PublicationMulti< optical_flow_s > _optical_flow_pub
count the number of times an event occurs
perf_counter_t _comms_errors
uint64_t _flow_dt_sum_usec
void perf_count(perf_counter_t handle)
Count a performance event.
void perf_free(perf_counter_t handle)
Free a counter.
void init()
Activates/configures the hardware registers.
void Run() override
Perform a poll cycle; collect from the previous measurement and start a new one.
#define DEVICE_LOG(FMT,...)
int writeRegister(unsigned reg, uint8_t data)
Rotation
Enum for board and external compass rotations.
#define PMW3901_SAMPLE_INTERVAL
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
void stop()
Stop the automatic measurement state machine.
void perf_end(perf_counter_t handle)
End a performance event.
enum Rotation _yaw_rotation
void start()
Initialise the automatic measurement state machine and start it.
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
const uint64_t _collect_time
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
PMW3901(int bus=PMW3901_BUS, enum Rotation yaw_rotation=(enum Rotation) 0)
uint16_t _flow_quality_sum
perf_counter_t _sample_perf
#define PMW3901_DEVICE_PATH
bool publish(const T &data)
Publish the struct.
void perf_begin(perf_counter_t handle)
Begin a performance event.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
uint32_t param_t
Parameter handle.