Plane: Update to support new RC_Overrides conventions

This commit is contained in:
Michael du Breuil 2018-04-26 16:39:00 -07:00 committed by Andrew Tridgell
parent 1f1ba54990
commit a98a8d0789

View File

@ -1247,28 +1247,27 @@ void GCS_MAVLINK_Plane::handleMessage(mavlink_message_t* msg)
// allow override of RC channel values for HIL
// or for complete GCS control of switch position
// and RC PWM values.
if(msg->sysid != plane.g.sysid_my_gcs) break; // Only accept control from our gcs
if(msg->sysid != plane.g.sysid_my_gcs) {
break; // Only accept control from our gcs
}
uint32_t tnow = AP_HAL::millis();
mavlink_rc_channels_override_t packet;
bool override_active = false;
mavlink_msg_rc_channels_override_decode(msg, &packet);
override_active |= RC_Channels::set_override(0, packet.chan1_raw);
override_active |= RC_Channels::set_override(1, packet.chan2_raw);
override_active |= RC_Channels::set_override(2, packet.chan3_raw);
override_active |= RC_Channels::set_override(3, packet.chan4_raw);
override_active |= RC_Channels::set_override(4, packet.chan5_raw);
override_active |= RC_Channels::set_override(5, packet.chan6_raw);
override_active |= RC_Channels::set_override(6, packet.chan7_raw);
override_active |= RC_Channels::set_override(7, packet.chan8_raw);
if (override_active) {
plane.failsafe.last_valid_rc_ms = AP_HAL::millis();
plane.failsafe.AFS_last_valid_rc_ms = plane.failsafe.last_valid_rc_ms;
}
RC_Channels::set_override(0, packet.chan1_raw, tnow);
RC_Channels::set_override(1, packet.chan2_raw, tnow);
RC_Channels::set_override(2, packet.chan3_raw, tnow);
RC_Channels::set_override(3, packet.chan4_raw, tnow);
RC_Channels::set_override(4, packet.chan5_raw, tnow);
RC_Channels::set_override(5, packet.chan6_raw, tnow);
RC_Channels::set_override(6, packet.chan7_raw, tnow);
RC_Channels::set_override(7, packet.chan8_raw, tnow);
// a RC override message is consiered to be a 'heartbeat' from
// the ground station for failsafe purposes
plane.failsafe.last_heartbeat_ms = AP_HAL::millis();
plane.failsafe.last_heartbeat_ms = tnow;
break;
}
@ -1285,24 +1284,20 @@ void GCS_MAVLINK_Plane::handleMessage(mavlink_message_t* msg)
break; // only accept messages aimed at us
}
bool override_active = false;
uint32_t tnow = AP_HAL::millis();
int16_t roll = (packet.y == INT16_MAX) ? 0 : plane.channel_roll->get_radio_min() + (plane.channel_roll->get_radio_max() - plane.channel_roll->get_radio_min()) * (packet.y + 1000) / 2000.0f;
int16_t pitch = (packet.x == INT16_MAX) ? 0 : plane.channel_pitch->get_radio_min() + (plane.channel_pitch->get_radio_max() - plane.channel_pitch->get_radio_min()) * (-packet.x + 1000) / 2000.0f;
int16_t throttle = (packet.z == INT16_MAX) ? 0 : plane.channel_throttle->get_radio_min() + (plane.channel_throttle->get_radio_max() - plane.channel_throttle->get_radio_min()) * (packet.z) / 1000.0f;
int16_t yaw = (packet.r == INT16_MAX) ? 0 : plane.channel_rudder->get_radio_min() + (plane.channel_rudder->get_radio_max() - plane.channel_rudder->get_radio_min()) * (packet.r + 1000) / 2000.0f;
override_active |= RC_Channels::set_override(uint8_t(plane.rcmap.roll() - 1), roll);
override_active |= RC_Channels::set_override(uint8_t(plane.rcmap.pitch() - 1), pitch);
override_active |= RC_Channels::set_override(uint8_t(plane.rcmap.throttle() - 1), throttle);
override_active |= RC_Channels::set_override(uint8_t(plane.rcmap.yaw() - 1), yaw);
if (override_active) {
plane.failsafe.last_valid_rc_ms = AP_HAL::millis();
plane.failsafe.AFS_last_valid_rc_ms = plane.failsafe.last_valid_rc_ms;
}
RC_Channels::set_override(uint8_t(plane.rcmap.roll() - 1), roll, tnow);
RC_Channels::set_override(uint8_t(plane.rcmap.pitch() - 1), pitch, tnow);
RC_Channels::set_override(uint8_t(plane.rcmap.throttle() - 1), throttle, tnow);
RC_Channels::set_override(uint8_t(plane.rcmap.yaw() - 1), yaw, tnow);
// a manual control message is considered to be a 'heartbeat' from the ground station for failsafe purposes
plane.failsafe.last_heartbeat_ms = AP_HAL::millis();
plane.failsafe.last_heartbeat_ms = tnow;
break;
}