Skip to content

Commit

Permalink
AP_Mount: Add parameter to control relative pan option for servo mounts
Browse files Browse the repository at this point in the history
* Change from a dedicated parameter to a reusable options field
  • Loading branch information
spark404 authored and tridge committed Mar 3, 2021
1 parent bcee4b7 commit 44902ef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
22 changes: 12 additions & 10 deletions libraries/AP_Mount/AP_Mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion libraries/AP_Mount/AP_Mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -190,7 +193,7 @@ class AP_Mount
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];

Expand Down
8 changes: 5 additions & 3 deletions libraries/AP_Mount/AP_Mount_Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 44902ef

Please sign in to comment.