Skip to content

Commit 876ca43

Browse files
committed
AP_OpticalFlow: handle stabilised sensors
1 parent c1a9719 commit 876ca43

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

libraries/AP_OpticalFlow/AP_OpticalFlow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ const AP_Param::GroupInfo AP_OpticalFlow::var_info[] = {
9898
// @User: Advanced
9999
AP_GROUPINFO_FRAME("_HGT_OVR", 6, AP_OpticalFlow, _height_override, 0.0f, AP_PARAM_FRAME_ROVER),
100100

101+
// @Param: _OPTIONS
102+
// @DisplayName: Optical flow options
103+
// @Description: Optical flow options. Bit 0 should be set if the sensor is stabilised (e.g. mounted on a gimbal)
104+
// @Bitmask: 0:Roll/Pitch stabilised
105+
// @User: Standard
106+
AP_GROUPINFO("_OPTIONS", 7, AP_OpticalFlow, _options, 0),
107+
101108
AP_GROUPEND
102109
};
103110

libraries/AP_OpticalFlow/AP_OpticalFlow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class AP_OpticalFlow
145145
AP_Vector3f _pos_offset; // position offset of the flow sensor in the body frame
146146
AP_Int8 _address; // address on the bus (allows selecting between 8 possible I2C addresses for px4flow)
147147
AP_Float _height_override; // height of the sensor above the ground. Only used in rover
148+
AP_Int16 _options; // options parameter
148149

149150
// method called by backend to update frontend state:
150151
void update_state(const OpticalFlow_state &state);

libraries/AP_OpticalFlow/AP_OpticalFlow_Backend.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ class OpticalFlow_backend
6565

6666
// get ADDR parameter value
6767
uint8_t get_address(void) const { return frontend._address; }
68-
68+
69+
// options parameter values
70+
enum class Option : uint16_t {
71+
Stabilised = (1 << 0U) // sensor is stabilised (e.g. mounted on a gimbal)
72+
};
73+
74+
// returns true if an option is enabled
75+
bool option_is_enabled(Option option) const {
76+
return ((uint8_t)frontend._options.get() & (uint16_t)option) != 0;
77+
}
78+
6979
// semaphore for access to shared frontend data
7080
HAL_Semaphore _sem;
7181
};

libraries/AP_OpticalFlow/AP_OpticalFlow_MAV.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ void AP_OpticalFlow_MAV::update(void)
6767
state.flowRate = { ((float)flow_sum.x / count) * flow_scale_factor_x * dt_used,
6868
((float)flow_sum.y / count) * flow_scale_factor_y * dt_used };
6969

70-
// copy average body rate to state structure
71-
state.bodyRate = { gyro_sum.x / gyro_sum_count, gyro_sum.y / gyro_sum_count };
70+
// copy body-rates from gyro or set to zero
71+
if (option_is_enabled(Option::Stabilised)) {
72+
// if the sensor is stabilised then body rates are always zero
73+
state.bodyRate.zero();
74+
} else {
75+
// copy average body rate to state structure
76+
state.bodyRate = { gyro_sum.x / gyro_sum_count, gyro_sum.y / gyro_sum_count };
77+
}
7278

7379
// we only apply yaw to flowRate as body rate comes from AHRS
7480
_applyYaw(state.flowRate);

0 commit comments

Comments
 (0)