-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
actuators_pwm_supervision.c
74 lines (61 loc) · 2.24 KB
/
actuators_pwm_supervision.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* $Id$
*
* Copyright (C) 2010 The Paparazzi Team
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "firmwares/rotorcraft/actuators.h"
#include "actuators_pwm_supervision.h"
#include "booz/booz2_commands.h"
#include "subsystems/radio_control.h"
#include "downlink.h"
#include "messages.h"
#include "mcu_periph/uart.h"
/* let's start butchery now and use the actuators_pwm arch functions */
#include "firmwares/rotorcraft/actuators/actuators_pwm.h"
/* get SetActuatorsFromCommands() macro */
#include "generated/airframe.h"
/* define the glue between control and SetActuatorsFromCommands */
#define actuators actuators_pwm_values
#define SERVOS_TICS_OF_USEC(_v) (_v)
#define Actuator(_x) actuators_pwm_values[_x]
#define ChopServo(x,a,b) Chop(x, a, b)
#define ActuatorsCommit actuators_pwm_commit
int32_t actuators_pwm_values[ACTUATORS_PWM_NB];
void actuators_init(void)
{
supervision_init();
actuators_pwm_arch_init();
}
#define PWM_GAIN_SCALE 5
#define PWM_OFF 1000
void actuators_set(bool_t motors_on) {
booz2_commands[COMMAND_PITCH] = booz2_commands[COMMAND_PITCH] * PWM_GAIN_SCALE;
booz2_commands[COMMAND_ROLL] = booz2_commands[COMMAND_ROLL] * PWM_GAIN_SCALE;
booz2_commands[COMMAND_YAW] = booz2_commands[COMMAND_YAW] * PWM_GAIN_SCALE;
supervision_run(motors_on, FALSE, booz2_commands);
if (motors_on) {
for (int i = 0; i < SUPERVISION_NB_MOTOR; i++)
actuators_pwm_values[i] = supervision.commands[i];
} else {
for (int i = 0; i < ACTUATORS_PWM_NB; i++)
actuators_pwm_values[i] = PWM_OFF;
}
actuators_pwm_commit();
}