[FLYWOOF411] add board documentation
[inav/snaewe.git] / src / main / flight / hil.c
blobbb3b4a2d5dd22bce92e80fdebb6436e563c3c529
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 // Inertial Measurement Unit (IMU)
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <math.h>
24 #include "platform.h"
26 #ifdef HIL
28 #include "build/build_config.h"
29 #include "build/debug.h"
31 #include "common/axis.h"
32 #include "common/maths.h"
33 #include "common/filter.h"
35 #include "drivers/time.h"
37 #include "sensors/sensors.h"
38 #include "sensors/acceleration.h"
39 #include "sensors/boardalignment.h"
41 #include "flight/pid.h"
42 #include "flight/imu.h"
43 #include "flight/hil.h"
45 #include "fc/config.h"
46 #include "fc/runtime_config.h"
48 #include "navigation/navigation.h"
49 #include "navigation/navigation_private.h"
52 bool hilActive = false;
53 hilIncomingStateData_t hilToFC;
54 hilOutgoingStateData_t hilToSIM;
56 void hilUpdateControlState(void)
58 // FIXME: There must be a cleaner way to to this
59 // If HIL active, store PID outout into hilState and disable motor control
60 if (FLIGHT_MODE(MANUAL_MODE) || !STATE(AIRPLANE)) {
61 hilToSIM.pidCommand[ROLL] = rcCommand[ROLL];
62 hilToSIM.pidCommand[PITCH] = rcCommand[PITCH];
63 hilToSIM.pidCommand[YAW] = rcCommand[YAW];
64 } else {
65 hilToSIM.pidCommand[ROLL] = axisPID[ROLL];
66 hilToSIM.pidCommand[PITCH] = axisPID[PITCH];
67 hilToSIM.pidCommand[YAW] = axisPID[YAW];
70 hilToSIM.pidCommand[THROTTLE] = rcCommand[THROTTLE];
73 #endif