Skip to content

Commit 595aa6e

Browse files
amathamkamathamk
authored andcommitted
ArduCopter: simulink support for ArduCopter
Glue code to enable Simulink-generated controller with ArduCopter
1 parent 3b0d619 commit 595aa6e

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

ArduCopter/Copter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ const AP_Scheduler::Task Copter::scheduler_tasks[] = {
118118
#if AC_CUSTOMCONTROL_MULTI_ENABLED
119119
FAST_TASK(run_custom_controller),
120120
#endif
121+
#ifdef SIMULINK_APP_ENABLED
122+
//Simulink controller hook
123+
FAST_TASK(run_simulink_step),
124+
#endif
121125
#if FRAME_CONFIG == HELI_FRAME
122126
FAST_TASK(heli_update_autorotation),
123127
#endif //HELI_FRAME

ArduCopter/Copter.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@
156156
#include <AC_CustomControl/AC_CustomControl.h> // Custom control library
157157
#endif
158158

159+
#ifdef SIMULINK_APP_ENABLED
160+
#include <AC_Simulink/AC_Simulink_ControllerInterfaces.h> // Simulink controller interface
161+
#include <AC_Simulink/AC_Simulink_Base.h>
162+
#include <AC_Simulink/AC_Simulink_Factory.h>
163+
#endif
164+
159165
#if AP_AVOIDANCE_ENABLED && !AP_FENCE_ENABLED
160166
#error AC_Avoidance relies on AP_FENCE_ENABLED which is disabled
161167
#endif
@@ -487,6 +493,13 @@ class Copter : public AP_Vehicle {
487493
AC_CustomControl custom_control{ahrs_view, attitude_control, motors, scheduler.get_loop_period_s()};
488494
#endif
489495

496+
#ifdef SIMULINK_APP_ENABLED
497+
#if FRAME_CONFIG == MULTICOPTER_FRAME
498+
AC_Simulink_ControllerInterfaces ac_sl_interfaces{ahrs_view, attitude_control, pos_control, motors};
499+
#endif
500+
AC_Simulink_Base *ac_simulink = AC_Simulink_Factory::createSimulinkInstance();
501+
#endif
502+
490503
#if MODE_CIRCLE_ENABLED
491504
AC_Circle *circle_nav;
492505
#endif
@@ -761,6 +774,10 @@ class Copter : public AP_Vehicle {
761774
void run_custom_controller() { custom_control.update(); }
762775
#endif
763776

777+
#ifdef SIMULINK_APP_ENABLED
778+
void run_simulink_step() { ac_simulink->update(); }
779+
#endif
780+
764781
// avoidance.cpp
765782
void low_alt_avoidance();
766783

ArduCopter/system.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ void Copter::init_ardupilot()
181181
custom_control.init();
182182
#endif
183183

184+
#ifdef SIMULINK_APP_ENABLED
185+
ac_simulink->init();
186+
#endif
187+
184188
// set landed flags
185189
set_land_complete(true);
186190
set_land_complete_maybe(true);

0 commit comments

Comments
 (0)