Browse Source

AP_Arming: support KDECAN

master
Francisco Ferreira 7 years ago
parent
commit
de1d02d697
No known key found for this signature in database
GPG Key ID: F63C20A6773E787E
  1. 53
      libraries/AP_Arming/AP_Arming.cpp
  2. 2
      libraries/AP_Arming/AP_Arming.h

53
libraries/AP_Arming/AP_Arming.cpp

@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
*/
#include "AP_Arming.h"
#include <AP_HAL/AP_HAL.h>
#include <AP_BoardConfig/AP_BoardConfig.h>
#include <AP_BattMonitor/AP_BattMonitor.h>
#include <AP_Notify/AP_Notify.h>
@ -23,6 +24,17 @@ @@ -23,6 +24,17 @@
#include <AP_Rally/AP_Rally.h>
#include <SRV_Channel/SRV_Channel.h>
#if HAL_WITH_UAVCAN
#include <AP_BoardConfig/AP_BoardConfig_CAN.h>
#include <AP_Common/AP_Common.h>
#include <AP_Vehicle/AP_Vehicle.h>
// To be replaced with macro saying if KDECAN library is included
#if APM_BUILD_TYPE(APM_BUILD_ArduCopter) || APM_BUILD_TYPE(APM_BUILD_ArduPlane) || APM_BUILD_TYPE(APM_BUILD_ArduSub)
#include <AP_KDECAN/AP_KDECAN.h>
#endif
#endif
#define AP_ARMING_COMPASS_MAGFIELD_EXPECTED 530
#define AP_ARMING_COMPASS_MAGFIELD_MIN 185 // 0.35 * 530 milligauss
#define AP_ARMING_COMPASS_MAGFIELD_MAX 875 // 1.65 * 530 milligauss
@ -635,6 +647,44 @@ bool AP_Arming::system_checks(bool report) @@ -635,6 +647,44 @@ bool AP_Arming::system_checks(bool report)
return true;
}
bool AP_Arming::can_checks(bool report)
{
#if HAL_WITH_UAVCAN
if (check_enabled(ARMING_CHECK_SYSTEM)) {
const char *fail_msg = nullptr;
uint8_t num_drivers = AP::can().get_num_drivers();
for (uint8_t i = 0; i < num_drivers; i++) {
switch (AP::can().get_protocol_type(i)) {
case AP_BoardConfig_CAN::Protocol_Type_KDECAN: {
// To be replaced with macro saying if KDECAN library is included
#if APM_BUILD_TYPE(APM_BUILD_ArduCopter) || APM_BUILD_TYPE(APM_BUILD_ArduPlane) || APM_BUILD_TYPE(APM_BUILD_ArduSub)
AP_KDECAN *ap_kdecan = AP_KDECAN::get_kdecan(i);
if (ap_kdecan != nullptr && !ap_kdecan->pre_arm_check(fail_msg)) {
if (fail_msg == nullptr) {
check_failed(ARMING_CHECK_SYSTEM, report, "KDECAN failed");
} else {
check_failed(ARMING_CHECK_SYSTEM, report, "%s", fail_msg);
}
return false;
}
break;
#else
UNUSED_RESULT(fail_msg); // prevent unused variable error
#endif
}
case AP_BoardConfig_CAN::Protocol_Type_UAVCAN:
case AP_BoardConfig_CAN::Protocol_Type_None:
default:
break;
}
}
}
#endif
return true;
}
bool AP_Arming::pre_arm_checks(bool report)
{
#if !APM_BUILD_TYPE(APM_BUILD_ArduCopter)
@ -656,7 +706,8 @@ bool AP_Arming::pre_arm_checks(bool report) @@ -656,7 +706,8 @@ bool AP_Arming::pre_arm_checks(bool report)
& mission_checks(report)
& servo_checks(report)
& board_voltage_checks(report)
& system_checks(report);
& system_checks(report)
& can_checks(report);
}
bool AP_Arming::arm_checks(ArmingMethod method)

2
libraries/AP_Arming/AP_Arming.h

@ -115,6 +115,8 @@ protected: @@ -115,6 +115,8 @@ protected:
bool mission_checks(bool report);
virtual bool system_checks(bool report);
bool can_checks(bool report);
bool servo_checks(bool report) const;
bool rc_checks_copter_sub(bool display_failure, const RC_Channel *channels[4]) const;

Loading…
Cancel
Save