5
0
mirror of https://github.com/ArduPilot/ardupilot synced 2025-01-05 15:38:29 -04:00

ArduCopter: support custom controller

This commit is contained in:
esaldiran 2022-07-17 02:49:47 +01:00 committed by Peter Barker
parent 8eeb4227f7
commit cbadf77652
7 changed files with 37 additions and 0 deletions

View File

@ -114,6 +114,9 @@ const AP_Scheduler::Task Copter::scheduler_tasks[] = {
FAST_TASK_CLASS(AP_InertialSensor, &copter.ins, update), FAST_TASK_CLASS(AP_InertialSensor, &copter.ins, update),
// run low level rate controllers that only require IMU data // run low level rate controllers that only require IMU data
FAST_TASK(run_rate_controller), FAST_TASK(run_rate_controller),
#if AC_CUSTOMCONTROL_MULTI_ENABLED == ENABLED
FAST_TASK(run_custom_controller),
#endif
// send outputs to the motors library immediately // send outputs to the motors library immediately
FAST_TASK(motors_output), FAST_TASK(motors_output),
// run EKF state estimator (expensive) // run EKF state estimator (expensive)

View File

@ -157,6 +157,10 @@
#include <AP_Scripting/AP_Scripting.h> #include <AP_Scripting/AP_Scripting.h>
#endif #endif
#if AC_CUSTOMCONTROL_MULTI_ENABLED == ENABLED
#include <AC_CustomControl/AC_CustomControl.h> // Custom control library
#endif
#if AC_AVOID_ENABLED && !AP_FENCE_ENABLED #if AC_AVOID_ENABLED && !AP_FENCE_ENABLED
#error AC_Avoidance relies on AP_FENCE_ENABLED which is disabled #error AC_Avoidance relies on AP_FENCE_ENABLED which is disabled
#endif #endif
@ -464,6 +468,10 @@ private:
AC_WPNav *wp_nav; AC_WPNav *wp_nav;
AC_Loiter *loiter_nav; AC_Loiter *loiter_nav;
#if AC_CUSTOMCONTROL_MULTI_ENABLED == ENABLED
AC_CustomControl custom_control{ahrs_view, attitude_control, motors, scheduler.get_loop_period_s()};
#endif
#if MODE_CIRCLE_ENABLED == ENABLED #if MODE_CIRCLE_ENABLED == ENABLED
AC_Circle *circle_nav; AC_Circle *circle_nav;
#endif #endif
@ -687,6 +695,10 @@ private:
uint16_t get_pilot_speed_dn() const; uint16_t get_pilot_speed_dn() const;
void run_rate_controller() { attitude_control->rate_controller_run(); } void run_rate_controller() { attitude_control->rate_controller_run(); }
#if AC_CUSTOMCONTROL_MULTI_ENABLED == ENABLED
void run_custom_controller() { custom_control.update(); }
#endif
// avoidance.cpp // avoidance.cpp
void low_alt_avoidance(); void low_alt_avoidance();

View File

@ -718,6 +718,12 @@ const AP_Param::Info Copter::var_info[] = {
GOBJECT(osd, "OSD", AP_OSD), GOBJECT(osd, "OSD", AP_OSD),
#endif #endif
#if AC_CUSTOMCONTROL_MULTI_ENABLED == ENABLED
// @Group: CC
// @Path: ../libraries/AC_CustomControl/AC_CustomControl.cpp
GOBJECT(custom_control, "CC", AC_CustomControl),
#endif
// @Group: // @Group:
// @Path: Parameters.cpp // @Path: Parameters.cpp
GOBJECT(g2, "", ParametersG2), GOBJECT(g2, "", ParametersG2),

View File

@ -199,6 +199,7 @@ public:
k_param_pos_control, k_param_pos_control,
k_param_circle_nav, k_param_circle_nav,
k_param_loiter_nav, // 105 k_param_loiter_nav, // 105
k_param_custom_control,
// 110: Telemetry control // 110: Telemetry control
// //

View File

@ -120,6 +120,7 @@ void RC_Channel_Copter::init_aux_function(const aux_func_t ch_option, const AuxS
case AUX_FUNC::WINCH_ENABLE: case AUX_FUNC::WINCH_ENABLE:
case AUX_FUNC::AIRMODE: case AUX_FUNC::AIRMODE:
case AUX_FUNC::FORCEFLYING: case AUX_FUNC::FORCEFLYING:
case AUX_FUNC::CUSTOM_CONTROLLER:
run_aux_function(ch_option, ch_flag, AuxFuncTriggerSource::INIT); run_aux_function(ch_option, ch_flag, AuxFuncTriggerSource::INIT);
break; break;
default: default:
@ -611,6 +612,12 @@ bool RC_Channel_Copter::do_aux_function(const aux_func_t ch_option, const AuxSwi
} }
break; break;
#if AC_CUSTOMCONTROL_MULTI_ENABLED == ENABLED
case AUX_FUNC::CUSTOM_CONTROLLER:
copter.custom_control.set_custom_controller(ch_flag == AuxSwitchPos::HIGH);
break;
#endif
default: default:
return RC_Channel::do_aux_function(ch_option, ch_flag); return RC_Channel::do_aux_function(ch_option, ch_flag);
} }

View File

@ -711,3 +711,7 @@
#ifndef HAL_FRAME_TYPE_DEFAULT #ifndef HAL_FRAME_TYPE_DEFAULT
#define HAL_FRAME_TYPE_DEFAULT AP_Motors::MOTOR_FRAME_TYPE_X #define HAL_FRAME_TYPE_DEFAULT AP_Motors::MOTOR_FRAME_TYPE_X
#endif #endif
#ifndef AC_CUSTOMCONTROL_MULTI_ENABLED
#define AC_CUSTOMCONTROL_MULTI_ENABLED FRAME_CONFIG == MULTICOPTER_FRAME && AP_CUSTOMCONTROL_ENABLED
#endif

View File

@ -183,6 +183,10 @@ void Copter::init_ardupilot()
g2.scripting.init(); g2.scripting.init();
#endif // AP_SCRIPTING_ENABLED #endif // AP_SCRIPTING_ENABLED
#if AC_CUSTOMCONTROL_MULTI_ENABLED == ENABLED
custom_control.init();
#endif
// set landed flags // set landed flags
set_land_complete(true); set_land_complete(true);
set_land_complete_maybe(true); set_land_complete_maybe(true);