AP_Mount: Add parameter to control relative pan option for servo mounts

* Change from a dedicated parameter to a reusable options field
This commit is contained in:
Hugo Trippaers 2021-01-26 22:01:17 +01:00 committed by Andrew Tridgell
parent bcee4b7b82
commit 44902ef535
3 changed files with 21 additions and 14 deletions

View File

@ -213,12 +213,13 @@ const AP_Param::GroupInfo AP_Mount::var_info[] = {
// 23 formerly _K_RATE
// @Param: _REL_PAN
// @DisplayName: Relative pan flag for Servo Mount
// @Description: Enable to calculate pan angle to GPS location relative to vehicle orientation (for type servo (1))
// @Values: 0:Disabled,1:Enabled
// @Param: _OPTIONS
// @DisplayName: Options field
// @Description: User configurable options; 0 = Enable Relative Pan on Servo Mounts
// @Values: 0:RelativePan
// @Bitmask: 0:RelativePan
// @User: Standard
AP_GROUPINFO("_REL_PAN", 24, AP_Mount, state[0]._rel_pan, 0),
AP_GROUPINFO("_OPTIONS", 24, AP_Mount, state[0]._options, 0),
#if AP_MOUNT_MAX_INSTANCES > 1
// @Param: 2_DEFLT_MODE
@ -401,12 +402,13 @@ const AP_Param::GroupInfo AP_Mount::var_info[] = {
// @User: Standard
AP_GROUPINFO("2_TYPE", 42, AP_Mount, state[1]._type, 0),
// @Param: 2_REL_PAN
// @DisplayName: Relative pan flag for Servo Mount 2
// @Description: Enable to calculate pan angle to GPS location relative to vehicle orientation (for type servo (1))
// @Values: 0:Disabled,1:Enabled
// @Param: 2_OPTIONS
// @DisplayName: Options field for Mount 2
// @Description: User configurable options; 0 = Enable Relative Pan on Servo Mounts
// @Values: 0:RelativePan
// @Bitmask: 0:RelativePan
// @User: Standard
AP_GROUPINFO("2_REL_PAN", 43, AP_Mount, state[0]._rel_pan, 0),
AP_GROUPINFO("2_OPTIONS", 43, AP_Mount, state[1]._options, 0),
#endif // AP_MOUNT_MAX_INSTANCES > 1
AP_GROUPEND

View File

@ -40,6 +40,9 @@
// maximum number of mounts
#define AP_MOUNT_MAX_INSTANCES 1
// options (see _OPTIONS parameter)
#define AP_MOUNT_OPTION_RELATIVE_PAN (1<<0)
// declare backend classes
class AP_Mount_Backend;
class AP_Mount_Servo;
@ -190,7 +193,7 @@ protected:
Location _target_sysid_location; // sysid target location
bool _target_sysid_location_set;
AP_Int8 _rel_pan; // Use relative pan for servo mounts (0=Disable, 1=Enable)
AP_Int8 _options; // Options field, bit 0 = use relative pan
} state[AP_MOUNT_MAX_INSTANCES];

View File

@ -35,6 +35,8 @@ void AP_Mount_Servo::update()
_last_check_servo_map_ms = now;
}
uint8_t relative_pan = _state._options & AP_MOUNT_OPTION_RELATIVE_PAN;
switch(get_mode()) {
// move mount to a "retracted position" or to a position where a fourth servo can retract the entire mount into the fuselage
case MAV_MOUNT_MODE_RETRACT:
@ -70,7 +72,7 @@ void AP_Mount_Servo::update()
// point mount to a GPS point given by the mission planner
case MAV_MOUNT_MODE_GPS_POINT:
{
if (calc_angle_to_roi_target(_angle_ef_target_rad, _flags.tilt_control, _flags.pan_control, _state._rel_pan)) {
if (calc_angle_to_roi_target(_angle_ef_target_rad, _flags.tilt_control, _flags.pan_control, relative_pan)) {
stabilize();
}
break;
@ -83,7 +85,7 @@ void AP_Mount_Servo::update()
}
_state._roi_target = AP::ahrs().get_home();
_state._roi_target_set = true;
if (calc_angle_to_roi_target(_angle_ef_target_rad, _flags.tilt_control, _flags.pan_control, _state._rel_pan)) {
if (calc_angle_to_roi_target(_angle_ef_target_rad, _flags.tilt_control, _flags.pan_control, relative_pan)) {
stabilize();
}
break;
@ -92,7 +94,7 @@ void AP_Mount_Servo::update()
if (calc_angle_to_sysid_target(_angle_ef_target_rad,
_flags.tilt_control,
_flags.pan_control,
_state._rel_pan)) {
relative_pan)) {
stabilize();
}
break;