Skip to content

Commit cdcb27b

Browse files
eppravitrarmackay9
authored andcommitted
AP_Mount: send zero rate command if the rate command was not received longer than a certain time.
1 parent a0452ba commit cdcb27b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

libraries/AP_Mount/AP_Mount_Backend.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ void AP_Mount_Backend::update()
4444
// move mount to a "retracted position" into the fuselage or out of it
4545
const bool mount_open = (_mode == MAV_MOUNT_MODE_RETRACT);
4646
SRV_Channels::move_servo(_open_idx, mount_open, 0, 1);
47+
48+
// set target rate to zero if we have not received rate command for a while
49+
if ((get_mode() == MAV_MOUNT_MODE_MAVLINK_TARGETING) &&
50+
(mnt_target.target_type == MountTargetType::RATE) &&
51+
(AP_HAL::millis() - mnt_target.last_rate_request_ms > 3000)) {
52+
mnt_target.rate_rads.roll = 0;
53+
mnt_target.rate_rads.pitch = 0;
54+
mnt_target.rate_rads.yaw = 0;
55+
}
4756
}
4857

4958
// return true if this mount accepts roll targets
@@ -144,6 +153,7 @@ void AP_Mount_Backend::set_rate_target(float roll_degs, float pitch_degs, float
144153
mnt_target.rate_rads.pitch = radians(pitch_degs);
145154
mnt_target.rate_rads.yaw = radians(yaw_degs);
146155
mnt_target.rate_rads.yaw_is_ef = yaw_is_earth_frame;
156+
mnt_target.last_rate_request_ms = AP_HAL::millis();
147157

148158
// set the mode to mavlink targeting
149159
set_mode(MAV_MOUNT_MODE_MAVLINK_TARGETING);

libraries/AP_Mount/AP_Mount_Backend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class AP_Mount_Backend
301301
MountTargetType target_type;// MAVLink targeting mode's current target type (e.g. angle or rate)
302302
MountTarget angle_rad; // angle target in radians
303303
MountTarget rate_rads; // rate target in rad/s
304+
uint32_t last_rate_request_ms;
304305
} mnt_target;
305306

306307
private:

0 commit comments

Comments
 (0)