Library containing Crazyflie 2.0 sensors drivers: - LPS25H (barometer) - MPU9250 (IMU) - PMW3901 (optical flow) - VL53L0X (range)
Dependents: Drones-Controlador controladoatitude_cteste Drone_Controlador_Atitude optical_test
PMW3901/PMW3901.h@12:2bbe233d25fb, 2018-09-26 (annotated)
- Committer:
- fbob
- Date:
- Wed Sep 26 13:14:36 2018 +0000
- Revision:
- 12:2bbe233d25fb
- Parent:
- 7:56608cce81ee
- Child:
- 15:e07de535b86f
Included VL53L0X (range) sensor class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fbob | 5:1ef8b91a0318 | 1 | #ifndef PMW3901_h |
fbob | 5:1ef8b91a0318 | 2 | #define PMW3901_h |
fbob | 5:1ef8b91a0318 | 3 | |
fbob | 5:1ef8b91a0318 | 4 | #include "mbed.h" |
fbob | 5:1ef8b91a0318 | 5 | |
fbob | 6:c7bc001826ba | 6 | // |
fbob | 6:c7bc001826ba | 7 | #define PRODUCT_ID 0x00 |
fbob | 6:c7bc001826ba | 8 | // |
fbob | 5:1ef8b91a0318 | 9 | #define MOTION 0x02 |
fbob | 5:1ef8b91a0318 | 10 | // Accelerometer output register addresses |
fbob | 5:1ef8b91a0318 | 11 | #define DELTA_X_L 0x03 |
fbob | 5:1ef8b91a0318 | 12 | #define DELTA_X_H 0x04 |
fbob | 5:1ef8b91a0318 | 13 | #define DELTA_Y_L 0x05 |
fbob | 5:1ef8b91a0318 | 14 | #define DELTA_Y_H 0x06 |
fbob | 5:1ef8b91a0318 | 15 | |
fbob | 5:1ef8b91a0318 | 16 | /** PMW3901 (optical flow sensor) class |
fbob | 5:1ef8b91a0318 | 17 | * |
fbob | 7:56608cce81ee | 18 | * Example code (print optical flow data on serial port every 0.2 second): |
fbob | 5:1ef8b91a0318 | 19 | * @code |
fbob | 5:1ef8b91a0318 | 20 | * #include "mbed.h" |
fbob | 5:1ef8b91a0318 | 21 | * #include "USBSerial.h" |
fbob | 5:1ef8b91a0318 | 22 | * #include "PMW3901.h" |
fbob | 5:1ef8b91a0318 | 23 | * |
fbob | 5:1ef8b91a0318 | 24 | * USBSerial pc; |
fbob | 5:1ef8b91a0318 | 25 | * PMW3901 flow(PA_7,PA_6,PA_5,PB_4); |
fbob | 5:1ef8b91a0318 | 26 | * |
fbob | 5:1ef8b91a0318 | 27 | * int main() |
fbob | 7:56608cce81ee | 28 | * { |
fbob | 12:2bbe233d25fb | 29 | * flow.init(); |
fbob | 12:2bbe233d25fb | 30 | * while(1) |
fbob | 5:1ef8b91a0318 | 31 | * { |
fbob | 5:1ef8b91a0318 | 32 | * flow.read(); |
fbob | 7:56608cce81ee | 33 | * pc.printf("Optical flow [px]: %6.2f %6.2f \n\n", flow.x, flow.y); |
fbob | 7:56608cce81ee | 34 | * wait(0.2); |
fbob | 5:1ef8b91a0318 | 35 | * } |
fbob | 5:1ef8b91a0318 | 36 | * } |
fbob | 5:1ef8b91a0318 | 37 | * @endcode |
fbob | 5:1ef8b91a0318 | 38 | * (Need to target to NUCLEO-F401RE board platform) |
fbob | 5:1ef8b91a0318 | 39 | */ |
fbob | 5:1ef8b91a0318 | 40 | class PMW3901 |
fbob | 5:1ef8b91a0318 | 41 | { |
fbob | 5:1ef8b91a0318 | 42 | public: |
fbob | 5:1ef8b91a0318 | 43 | /** Class constructor */ |
fbob | 5:1ef8b91a0318 | 44 | PMW3901(PinName mosi, PinName miso, PinName sclk, PinName csel); |
fbob | 5:1ef8b91a0318 | 45 | |
fbob | 5:1ef8b91a0318 | 46 | /** Initialize optical flow */ |
fbob | 6:c7bc001826ba | 47 | bool init(); |
fbob | 5:1ef8b91a0318 | 48 | /** **/ |
fbob | 5:1ef8b91a0318 | 49 | void read(); |
fbob | 5:1ef8b91a0318 | 50 | |
fbob | 6:c7bc001826ba | 51 | /** Optical flow data in x-axis (px) **/ |
fbob | 6:c7bc001826ba | 52 | float x; |
fbob | 6:c7bc001826ba | 53 | /** Optical flow data in y-axis (px) **/ |
fbob | 6:c7bc001826ba | 54 | float y; |
fbob | 5:1ef8b91a0318 | 55 | private: |
fbob | 5:1ef8b91a0318 | 56 | /** SPI bus */ |
fbob | 5:1ef8b91a0318 | 57 | SPI spi; |
fbob | 5:1ef8b91a0318 | 58 | /** Chip select */ |
fbob | 5:1ef8b91a0318 | 59 | DigitalOut cs; |
fbob | 5:1ef8b91a0318 | 60 | |
fbob | 6:c7bc001826ba | 61 | /** **/ |
fbob | 6:c7bc001826ba | 62 | void setup_spi(); |
fbob | 6:c7bc001826ba | 63 | /** **/ |
fbob | 6:c7bc001826ba | 64 | bool test_spi(); |
fbob | 5:1ef8b91a0318 | 65 | /** **/ |
fbob | 5:1ef8b91a0318 | 66 | void setup_flow(); |
fbob | 5:1ef8b91a0318 | 67 | /** **/ |
fbob | 5:1ef8b91a0318 | 68 | void read_flow(); |
fbob | 5:1ef8b91a0318 | 69 | }; |
fbob | 5:1ef8b91a0318 | 70 | |
fbob | 5:1ef8b91a0318 | 71 | #endif |