Paparazzi UAS  v7.0_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
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:217
pprz_t command_pitch_trim
Definition: commands.c:34
pprz_t commands[COMMANDS_NB]
Definition: commands.c:30
pprz_t command_roll_trim
Definition: commands.c:33
pprz_t command_yaw_trim
Definition: commands.c:35
Hardware independent code for commands handling.
static void send_actuators(struct transport_tx *trans, struct link_device *dev)
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
Inter-MCU on the AP side.
Fly By Wire:
void actuators_periodic(void)
Definition: actuators.c:123
void actuators_init(void)
Definition: actuators.c:122
Hardware independent API for actuators (servos, motor controllers).
int16_t pprz_t
Definition: paparazzi.h:6
#define MAX_PPRZ
Definition: paparazzi.h:8
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
Architecture independent timing functions.
#define SysTimeTimerStart(_t)
Definition: sys_time.h:227
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93