Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
actuators.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Pascal Brisset, Antoine Drouin
3  * Copyright (C) 2012 Gautier Hattenberger
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
29 #include "modules/core/commands.h"
30 #include "mcu_periph/sys_time.h"
31 #ifdef INTERMCU_AP
33 #endif
34 #ifdef INTERMCU_FBW
35 #include "main_fbw.h"
36 #endif
37 
38 #if ACTUATORS_NB
39 
40 #if PERIODIC_TELEMETRY
42 
43 static void send_actuators(struct transport_tx *trans, struct link_device *dev)
44 {
45  pprz_msg_send_ACTUATORS(trans, dev, AC_ID , ACTUATORS_NB, actuators);
46 }
47 #endif
48 
49 int16_t actuators[ACTUATORS_NB];
50 
51 // Can be used to directly control each actuator from the control algorithm
52 int16_t actuators_pprz[ACTUATORS_NB];
53 
54 uint32_t actuators_delay_time;
55 bool actuators_delay_done;
56 
57 void actuators_init(void)
58 {
59 
60 #if defined ACTUATORS_START_DELAY && ! defined SITL
61  actuators_delay_done = false;
62  SysTimeTimerStart(actuators_delay_time);
63 #else
64  actuators_delay_done = true;
65  actuators_delay_time = 0;
66 #endif
67 
68  // Init macro from generated airframe.h
69 #if (defined INTERMCU_AP)
70  // TODO ApOnlyActuatorsInit();
71 #elif (defined INTERMCU_FBW)
72  AllActuatorsInit();
73 #else
74  // default, init all actuators
75  AllActuatorsInit();
76  // TODO ApOnlyActuatorsInit();
77 #endif
78 
79 #if PERIODIC_TELEMETRY
81 #endif
82 }
83 
88 void actuators_periodic(void)
89 {
90 #if USE_COMMANDS
91  pprz_t trimmed_commands[COMMANDS_NB];
92  int i;
93  for (i = 0; i < COMMANDS_NB; i++) {trimmed_commands[i] = commands[i];}
94 
95 #ifdef COMMAND_ROLL
96  trimmed_commands[COMMAND_ROLL] += ClipAbs(command_roll_trim, MAX_PPRZ / 10);
97 #endif /* COMMAND_ROLL */
98 
99 #ifdef COMMAND_PITCH
100  trimmed_commands[COMMAND_PITCH] += ClipAbs(command_pitch_trim, MAX_PPRZ / 10);
101 #endif /* COMMAND_PITCH */
102 
103 #ifdef COMMAND_YAW
104  trimmed_commands[COMMAND_YAW] += ClipAbs(command_yaw_trim, MAX_PPRZ);
105 #endif /* COMMAND_YAW */
106 
107 #if (defined INTERMCU_AP)
108  intermcu_send_commands(trimmed_commands, autopilot_get_mode());
109  // TODO SetApOnlyActuatorsFromCommands(ap_commands, autopilot_get_mode());
110 #elif (defined INTERMCU_FBW)
111  SetActuatorsFromCommands(trimmed_commands, autopilot_get_mode());
112 #else
113  // default, apply all commands
114  SetActuatorsFromCommands(trimmed_commands, autopilot_get_mode());
115  // TODO SetApOnlyActuatorsFromCommands(ap_commands, autopilot_get_mode());
116 #endif
117 #endif // USE_COMMANDS
118 }
119 
120 #else // No command_laws section or no actuators
121 
122 void actuators_init(void) {}
123 void actuators_periodic(void) {}
124 
125 #endif
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
uint32_t
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
intermcu_ap.h
Inter-MCU on the AP side.
commands
pprz_t commands[COMMANDS_NB]
Definition: commands.c:30
main_fbw.h
telemetry.h
int16_t
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
actuators_periodic
void actuators_periodic(void)
Definition: actuators.c:123
pprz_t
int16_t pprz_t
Definition: paparazzi.h:6
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
sys_time.h
Architecture independent timing functions.
register_periodic_telemetry
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
command_pitch_trim
pprz_t command_pitch_trim
Definition: commands.c:34
command_roll_trim
pprz_t command_roll_trim
Definition: commands.c:33
actuators.h
send_actuators
static void send_actuators(struct transport_tx *trans, struct link_device *dev)
Definition: demo_ahrs_actuators.c:154
intermcu_send_commands
void intermcu_send_commands(pprz_t *command_values, uint8_t ap_mode)
send command vector over intermcu link instead of actuators
Definition: intermcu_ap.c:129
commands.h
Hardware independent code for commands handling.
command_yaw_trim
pprz_t command_yaw_trim
Definition: commands.c:35
autopilot_get_mode
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:216
actuators_init
void actuators_init(void)
Definition: actuators.c:122
SysTimeTimerStart
#define SysTimeTimerStart(_t)
Definition: sys_time.h:227
DefaultPeriodic
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66