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_raw(struct transport_tx *trans, struct link_device *dev)
44 {
45  // Downlink the actuators raw driver values
46  int16_t v[ACTUATORS_NB] = {0};
47  for (int i = 0; i < ACTUATORS_NB; i++) {
48  v[i] = actuators[i].driver_val;
49  }
50  pprz_msg_send_ACTUATORS_RAW(trans, dev, AC_ID , ACTUATORS_NB, v);
51 }
52 
53 static void send_actuators(struct transport_tx *trans, struct link_device *dev)
54 {
55  // Downlink the actuators pprz actuator values
56  int16_t v[ACTUATORS_NB] = {0};
57  for (int i = 0; i < ACTUATORS_NB; i++) {
58  v[i] = actuators[i].pprz_val;
59  }
60  pprz_msg_send_ACTUATORS(trans, dev, AC_ID , ACTUATORS_NB, v);
61 }
62 #endif
63 
64 struct actuator_t actuators[ACTUATORS_NB];
65 
66 // Can be used to directly control each actuator from the control algorithm
67 int16_t actuators_pprz[ACTUATORS_NB];
68 
69 uint32_t actuators_delay_time;
70 bool actuators_delay_done;
71 
72 void actuators_init(void)
73 {
74 
75 #if defined ACTUATORS_START_DELAY && ! defined SITL
76  actuators_delay_done = false;
77  SysTimeTimerStart(actuators_delay_time);
78 #else
79  actuators_delay_done = true;
80  actuators_delay_time = 0;
81 #endif
82 
83  // Init macro from generated airframe.h
84 #if (defined INTERMCU_AP)
85  // TODO ApOnlyActuatorsInit();
86 #elif (defined INTERMCU_FBW)
87  AllActuatorsInit();
88 #else
89  // default, init all actuators
90  AllActuatorsInit();
91  // TODO ApOnlyActuatorsInit();
92 #endif
93 
94 #if PERIODIC_TELEMETRY
95  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ACTUATORS_RAW, send_actuators_raw);
97 #endif
98 }
99 
104 void actuators_periodic(void)
105 {
106 #if USE_COMMANDS
107  pprz_t trimmed_commands[COMMANDS_NB];
108  int i;
109  for (i = 0; i < COMMANDS_NB; i++) {trimmed_commands[i] = commands[i];}
110 
111 #ifdef COMMAND_ROLL
112  trimmed_commands[COMMAND_ROLL] += ClipAbs(command_roll_trim, MAX_PPRZ / 10);
113 #endif /* COMMAND_ROLL */
114 
115 #ifdef COMMAND_PITCH
116  trimmed_commands[COMMAND_PITCH] += ClipAbs(command_pitch_trim, MAX_PPRZ / 10);
117 #endif /* COMMAND_PITCH */
118 
119 #ifdef COMMAND_YAW
120  trimmed_commands[COMMAND_YAW] += ClipAbs(command_yaw_trim, MAX_PPRZ);
121 #endif /* COMMAND_YAW */
122 
123 #if (defined INTERMCU_AP)
124  intermcu_send_commands(trimmed_commands, autopilot_get_mode());
125  // TODO SetApOnlyActuatorsFromCommands(ap_commands, autopilot_get_mode());
126 #elif (defined INTERMCU_FBW)
127  SetActuatorsFromCommands(trimmed_commands, autopilot_get_mode());
128 #else
129  // default, apply all commands
130  SetActuatorsFromCommands(trimmed_commands, autopilot_get_mode());
131  // TODO SetApOnlyActuatorsFromCommands(ap_commands, autopilot_get_mode());
132 #endif
133 #endif // USE_COMMANDS
134 }
135 
136 #else // No command_laws section or no actuators
137 
138 void actuators_init(void) {}
139 void actuators_periodic(void) {}
140 
141 #endif
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:222
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:139
void actuators_init(void)
Definition: actuators.c:138
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