Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
PX4Flow.h@3:e03714326b83, 2019-08-22 (annotated)
- Committer:
- pmic
- Date:
- Thu Aug 22 14:22:58 2019 +0000
- Revision:
- 3:e03714326b83
- Parent:
- 1:562a583eb77c
- Child:
- 9:be40afb750d3
Gyro parameterization in Flow and evaluation/comparison with pesboard gyro.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
altb2 | 0:4b02060af95b | 1 | #ifndef _PX4FLOW_MBED_H |
altb2 | 0:4b02060af95b | 2 | #define _PX4FLOW_MBED_H |
altb2 | 0:4b02060af95b | 3 | |
altb2 | 0:4b02060af95b | 4 | # include <stdint.h> |
altb2 | 0:4b02060af95b | 5 | # include "mbed.h" |
altb2 | 0:4b02060af95b | 6 | |
altb2 | 0:4b02060af95b | 7 | // 7 Bit I2C Address of the Flow Module: Default 0x42 (user selectable bits 0,1,2) |
altb2 | 0:4b02060af95b | 8 | #define PX4FLOW_ADDRESS 0x42<<1 |
altb2 | 0:4b02060af95b | 9 | |
altb2 | 0:4b02060af95b | 10 | // Commands |
altb2 | 0:4b02060af95b | 11 | #define FRAME 0x00 |
altb2 | 0:4b02060af95b | 12 | #define INTEGRAL_FRAME 0x16 |
altb2 | 0:4b02060af95b | 13 | |
altb2 | 0:4b02060af95b | 14 | // define buffer indicees |
altb2 | 0:4b02060af95b | 15 | // simple frame |
altb2 | 0:4b02060af95b | 16 | #define FRAME_COUNT 0 |
altb2 | 0:4b02060af95b | 17 | #define PIXEL_FLOW_X_SUM 2 |
altb2 | 0:4b02060af95b | 18 | #define PIXEL_FLOW_Y_SUM 4 |
altb2 | 0:4b02060af95b | 19 | #define FLOW_COMP_M_X 6 |
altb2 | 0:4b02060af95b | 20 | #define FLOW_COMP_M_Y 8 |
altb2 | 0:4b02060af95b | 21 | #define QUAL 10 |
altb2 | 0:4b02060af95b | 22 | #define GYRO_X_RATE 12 |
altb2 | 0:4b02060af95b | 23 | #define GYRO_Y_RATE 14 |
altb2 | 0:4b02060af95b | 24 | #define GYRO_Z_RATE 16 |
altb2 | 0:4b02060af95b | 25 | #define GYRO_RANGE 18 |
altb2 | 0:4b02060af95b | 26 | #define SONAR_TIMESTAMP 19 |
altb2 | 0:4b02060af95b | 27 | #define GROUND_DISTANCE 20 |
altb2 | 0:4b02060af95b | 28 | |
altb2 | 0:4b02060af95b | 29 | // integral frame |
altb2 | 0:4b02060af95b | 30 | #define FRAME_COUNT_SINCE_LAST_READOUT 0 |
altb2 | 0:4b02060af95b | 31 | #define PIXEL_FLOW_X_INTEGRAL 2 |
altb2 | 0:4b02060af95b | 32 | #define PIXEL_FLOW_Y_INTEGRAL 4 |
altb2 | 0:4b02060af95b | 33 | #define GYRO_X_RATE_INTEGRAL 6 |
altb2 | 0:4b02060af95b | 34 | #define GYRO_Y_RATE_INTEGRAL 8 |
altb2 | 0:4b02060af95b | 35 | #define GYRO_Z_RATE_INTEGRAL 10 |
altb2 | 0:4b02060af95b | 36 | #define INTEGRATION_TIMESPAN 12 |
altb2 | 0:4b02060af95b | 37 | #define SONAR_TIMESTAMP_INTEGRAL 16 |
altb2 | 0:4b02060af95b | 38 | #define GROUND_DISTANCE_INTEGRAL 20 |
altb2 | 0:4b02060af95b | 39 | #define GYRO_TEMPERATURE 22 |
altb2 | 0:4b02060af95b | 40 | #define QUALITY_INTEGRAL 24 |
altb2 | 0:4b02060af95b | 41 | |
altb2 | 1:562a583eb77c | 42 | typedef struct i2c_frame { |
altb2 | 0:4b02060af95b | 43 | uint16_t frame_count; // counts created I2C frames 0 |
altb2 | 0:4b02060af95b | 44 | int16_t pixel_flow_x_sum; // accumulated x flow in pixels*10 since last I2C frame 2 |
altb2 | 0:4b02060af95b | 45 | int16_t pixel_flow_y_sum; // accumulated y flow in pixels*10 since last I2C frame 4 |
altb2 | 0:4b02060af95b | 46 | int16_t flow_comp_m_x; // x velocity*1000 in meters / timestep 6 |
altb2 | 0:4b02060af95b | 47 | int16_t flow_comp_m_y; // y velocity*1000 in meters / timestep 8 |
altb2 | 0:4b02060af95b | 48 | int16_t qual; // Optical flow quality / confidence 0: bad, 255: maximum quality 10 |
pmic | 3:e03714326b83 | 49 | int16_t gyro_x_rate; // gyro x rate 12 |
pmic | 3:e03714326b83 | 50 | int16_t gyro_y_rate; // gyro y rate 14 |
pmic | 3:e03714326b83 | 51 | int16_t gyro_z_rate; // gyro z rate 16 |
altb2 | 0:4b02060af95b | 52 | uint8_t gyro_range; // gyro range 18 |
altb2 | 0:4b02060af95b | 53 | uint8_t sonar_timestamp; // timestep in milliseconds between I2C frames 19 |
altb2 | 0:4b02060af95b | 54 | int16_t ground_distance; // Ground distance in meters*1000. Positive value: distance known. Negative value: Unknown distance 20 |
altb2 | 0:4b02060af95b | 55 | } i2c_frame; |
altb2 | 0:4b02060af95b | 56 | |
altb2 | 0:4b02060af95b | 57 | typedef struct i2c_integral_frame { |
pmic | 3:e03714326b83 | 58 | uint16_t frame_count_since_last_readout; // number of flow measurements since last I2C readout [#frames] 22 |
pmic | 3:e03714326b83 | 59 | int16_t pixel_flow_x_integral; // accumulated flow in radians*10000 around x axis since last I2C readout [rad*10000] 24 |
pmic | 3:e03714326b83 | 60 | int16_t pixel_flow_y_integral; // accumulated flow in radians*10000 around y axis since last I2C readout [rad*10000] 26 |
pmic | 3:e03714326b83 | 61 | int16_t gyro_x_rate_integral; // accumulated gyro x rates in radians*10000 since last I2C readout [rad*10000] 28 |
pmic | 3:e03714326b83 | 62 | int16_t gyro_y_rate_integral; // accumulated gyro y rates in radians*10000 since last I2C readout [rad*10000] 30 |
pmic | 3:e03714326b83 | 63 | int16_t gyro_z_rate_integral; // accumulated gyro z rates in radians*10000 since last I2C readout [rad*10000] 32 |
pmic | 3:e03714326b83 | 64 | uint32_t integration_timespan; // accumulation timespan in microseconds since last I2C readout [microseconds] 34 |
pmic | 3:e03714326b83 | 65 | uint32_t sonar_timestamp; // time since last sonar update [microseconds] 38 |
pmic | 3:e03714326b83 | 66 | int16_t ground_distance; // Ground distance in meters*1000 [meters*1000] 42 |
pmic | 3:e03714326b83 | 67 | int16_t gyro_temperature; // Temperature * 100 in centi-degrees Celsius [degcelsius*100] 44 |
pmic | 3:e03714326b83 | 68 | uint8_t quality; // averaged quality of accumulated flow values [0:bad quality;255: max quality] 46 |
altb2 | 0:4b02060af95b | 69 | } i2c_integral_frame; |
altb2 | 0:4b02060af95b | 70 | |
altb2 | 0:4b02060af95b | 71 | |
altb2 | 0:4b02060af95b | 72 | class PX4Flow |
altb2 | 0:4b02060af95b | 73 | { |
altb2 | 0:4b02060af95b | 74 | public: |
altb2 | 0:4b02060af95b | 75 | // Constructor |
altb2 | 0:4b02060af95b | 76 | PX4Flow(I2C& i2c, Serial& pc); |
pmic | 3:e03714326b83 | 77 | |
altb2 | 0:4b02060af95b | 78 | // Deconstructor |
altb2 | 0:4b02060af95b | 79 | virtual ~PX4Flow(); |
altb2 | 0:4b02060af95b | 80 | |
altb2 | 0:4b02060af95b | 81 | // Methods |
altb2 | 0:4b02060af95b | 82 | bool update(); |
altb2 | 0:4b02060af95b | 83 | bool update_integral(); |
altb2 | 0:4b02060af95b | 84 | |
altb2 | 0:4b02060af95b | 85 | // Simple frame |
altb2 | 0:4b02060af95b | 86 | uint16_t frame_count(); |
altb2 | 0:4b02060af95b | 87 | int16_t pixel_flow_x_sum(); |
altb2 | 0:4b02060af95b | 88 | int16_t pixel_flow_y_sum(); |
altb2 | 0:4b02060af95b | 89 | int16_t flow_comp_m_x(); |
altb2 | 0:4b02060af95b | 90 | int16_t flow_comp_m_y(); |
altb2 | 0:4b02060af95b | 91 | int16_t qual(); |
altb2 | 0:4b02060af95b | 92 | int16_t gyro_x_rate(); |
altb2 | 0:4b02060af95b | 93 | int16_t gyro_y_rate(); |
altb2 | 0:4b02060af95b | 94 | int16_t gyro_z_rate(); |
altb2 | 0:4b02060af95b | 95 | uint8_t gyro_range(); |
altb2 | 0:4b02060af95b | 96 | uint8_t sonar_timestamp(); |
altb2 | 0:4b02060af95b | 97 | int16_t ground_distance(); |
altb2 | 0:4b02060af95b | 98 | |
altb2 | 0:4b02060af95b | 99 | // Integral frame |
altb2 | 0:4b02060af95b | 100 | uint16_t frame_count_since_last_readout(); |
altb2 | 0:4b02060af95b | 101 | int16_t pixel_flow_x_integral(); |
altb2 | 0:4b02060af95b | 102 | int16_t pixel_flow_y_integral(); |
altb2 | 0:4b02060af95b | 103 | int16_t gyro_x_rate_integral(); |
altb2 | 0:4b02060af95b | 104 | int16_t gyro_y_rate_integral(); |
altb2 | 0:4b02060af95b | 105 | int16_t gyro_z_rate_integral(); |
altb2 | 0:4b02060af95b | 106 | uint32_t integration_timespan(); |
altb2 | 0:4b02060af95b | 107 | uint32_t sonar_timestamp_integral(); |
altb2 | 0:4b02060af95b | 108 | int16_t ground_distance_integral(); |
altb2 | 0:4b02060af95b | 109 | int16_t gyro_temperature(); |
altb2 | 0:4b02060af95b | 110 | uint8_t quality_integral(); |
altb2 | 0:4b02060af95b | 111 | |
altb2 | 0:4b02060af95b | 112 | |
altb2 | 0:4b02060af95b | 113 | protected: |
altb2 | 0:4b02060af95b | 114 | I2C i2c; |
altb2 | 0:4b02060af95b | 115 | Serial pc; |
altb2 | 0:4b02060af95b | 116 | |
altb2 | 0:4b02060af95b | 117 | // Buffer to read in the sensordata |
altb2 | 0:4b02060af95b | 118 | char bufferS[22]; |
altb2 | 0:4b02060af95b | 119 | char bufferI[26]; |
altb2 | 0:4b02060af95b | 120 | |
altb2 | 0:4b02060af95b | 121 | char i2c_commands[2]; |
altb2 | 0:4b02060af95b | 122 | |
altb2 | 0:4b02060af95b | 123 | struct i2c_frame frame; |
altb2 | 0:4b02060af95b | 124 | struct i2c_integral_frame iframe; |
altb2 | 0:4b02060af95b | 125 | |
altb2 | 0:4b02060af95b | 126 | uint8_t read8(char *buffer, const unsigned int& idx = 0); |
altb2 | 0:4b02060af95b | 127 | uint16_t read16(char *buffer, const unsigned int& idx = 0); |
altb2 | 0:4b02060af95b | 128 | uint32_t read32(char *buffer, const unsigned int& idx = 0); |
altb2 | 0:4b02060af95b | 129 | }; |
altb2 | 0:4b02060af95b | 130 | |
altb2 | 0:4b02060af95b | 131 | #endif |